Ejemplo n.º 1
0
        public static bool Save(Microsoft.AnalysisServices.Server server, OutputContext output, IMajorObject obj)
        {
            var builder = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(builder, new XmlWriterSettings {
                OmitXmlDeclaration = true
            })) {
                Scripter.WriteAlter(xmlWriter, obj, true, true);
                xmlWriter.Flush();
            }

            var command = builder.ToString();

            output.Debug(() => command);
            var results = server.Execute(command);

            if (results.Count > 0)
            {
                foreach (XmlaResult result in results)
                {
                    if (result.Messages.Count > 0)
                    {
                        foreach (XmlaMessage message in result.Messages)
                        {
                            output.Error(message.Description);
                        }
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XmlTextWriter xmlwrite = new XmlTextWriter(textBoxFile.Text, System.Text.Encoding.UTF8);

            xmlwrite.Formatting  = Formatting.Indented;
            xmlwrite.Indentation = 2;

            Scripter.WriteAlter(xmlwrite, mg1, true, true);
            xmlwrite.Close();
            MessageBox.Show("MeasureGroup definition scripted to the :" + textBoxFile.Text + " \n");

            this.Close();
        }
        public static string BuildDeployScript(Database database, PartitionEnhancedDeployModes partMode, RoleEnhancedDeployModes roleMode)
        {
            //string script = "";
            Database dbCopy = database.Clone();
            Scripter scr    = new Scripter();

            if (partMode == PartitionEnhancedDeployModes.NoPartitionsDeployed ||
                partMode == PartitionEnhancedDeployModes.DeployButKeepExisting)
            {
                foreach (Cube c in  dbCopy.Cubes)
                {
                    foreach (MeasureGroup mg in c.MeasureGroups)
                    {
                        mg.Partitions.Clear();
                    }
                }
            }

            if (roleMode == RoleEnhancedDeployModes.NoRolesDeployed ||
                roleMode == RoleEnhancedDeployModes.DeployButKeepExisting)
            {
                dbCopy.Roles.Clear();
            }

            StringBuilder sb = new StringBuilder();

            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Indent             = true;
            xws.Encoding           = Encoding.UTF8;
            xws.OmitXmlDeclaration = true;

            //XmlWriter xw = XmlWriter.Create(sb,xws);
            XmlWriter xw = XmlWriter.Create("c:\\data\\EnhancedDeploy.xmla", xws);

            Scripter.WriteStartBatch(xw, true);
            // script roles first as the other objects may have a dependency on
            // a new role.
            if (roleMode == RoleEnhancedDeployModes.DeployButKeepExisting)
            {
                foreach (Role r in database.Roles)
                {
                    Scripter.WriteAlter(xw, r, true, true);
                }
            }

            // script out dbcopy
            Scripter.WriteAlter(xw, dbCopy, true, true);

            // script out partitions
            if (partMode == PartitionEnhancedDeployModes.DeployButKeepExisting)
            {
                foreach (Cube c in database.Cubes)
                {
                    foreach (MeasureGroup mg in c.MeasureGroups)
                    {
                        foreach (Partition p in mg.Partitions)
                        {
                            //script partition as create/AlterIfExists
                        }
                    }
                }
            }
            Scripter.WriteEndBatch(xw);
            xw.Flush();
            //sb.ToString();
            xw.Close();

            //TODO - need to replace object expansion tag if we are keeping existing

            return(sb.ToString());
        }