Exemplo n.º 1
0
        public void CancelAsyncWithKill()
        {
            _executionCancelled = true;
            base.CancelAsync();

            if (_executionRunning && !string.IsNullOrEmpty(_currentSsasSessionID))
            {
                using (AdomdConnection con = new AdomdConnection(this.ConnectionString))
                {
                    con.Open();
                    // ignore errors as the session may already has been cancelled or finished
                    MdxScriptHelper.ExecuteXMLA(con, MdxScriptHelper.CancelSessionCommand(_currentSsasSessionID), true);
                }
            }
        }
Exemplo n.º 2
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;
        }