void BackgroundWorker_SaveMeasuresAndCalcColumns(object sender, DoWorkEventArgs e)
        {
            var cmdProducer = new ServerCommandProducer(_database.Name, _database.CompatibilityLevel, _database.Cubes[0].Name);

            try
            {
                var bw = sender as BackgroundWorker;
                bw.DoWork -= new DoWorkEventHandler(BackgroundWorker_SaveMeasuresAndCalcColumns);

                LogLine("Begin saving measures.");

                string viewText = e.Argument as string;
                var    mc       = MeasuresContainer.ParseDaxScript(viewText);

                LogLine("Begin transaction.");
                using (var cmd = new AdomdCommand("@CommandText", _adomdConn))
                {
                    cmd.Parameters.Add(new AdomdParameter("CommandText", cmdProducer.ProduceBeginTransaction()));
                    cmd.ExecuteNonQuery();
                }

                LogLine("Alter MDX script.");
                using (var cmd = new AdomdCommand("@CommandText", _adomdConn))
                {
                    cmd.Parameters.Add(new AdomdParameter("CommandText", cmdProducer.ProduceAlterMdxScript(mc.Measures)));
                    cmd.ExecuteNonQuery();
                }

                LogLine("Run ProcessRecalc.");
                using (var cmd = new AdomdCommand("@CommandText", _adomdConn))
                {
                    cmd.Parameters.Add(new AdomdParameter("CommandText", cmdProducer.ProduceProcessRecalc()));
                    cmd.ExecuteNonQuery();
                }


                LogLine("Commit transaction.");
                using (var cmd = new AdomdCommand("@CommandText", _adomdConn))
                {
                    cmd.Parameters.Add(new AdomdParameter("CommandText", cmdProducer.ProduceCommitTransaction()));
                    cmd.ExecuteNonQuery();
                }

                LogLine("End saving measures.");
            }
            catch (Exception ex)
            {
                using (var cmd = new AdomdCommand("@CommandText", _adomdConn))
                {
                    cmd.Parameters.Add(new AdomdParameter("CommandText", cmdProducer.ProduceRollbackTransaction()));
                    cmd.ExecuteNonQuery();
                }

                LogError("Error while saving measures. " + ex.ToString());
            }
        }
예제 #2
0
        public static MeasuresContainer ParseXmla(string text)
        {
            try
            {
                var database = ServerCommandProducer.GetDatabase(text);
                Debug.Assert(database != null);

                return(CreateFromXmlDatabase(database));
            }
            catch (Exception exception)
            {
                throw new DaxException(
                          $@"Error while parsing Xmla.
Message: {exception.Message}
Input text: {text}", exception);
            }
        }
예제 #3
0
        /// <summary>
        /// Update input XMLA with the measures of this object.
        /// </summary>
        /// <param name="text">input XMLA text</param>
        /// <exception cref="ArgumentException">Exception if text is null or whitespace</exception>
        /// <returns>updated XMLA with measures from this object</returns>
        public string UpdateMeasuresInXmla(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException(nameof(text) + " is empty");
            }

            var document = XDocument.Parse(text);

            var producer          = new ServerCommandProducer(text);
            var newScript         = producer.ProduceAlterScriptElement(this);
            var newScriptDocument = XDocument.Parse(newScript);

            document.Descendants(NS + "MdxScript").First().ReplaceWith(newScriptDocument.Root);

            return(document.ToString(SaveOptions.OmitDuplicateNamespaces));
        }