using Microsoft.AnalysisServices.Tabular;
using Tom=Microsoft.AnalysisServices.Tabular;
namespace BismNormalizer.TabularCompare.TabularMetadata
{
///
/// Abstraction of a tabular model culture with properties and methods for comparison purposes.
///
public class Culture : TabularObject
{
#region Private Members
private TabularModel _parentTabularModel;
private Tom.Culture _tomCulture;
#endregion
#region Constructors
///
/// Initializes a new instance of the Culture class using multiple parameters.
///
/// TabularModel object that the Culture object belongs to.
/// Tabular Object Model Culture object abtstracted by the Culture class.
public Culture(TabularModel parentTabularModel, Tom.Culture tomCulture) : base(tomCulture, parentTabularModel)
{
_parentTabularModel = parentTabularModel;
_tomCulture = tomCulture;
}
#endregion
#region Properties
///
/// TabularModel object that the Culture object belongs to.
///
public TabularModel ParentTabularModel => _parentTabularModel;
///
/// Tabular Object Model Culture object abtstracted by the Culture class.
///
public Tom.Culture TomCulture => _tomCulture;
public override string ToString() => this.GetType().FullName;
#endregion
#region Public Methods
///
/// Verifies whether another Culture object's translations are included in this one.
///
/// The other culture for comparison.
/// Returns true if all translations contained.
public bool ContainsOtherCultureTranslations(Culture otherCulture)
{
foreach (ObjectTranslation otherTranslation in otherCulture.TomCulture.ObjectTranslations)
{
bool foundMatch = false;
foreach (ObjectTranslation translation in _tomCulture.ObjectTranslations)
{
if (translation.Object is NamedMetadataObject &&
otherTranslation.Object is NamedMetadataObject &&
(
((NamedMetadataObject)translation.Object).Name == ((NamedMetadataObject)otherTranslation.Object).Name //Name of the object matches
|| (translation.Object.ObjectType == ObjectType.Model && otherTranslation.Object.ObjectType == ObjectType.Model) //Model name can legitimately have different names - and there can only be 1 model, so we are OK.
) &&
translation.Object.ObjectType == otherTranslation.Object.ObjectType && //ObjectType like Measure, Table, ...
translation.Property == otherTranslation.Property && //Property like Caption, DisplayFolder, Description
translation.Value == otherTranslation.Value) //Value is the translated value
{
foundMatch = true;
break;
}
}
if (!foundMatch)
{
return false;
}
}
return true;
}
#endregion
}
}