using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.AnalysisServices;
using Amo=Microsoft.AnalysisServices;
namespace BismNormalizer.TabularCompare.MultidimensionalMetadata
{
///
/// Abstraction of a tabular model data source with properties and methods for comparison purposes.
///
public class DataSource : ITabularObject
{
private TabularModel _parentTabularModel;
private Microsoft.AnalysisServices.DataSource _amoDataSource;
private string _substituteId;
///
/// Initializes a new instance of the DataSource class using multiple parameters.
///
/// TabularModel object that the DataSource object belongs to.
/// Analysis Management Objects DataSource object abtstracted by the DataSource object.
public DataSource(TabularModel parentTabularModel, Microsoft.AnalysisServices.DataSource datasource)
{
_parentTabularModel = parentTabularModel;
_amoDataSource = datasource;
}
///
/// TabularModel object that the DataSource object belongs to.
///
public TabularModel ParentTabularModel => _parentTabularModel;
///
/// Analysis Management Objects DataSource object abtstracted by the DataSource object.
///
public Amo.DataSource AmoDataSource => _amoDataSource;
///
/// Name of the DataSource object.
///
public string Name => _amoDataSource.Name;
///
/// Long name of the DataSource object.
///
public string LongName => _amoDataSource.Name;
///
/// Id of the DataSource object.
///
public string Id => _amoDataSource.ID;
///
/// Object definition of the DataSource object. This is a simplified list of relevant attribute values for comparison; not the XMLA definition of the abstracted AMO object.
///
public string ObjectDefinition
{
get
{
//the order of items in the connection string is not guaranteed to come out in a consistent order ...
string[] elements = _amoDataSource.ConnectionString.Split(';');
Array.Sort(elements);
string returnValue = string.Empty;
foreach (string element in elements)
{
returnValue += element + ";";
}
return returnValue.Substring(0, returnValue.Length - 1) + "\n";
}
}
///
/// Substitute Id of the DataSource object.
///
public string SubstituteId
{
get
{
if (string.IsNullOrEmpty(_substituteId))
{
return _amoDataSource.ID;
}
else
{
return _substituteId;
}
}
set
{
_substituteId = value;
}
}
public override string ToString() => this.GetType().FullName;
}
}