/// <summary> /// Add dimension into cube (instead of cube db) /// </summary> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cubeDB"></param> /// <param name="cube"></param> public void ADD_DIMENSION_TO_CUBE(DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , Microsoft.AnalysisServices.Database cubeDB , Cube cube ) { try { DataTable DimensionSet = asMeta.GET_SSAS_DIMENSION_SET(sqlHelper); foreach (DataRow row in DimensionSet.Rows) { String DimensionID = row["dimension_id"].ToString(); String DimensionName = row["dimension_name"].ToString(); String DimensionType = row["dimension_type"].ToString(); AS_API.ADD_CUBE_DIMENSION( sqlHelper, cubeDB, cube, DimensionID, DimensionType); sqlHelper.ADD_MESSAGE_LOG( String.Format("Addedd Dimension {0} into Cube ", DimensionID) , MESSAGE_TYPE.ADD_CUBE_DIMENSION , MESSAGE_RESULT_TYPE.Normal); } cube.Update(Microsoft.AnalysisServices.UpdateOptions.ExpandFull); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message.ToString(), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Error); throw (ex); } }
/// <summary> /// Add cube dimension (instead of cube db) /// </summary> /// <param name="cubedb"></param> /// <param name="cube"></param> /// <param name="dimID"></param> /// <param name="dimension_type"></param> /// <param name="cube_dimName"></param> /// <param name="visible"></param> internal static void ADD_CUBE_DIMENSION( DB_SQLHELPER_BASE sqlHelper, Database cubedb, Cube cube, String dimID, String dimension_type, String cube_dimName = "", bool visible = true) { Dimension dim = cubedb.Dimensions.Find(dimID); if (dim == null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Detected dimension name [{0}] is not existed in current cube db", cube_dimName), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Warning); } CubeDimension cube_dim = cube.Dimensions.Add(dim.ID); cube_dim.Visible = visible; cube_dim.Name = dim.Name; sqlHelper.ADD_MESSAGE_LOG( String.Format("Added dimension [{0}] into cube (instead of cube db)", cube.Dimensions.FindByName(dim.Name).Name), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Succeed); }
/// <summary> /// Cube full process /// </summary> /// <param name="cube_server"></param> /// <param name="cubeDBName"></param> /// <param name="xmla"></param> public void CUBE_PROCESS_FULL(DB_SQLHELPER_BASE sqlHelper, Server cube_server, String cubeDBName) { try { String cubeProcessXMLAPath = CONFIGURATION_HELPER.BASIC_CONFIGURATION_FOLDER + @"\SSASConfiguration\CubeProcess.xml"; String cubeProcessXMLA = System.IO.File.ReadAllText(cubeProcessXMLAPath); cubeProcessXMLA = cubeProcessXMLA.Replace("$(cubeDBName)", cubeDBName); XmlaResultCollection _result = cube_server.Execute(cubeProcessXMLA); foreach (XmlaResult _res in _result) { foreach (XmlaMessage message in _res.Messages) { sqlHelper.ADD_MESSAGE_LOG( message.ToString(), MESSAGE_TYPE.CUBE_PROCESS, MESSAGE_RESULT_TYPE.Normal); } } sqlHelper.ADD_MESSAGE_LOG( String.Format("Processed cube {0}", cubeDBName), MESSAGE_TYPE.CUBE_PROCESS, MESSAGE_RESULT_TYPE.Normal); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message.ToString(), MESSAGE_TYPE.CUBE_PROCESS, MESSAGE_RESULT_TYPE.Error); throw (ex); } }
/// <summary> /// Create Column Binding Data Item /// </summary> /// <param name="dsv"></param> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="dataType"></param> /// <returns></returns> internal static DataItem CREATE_COLUMN_BINDING_DATA_ITEM( DB_SQLHELPER_BASE sqlHelper, DataSourceView dsv, String tableName, String columnName, System.Data.OleDb.OleDbType dataType) { DataItem dataItem = null; DataTable data_table = dsv.Schema.Tables[tableName]; if (data_table == null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Table {0} is not existed in current DSV", tableName), MESSAGE_TYPE.COLUMN_BINDING_DATA_ITEM, MESSAGE_RESULT_TYPE.Warning); } DataColumn dataColumn = data_table.Columns[columnName]; if (dataColumn == null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Column {0} is not existed in table {1}", columnName, tableName), MESSAGE_TYPE.COLUMN_BINDING_DATA_ITEM, MESSAGE_RESULT_TYPE.Warning); } dataItem = new DataItem(tableName, dataColumn.ColumnName); if (dataType != null) { dataItem.DataType = dataType; } else { dataItem.DataType = OleDbTypeConverter.GetRestrictedOleDbType(dataColumn.DataType); } return(dataItem); }
/// <summary> /// Create common cube by configured metadata /// </summary> /// <param name="oledb"></param> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cube_server"></param> /// <param name="cube_db_name"></param> /// <param name="cube_name"></param> /// <param name="cubeProcessXMLA"></param> /// <param name="is_rolap"></param> public void CREATE_CUBE_COMMON( DB_SQLHELPER_BASE sqlHelper , IDbConnection oledb , AS_METADATA asMeta , Server cube_server , String cube_db_name , String cube_name , int is_rolap) { try { Database cube_db = cube_server.Databases.FindByName(cube_db_name); DataSourceView cube_dsv = cube_db.DataSourceViews.FindByName("SSAS_DSV"); DataSet dsv_schema = cube_dsv.Schema; // 1.create dsv CREATE_CUBE_DSV(sqlHelper, asMeta, oledb, cube_dsv, dsv_schema.DataSetName); cube_dsv.Update(); // 2.create dimensions CREATE_CUBE_DIMENSION(sqlHelper, asMeta, cube_db, cube_dsv); cube_db.Update(); // 3.cube Cube cube = cube_db.Cubes.FindByName(cube_name); // 4.add dimension into cube ADD_DIMENSION_TO_CUBE(sqlHelper, asMeta, cube_db, cube); // 5.create measure groups CREATE_MEASURE_GROUP(cube_dsv, sqlHelper, asMeta, cube, is_rolap); // 6.remove unnecessary objects REMOVE_CUBE_OBJECTS(sqlHelper, cube_db, cube); // 8.create partitions // 9.create aggregations // 10.cube customized //customized_cube_changes(self,db_connection,cube_server,cube_db,cube,is_rolap); sqlHelper.ADD_MESSAGE_LOG( "[Create cube common] Saving cube changes...", MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Normal); //11.cube save cube_db.Update(UpdateOptions.ExpandFull); sqlHelper.ADD_MESSAGE_LOG( "[Create cube common] Saved cube changes, processing cube...", MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Normal); CUBE_PROCESS_FULL(sqlHelper, cube_server, cube_db_name); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG("[Create cube common] " + ex.Message.ToString(), MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Error); throw(ex); } finally { //oledb.close_connection(); } }
/// <summary> /// Update Cube Command /// </summary> /// <param name="cube_server"></param> /// <param name="cube_db"></param> /// <param name="cube"></param> /// <param name="mdx_code"></param> public void UPDATE_CUBE_COMMAND(DB_SQLHELPER_BASE sqlHelper, Server cube_server, Database cube_db, Cube cube, String mdx_code) { try { MdxScript mdx = new MdxScript(); if (cube.DefaultMdxScript == null) { sqlHelper.ADD_MESSAGE_LOG( "DefaultMdxScript is none, creating a new one", MESSAGE_TYPE.MDX, MESSAGE_RESULT_TYPE.Normal); mdx.ID = cube.MdxScripts.GetNewID(); mdx.Name = "MDXHelper"; } else { mdx = cube.DefaultMdxScript; } Command cmd = new Command(); if (cube.DefaultMdxScript == null || cube.DefaultMdxScript.Commands == null) { sqlHelper.ADD_MESSAGE_LOG( "DefaultMdxScript.Commands is none, creating a new one", MESSAGE_TYPE.MDX, MESSAGE_RESULT_TYPE.Normal); } else { cmd = cube.DefaultMdxScript.Commands[0]; } cmd.Text = mdx_code; mdx.Commands.Remove(cmd); mdx.Commands.Add(cmd); cube.MdxScripts.Remove(mdx); cube.MdxScripts.Add(mdx); sqlHelper.ADD_MESSAGE_LOG( "Refreshed cube mdx calculations.", MESSAGE_TYPE.MDX, MESSAGE_RESULT_TYPE.Normal); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG( "Failed to refreshed cube mdx calculations:" + ex.Message.ToString(), MESSAGE_TYPE.MDX, MESSAGE_RESULT_TYPE.Error); throw ex; } }
/// <summary> /// Add relation ship to attribute /// </summary> /// <param name="dim"></param> /// <param name="basedAttributeID"></param> /// <param name="relatedAttributeID"></param> /// <param name="attributeRelationShipType"></param> /// <param name="relationShipName"></param> internal static void ADD_ATTRIBUTE_RELATIONSHIP( DB_SQLHELPER_BASE sqlHelper, Dimension dim, String basedAttributeID, String relatedAttributeID, RelationshipType attributeRelationShipType = RelationshipType.Flexible, String relationShipName = null) { DimensionAttribute attr = dim.Attributes.Find(basedAttributeID); DimensionAttribute relatedAttr = dim.Attributes.Find(relatedAttributeID); if (relationShipName == null) { relationShipName = relatedAttr.Name; } AttributeRelationship relationship = new AttributeRelationship(); relationship.Attribute = attr; relationship.Name = relationShipName; relationship.AttributeID = relatedAttributeID; if (attributeRelationShipType != null) { relationship.RelationshipType = attributeRelationShipType; } else { sqlHelper.ADD_MESSAGE_LOG( String.Format("A None RelationShipType is passed between [{0} and [{1}]", basedAttributeID, relatedAttributeID), MESSAGE_TYPE.ATTRIBUTE_RELATIONSHIP, MESSAGE_RESULT_TYPE.Warning); } if (!attr.AttributeRelationships.Contains(relatedAttributeID)) { attr.AttributeRelationships.Add(relationship); } }
/// <summary> /// Create data item /// </summary> /// <param name="dsv"></param> /// <param name="factTableName"></param> /// <param name="factFKDimColumnName"></param> /// <param name="dataType"></param> /// <returns></returns> internal static DataItem CREATE_DATA_ITEM( DB_SQLHELPER_BASE sqlHelper, DataSourceView dsv, String factTableName, String factFKDimColumnName, System.Data.OleDb.OleDbType dataType) { DataTable data_table = dsv.Schema.Tables[factTableName]; DataColumn dataColumn = data_table.Columns[factFKDimColumnName]; if (dataColumn == null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Table [{0}] doesn't have column [{0}]", factTableName, factFKDimColumnName), MESSAGE_TYPE.COLUMN_BINDING_DATA_ITEM, MESSAGE_RESULT_TYPE.Error); } DataItem dataItem = new DataItem(factTableName, dataColumn.ColumnName); if (dataType != null) { dataItem.DataType = dataType; } else { dataItem.DataType = OleDbTypeConverter.GetRestrictedOleDbType(dataColumn.DataType); } return(dataItem); }
public int EXECUTE_PROCEDURE_WITH_PARAMETERS(DB_SQLHELPER_BASE sqlHelper, String StoreProcedureName, IDataParameter[] PassedParameters) { int return_value = 0; try { IDbCommand iCom = sqlHelper.GET_DATABASE_CONNECTION().CreateCommand(); iCom.CommandType = System.Data.CommandType.StoredProcedure; iCom.CommandText = StoreProcedureName; foreach (IDataParameter parameter in PassedParameters) { iCom.Parameters.Add(parameter); } iCom.CommandTimeout = Convert.ToInt32(CONFIGURATION_HELPER.GET_METADATA_PROPERTY("command_time_out")); iCom.ExecuteNonQuery(); iCom.Dispose(); return_value = 1; } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message, MESSAGE_TYPE.SQLQuery, MESSAGE_RESULT_TYPE.Error); throw (ex); } finally { CLOSE_CONNECTION(); } return(return_value); }
/// <summary> /// Add dimension into Cube dataBase, instead of cube /// </summary> /// <param name="cubedb">Cube dataBase</param> /// <param name="datasourcename">dataSourceName</param> /// <param name="dimensionid">dimension id</param> /// <param name="dimensionname">dimension id</param> /// <param name="dim_type">dimension type, eg..time、regular</param> /// <returns></returns> internal static Dimension ADD_DIMENSION( DB_SQLHELPER_BASE sqlHelper, Database cubedb, String datasourcename, String dimensionid, String dimensionname, String dim_type) { Dimension dim = cubedb.Dimensions.FindByName(dimensionname); try { String[] nullvalue = new String[] { "null" }; if (!nullvalue.Contains(dimensionname)) { dim = cubedb.Dimensions.Add(dimensionid); dim.Name = dimensionname; dim.Type = DimensionType.Regular; if (dim_type.ToLower() == "time") { dim.Type = DimensionType.Time; } dim.Source = new DataSourceViewBinding(datasourcename); dim.StorageMode = DimensionStorageMode.Molap; dim.ProcessingGroup = ProcessingGroup.ByAttribute; } sqlHelper.ADD_MESSAGE_LOG( String.Format("Added dimension [{0}]", dimensionname), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Succeed); } finally { } return(dim); }
/// <summary> /// Add regular dim usage /// </summary> /// <param name="cube"></param> /// <param name="measureGroup"></param> /// <param name="factDataItem"></param> /// <param name="dimID"></param> /// <param name="dimAttrId"></param> /// <returns>Regular dim usage</returns> internal static RegularMeasureGroupDimension ADD_DIM_USAGE_REGULAR_RELATIONSHIP( DB_SQLHELPER_BASE sqlHelper, Cube cube, MeasureGroup measureGroup, DataItem factDataItem, String dimID, String dimAttrId) { RegularMeasureGroupDimension regMgDim = null; CubeDimension curDim = cube.Dimensions.Find(dimID); if (curDim == null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Cann't find dimension {0}", dimID), MESSAGE_TYPE.DIM_USAGE_REGULAR, MESSAGE_RESULT_TYPE.Error); } regMgDim = new RegularMeasureGroupDimension(curDim.Name); regMgDim.CubeDimensionID = dimID; measureGroup.Dimensions.Add(regMgDim); MeasureGroupAttribute mgAttr = regMgDim.Attributes.Add(dimAttrId); mgAttr.Type = MeasureGroupAttributeType.Granularity; mgAttr.KeyColumns.Add(factDataItem); return(regMgDim); }
public DataTable EXECUTE_SQL_QUERY_RETURN_TABLE(DB_SQLHELPER_BASE sqlHelper, String SqlQuery) { DataTable returnTable = null; try { IDbCommand iCom = sqlHelper.GET_DATABASE_CONNECTION().CreateCommand(); iCom.CommandText = SqlQuery; iCom.CommandTimeout = Convert.ToInt32(CONFIGURATION_HELPER.GET_METADATA_PROPERTY("command_time_out"));; IDbDataAdapter iAdap = GET_DATABASE_ADAPATER_DEFAULT(); iAdap.SelectCommand = iCom; DataSet dataSet = new System.Data.DataSet(); iAdap.Fill(dataSet); iCom.Dispose(); returnTable = dataSet.Tables[0]; } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message, MESSAGE_TYPE.SQLQuery, MESSAGE_RESULT_TYPE.Error); throw(ex); } finally { CLOSE_CONNECTION(); } return(returnTable); }
/// <summary> /// Add Attribute To Dimension /// </summary> /// <param name="cubeDSV"></param> /// <param name="dim"></param> /// <param name="tableID"></param> /// <param name="colName"></param> /// <param name="attribID"></param> /// <param name="attribName"></param> /// <param name="type"></param> /// <param name="usage"></param> /// <param name="nameColumn"></param> /// <param name="visible"></param> /// <param name="AttHierEnabled"></param> /// <param name="orderby"></param> /// <param name="attDisplayFolder"></param> /// <param name="orderByAttName"></param> /// <param name="attType"></param> /// <param name="valueColumn"></param> /// <param name="valueColtype"></param> internal static void ADD_ATTRIBUTE_TO_DIMENSION( DB_SQLHELPER_BASE sqlHelper, DataSourceView cubeDSV, Dimension dim, String tableID, String colName, String attribID, String attribName, System.Data.OleDb.OleDbType type, AttributeUsage usage, String nameColumn, bool visible = true, bool AttHierEnabled = true, OrderBy orderby = OrderBy.Name, String attDisplayFolder = "", String orderByAttName = null, String attType = "Regular", String valueColumn = null, System.Data.OleDb.OleDbType valueColtype = System.Data.OleDb.OleDbType.Integer) { DimensionAttribute attr = dim.Attributes.FindByName(attribName); if (attr == null) { attr = dim.Attributes.Add(attribID); attr.Name = attribName; attr.Usage = usage; attr.Type = AttributeType.Regular; attr.AttributeHierarchyEnabled = AttHierEnabled; DataItem dataItem = CREATE_COLUMN_BINDING_DATA_ITEM(sqlHelper, cubeDSV, tableID, colName, type); attr.KeyColumns.Add(dataItem); attr.KeyColumns[0].DataType = type; attr.AttributeHierarchyVisible = visible; attr.OrderBy = orderby; if (nameColumn != colName && nameColumn != "") { DataItem nameColDataItem = CREATE_COLUMN_BINDING_DATA_ITEM(sqlHelper, cubeDSV, tableID, nameColumn, System.Data.OleDb.OleDbType.WChar); attr.NameColumn = nameColDataItem; } if (attDisplayFolder != null && attDisplayFolder != "") { attr.AttributeHierarchyDisplayFolder = attDisplayFolder; } if (orderByAttName != null && orderByAttName != "") { attr.OrderByAttributeID = orderByAttName; } if (valueColumn != null && valueColumn != "") { DataItem valueColDataItem = CREATE_COLUMN_BINDING_DATA_ITEM(sqlHelper, cubeDSV, tableID, valueColumn, valueColtype); attr.ValueColumn = valueColDataItem; } sqlHelper.ADD_MESSAGE_LOG( String.Format("Added attribute [{0}] to dimension [{1}]", attribName, dim.Name), MESSAGE_TYPE.ATTRIBUTE, MESSAGE_RESULT_TYPE.Succeed); } }
/// <summary> /// Create molap partition /// </summary> /// <param name="measureGroup"></param> /// <param name="datasourceName"></param> /// <param name="partitionid"></param> /// <param name="MGdsvTableName"></param> /// <param name="filter_string"></param> /// <param name="aggregation_design_id"></param> /// <param name="is_real_time"></param> /// <param name="depended_fact_table"></param> internal static void CREATE_MOLAP_PARTITION( DB_SQLHELPER_BASE sqlHelper, MeasureGroup measureGroup, String datasourceName, String partitionid, String MGdsvTableName, String filter_string, String aggregation_design_id, int is_rolap_mg, String depended_fact_table) { Partition part = measureGroup.Partitions.FindByName(partitionid); if (part != null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Drop Partition {0}", partitionid), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Succeed); part.Drop(DropOptions.AlterOrDeleteDependents); } part = measureGroup.Partitions.Add(partitionid); part.ID = partitionid; part.Name = partitionid; part.Source = new QueryBinding(datasourceName, "SELECT * FROM " + MGdsvTableName + " WHERE 1=1 " + filter_string); if (is_rolap_mg.ToString() == "1") { part.StorageMode = StorageMode.Rolap; part.CurrentStorageMode = StorageMode.Rolap; ProactiveCachingTablesBinding tables_binding = new ProactiveCachingTablesBinding(); tables_binding.NotificationTechnique = NotificationTechnique.Server; TableNotification table_notification = new TableNotification(depended_fact_table, CONFIGURATION_HELPER.GET_METADATA_PROPERTY("db_table_schema_name")); tables_binding.TableNotifications.Add(table_notification); ProactiveCaching proactive_caching = new ProactiveCaching(); proactive_caching.OnlineMode = ProactiveCachingOnlineMode.Immediate; proactive_caching.AggregationStorage = ProactiveCachingAggregationStorage.MolapOnly; proactive_caching.Enabled = true; proactive_caching.Source = tables_binding; System.TimeSpan SilenceInterval_time = new System.TimeSpan(0, 0, 1); proactive_caching.SilenceInterval = SilenceInterval_time.Negate(); proactive_caching.SilenceOverrideInterval = proactive_caching.SilenceInterval; proactive_caching.ForceRebuildInterval = proactive_caching.SilenceInterval; proactive_caching.Latency = System.TimeSpan.Zero; part.ProactiveCaching = proactive_caching; } else { part.StorageMode = StorageMode.Molap; } part.ProcessingMode = ProcessingMode.Regular; if (aggregation_design_id != null) { part.AggregationDesignID = aggregation_design_id.ToString(); } }
/// <summary> /// Create ssas base cube by calling SSAS API /// </summary> /// <param name="cubeServer">Cube server</param> /// <param name="cubeDBName">Cube data base name</param> /// <param name="cubeXmla">Base cube xmla</param> public void CREATE_SSAS_BASE_CUBE( DB_SQLHELPER_BASE sqlHelper, Server cubeServer, String cubeDBName, String cubeName, String dwConnectionString ) { String SSASConfigurationPath = CONFIGURATION_HELPER.BASIC_CONFIGURATION_FOLDER + @"\SSASConfiguration\BaseCubeXMLA.xml"; String SSASConfiguration = ""; System.Security.Principal.NTAccount _Everyone_Account = new System.Security.Principal.NTAccount("Everyone"); System.Security.Principal.SecurityIdentifier _SecurityIdentifier = (System.Security.Principal.SecurityIdentifier)_Everyone_Account.Translate(typeof(System.Security.Principal.SecurityIdentifier)); String sidString = _SecurityIdentifier.ToString(); SSASConfiguration = System.IO.File.ReadAllText(SSASConfigurationPath); SSASConfiguration = SSASConfiguration .Replace("$(dwConnectionString)", dwConnectionString) .Replace("$(cubeDBName)", cubeDBName) .Replace("$(cubeName)", cubeName) .Replace("$(DBTableSchemaName)", CONFIGURATION_HELPER.GET_METADATA_PROPERTY("db_table_schema_name")) .Replace("$(sid)", sidString); sqlHelper.ADD_MESSAGE_LOG(String.Format("[Create base cube] Starting create cube database {0}", cubeDBName), MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Normal); XmlaResultCollection resultCol = cubeServer.Execute(SSASConfiguration); foreach (XmlaResult result in resultCol) { foreach (XmlaMessage message in result.Messages) { if (message.ToString().Contains("error") || message.ToString().Contains("failed")) { sqlHelper.ADD_MESSAGE_LOG("[Create base cube]" + message.ToString(), MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Error); return; } else { sqlHelper.ADD_MESSAGE_LOG("[Create base cube]" + message.ToString(), MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Succeed); } } } sqlHelper.ADD_MESSAGE_LOG("[Create base cube]" + String.Format("Succeed to create cube database {0}", cubeDBName), MESSAGE_TYPE.CREATE_CUBE, MESSAGE_RESULT_TYPE.Succeed); }
/// <summary> /// add measure group into cube /// </summary> /// <param name="cube"> cube (instead of cube db)</param> /// <param name="measureGroupName"></param> /// <param name="measureGroupID"></param> /// <param name="isRealTime"></param> /// <param name="keyNotFoundAction"></param> /// <param name="dropIfExisted"></param> /// <returns>measure group</returns> internal static MeasureGroup ADD_MEASURE_GROUP( DB_SQLHELPER_BASE sqlHelper, Cube cube, String measureGroupName, String measureGroupID, int isRealTime, String keyNotFoundAction, bool dropIfExisted = false) { MeasureGroup measure_group = cube.MeasureGroups.Find(measureGroupID); if (measure_group != null && dropIfExisted) { measure_group.Drop(); } measure_group = cube.MeasureGroups.Add(measureGroupID); measure_group.Name = measureGroupName; if (isRealTime == '0') { measure_group.StorageMode = StorageMode.Molap; } else { measure_group.StorageMode = StorageMode.Rolap; } measure_group.Type = MeasureGroupType.Regular; if (keyNotFoundAction != "0") { ErrorConfiguration error_configuration = new ErrorConfiguration(); switch (keyNotFoundAction.ToLower()) { case "ignoreerror": error_configuration.KeyNotFound = ErrorOption.IgnoreError; break; case "reportandcontinue": error_configuration.KeyNotFound = ErrorOption.ReportAndContinue; break; case "reportandstop": error_configuration.KeyNotFound = ErrorOption.ReportAndStop; break; default: error_configuration.KeyNotFound = ErrorOption.IgnoreError; break; } measure_group.ErrorConfiguration = error_configuration; } sqlHelper.ADD_MESSAGE_LOG( String.Format("Added measure group {0} into cube", measureGroupName), MESSAGE_TYPE.MEASURE_GROUP, MESSAGE_RESULT_TYPE.Succeed); return(measure_group); }
/// <summary> /// Remove measure group /// </summary> /// <param name="cube"></param> /// <param name="mgID"></param> internal static void REMOVE_MEASURE_GROUPS(DB_SQLHELPER_BASE sqlHelper, Cube cube, String mgID) { MeasureGroup mg = cube.MeasureGroups.Find(mgID); if (mg != null) { cube.MeasureGroups.Remove(mg); sqlHelper.ADD_MESSAGE_LOG( String.Format("Deleted [{0}] measure group", mgID), MESSAGE_TYPE.MEASURE_GROUP, MESSAGE_RESULT_TYPE.Succeed); } }
/// <summary> /// Create Create Cube DSV /// </summary> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="oleDB"></param> /// <param name="DSV"></param> /// <param name="dsvSchema"></param> public void CREATE_CUBE_DSV(DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , IDbConnection oleDB , Microsoft.AnalysisServices.DataSourceView DSV , String dsvSchema) { try { sqlHelper.ADD_MESSAGE_LOG("[Create cube dsv] Starting add cube dsv", MESSAGE_TYPE.DSV, MESSAGE_RESULT_TYPE.Normal); DataTable dsvSet = asMeta.GET_SSAS_DSV_SET(sqlHelper); foreach (DataRow row in dsvSet.Rows) { String dsv_schema_name = row["dsv_schema_name"].ToString(); String db_table_name = row["db_table_name"].ToString(); String table_type = row["table_type"].ToString(); String is_name_query = row["is_named_query"].ToString(); String dsv_query_text = String.Format("SELECT * FROM {0} WHERE 1=0", db_table_name); sqlHelper.ADD_MESSAGE_LOG(String.Format("[Create cube dsv->{0}] Adding to add cube dsv", db_table_name), MESSAGE_TYPE.DSV, MESSAGE_RESULT_TYPE.Succeed); AS_API.ADD_TABLE_TO_CUBE_DSV(oleDB , DSV , db_table_name , dsv_query_text , db_table_name , "View" , CONFIGURATION_HELPER.GET_METADATA_PROPERTY("db_table_schema_name")); } DSV.Update(); sqlHelper.ADD_MESSAGE_LOG("[Create cube dsv] Succeed to add cube dsv", MESSAGE_TYPE.DSV, MESSAGE_RESULT_TYPE.Succeed); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG("[Create cube dsv] " + ex.Message.ToString(), MESSAGE_TYPE.DSV, MESSAGE_RESULT_TYPE.Error); throw(ex); } }
/// <summary> /// Remove cube objects (FactBool) /// </summary> /// <param name="cubedb"></param> /// <param name="cube"></param> public void REMOVE_CUBE_OBJECTS(DB_SQLHELPER_BASE sqlHelper, Database cubedb, Cube cube) { try { AS_API.REMOVE_MEASURE_GROUPS(sqlHelper, cube, "FactBool"); } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG( "Failed to refreshed cube mdx calculations:" + ex.Message.ToString(), MESSAGE_TYPE.REMOVE_CUBE_OBJECT, MESSAGE_RESULT_TYPE.Error); throw ex; } }
/// <summary> /// Create aggregation design /// </summary> /// <param name="mg"></param> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <returns></returns> public AggregationDesign CREATE_AGGREGATION_DESIGN(MeasureGroup mg, DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta) { DataTable agg_design_list = null; AggregationDesign agg_design = null; try { agg_design_list = asMeta.GET_SSAS_AGGREGATION_DESIGN_SET(sqlHelper, mg.ID); foreach (DataRow measure in agg_design_list.Rows) { String AggregationDesignName = measure["aggregation_design_name"].ToString(); //agg_design=AggregationDesignName; String AggregationName = measure["aggregation_name"].ToString(); String DimensionID = measure["dimension_id"].ToString(); String AttributeID = measure["attribute_id"].ToString(); if (mg.AggregationDesigns.Find(AggregationDesignName) == null) { mg.AggregationDesigns.Add(AggregationDesignName); } agg_design = mg.AggregationDesigns[AggregationDesignName]; Aggregation agg = agg_design.Aggregations.Find(AggregationName); if (agg == null) { agg = agg_design.Aggregations.Add(AggregationName, AggregationName); } AggregationDimension agg_dim = agg.Dimensions.Find(DimensionID); if (agg_dim == null) { agg.Dimensions.Add(DimensionID); } agg.Dimensions[DimensionID].Attributes.Add(AttributeID); } } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message.ToString(), MESSAGE_TYPE.AGGREGATION_DESIGN, MESSAGE_RESULT_TYPE.Error); throw (ex); } return(agg_design); }
/// <summary> /// Create cube core measure /// </summary> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cube"></param> public void CREATE_CUBE_CORE_MEASURES(DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , Cube cube) { try { DataTable coreMeasureSet = asMeta.GET_SSAS_CORE_MEASURES_SET(sqlHelper); foreach (DataRow row in coreMeasureSet.Rows) { String measureGroupID = row["measure_group_id"].ToString(); String MeasureId = row["measure_id"].ToString(); String MeasureName = row["measure_name"].ToString(); String DSVSchemaName = row["dsv_schema_name"].ToString(); String DisplayFolder = row["display_folder"].ToString(); String FormatString = row["format_string"].ToString(); String MeasureDataType = row["measure_data_type"].ToString(); String DBColumn = row["db_column"].ToString(); String AggregationFunction = row["aggregation_function"].ToString(); MeasureGroup measureGroup = cube.MeasureGroups.Find(measureGroupID); AS_API.ADD_MEASURE_TO_MEASURE_GROUP( sqlHelper , measureGroup , DSVSchemaName , DBColumn , MeasureName , MeasureId , DisplayFolder , FormatString , AggregationFunction , true , MeasureDataType , MeasureDataType); measureGroup.Update(); } } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG("Failed to create cube core measures:" + ex.Message.ToString(), MESSAGE_TYPE.MEASURES, MESSAGE_RESULT_TYPE.Error); throw (ex); } }
/// <summary> /// Remove dimension /// </summary> /// <param name="cubedb"></param> /// <param name="cube"></param> /// <param name="dimID"></param> internal static void REMOVE_DIMENSIONS( DB_SQLHELPER_BASE sqlHelper, Database cubedb, Cube cube, String dimID) { CubeDimension cube_dim = cube.Dimensions.Find(dimID); if (cube_dim != null) { cube.Dimensions.Remove(cube_dim); } Dimension dim = cubedb.Dimensions.Find(dimID); if (dim != null) { cubedb.Dimensions.Remove(dim); sqlHelper.ADD_MESSAGE_LOG( String.Format("Delete [{0}] dimension", dim.Name), MESSAGE_TYPE.DIMENSION, MESSAGE_RESULT_TYPE.Succeed); } }
/// <summary> /// Add attribute hierachies /// </summary> /// <param name="dim"></param> /// <param name="hierarchyName"></param> /// <param name="levelName"></param> /// <param name="sourceAttributeID"></param> internal static void ADD_ATTRIBUTE_HIERACHIES( DB_SQLHELPER_BASE sqlHelper, Dimension dim, String hierarchyName, String levelName, String sourceAttributeID) { if (dim.Hierarchies.FindByName(hierarchyName) == null) { dim.Hierarchies.Add(hierarchyName); } Hierarchy hierarchy = dim.Hierarchies.FindByName(hierarchyName); if (hierarchy.Levels.FindByName(levelName) != null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("Level [{0}] already existed for hierarchy [{0}] ", levelName, hierarchyName), MESSAGE_TYPE.HIERARCHIES, MESSAGE_RESULT_TYPE.Warning); } Level level = hierarchy.Levels.Add(levelName); level.SourceAttributeID = sourceAttributeID; }
//----------------------------- //---------Query--------------- //----------------------------- public int EXECUTE_SQL_QUERY(DB_SQLHELPER_BASE sqlHelper, String SqlString) { int return_value = 0; try { IDbCommand iCom = sqlHelper.GET_DATABASE_CONNECTION().CreateCommand(); iCom.CommandText = SqlString; iCom.CommandTimeout = Convert.ToInt32(CONFIGURATION_HELPER.GET_METADATA_PROPERTY("command_time_out")); iCom.ExecuteNonQuery(); iCom.Dispose(); return_value = 1; } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message, MESSAGE_TYPE.SQLQuery, MESSAGE_RESULT_TYPE.Error); throw (ex); } finally { CLOSE_CONNECTION(); } return(return_value); }
/// <summary> /// Add measure into a measure group /// </summary> /// <param name="measureGroup"></param> /// <param name="tableID"></param> /// <param name="columnID"></param> /// <param name="measureName"></param> /// <param name="measureID"></param> /// <param name="displayFolder"></param> /// <param name="formatStr"></param> /// <param name="aggregationFunction"></param> /// <param name="visible"></param> /// <param name="sourceColDataType"></param> /// <param name="measureDataType"></param> internal static void ADD_MEASURE_TO_MEASURE_GROUP( DB_SQLHELPER_BASE sqlHelper , MeasureGroup measureGroup , String tableID , String columnID , String measureName , String measureID , String displayFolder , String formatStr , String aggregationFunction , bool visible = true , String sourceColDataType = "double" , String measureDataType = "double") { Microsoft.AnalysisServices.DataItem source = new Microsoft.AnalysisServices.DataItem(); source.NullProcessing = NullProcessing.Preserve; Measure measure = new Measure(measureName, measureID); String aggType = aggregationFunction.ToLower(); measure.DataType = AS_API_HELPER.GET_SSAS_MEASURE_DATA_TYPE_BY_NAME(measureDataType); if (aggType == "count*") { RowBinding rowBind = new RowBinding(); rowBind.TableID = tableID; measure.AggregateFunction = AggregationFunction.Count; source.Source = rowBind; measure.Source = source; measure.DataType = MeasureDataType.Integer; //source.DataType = AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME(sourceColDataType); } else { ColumnBinding colBind = new ColumnBinding(); colBind.TableID = tableID; colBind.ColumnID = columnID; source.DataType = AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME(sourceColDataType); source.Source = colBind; measure.AggregateFunction = AS_API_HELPER.GET_SSAS_AGGREGATION_FUNCTION_BY_NAME(aggType.ToLower()); if (aggType.ToLower() == "distinctcount") { source.NullProcessing = NullProcessing.Automatic; source.DataType = AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME("integer"); measure.DataType = MeasureDataType.Integer; } measure.Source = source; } String dataType = sourceColDataType.ToLower(); measure.DisplayFolder = displayFolder; //measure.FormatString = formatStr measure.Visible = visible; Measure measureEx = measureGroup.Measures.Find(measureID); if (measureEx != null) { sqlHelper.ADD_MESSAGE_LOG( String.Format("measure {0} exists", measureName), MESSAGE_TYPE.MEASURES, MESSAGE_RESULT_TYPE.Warning); measureEx.Name = measure.Name; measureEx.AggregateFunction = measure.AggregateFunction; measureEx.DataType = AS_API_HELPER.GET_SSAS_MEASURE_DATA_TYPE_BY_NAME(measureDataType); measureEx.DisplayFolder = measure.DisplayFolder; measureEx.Visible = measure.Visible; measureEx.FormatString = measure.FormatString; measureEx.Source = source.Clone(); } else { sqlHelper.ADD_MESSAGE_LOG( String.Format("Added measure {0} into measure group {1}", measureName, measureGroup.Name), MESSAGE_TYPE.MEASURES, MESSAGE_RESULT_TYPE.Succeed); measureGroup.Measures.Add(measure); } }
/// <summary> /// CREATE_CUBE_PARTITION_FOR_MEASURE_GROUP /// </summary> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cube"></param> /// <param name="is_rolap_cube"></param> /// <param name="mg"></param> /// <param name="aggregation_design"></param> /// <param name="is_rolap_mg"></param> /// <param name="depended_fact_table"></param> /// <param name="DSVSchemaName"></param> public void CREATE_CUBE_PARTITION_FOR_MEASURE_GROUP( DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , Cube cube , int is_rolap_cube , MeasureGroup mg , AggregationDesign aggregation_design , int is_rolap_mg , String depended_fact_table , String DSVSchemaName) { DataTable partition_date_filter = asMeta.GET_SSAS_PARTITION_SET(sqlHelper, mg.ID); String aggregation_design_id = null; if (aggregation_design != null) { aggregation_design_id = aggregation_design.ID.ToString(); } if (partition_date_filter != null && partition_date_filter.Rows != null && partition_date_filter.Rows.Count > 0) { String factFKDimColumnName = partition_date_filter.Rows[0]["fact_fk_dim_column_name"].ToString(); int month_volumn_per_partition = Convert.ToInt32(CONFIGURATION_HELPER.GET_METADATA_PROPERTY("month_volumn_per_partition")); int year_volumn_per_cube = Convert.ToInt32(CONFIGURATION_HELPER.GET_METADATA_PROPERTY("year_volumn_per_cube")); int partitionCount = 0; partitionCount = year_volumn_per_cube * 12 / month_volumn_per_partition; for (int i = 1; i <= partitionCount + 1; i++) { String partitionSelectQuery = "";// String.Format("SELECT * FROM {0} WHERE 1=1 ", DSVSchemaName); //if rolap cube, and current mg is molap, then add where 1=2 filter, select * from tb_name where 1=1 and 1=2 if (is_rolap_cube == 1 && is_rolap_mg == 0) { partitionSelectQuery = partitionSelectQuery + " AND 1=2"; } //if rolap cube, then no need additional date column filter, if molap , then need date column filter, //select * from tb_name where 1=1 and dateid>=20100101 and dateid<20100201 if (is_rolap_cube == 0) { partitionSelectQuery = partitionSelectQuery + " " + asMeta.GET_SSAS_PARTITION_FILTER(factFKDimColumnName, i, month_volumn_per_partition); } AS_API.CREATE_MOLAP_PARTITION( sqlHelper, mg, "DW_DataSource", mg.ID.ToString() + "_" + i.ToString(), DSVSchemaName, partitionSelectQuery, aggregation_design_id, is_rolap_mg, depended_fact_table ); //if rolap cube, then only need one partition if (is_rolap_cube == 1) { break; } } } else { sqlHelper.ADD_MESSAGE_LOG(String.Format("Create cube partition-> No partition date column been detected for mg {0}", mg.ID), MESSAGE_TYPE.PARTITION, MESSAGE_RESULT_TYPE.Warning); AS_API.CREATE_MOLAP_PARTITION( sqlHelper, mg, "DW_DataSource", mg.ID.ToString() + "_1", DSVSchemaName, "", aggregation_design_id, is_rolap_mg, depended_fact_table ); } }
/// <summary> /// Create measure group /// </summary> /// <param name="dsv"></param> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cube"></param> /// <param name="is_rolap"></param> /// <param name="measure_group_id"></param> public void CREATE_MEASURE_GROUP(DataSourceView dsv , DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , Cube cube , int is_rolap_cube , String measure_group_id = null) { try { DataTable MGSet = asMeta.GET_SSAS_MEASURE_GROUPS_SET(sqlHelper, is_rolap_cube); String DSVSchemaName = ""; foreach (DataRow row in MGSet.Rows) { String measureGroupID = row["measure_group_id"].ToString(); String measureGroupName = row["measure_group_name"].ToString(); String DependedFactTable = row["depended_fact_table"].ToString(); String KeyNotFound_Action = row["key_not_found_action"].ToString(); int is_rolap_mg = Convert.ToInt16(row["is_rolap_mg"].ToString()); MeasureGroup newMG = AS_API.ADD_MEASURE_GROUP(sqlHelper, cube, measureGroupName, measureGroupID, is_rolap_mg, KeyNotFound_Action); DataTable dimUsageSet = asMeta.GET_SSAS_DIM_USAGE_SET(sqlHelper, measureGroupID); DataTable CoreMeasureSet = asMeta.GET_SSAS_CORE_MEASURES_SET(sqlHelper, measureGroupID); foreach (DataRow measure in CoreMeasureSet.Rows) { measureGroupID = measure["measure_group_id"].ToString(); measureGroupName = measure["measure_group_name"].ToString(); String MeasureId = measure["measure_id"].ToString(); String MeasureName = measure["measure_name"].ToString(); String MeasureDataType = measure["measure_data_type"].ToString(); String DBColumn = measure["db_column"].ToString(); DSVSchemaName = measure["dsv_schema_name"].ToString(); String AggregationFunction = measure["aggregation_function"].ToString(); String DisplayFolder = measure["display_folder"].ToString(); String FormatString = measure["format_string"].ToString(); AS_API.ADD_MEASURE_TO_MEASURE_GROUP( sqlHelper, newMG, DSVSchemaName, DBColumn, MeasureName, MeasureId, DisplayFolder, FormatString, AggregationFunction, true, MeasureDataType, MeasureDataType); } foreach (DataRow dimUsage in dimUsageSet.Rows) { String DimUsageType = dimUsage["dim_usage_type"].ToString(); String InternalDimID = dimUsage["internal_dim_id"].ToString(); String InternalDimAttrID = dimUsage["internal_dim_attrid"].ToString(); DSVSchemaName = dimUsage["dsv_schema_name"].ToString(); String factFKDimColumnName = dimUsage["fact_fk_dim_column_name"].ToString(); String DataType = dimUsage["fact_fk_dim_column_data_type"].ToString(); String DimensionID = dimUsage["dimension_id"].ToString(); String AttributeID = dimUsage["attribute_id"].ToString(); String InternalMeasureGroupID = dimUsage["internal_measure_group_id"].ToString(); switch (DimUsageType.ToLower()) { case "regular": DataItem factDataItem = AS_API.CREATE_DATA_ITEM( sqlHelper, dsv, DSVSchemaName, factFKDimColumnName, AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME(DataType)); AS_API.ADD_DIM_USAGE_REGULAR_RELATIONSHIP( sqlHelper, cube, newMG, factDataItem, DimensionID, AttributeID); break; case "reference": AS_API.ADD_DIM_USAGE_REFERENCE_RELATIONSHIP(newMG, DimensionID, AttributeID, InternalDimID, InternalDimAttrID); break; case "manytomany": AS_API.ADD_DIM_USAGE_MANY_RELATIONSHIP(newMG, InternalMeasureGroupID, DimensionID); break; case "fact": AS_API.ADD_DIM_USAGE_FACT_RELATIONSHIP(newMG, InternalDimAttrID, DimensionID); break; default: break; } } AggregationDesign agg_design = CREATE_AGGREGATION_DESIGN(newMG, sqlHelper, asMeta); CREATE_CUBE_PARTITION_FOR_MEASURE_GROUP(sqlHelper, asMeta, cube, is_rolap_cube, newMG, agg_design, is_rolap_mg, DependedFactTable, DSVSchemaName); newMG.Update(); } } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG(ex.Message.ToString(), MESSAGE_TYPE.MEASURE_GROUP, MESSAGE_RESULT_TYPE.Error); throw (ex); } }
/// <summary> /// Create cube dimension /// </summary> /// <param name="sqlHelper"></param> /// <param name="asMeta"></param> /// <param name="cubeDB"></param> /// <param name="DSV"></param> public void CREATE_CUBE_DIMENSION(DB_SQLHELPER_BASE sqlHelper , AS_METADATA asMeta , Microsoft.AnalysisServices.Database cubeDB , Microsoft.AnalysisServices.DataSourceView DSV ) { try { sqlHelper.ADD_MESSAGE_LOG("[Create dimension] Starting create dimension" , MESSAGE_TYPE.DIMENSION , MESSAGE_RESULT_TYPE.Normal); DataTable DimensionSet = asMeta.GET_SSAS_DIMENSION_SET(sqlHelper); foreach (DataRow dimension_row in DimensionSet.Rows) { String DimensionID = dimension_row["dimension_id"].ToString(); String DimensionName = dimension_row["dimension_name"].ToString(); String DimensionType = dimension_row["dimension_type"].ToString(); String DataSourceName = dimension_row["dsv_schema_name"].ToString(); String dsvName = DSV.Name; Microsoft.AnalysisServices.Dimension dim = AS_API.ADD_DIMENSION(sqlHelper, cubeDB, dsvName, DimensionID, DimensionName, DimensionType); DataTable AttributeSet = asMeta.GET_SSAS_ATTRIBUTES_SET(sqlHelper, DimensionID); if (AttributeSet == null || AttributeSet.Rows == null || AttributeSet.Rows.Count == 0) { sqlHelper.ADD_MESSAGE_LOG( String.Format("[Create dimension] Dimension {0} has not any attributes, is it expected?", DimensionID) , MESSAGE_TYPE.DIMENSION , MESSAGE_RESULT_TYPE.Warning); } else { sqlHelper.ADD_MESSAGE_LOG( String.Format("[Create dimension] Adding {0} attributeds for dimension {1}", AttributeSet.Rows.Count.ToString(), DimensionID) , MESSAGE_TYPE.DIMENSION , MESSAGE_RESULT_TYPE.Normal); } foreach (DataRow attribute_row in AttributeSet.Rows) { String AttributeID = attribute_row["attribute_id"].ToString(); String AttributeName = attribute_row["attribbute_name"].ToString(); String DSVSchemaName = attribute_row["dsv_schema_name"].ToString(); String DBColumn = attribute_row["key_column_db_column"].ToString(); String OleDbType = attribute_row["key_column_oledb_type"].ToString(); String AttributeUsage = attribute_row["attribute_usage"].ToString(); String NameColumn = attribute_row["name_column"].ToString(); String Visible = attribute_row["visible"].ToString(); String AttHierEnabled = attribute_row["atthier_enabled"].ToString(); String OrderBy = attribute_row["order_by"].ToString(); Microsoft.AnalysisServices.OrderBy attribute_order_by = Microsoft.AnalysisServices.OrderBy.Name; if (OrderBy.ToLower() == "key") { attribute_order_by = Microsoft.AnalysisServices.OrderBy.Key; } AS_API.ADD_ATTRIBUTE_TO_DIMENSION( sqlHelper, DSV, dim, DataSourceName, DBColumn, AttributeID, AttributeName, AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME(OleDbType), AS_API_HELPER.GET_SSAS_ATTRIBUTE_USAGE_BY_NAME(AttributeUsage), NameColumn, Convert.ToBoolean(Visible), Convert.ToBoolean(AttHierEnabled), attribute_order_by ); } DataTable AttributeRelationShipSet = asMeta.GET_SSAS_ATTRIBUTE_RELATION_SHIPS_SET(sqlHelper, DimensionID); sqlHelper.ADD_MESSAGE_LOG(String.Format("[Create dimension] Adding {0} attribute relationships for dimension {1}", AttributeRelationShipSet.Rows.Count.ToString(), DimensionID) , MESSAGE_TYPE.ATTRIBUTE_RELATIONSHIP , MESSAGE_RESULT_TYPE.Normal); foreach (DataRow row in AttributeRelationShipSet.Rows) { String BasedAttributeID = row["based_attribute_id"].ToString(); String RelatedAttributeID = row["related_attribute_id"].ToString(); String RelationShipType = row["relationship_type"].ToString(); Microsoft.AnalysisServices.RelationshipType AttributeRelationShipType = AS_API_HELPER.GET_SSAS_ATTRIBUTE_RELATION_SHIP_TYPE_BY_NAME(RelationShipType); AS_API.ADD_ATTRIBUTE_RELATIONSHIP( sqlHelper, dim, BasedAttributeID, RelatedAttributeID, AttributeRelationShipType); } DataTable HierarchiesSet = asMeta.GET_SSAS_HIERARCHIES_SET(sqlHelper, DimensionID); sqlHelper.ADD_MESSAGE_LOG( String.Format("[Create dimension] Adding {0} hierarchy levels for dimension {1}", HierarchiesSet.Rows.Count.ToString(), DimensionID) , MESSAGE_TYPE.HIERARCHIES , MESSAGE_RESULT_TYPE.Normal); foreach (DataRow row in HierarchiesSet.Rows) { String HierarchyName = row["hierarchy_name"].ToString(); String LevelName = row["level_name"].ToString(); String LevelID = row["level_id"].ToString(); String SourceAttributeID = row["source_attribute_id"].ToString(); AS_API.ADD_ATTRIBUTE_HIERACHIES( sqlHelper, dim, HierarchyName, LevelName, SourceAttributeID); sqlHelper.ADD_MESSAGE_LOG( "[Create dimension->Hierarchy] |" + new string('_', Convert.ToInt16(LevelID)) + LevelName , MESSAGE_TYPE.HIERARCHIES , MESSAGE_RESULT_TYPE.Normal); } sqlHelper.ADD_MESSAGE_LOG( "[Create dimension] Updating changes of dimension objects.." , MESSAGE_TYPE.DIMENSION , MESSAGE_RESULT_TYPE.Normal); dim.Update(); sqlHelper.ADD_MESSAGE_LOG( "[Create dimension] Succeed to add changes to dimension objects.." , MESSAGE_TYPE.DIMENSION , MESSAGE_RESULT_TYPE.Normal); } } catch (Exception ex) { sqlHelper.ADD_MESSAGE_LOG("[Create dimension] " + ex.Message.ToString(), MESSAGE_TYPE.ADD_DIMENSION, MESSAGE_RESULT_TYPE.Error); throw (ex); } }