테이블 형식 모델에서 계층 구조는 사용자가 선택한 값에 따라 한 특성에서 다른 특성으로의 탐색 경로입니다.
계층 구조 표현
AMO의 계층 구조
AMO를 사용하여 테이블 형식 모델 테이블을 관리하는 경우 AMO에서 계층 구조에 대한 일대일 개체 일치가 있습니다. 계층 구조는 개체로 Hierarchy 표시됩니다.
다음 코드 조각은 기존 테이블 형식 모델에 계층 구조를 추가하는 방법을 보여 주는 코드 조각입니다. 이 코드는 AMO 데이터베이스 개체, newDatabase 및 AMO 큐브 개체 modelCube가 있다고 가정합니다.
private void addHierarchy(
AMO.Database newDatabase
, AMO.Cube modelCube
, string tableName
, string hierarchyName
, string levelsText
)
{
//Validate input
if (string.IsNullOrEmpty(hierarchyName) || string.IsNullOrEmpty(levelsText))
{
MessageBox.Show(String.Format("Hierarchy Name or Layout must be provided."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (!overwriteHierarchy.Checked && newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
{
MessageBox.Show(String.Format("Hierarchy already exists.\nGive a new name or enable overwriting"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
if (newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
{
//Hierarchy exists... deleting it to write it later
newDatabase.Dimensions[tableName].Hierarchies.Remove(hierarchyName, true);
newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);
}
AMO.Hierarchy currentHierarchy = newDatabase.Dimensions[tableName].Hierarchies.Add(hierarchyName, hierarchyName);
currentHierarchy.AllMemberName = string.Format("(All of {0})", hierarchyName);
//Parse hierarchyLayout
using (StringReader levels = new StringReader(levelsText))
{
//Each line:
// must come with: The columnId of the attribute in the dimension --> this represents the SourceAttributeID
// optional: A display name for the Level (if this argument doesn't come the default is the SourceAttributeID)
string line;
while ((line = levels.ReadLine()) != null)
{
if (string.IsNullOrEmpty(line) || string.IsNullOrWhiteSpace(line)) continue;
line = line.Trim();
string[] hierarchyData = line.Split(',');
if (string.IsNullOrEmpty(hierarchyData[0])) continue; //first argument cannot be empty or blank,
//assume is a blank line and ignore it
string levelSourceAttributeID = hierarchyData[0].Trim();
string levelID = (hierarchyData.Length > 1 && !string.IsNullOrEmpty(hierarchyData[1])) ? hierarchyData[1].Trim() : levelSourceAttributeID;
currentHierarchy.Levels.Add(levelID).SourceAttributeID = levelSourceAttributeID;
}
}
newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error creating hierarchy [{0}].\nError message: {1}", newHierarchyName.Text, ex.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (newDatabase.Dimensions[tableName].Hierarchies.Contains(hierarchyName))
{
//Hierarchy was created but exception prevented complete hierarchy to be written... deleting incomplete hierarchy
newDatabase.Dimensions[tableName].Hierarchies.Remove(hierarchyName, true);
newDatabase.Dimensions[tableName].Update(AMO.UpdateOptions.AlterDependents);
}
}
newDatabase.Dimensions[tableName].Process(AMO.ProcessType.ProcessFull);
modelCube.MeasureGroups[tableName].Process(AMO.ProcessType.ProcessFull);
}