パースペクティブは、クライアント アプリケーションのモデルをより小さな部分に単純化または集中させるメカニズムです。
パースペクティブ表現を作成および操作する方法の詳細については、「 パースペクティブ表現 (表形式)」 を参照してください。
警告
パースペクティブはセキュリティ メカニズムではありません。パースペクティブ外のオブジェクトは、他のインターフェイスを介してユーザーが引き続きアクセスできます。
パースペクティブ表現
AMO オブジェクトの観点では、パースペクティブ表現には、 Perspective との 1 対 1 のマッピング関係があり、他の主要な AMO オブジェクトは必要ありません。
AMO のパースペクティブ
次のコード スニペットは、表形式モデルでパースペクティブを作成する方法を示しています。 このコードの重要な要素は perspectiveElements です。このオブジェクトは、ユーザーに公開されている表形式モデル内のすべてのオブジェクトをグラフィカルに表現したものです。 perspectiveElements には 4 つの列が含まれており、このシナリオでは列 1、2、3 のみが関連します。 列 1 には、表示される要素の型 -elementTypeValue-; が含まれています。列 2 には、パースペクティブに要素を入力するために解析する必要がある要素--,の完全な名前が含まれています。列 3 には、要素がパースペクティブの一部であるかどうかを示すチェック ボックス項目 -checkedElement が含まれています。
private void updatePerspective_Click(
AMO.Cube modelCube
, DataGridView perspectiveElements
, string updatedPerspectiveID
)
{
//Update is done by delete first, create new and insert after
//if perspective doesn't exist then create first and insert after
updatedPerspectiveID = updatedPerspectiveID.Trim();
if (modelCube.Perspectives.Contains(updatedPerspectiveID))
{
modelCube.Perspectives.Remove(updatedPerspectiveID, true);
newDatabase.Update(AMO.UpdateOptions.ExpandFull, AMO.UpdateMode.UpdateOrCreate);
}
AMO.Perspective currentPerspective = modelCube.Perspectives.Add(updatedPerspectiveID, updatedPerspectiveID);
foreach (DataGridViewRow currentDGVRow in perspectiveElements.Rows)
{
bool checkedElement = (bool)currentDGVRow.Cells[3].Value;
if (checkedElement)
{
string elementTypeValue = currentDGVRow.Cells[1].Value.ToString();
string elementNameValue = currentDGVRow.Cells[2].Value.ToString();
switch (elementTypeValue)
{
case "Column: Attribute":
case "Column: Calculated Column":
{
string perspectiveDimensionName = Regex.Match(elementNameValue, @"(?<=')(.*?)(?=')").ToString();
string perspectiveDimensionAttributeName = Regex.Match(elementNameValue, @"(?<=\[)(.*?)(?=\])").ToString();
AMO.PerspectiveDimension currentPerspectiveDimension;
if (!currentPerspective.Dimensions.Contains(perspectiveDimensionName))
{
currentPerspectiveDimension = currentPerspective.Dimensions.Add(perspectiveDimensionName);
}
else
{
currentPerspectiveDimension = currentPerspective.Dimensions[perspectiveDimensionName];
}
if (!currentPerspectiveDimension.Attributes.Contains(perspectiveDimensionAttributeName))
{
currentPerspectiveDimension.Attributes.Add(perspectiveDimensionAttributeName);
}
}
break;
case "Hierarchy":
{
string perspectiveDimensionName = Regex.Match(elementNameValue, @"(?<=')(.*?)(?=')").ToString();
string perspectiveDimensionHierarchyName = Regex.Match(elementNameValue, @"(?<=\[)(.*?)(?=\])").ToString();
AMO.PerspectiveDimension currentPerspectiveDimension;
if (!currentPerspective.Dimensions.Contains(perspectiveDimensionName))
{
currentPerspectiveDimension = currentPerspective.Dimensions.Add(perspectiveDimensionName);
}
else
{
currentPerspectiveDimension = currentPerspective.Dimensions[perspectiveDimensionName];
}
if (!currentPerspectiveDimension.Hierarchies.Contains(perspectiveDimensionHierarchyName))
{
currentPerspectiveDimension.Hierarchies.Add(perspectiveDimensionHierarchyName);
}
}
break;
case "Measure":
{
string perspectiveMeasureGroupName = Regex.Match(elementNameValue, @"(?<=')(.*?)(?=')").ToString();
string measureName = Regex.Match(elementNameValue, @"(?<=\[)(.*?)(?=\])").ToString();
string perspectiveMeasureName = string.Format("[Measures].[{0}]", measureName);
AMO.PerspectiveCalculation currentPerspectiveCalculation = new AMO.PerspectiveCalculation(perspectiveMeasureName, AMO.PerspectiveCalculationType.Member);
if (!currentPerspective.Calculations.Contains(perspectiveMeasureName))
{
currentPerspective.Calculations.Add(currentPerspectiveCalculation);
}
if (modelCube.MdxScripts["MdxScript"].CalculationProperties.Contains(string.Format("KPIs.[{0}]", measureName)))
{//Current Measure is also a KPI ==> will be added to the KPIs collection of the perspective
AMO.PerspectiveKpi currentPerspectiveKpi = new AMO.PerspectiveKpi(perspectiveMeasureName);
if (!currentPerspective.Kpis.Contains(perspectiveMeasureName))
{
currentPerspective.Kpis.Add(currentPerspectiveKpi);
}
}
}
break;
default:
break;
}
}
}
newDatabase.Update(AMO.UpdateOptions.ExpandFull, AMO.UpdateMode.CreateOrReplace);
MessageBox.Show(String.Format("Perpective successfully updated."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
AMO2Tabular サンプル
ただし、AMO を使用してパースペクティブ表現を作成および操作する方法を理解するには、AMO から表形式へのサンプルのソース コードを参照してください。 サンプルは Codeplex で入手できます。 コードに関する重要な注意事項: コードは、ここで説明する論理的な概念のサポートとしてのみ提供され、運用環境では使用しないでください。また、教育的な目的以外の目的で使用してはなりません。