Beispiel #1
0
        private List <DataSource> getCubeDataSource(string cubePath)
        {
            List <DataSource> myDataSources = new List <DataSource>();

            // Load current cube
            XmlDocument myXmlCube = new XmlDocument();

            myXmlCube = loadCube(cubePath);

            //// Determine xpath to search for dsv
            XmlNodeList nodes;
            string      xBasePath = "/~ns~:Batch/~ns~:Alter/~ns~:ObjectDefinition/~ns~:Database";
            string      xPath     = "/~ns~:DataSources/~ns~:DataSource/~ns~:ConnectionString";

            // Return nodes with data source(s)
            nodes = ArtifactReader.getArtifactNodes(xPath, myXmlCube, xBasePath);

            // TODO: Check for multiple connection stringsB
            foreach (XmlNode node in nodes)
            {
                DataSource dataSource = new DataSource();
                dataSource._dsConnString  = node.InnerText;
                dataSource._dsInitCatalog = getCubeInitialCatalog(dataSource);

                myDataSources.Add(dataSource);
            }

            return(myDataSources);
        }
        // Get the data type from the cube
        public static Tuple <string, string> GetCubeColumnDataType(XmlNodeList nodes)
        {
            //
            // Summary:
            //      Finds the cube data type
            //      and corresponding metadata
            //      such as length
            //

            Tuple <string, string> tuple = null;
            string dataType = null;
            string length   = "not applicable";

            // datatype selection is always based on the first node in the NodeList

            // datatypes int, decimal, double, dateTime and boolean are
            // stored in the "type" attribute
            if (nodes.Item(0).Attributes[$"type"] != null)
            {
                dataType = ArtifactReader.FindXmlAttribute(nodes, "type");
            }
            // string datatype and character length are stored
            // in the child nodes
            else if (nodes.Item(0).HasChildNodes)
            {
                dataType = ArtifactReader.FindXmlAttribute(nodes.Item(0).ChildNodes, "base");
                length   = ArtifactReader.FindXmlAttribute(nodes.Item(0).ChildNodes, "value");
            }

            tuple = Tuple.Create(dataType.Replace("xs:", ""), length.Replace("xs:", ""));
            return(tuple);
        }
Beispiel #3
0
        private List <Table> getDbTables(string modelPath, string tableOrView)
        {
            List <Table> tables = new List <Table>();

            XmlDocument myDatabase = new XmlDocument();

            myDatabase.Load(modelPath);

            // Determine xpath to search for dsv
            XmlNodeList nodes;
            string      xPath = tableOrView == "table" ? "/~ns~:DataSchemaModel/~ns~:Model/~ns~:Element[@Type='SqlTable']/@Name" : "/~ns~:DataSchemaModel/~ns~:Model/~ns~:Element[@Type='SqlView']/@Name";

            nodes = ArtifactReader.getArtifactNodes(xPath, myDatabase);

            foreach (XmlNode x in nodes)
            {
                Table table = new Table();
                table.TableName = x.InnerText.Replace("[", "").Replace("]", "");
                table.TableType = tableOrView == "table" ? "table" : "view";

                tables.Add(table);
                Console.WriteLine($"Found table {x.InnerText}");

                string xPathCols = xPath.Replace("]/@Name", $" and @Name='{x.InnerText}']");
                xPathCols += tableOrView == "table" ? "/~ns~:Relationship/~ns~:Entry/~ns~:Element[@Type='SqlSimpleColumn']/@Name" : "/~ns~:Relationship/~ns~:Entry/~ns~:Element[@Type='SqlComputedColumn']/@Name";

                XmlNodeList columns;

                columns = ArtifactReader.getArtifactNodes(xPathCols, myDatabase);

                foreach (XmlNode c in columns)
                {
                    Column column = new Column();

                    column.ColumnName = simplifyColumnName(c.InnerText.Replace("[", "").Replace("]", ""));
                    table.AddColumn(column);
                    Console.WriteLine($"Found column {c.InnerText} and added it to the {tableOrView}.");
                }
            }
            return(tables);
        }
Beispiel #4
0
        private string getCubeName(string cubePath)
        {
            // Create, configure and load xml items and values
            XmlDocument myXmlCube = new XmlDocument();

            myXmlCube = loadCube(cubePath);

            // Determine xpath to search for cube name
            XmlNodeList nameNodes;
            string      xNamePath = "/~ns~:Batch/~ns~:Alter/~ns~:ObjectDefinition/~ns~:Database/~ns~:Name";

            nameNodes = ArtifactReader.getArtifactNodes(xNamePath, myXmlCube);

            if (nameNodes.Count == 1)
            {
                return(nameNodes.Item(0).InnerText.ToString());
            }
            else
            {
                // TODO: throw error
                Console.WriteLine("Multiple names where found for a cube. No name was passed to the cube property.");
                return(null);
            }
        }
Beispiel #5
0
        private DataSource getDbDataSource(string modelPath)
        {
            DataSource dataSource = new DataSource();

            string metadataPath = Path.GetDirectoryName(modelPath) + "\\DacMetadata.xml";

            XmlDocument myDatabase = new XmlDocument();

            myDatabase.Load(metadataPath);

            // Determine xpath to search for dsv
            XmlNodeList nodes;
            string      xPath = "/~ns~:DacType/~ns~:Name";

            nodes = ArtifactReader.getArtifactNodes(xPath, myDatabase);

            foreach (XmlNode x in nodes)
            {
                dataSource._dsInitCatalog = x.InnerText;
                Console.WriteLine($"Found node {x.InnerText}");
            }

            return(dataSource);
        }
Beispiel #6
0
        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);
        }