using System; using BismNormalizer.TabularCompare.Core; namespace BismNormalizer.TabularCompare.TabularMetadata { /// /// Represents source and target objects for comparison, their type and status. This class is for tabular models that use tabular metadata with SSAS compatibility level 1200 or above. /// public class ComparisonObject : Core.ComparisonObject { private TabularObject _sourceObject; private TabularObject _targetObject; public ComparisonObject( ComparisonObjectType comparisonObjectType, ComparisonObjectStatus status, TabularObject sourceObject, TabularObject targetObject, MergeAction mergeAction) : base(comparisonObjectType, status, mergeAction) { _sourceObject = sourceObject; _targetObject = targetObject; } /// /// Source TabularObject instance for comparison. /// public TabularObject SourceObject { get { return _sourceObject; } set { _sourceObject = value; } } /// /// Name of source TabularObject instance. /// public override string SourceObjectName { get { if (_sourceObject == null) { return ""; } else { if (_comparisonObjectType == ComparisonObjectType.Relationship || _comparisonObjectType == ComparisonObjectType.Measure || _comparisonObjectType == ComparisonObjectType.Kpi || _comparisonObjectType == ComparisonObjectType.CalculationItem) { return " " + _sourceObject.Name; } else { return _sourceObject.Name; } } } } /// /// Internal name of source TabularObject instance. This can be different than SourceObjectName for Relationship objects where the internal name is the SSDT assigned GUID. /// public override string SourceObjectInternalName { get { if (_sourceObject == null) { return ""; } else { return _sourceObject.InternalName; } } } /// /// Definition of source TabularObject instance. /// public override string SourceObjectDefinition { get { if (_sourceObject == null) { return ""; } else { return _sourceObject.ObjectDefinition; } } } /// /// Target TabularObject instance for comparison. /// public TabularObject TargetObject { get { return _targetObject; } set { _targetObject = value; } } /// /// Name of target TabularObject instance. /// public override string TargetObjectName { get { if (_targetObject == null) { return ""; } else { if (_comparisonObjectType == ComparisonObjectType.Relationship || _comparisonObjectType == ComparisonObjectType.Measure || _comparisonObjectType == ComparisonObjectType.Kpi || _comparisonObjectType == ComparisonObjectType.CalculationItem) { return " " + _targetObject.Name; } else { return _targetObject.Name; } } } } /// /// Internal name of target TabularObject instance. This can be different than SourceObjectName for Relationship objects where the internal name is the SSDT assigned GUID. /// public override string TargetObjectInternalName { get { if (_targetObject == null) { return ""; } else { return _targetObject.InternalName; } } } /// /// Definition of target TabularObject instance. /// public override string TargetObjectDefinition { get { if (_targetObject == null) { return ""; } else { return _targetObject.ObjectDefinition; } } } /// /// Provides key for CompareTo method. /// public override string SortKey() { string sortKey = ""; switch (this.ComparisonObjectType) { //tabular objects case ComparisonObjectType.Model: sortKey = "A"; break; case ComparisonObjectType.DataSource: sortKey = "B"; break; case ComparisonObjectType.Expression: sortKey = "C"; break; case ComparisonObjectType.Table: sortKey = "D"; break; case ComparisonObjectType.Relationship: sortKey = "E"; break; case ComparisonObjectType.Measure: sortKey = "F"; break; case ComparisonObjectType.Kpi: sortKey = "G"; break; case ComparisonObjectType.CalculationItem: sortKey = "H"; break; case ComparisonObjectType.Action: sortKey = "I"; break; case ComparisonObjectType.Perspective: sortKey = "J"; break; case ComparisonObjectType.Culture: sortKey = "K"; break; case ComparisonObjectType.Role: sortKey = "L"; break; default: sortKey = "Z"; break; } sortKey += this.SourceObjectName != "" ? this.SourceObjectName : this.TargetObjectName; return sortKey; } public override int CompareTo(Core.ComparisonObject other) => string.Compare(this.SortKey(), other.SortKey()); } }