예제 #1
0
        private void ExecInternal(ProjectItem projItem, DataModelingSandbox sandbox)
        {
#if DENALI || SQL2014
            var db = sandbox.Database;
#else
            var db = ((DataModelingSandboxAmo)sandbox.Impl).Database;
#endif
            // extract deployment information
            DeploymentSettings deploySet = new DeploymentSettings(projItem);

            ApplicationObject.StatusBar.Progress(true, "Deploying Tabular Database", 3, 5);
            // Connect to Analysis Services
            Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
            svr.Connect(deploySet.TargetServer);
            ApplicationObject.StatusBar.Progress(true, "Deploying Tabular Database", 4, 5);
            // execute the xmla
            try
            {
                Microsoft.AnalysisServices.Scripter scr = new Microsoft.AnalysisServices.Scripter();

                Database targetDB = svr.Databases.FindByName(deploySet.TargetDatabase);
                if (targetDB == null)
                {
                    throw new System.Exception(
                              string.Format("A database called {0} could not be found on the {1} server",
                                            deploySet.TargetDatabase, deploySet.TargetServer));
                }
                StringBuilder     sb  = new StringBuilder();
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = true;
                xws.ConformanceLevel   = ConformanceLevel.Fragment;
                XmlWriter xwrtr = XmlWriter.Create(sb, xws);
                // TODO - do we need different code for JSON based models??
                scr.ScriptAlter(new Microsoft.AnalysisServices.MajorObject[] { db }, xwrtr, true);

                // update the MDX Script
                XmlaResultCollection xmlaRC = svr.Execute(sb.ToString());
                if (xmlaRC.Count == 1 && xmlaRC[0].Messages.Count == 0)
                {
                    // all OK - 1 result - no messages
                }
                else
                {
                    StringBuilder sbErr = new StringBuilder();
                    for (int iRC = 0; iRC < xmlaRC.Count; iRC++)
                    {
                        for (int iMsg = 0; iMsg < xmlaRC[iRC].Messages.Count; iMsg++)
                        {
                            sbErr.AppendLine(xmlaRC[iRC].Messages[iMsg].Description);
                        }
                    }
                    MessageBox.Show(sbErr.ToString(), "BIDSHelper - Deploy Tabular Database");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "BIDSHelper - Deploy Tabular Database - Exception");
                package.Log.Exception("Deploy Tabular Database Failed", ex);
            }
        }
        public static List <DimensionUsage> GetTabularDimensionUsage(DataModelingSandboxWrapper sandbox, bool bIsBusMatrix)
        {
            //Cube c = sandbox.Cube;
            DataModelingSandbox tomSandbox = sandbox.GetSandbox();

            List <CubeDimension>  listCubeDimensions = new List <CubeDimension>();
            List <DimensionUsage> dimUsage           = new List <DimensionUsage>();

            List <DataModelingTable> listDimensions = new List <DataModelingTable>();

            foreach (DataModelingTable table in tomSandbox.Tables)
            {
                bool bFoundVisibleAttribute = false;
                foreach (DataModelingColumn col in table.Columns)
                {
                    if (!table.IsPrivate && !col.IsPrivate && col.IsAttributeHierarchyQueriable)
                    {
                        bFoundVisibleAttribute = true;
                        break;
                    }
                }
                if (bFoundVisibleAttribute)
                {
                    listDimensions.Add(table);
                }

                bool bFoundVisibleMeasure = false;
                foreach (DataModelingMeasure m in sandbox.Measures)
                {
                    if (!m.IsPrivate && m.Table == table.Name)
                    {
                        bFoundVisibleMeasure = true;
                        break;
                    }
                }
                if (!bFoundVisibleMeasure && bIsBusMatrix)
                {
                    continue;
                }

                List <DimensionUsage> tmp = RecurseTabularRelationships(table, table, bIsBusMatrix, new List <Microsoft.AnalysisServices.BackEnd.Relationship>(), false);
                dimUsage.AddRange(tmp);

                if (bFoundVisibleAttribute && bFoundVisibleMeasure) //if this table had a measure but no dimension relationships (except to itself)
                {
                    DimensionUsage du = new DimensionUsage("Fact", table, table);
                    dimUsage.Add(du);
                }
                else if (tmp.Count == 0 && bIsBusMatrix && bFoundVisibleMeasure) //if this table with a measure had no dimension relationships, add it as such...
                {
                    DimensionUsage du = new DimensionUsage(string.Empty, table, null);
                    dimUsage.Add(du);
                }
            }

            List <DataModelingTable> listTables = new List <DataModelingTable>(sandbox.GetSandbox().Tables);

            //remove dimensions in relationships or hidden or not having any visible columns
            foreach (DimensionUsage du in dimUsage)
            {
                for (int i = 0; i < listTables.Count; i++)
                {
                    bool bFoundVisibleAttribute = false;
                    foreach (DataModelingColumn col in listTables[i].Columns)
                    {
                        if (!col.IsPrivate && col.IsAttributeHierarchyQueriable)
                        {
                            bFoundVisibleAttribute = true;
                            break;
                        }
                    }

                    if (!bFoundVisibleAttribute || listTables[i].Name == du.DimensionName || listTables[i].IsPrivate)
                    {
                        listTables.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
            }

            //add any dimensions which aren't related to any fact tables
            foreach (DataModelingTable cd in listTables)
            {
                DimensionUsage du = new DimensionUsage(string.Empty, null, cd);
                dimUsage.Add(du);
            }

            return(dimUsage);
        }
        private void ExecInternal(ProjectItem projItem, DataModelingSandbox sandbox)
        {
            //sandbox.
            // extract deployment information
                DeploymentSettings deploySet = new DeploymentSettings(projItem);

                        ApplicationObject.StatusBar.Progress(true, "Deploying Tabular Database", 3, 5);
                        // Connect to Analysis Services
                        Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
                        svr.Connect(deploySet.TargetServer);
                        ApplicationObject.StatusBar.Progress(true, "Deploying Tabular Database", 4, 5);
                        // execute the xmla
            try
            {
                Microsoft.AnalysisServices.Scripter scr = new Microsoft.AnalysisServices.Scripter();

                Database targetDB = svr.Databases.FindByName(deploySet.TargetDatabase);
                if (targetDB == null)
                {
                    throw new System.Exception(
                        string.Format("A database called {0} could not be found on the {1} server",
                                      deploySet.TargetDatabase, deploySet.TargetServer));
                }
                StringBuilder sb = new StringBuilder();
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = true;
                xws.ConformanceLevel = ConformanceLevel.Fragment;
                XmlWriter xwrtr = XmlWriter.Create(sb, xws);
                scr.ScriptAlter(new Microsoft.AnalysisServices.MajorObject[] {sandbox.Database}, xwrtr, true);

                // update the MDX Script
                XmlaResultCollection xmlaRC = svr.Execute(sb.ToString());
                if (xmlaRC.Count == 1 && xmlaRC[0].Messages.Count == 0)
                {
                    // all OK - 1 result - no messages    
                }
                else
                {
                    StringBuilder sbErr = new StringBuilder();
                    for (int iRC = 0; iRC < xmlaRC.Count; iRC++)
                    {
                        for (int iMsg = 0; iMsg < xmlaRC[iRC].Messages.Count; iMsg++)
                        {
                            sbErr.AppendLine(xmlaRC[iRC].Messages[iMsg].Description);
                        }
                    }
                    MessageBox.Show(sbErr.ToString(), "BIDSHelper - Deploy Tabular Database");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "BIDSHelper - Deploy Tabular Database - Exception");
            }
        }