SchemaChangesResult result = SchemaChangesResult.NoChanges;
//Get the current data warehouse configuration
WarehouseConfig warehouseConfig = _DataStore.GetWarehouseConfig();
//As the IWarehouseAdapter.MakeSchemaChanges can be called many times in one sessions
//I needed to see if your fact was already created
Fact MyNewFact = warehouseConfig.GetFact("MyNewFact");
if (MyNewFact == null)
{
//Create My New Fact
MyNewFact = new Fact();
MyNewFact.Name = "MyNewFact";
//Adding a link to the Team Project – I had to do this otherwise my save would not work
MyNewFact.DimensionUses.Add(CreateDimensionUse("Team Project", "Team Project"));
//Adding a link to the Build dimension also when use the dimension I needed to
//find out the dimension key attribute was for when saving my data.
MyNewFact.DimensionUses.Add(CreateDimensionUse("Build", "Build"));
MyNewFact.Fields.Add(CreateField("measure1","int",0,"Sum"));
MyNewFact.Fields.Add(CreateField("measure2", "int", 0, "Sum"));
//Setting which perspective it would show under if enterprise edition of AS was in use.
MyNewFact.PerspectiveName = "Code Churn";
MyNewFact.IncludeCountMeasure = true;
if (!_StopRequest)
{
//Starting a Transaction to rollback my changes if they fail
_DataStore.BeginTransaction();
try
{
//Adding to the data warehouse configuration xml file and saving the changes
warehouseConfig.Facts.Add(MyNewFact);
_DataStore.Add(warehouseConfig);
_DataStore.CommitTransaction();
result = SchemaChangesResult.ChangesComplete;
}
catch
{
_DataStore.RollbackTransaction();
throw;
}
}
else
{
result = SchemaChangesResult.StopRequested;
}
}
return result;
//The functions to create a new field and dimension link
private Field CreateField(string FieldName, string FieldType, short FieldLength, string FieldAggregationFunction)
{
Field newField = new Field();
newField.Name = FieldName;
newField.Type = FieldType;
newField.Length = FieldLength;
newField.AggregationFunction = FieldAggregationFunction;
return newField;
}
private DimensionUse CreateDimensionUse(string DimensionName, string UseName)
{
DimensionUse dimensionUse = new DimensionUse();
dimensionUse.DimensionName = DimensionName;
dimensionUse.UseName = UseName;
return dimensionUse;
}