public static Boolean HandleLogicalColumns(XmlNodeList trueColumns, CubeTable currentTable) { // // Summary: // Determines if a cube column // from the DSV is based on the // database (non logical) or based // on a calculation (logical). // Adds the column to the input // table if logical. // if (trueColumns.Item(0).Attributes["msprop:IsLogical"] != null) { if (trueColumns.Item(0).Attributes.GetNamedItem("msprop:IsLogical").Value.ToString() == "True") { CubeColumn myLogicalColumn = new CubeColumn { CubeColumnName = trueColumns.Item(0).Attributes.GetNamedItem("msprop:DbColumnName").Value.ToString() }; currentTable.LogicalColumns.Add(myLogicalColumn); // Return true to indicate the column is logical return(true); } } // Return false to indicate the column is not logical return(false); }
private List <CubeTable> GetCubeTables(string cubePath) { List <CubeTable> foundTables = new List <CubeTable>(); // Create, configure and load xml items and values XmlDocument myXmlCube = new XmlDocument(); myXmlCube = loadCube(cubePath); // Determine xpath to search for tables XmlNodeList nodes; string xDimPath = "/~ns~:Batch/~ns~:Alter/~ns~:ObjectDefinition/~ns~:Database/" + "~ns~:Dimensions/~ns~:Dimension"; string xPath = "/~ns~:Attributes/~ns~:Attribute/~ns~:KeyColumns/~ns~:KeyColumn/~ns~:Source"; // Read the cube's nodes based on the xPath expression nodes = ArtifactReader.getArtifactNodes(xPath, myXmlCube, xDimPath); string checkNode = null; foreach (XmlNode node in nodes) { CubeTable currentTable = foundTables.Find(x => x.CubeTableName.Equals(node.FirstChild.InnerText)); // Check if a new table is presented if (currentTable is null) { // Add cube table currentTable = new CubeTable(); currentTable.CubeTableName = node.FirstChild.InnerText; checkNode = currentTable.CubeTableName; // Add db ref table // Find db table name and schema XmlNodeList trueTables; xPath = $"/~ns~:Batch/~ns~:Alter/~ns~:ObjectDefinition/~ns~:Database/~ns~:DataSourceViews/" + $"~ns~:DataSourceView/~ns~:Schema/xs:schema/xs:element/xs:complexType/xs:choice/" + $"xs:element[@name=\'{node.FirstChild.InnerText}\']"; trueTables = ArtifactReader.getArtifactNodes(xPath, myXmlCube); // Add findings to property list string trueTableName, trueSchemaName; trueTableName = trueTables.Item(0).Attributes.GetNamedItem("msprop:DbTableName").Value.ToString(); trueSchemaName = trueTables.Item(0).Attributes.GetNamedItem("msprop:DbSchemaName").Value.ToString(); // Concat the schema and table name and store it as table name currentTable.TableName = trueSchemaName + "." + trueTableName; // Add table to output foundTables.Add(currentTable); } // Find matching db column name XmlNodeList trueColumns; xPath = $"/~ns~:Batch/~ns~:Alter/~ns~:ObjectDefinition/~ns~:Database/~ns~:DataSourceViews/" + $"~ns~:DataSourceView/~ns~:Schema/xs:schema/xs:element/xs:complexType/xs:choice/" + $"xs:element[@name=\'{currentTable.CubeTableName}\']/xs:complexType/xs:sequence/" + $"xs:element[@name=\'{node.LastChild.InnerText}\']"; trueColumns = ArtifactReader.getArtifactNodes(xPath, myXmlCube); // Do not include logical columns. These columns // are computed in the data source view and do not // directly correspond to database column. // Add them to a special logical column list for // later use. if (CubeColumn.HandleLogicalColumns(trueColumns, currentTable)) { break; } // Get cube column data type from the cube Tuple <string, string> dataType = CubeColumn.GetCubeColumnDataType(trueColumns); // TODO: Get database column data type from the dacpac // Add cube columns to table CubeColumn myColumn = new CubeColumn() { ColumnName = trueColumns.Item(0).Attributes.GetNamedItem("msprop:DbColumnName").Value.ToString(), CubeColumnName = node.LastChild.InnerText, CubeColumnDataType = dataType.Item1, CubeColumnDataLength = dataType.Item2 }; currentTable.AddColumn(myColumn); } return(foundTables); }