using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AnalysisServices.Tabular;
namespace BismNormalizer.TabularCompare.TabularMetadata
{
///
/// Represents a collection of Table objects.
///
public class TableCollection : List
{
///
/// Find an object in the collection by name.
///
///
/// Table object if found. Null if not found.
public Table FindByName(string name)
{
foreach (Table table in this)
{
if (table.Name == name)
{
return table;
}
}
return null;
}
///
/// A Boolean specifying whether the collection contains object by name.
///
///
/// True if the object is found, or False if it's not found.
public bool ContainsName(string name)
{
foreach (Table table in this)
{
if (table.Name == name)
{
return true;
}
}
return false;
}
///
/// Returns a collection of Table objects filtered by the parent DataSource's name.
///
///
/// TableCollection
public TableCollection FilterByDataSource(Microsoft.AnalysisServices.Tabular.DataSource dataSource)
{
TableCollection returnTables = new TableCollection();
foreach (Table table in this)
{
if (table.DataSourceName == dataSource.Name)
{
returnTables.Add(table);
}
}
return returnTables;
}
///
/// Returns a collection of Table objects that do not have a DataSource associated with them. These can be calculated tables or tables with M partitions that do not refer to a DataSource.
///
///
public TableCollection WithoutDataSource(Microsoft.AnalysisServices.Tabular.Model model)
{
TableCollection tablesWithDataSource = new TableCollection();
foreach (Microsoft.AnalysisServices.Tabular.DataSource dataSource in model.DataSources)
{
tablesWithDataSource.AddRange(this.FilterByDataSource(dataSource));
}
TableCollection tablesWithoutDataSource = new TableCollection();
foreach (Table table in this)
{
if (!tablesWithDataSource.ContainsName(table.Name))
{
tablesWithoutDataSource.Add(table);
}
}
return tablesWithoutDataSource;
}
///
/// Removes an object from the collection by its name.
///
///
/// True if the object was removed, or False if was not found.
public bool RemoveByName(string name)
{
foreach (Table table in this)
{
if (table.Name == name)
{
this.Remove(table);
return true;
}
}
return false;
}
}
}