using System;
using Microsoft.AnalysisServices.Tabular;
using Tom=Microsoft.AnalysisServices.Tabular;
namespace BismNormalizer.TabularCompare.TabularMetadata
{
///
/// Abstraction of a tabular model perspective with properties and methods for comparison purposes.
///
public class Perspective : TabularObject
{
private TabularModel _parentTabularModel;
private Tom.Perspective _tomPerspective;
///
/// Initializes a new instance of the Perspective class using multiple parameters.
///
/// TabularModel object that the perspective belongs to.
/// Tabular Object Model Perspective object abtstracted by the Perspective class.
public Perspective(TabularModel parentTabularModel, Tom.Perspective tomPerspective): base(tomPerspective, parentTabularModel)
{
_parentTabularModel = parentTabularModel;
_tomPerspective = tomPerspective;
}
///
/// TabularModel object that the Perspective object belongs to.
///
public TabularModel ParentTabularModel => _parentTabularModel;
///
/// Tabular Object Model Perspective object abtstracted by the Perspective class.
///
public Tom.Perspective TomPerspective => _tomPerspective;
public override string ToString() => this.GetType().FullName;
///
/// Verifies whether another Perspective object's selections are included in this Perspective object.
///
/// The other Perspective object to be verified.
/// True if otherPerspective matches. False if does not match.
public bool ContainsOtherPerspectiveSelections(Perspective otherPerspective)
{
bool everythingMatches = true;
//Tables
foreach (PerspectiveTable otherTable in otherPerspective.TomPerspective.PerspectiveTables)
{
bool foundTableMatch = false;
foreach (PerspectiveTable perspectiveTable in _tomPerspective.PerspectiveTables)
{
if (perspectiveTable.Name == otherTable.Name)
{
foundTableMatch = true;
#region Columns
foreach (PerspectiveColumn otherColumn in otherTable.PerspectiveColumns)
{
bool foundColumnMatch = false;
foreach (PerspectiveColumn perspectiveColumn in perspectiveTable.PerspectiveColumns)
{
if (perspectiveColumn.Name == otherColumn.Name)
{
foundColumnMatch = true;
break;
}
}
if (!foundColumnMatch)
{
everythingMatches = false;
break;
}
}
#endregion
#region Hierarchies
foreach (PerspectiveHierarchy otherHierarchy in otherTable.PerspectiveHierarchies)
{
bool foundHierarchyMatch = false;
foreach (PerspectiveHierarchy perspectiveHierarchy in perspectiveTable.PerspectiveHierarchies)
{
if (perspectiveHierarchy.Hierarchy.Name == otherHierarchy.Hierarchy.Name)
{
foundHierarchyMatch = true;
break;
}
}
if (!foundHierarchyMatch)
{
everythingMatches = false;
break;
}
}
#endregion
#region Measures
foreach (PerspectiveMeasure otherMeasure in otherTable.PerspectiveMeasures)
{
bool foundMeasureMatch = false;
foreach (PerspectiveMeasure perspectiveMeasure in perspectiveTable.PerspectiveMeasures)
{
if (perspectiveMeasure.Name == otherMeasure.Name)
{
foundMeasureMatch = true;
break;
}
}
if (!foundMeasureMatch)
{
everythingMatches = false;
break;
}
}
#endregion
}
if (!everythingMatches) break;
}
if (!foundTableMatch)
{
everythingMatches = false;
break;
}
}
return everythingMatches;
}
}
}