Skip to main content

Class DataTableBuilder

The DataTable Builder class is used to efficiently build a.NET DataTable by minimizing for loops required to build a final state DataTable.

Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableModifier is used to generate additional columns (think additional Column Generator).

Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGenerator is used to generate datarows from a different data format (think DataRow generator).

Below is a code exmaple showing one of the ways to use the DataTable

// Get the Json Data from some API source or something
var metricsJson = NewtonSoft.Json.Linq.JObject columnDataJson = GetMetricsJsonDataTable();
...

// Initialize DataTableBuilder
DataTableBuilder datatableBuilder = new DataTableBuilder();

// Add Modifiers
datatableBuilder.AddModifier(si, new FormattedStringDataTableMod(si, "ModelStage", "ModelStageVerbose), StringFormatter.StringConverionTypes.SuperSpacedCase));

// Instantiate a DataTable
DataTable dtMetrics = new DataTable();

// Create the a IDataTableGenerator (in this case its the JsonDataTableGenerator)
JsonDataTableGenerator genJsonDataTable = new JsonDataTableGenerator(si, metricsJson);

// Build the DataTable from the DataTableGenerator and apply the Modifiers
dtMetrics = datatableBuilder.BuildFromDataTableGenerator(si, genJsonDataTable);

Namespace: Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder

Assembly: Xperiflow.dll

Declaration
public class DataTableBuilder

Methods

AddModifier(SessionInfo, IDataTableModifier)

Adds a modifier to the list of modifiers that will be applied to the DataTable

Declaration
public void AddModifier(SessionInfo si, IDataTableModifier modifier)
Parameters
TypeName
OneStream.Shared.Common.SessionInfosi
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableModifiermodifier

ModifyExisting(SessionInfo, DataTable)

Apply all modifiers to an existing datatable. This will modify the datatable in place.

Declaration
public DataTable ModifyExisting(SessionInfo si, DataTable dt)
Returns

System.Data.DataTable

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe SessionInfo object.
System.Data.DataTabledtThe DataTable to modify in place.

BuildFromDataTableGenerator(SessionInfo, IDataTableGenerator)

Creates and returns a DataTable based on a IDataTableGenerator and the Modifiers that have been added to the DataTableBuilder.

Declaration
public DataTable BuildFromDataTableGenerator(SessionInfo si, IDataTableGenerator generator)
Returns

System.Data.DataTable

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGeneratorgeneratorThe generator.

AppendFromDataTableGenerator(SessionInfo, IDataTableGenerator, DataTable)

Creates and appends datarows generated by a generator to an existing DataTable while also applying Modifiers that exist on the this DataTableBuilder. The DataTable is modified in place.

Declaration
public DataTable AppendFromDataTableGenerator(SessionInfo si, IDataTableGenerator generator, DataTable dt)
Returns

System.Data.DataTable

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGeneratorgeneratorThe generator containing data that be turned into datarows.
System.Data.DataTabledtThe DataTable to the generator rows to.

StrictAppendFromDataTableGenerator(SessionInfo, IDataTableGenerator, DataTable)

Creates and appends datarows generated by a generator to an existing DataTable while also applying Modifiers that exist on the this DataTableBuilder. The DataTable is modified in place.

Declaration
public DataTable StrictAppendFromDataTableGenerator(SessionInfo si, IDataTableGenerator generator, DataTable dt)
Returns

System.Data.DataTable

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGeneratorgeneratorThe generator containing data that be turned into datarows.
System.Data.DataTabledtThe DataTable to the generator rows to.
Exceptions

OneStream.Shared.Common.XFException

YieldDataTableGenerator(SessionInfo, IDataTableGenerator, DataTable, bool)

A powerful method that allows you to yield datarows from a generator while also applying modifiers to the datarows. This allows you to reduce the number of loops you need to do to generate and modify datarows.

How to use:

  • Instantiate a DataTableBuilder

  • (Optional) Add Modifiers to the DataTableBuilder

  • Have a populated generator

  • Have a new or existing DataTable that you want to append the generator rows to

  • Call this method in a for loop like this: "foreach (DataRow dr in datatableBuilder.YieldDataTableGenerator(si, genJsonDataTable, dt, false))"

  • (Optional) Do any additional manipulations to the datarows

  • Remember to append the datarow to the datatable

This sample shows how to call the Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.DataTableBuilder.YieldDataTableGenerator(OneStream.Shared.Common.SessionInfo%2cWorkspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGenerator%2cSystem.Data.DataTable%2cSystem.Boolean) method.

DataTableBuilder datatableBuilder = new DataTableBuilder();
JsonDataTableGenerator genJsonDataTable = new JsonDataTableGenerator(si, columnDataJson[m_FilterableData][m_Datatable]);
DataTable dt = new DataTable();
dt.Columns.Add("Summation", typeof(double));
dt.Columns.Add("Attributes", typeof(string));
// Additional columns here

double totalSum = 0.0;
foreach (DataRow dr in datatableBuilder.YieldDataTableGenerator(si, genJsonDataTable, dt, false))
{
dr["AbsoluteSummation"] = Math.Abs((double)dr["Summation"]);
totalSum += (double)dr["AbsoluteSummation"];
dt.Rows.Add(dr);
}
Declaration
public IEnumerable<DataRow> YieldDataTableGenerator(SessionInfo si, IDataTableGenerator generator, DataTable dt, bool delayModify)
Returns

System.Collections.Generic.IEnumerable<System.Data.DataRow>

An IEnumerable of DataRows after applying the specified modifications.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiSession Information
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGeneratorgeneratorThe generator containing data will yield datarows
System.Data.DataTabledtThe datatable to abide the schema by
System.BooleandelayModifyWhether to apply the modifiers prior to yielding or after yielding.

StrictYieldFromDataTableGenerator(SessionInfo, IDataTableGenerator, DataTable, bool)

A powerful method that allows you to yield datarows from a generator while also applying modifiers to the datarows. This allows you to reduce the number of loops you need to do to generate and modify datarows.

How to use:

  • Instantiate a DataTableBuilder

  • (Optional) Add Modifiers to the DataTableBuilder

  • Have a populated generator

  • Have a new or existing DataTable that you want to append the generator rows to

  • Call this method in a for loop like this: "foreach (DataRow dr in datatableBuilder.YieldDataTableGenerator(si, genJsonDataTable, dt, false))"

  • (Optional) Do any additional manipulations to the datarows

  • Remember to append the datarow to the datatable

This sample shows how to call the Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.DataTableBuilder.StrictYieldFromDataTableGenerator(OneStream.Shared.Common.SessionInfo%2cWorkspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGenerator%2cSystem.Data.DataTable%2cSystem.Boolean) method.

DataTableBuilder datatableBuilder = new DataTableBuilder();
JsonDataTableGenerator genJsonDataTable = new JsonDataTableGenerator(si, columnDataJson[m_FilterableData][m_Datatable]);
DataTable dt = new DataTable();
dt.Columns.Add("Summation", typeof(double));
dt.Columns.Add("Attributes", typeof(string));
// Additional columns here

double totalSum = 0.0;
foreach (DataRow dr in datatableBuilder.StrictYieldFromDataTableGenerator(si, genJsonDataTable, dt, false))
{
dr["AbsoluteSummation"] = Math.Abs((double)dr["Summation"]);
totalSum += (double)dr["AbsoluteSummation"];
dt.Rows.Add(dr);
}
Declaration
public IEnumerable<DataRow> StrictYieldFromDataTableGenerator(SessionInfo si, IDataTableGenerator generator, DataTable dt, bool delayModify)
Returns

System.Collections.Generic.IEnumerable<System.Data.DataRow>

An IEnumerable of DataRows after applying the specified modifications.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiSession Information
Workspace.XBR.Xperiflow.Utilities.AdoDataTable.Builder.IDataTableGeneratorgeneratorThe generator containing data will yield datarows
System.Data.DataTabledtThe datatable to abide the schema by
System.BooleandelayModifyWhether to apply the modifiers prior to yielding or after yielding.

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?