Beispiel #1
0
        public UserState(string statusText, MdxScriptCommand command, StateChangeType changeType)
        {
            StatusText = statusText;

            if (command != null)
            {
                CommandNumber = command.CommandNumber;
            }
            else
            {
                CommandNumber = -1;
            }

            Command    = command;
            ChangeType = changeType;
        }
Beispiel #2
0
        public static SortedDictionary <int, MdxScriptCommand> GetCommandsFromText(string sMDX, int commandNr)
        {
            MDXSplitStatus          status = MDXSplitStatus.InMDX;
            MdxScriptCommand        newCmd;
            List <MdxScriptCommand> nestedScopes = new List <MdxScriptCommand>();
            int           iPos              = 0;
            int           iLastSplit        = 0;
            int           blockCommentCount = 0;
            List <string> arrSplits         = new List <string>();
            SortedDictionary <int, MdxScriptCommand> commands = new SortedDictionary <int, MdxScriptCommand>();

            while (iPos < sMDX.Length)
            {
                try
                {
                    if (status == MDXSplitStatus.InMDX)
                    {
                        if (sMDX.SafeSubstring(iPos, 2) == "/*")
                        {
                            status            = MDXSplitStatus.InBlockComment;
                            blockCommentCount = 1;
                            iPos += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 2) == "--")
                        {
                            status = MDXSplitStatus.InDashComment;
                            iPos  += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 2) == "//")
                        {
                            status = MDXSplitStatus.InSlashComment;
                            iPos  += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "[")
                        {
                            status = MDXSplitStatus.InBrackets;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "\"")
                        {
                            status = MDXSplitStatus.InDoubleQuotes;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "'")
                        {
                            status = MDXSplitStatus.InSingleQuotes;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == ";") //split on semicolon only when it's in general MDX context
                        {
                            newCmd = new MdxScriptCommand(sMDX.SafeSubstring(iLastSplit, iPos - iLastSplit) + ";", commandNr, nestedScopes.Count);

                            if (nestedScopes.Count > 0)
                            {
                                newCmd.ParentCommand = nestedScopes.Last();
                            }

                            if (newCmd.CommandType == MdxScriptCommandType.SCOPE)
                            {
                                nestedScopes.Add(newCmd);
                            }
                            else if (newCmd.CommandType == MdxScriptCommandType.END_SCOPE)
                            {
                                nestedScopes.Last().CorrespondingEndScopeCommand = newCmd;
                                nestedScopes.RemoveAt(nestedScopes.Count - 1);
                            }

                            commands.Add(newCmd.CommandNumber, newCmd);
                            commandNr++;

                            iLastSplit = iPos + 1;
                        }
                    }
                    else if (status == MDXSplitStatus.InDashComment || status == MDXSplitStatus.InSlashComment)
                    {
                        if (sMDX.SafeSubstring(iPos, Environment.NewLine.Length) == Environment.NewLine)
                        {
                            status = MDXSplitStatus.InMDX;
                        }
                    }
                    else if (status == MDXSplitStatus.InBlockComment)
                    {
                        // nested InBlockComments are possible so we need to count how often we have entered an InBlockComment
                        if (sMDX.SafeSubstring(iPos, 2) == "/*")
                        {
                            blockCommentCount += 1;
                            iPos += 1;
                        }
                        if (sMDX.SafeSubstring(iPos, 2) == "*/")
                        {
                            // check if its the last InBlockComment-Block open
                            if (blockCommentCount == 1)
                            {
                                status            = MDXSplitStatus.InMDX;
                                blockCommentCount = 0;
                                iPos += 1;
                            }
                            else // close the last InBlockComment-Block
                            {
                                blockCommentCount -= 1;
                                iPos += 1;
                            }
                        }
                    }
                    else if (status == MDXSplitStatus.InBrackets)
                    {
                        if (sMDX.SafeSubstring(iPos, 1) == "]" && sMDX.SafeSubstring(iPos, 2) == "]]")
                        {
                            iPos += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "]" && sMDX.SafeSubstring(iPos, 2) != "]]")
                        {
                            status = MDXSplitStatus.InMDX;
                        }
                    }
                    else if (status == MDXSplitStatus.InDoubleQuotes)
                    {
                        if (sMDX.SafeSubstring(iPos, 1) == "\"" && sMDX.SafeSubstring(iPos, 2) == "\"\"")
                        {
                            iPos += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "\"" && sMDX.SafeSubstring(iPos, 2) != "\"\"")
                        {
                            status = MDXSplitStatus.InMDX;
                        }
                    }
                    else if (status == MDXSplitStatus.InSingleQuotes)
                    {
                        if (sMDX.SafeSubstring(iPos, 1) == "'" && sMDX.SafeSubstring(iPos, 2) == "''")
                        {
                            iPos += 1;
                        }
                        else if (sMDX.SafeSubstring(iPos, 1) == "'" && sMDX.SafeSubstring(iPos, 2) != "''")
                        {
                            status = MDXSplitStatus.InMDX;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                iPos++;
            }
            return(commands);
        }
Beispiel #3
0
 public UserState(MdxScriptCommand command) : this(null, command)
 {
 }
Beispiel #4
0
 public UserState(MdxScriptCommand command, StateChangeType changeType) : this(null, command, changeType)
 {
 }
Beispiel #5
0
 public UserState(string statusText, MdxScriptCommand command) : this(statusText, command, StateChangeType.NotSpecified)
 {
 }
Beispiel #6
0
        public void DebugMdxScript(string query)
        {
            MdxScriptCommand clearCalcs = MdxScriptCommand.ClearCalculationsCommand;
            MdxScriptCommand cmdRec;

            if (string.IsNullOrEmpty(query) && !string.IsNullOrEmpty(_query))
            {
                query = _query;
            }

            query = query.Trim().TrimEnd(';');

            CheckQuery(query);

            using (AdomdConnection con = new AdomdConnection(this.ConnectionString))
            {
                con.Open();
                _currentSsasSessionID = con.SessionID;

                if (this.ClearCache)
                {
                    ReportProgress(0, new UserState("Clearing Cache ...", _clearCacheCmd, StateChangeType.ExecutionStarted));
                    MdxScriptHelper.ExecuteXMLA(con, MdxScriptHelper.ClearCacheCommand(_dbName, _cubeName));
                    ReportProgress(0, new UserState("Done!", _clearCacheCmd, StateChangeType.ExecutionFinished));
                }

                if (this.CreateMembersAndSetsFirst)
                {
                    PreExecuteCreateStatements();
                }

                // execute reference query on cold cache
                if (this.PreExecuteQueryColdCache && _preExecCmd_Cold != null)
                {
                    ReportProgress(0, new UserState("Running Reference Query (Cold Cache) ...", _preExecCmd_Cold, StateChangeType.ExecutionStarted));
                    _preExecCmd_Cold.ExecuteTestQuery(con, query, _queryCommandTimeout);
                    ReportProgress(0, new UserState("Done!", _preExecCmd_Cold, StateChangeType.ExecutionFinished));
                }

                // execute reference query on warm cache
                if (this.PreExecuteQueryWarmCache && _preExecCmd_Warm != null)
                {
                    ReportProgress(0, new UserState("Running Reference Query (Cold Cache) ...", _preExecCmd_Warm, StateChangeType.ExecutionStarted));
                    _preExecCmd_Warm.ExecuteTestQuery(con, query, _queryCommandTimeout);
                    ReportProgress(0, new UserState("Done!", _preExecCmd_Warm, StateChangeType.ExecutionFinished));
                }

                // clear existing calculations
                ReportProgress(0, new UserState("Running CLEAR CALCULATIONS ...", StateChangeType.PreExecute));
                MdxScriptCommand.ClearCalculationsCommand.Execute(con);

                // execute reference query without calculations
                if (this.PreExecuteQueryNoCalcs && _preExecCmd_NoCalcs != null)
                {
                    ReportProgress(0, new UserState("Running Reference Query (No Script) ...", _preExecCmd_NoCalcs, StateChangeType.ExecutionStarted));
                    _preExecCmd_NoCalcs.ExecuteTestQuery(con, query, _queryCommandTimeout);
                    ReportProgress(0, new UserState("Done!", _preExecCmd_NoCalcs, StateChangeType.ExecutionFinished));
                }

                if (this.ValueTracking)
                {
                    MdxScriptCommand.CreateValueTrackingCommand.Execute(con);
                    query = MdxScriptHelper.EnsureCellProperty(query, MdxScriptCommand.CellPropertyValueTracking);
                }

                foreach (MdxScriptCommand cmd in _commands.Values)
                {
                    if (base.CancellationPending)
                    {
                        _executionCancelled = true;
                        return;
                    }

                    ReportProgress((cmd.CommandNumber * 100) / this.CommandCount, new UserState("Executing MDX Script command ...", cmd, StateChangeType.ExecutionStarted));
                    cmd.Execute(con);
                    ReportProgress((cmd.CommandNumber * 100) / this.CommandCount, new UserState("Done!", cmd, StateChangeType.ExecutionFinished));



                    // execute the query if the current MdxScriptCommand is PerformanceRelevant or Verbose
                    if (cmd.IsPerformanceRelevant || this.Verbose)
                    {
                        if (this.ValueTracking)
                        {
                            MdxScriptCommand.DropValueTrackingCommand.Execute(con);
                            MdxScriptCommand.CreateValueTrackingCommand.Execute(con);
                        }

                        ReportProgress((cmd.CommandNumber * 100) / this.CommandCount, new UserState("Running Query ...", cmd, StateChangeType.ExecutionStarted));
                        cmd.ExecuteTestQuery(con, query, _queryCommandTimeout);

                        if (this.ValueTracking)
                        {
                            List <string> currentCellProperties = MdxScriptHelper.GetDistinctCellProperties(cmd.Results, MdxScriptCommand.CellPropertyValueTracking);
                            if (currentCellProperties.Contains(MdxScriptCommand.ValueChangeValueTracking))
                            {
                                cmd.IsEffective = true;

                                cmdRec = cmd;
                                // also set all parent SCOPE commands and their END SCOPE as Effective
                                while (cmdRec.ParentCommand != null)
                                {
                                    cmdRec.ParentCommand.IsEffective = true;
                                    cmdRec.ParentCommand.CorrespondingEndScopeCommand.IsEffective = true;

                                    cmdRec = cmdRec.ParentCommand;
                                }
                            }
                        }

                        ReportProgress((cmd.CommandNumber * 100) / this.CommandCount, new UserState("Done!", cmd, StateChangeType.ExecutionFinished));
                    }
                    else
                    {
                        // report finished if not yet reported due to IsPerformanceRelevant
                        ReportProgress((cmd.CommandNumber * 100) / this.CommandCount, new UserState("Done!", cmd, StateChangeType.ExecutionFinished));
                    }
                }

                // execute reference query with all calculations again
                if (this.PostExecuteQuery && _postExecCmd != null)
                {
                    if (this.ClearCache)
                    {
                        ReportProgress(0, new UserState("Clearing Cache ...", _clearCacheCmd, StateChangeType.ExecutionStarted));
                        MdxScriptHelper.ExecuteXMLA(con, MdxScriptHelper.ClearCacheCommand(_dbName, _cubeName));
                        ReportProgress(0, new UserState("Done!", _clearCacheCmd, StateChangeType.ExecutionFinished));
                    }

                    ReportProgress(0, new UserState("Running Query (No Script) ...", _postExecCmd, StateChangeType.ExecutionStarted));
                    _postExecCmd.ExecuteTestQuery(con, query, _queryCommandTimeout);
                    ReportProgress(0, new UserState("Done!", _postExecCmd, StateChangeType.ExecutionFinished));
                }
            }
            _currentSsasSessionID = null;
        }