using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.AnalysisServices.Tabular; namespace BismNormalizer.TabularCompare.TabularMetadata { /// /// Abstraction of a tabular model relationship with properties and methods for comparison purposes. /// public class Relationship : TabularObject { private Table _table; private SingleColumnRelationship _tomRelationship; private string _relationshipName; private bool _copiedFromSource; private bool _modifiedInternalName; private string _oldInternalName; /// /// Initializes a new instance of the Relationship class using multiple parameters. /// /// Table object that the Relationship belongs to. /// Tabular Object Model SingleColumnRelationship object abtstracted by the Relationship class. /// Boolean indicating whether the relationship was copied from the source TabularModel object. /// Boolean indicating whether the TOM Relationship object Name property was changed to avoid name conflict. /// If the TOM Relationship object Name property was changed, this parameter shows the old value. public Relationship(Table table, SingleColumnRelationship tomRelationship, bool copiedFromSource = false, bool modifiedInternalName = false, string oldInternalName = "") : base(tomRelationship, table.ParentTabularModel) { _table = table; _tomRelationship = tomRelationship; //_relationshipName = $"'{_relationship.FromTable.Name}'->'{_relationship.ToTable.Name}'"; //_relationshipName = $"[{_relationship.FromColumn.Name}]->'{_relationship.ToTable.Name}'[{_relationship.ToColumn.Name}]"; _relationshipName = $"'{_tomRelationship.FromTable.Name}'[{_tomRelationship.FromColumn.Name}]->'{_tomRelationship.ToTable.Name}'[{_tomRelationship.ToColumn.Name}]"; _copiedFromSource = copiedFromSource; _modifiedInternalName = modifiedInternalName; _oldInternalName = oldInternalName; } /// /// Table object that the Relationship oject belongs to. /// public Table Table => _table; /// /// Tabular Object Model SingleColumnRelationship object abtstracted by the Relationship class. /// public SingleColumnRelationship TomRelationship { get { return _tomRelationship; } set { _tomRelationship = value; } } /// /// Name of the Relationship object. Uses a friendly format. /// public override string Name => _relationshipName; /// /// The TOM Relationship object Name property, which is not displayed to users as its of GUID format. /// public override string InternalName => _tomRelationship.Name; /// /// Name of the from table for the Relationship object. /// public string FromTableName => _tomRelationship.FromTable.Name; /// /// Name of the to table for the Relationship object. /// public string ToTableName => _tomRelationship.ToTable.Name; /// /// Boolean indicating whether the relationship was copied from the source TabularModel object. /// public bool CopiedFromSource => _copiedFromSource; /// /// Boolean indicating whether the TOM Relationship object Name property was changed to avoid name conflict. /// public bool ModifiedInternalName => _modifiedInternalName; /// /// If the TOM Relationship object Name property was changed, this parameter shows the old value. /// public string OldInternalName => _oldInternalName; public override string ToString() => this.GetType().FullName; } }