Esempio n. 1
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_trace != null)
                    {
                        _trace.OnEvent -= OnTraceEventInternal;
                        _trace?.Drop();
                        _trace?.Dispose();
                        _trace = null;
                    }

                    _connection?.Dispose();
                    _connection = null;

                    _server?.Disconnect();
                    _server?.Dispose();
                    _server = null;

                    if (_startingTimer != null)
                    {
                        _startingTimer.Stop();
                        _startingTimer.Elapsed -= OnTimerElapsed;
                        _startingTimer.Dispose();
                        _startingTimer = null;
                    }
                }

                disposedValue = true;
            }
        }
Esempio n. 2
0
        private static void SetupTrace(xlAmo.Trace trace, List <DaxStudioTraceEventClass> events)
        {
            Log.Debug("{class} {method} {event}", "QueryTraceEngineExcel", "SetupTrace", "enter");
            trace.Events.Clear();
            // Add CommandBegin so we can catch the heartbeat events
            trace.Events.Add(TraceEventFactoryExcel.CreateTrace(xlAmo.TraceEventClass.CommandBegin));
            // Add QueryEnd so we know when to stop the trace
            trace.Events.Add(TraceEventFactoryExcel.CreateTrace(xlAmo.TraceEventClass.QueryEnd));

            // catch the events in the ITraceWatcher
            foreach (DaxStudioTraceEventClass eventClass in events)
            {
                // PowerPivot in Excel does not have direct query events, so skip it if makes it this far
                if (eventClass == DaxStudioTraceEventClass.DirectQueryEnd)
                {
                    continue;
                }

                var amoEventClass = (ExcelAmo.Microsoft.AnalysisServices.TraceEventClass)eventClass;
                if (trace.Events.Find(amoEventClass) != null)
                {
                    continue;
                }

                xlAmo.TraceEvent trcEvent = TraceEventFactoryExcel.CreateTrace(amoEventClass);
                trace.Events.Add(trcEvent);
            }
            trace.Update();
            Log.Debug("{class} {method} {event}", "QueryTraceEngineExcel", "SetupTrace", "exit");
        }
        public void Dispose()
        {
            if (_trace == null) return;
			_trace.OnEvent -= OnTraceEventInternal;
            _trace.Dispose();
			_trace = null;
        }
Esempio n. 4
0
        public void Start()
        {
            try
            {
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "entered");

                if (_trace != null)
                {
                    if (_trace.IsStarted || Status == QueryTraceStatus.Starting || Status == QueryTraceStatus.Started)
                    {
                        Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "exiting method - trace already started");
                        return; // if threturn; // exit here if trace is already startede trace is already running exit here
                    }
                }

                if (Status != QueryTraceStatus.Started)
                {
                    Status = QueryTraceStatus.Starting;
                }
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "Connecting to: " + _connectionString);
                //HACK - wait 1.5 seconds to allow trace to start
                //       using the ping method thows a connection was lost error when starting a second trace
                _connection = new ADOTabular.ADOTabularConnection($"{_originalConnectionString};SessionId={_sessionId}", _connectionType);
                _connection.Open();
                _trace = GetTrace();
                SetupTrace(_trace, Events);

                _trace.OnEvent += OnTraceEventInternal;
                _trace.Start();

                // create timer to "ping" the server with DISCOVER_SESSION requests
                // until the trace events start to fire.
                if (_startingTimer == null)
                {
                    _startingTimer = new Timer();
                }
                //HACK - wait 1.5 seconds to allow trace to start
                //       using the ping method thows a connection was lost error when starting a second trace
                _startingTimer.Interval = 300;
                _startingTimer.Elapsed += OnTimerElapsed;
                _startingTimer.Enabled  = true;
                _startingTimer.Start();
                utcPingStart = DateTime.UtcNow;
                // Wait for Trace to become active
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "exit");
            }
            catch (Exception ex)
            {
                OutputError($"Error starting trace: {ex.Message}");
                Log.Error("{class} {method} {message} {stacktrace}", "QueryTraceEngine", "Start", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 5
0
        //private void ServerPing()
        //{
        //    _server.StartXmlaRequest(ExcelAmo.Microsoft.AnalysisServices.XmlaRequestType.Execute);
        //    _server.EndXmlaRequest();
        //}

        private xlAmo.Trace GetTrace()
        {
            if (_trace == null)
            {
                Log.Debug("{class} {method} {event}", "QueryTraceEngineExcel", "GetTrace", "about to create new trace");
                _server = new xlAmo.Server();
                _server.Connect(_connectionString);
                _trace        = _server.Traces.Add(string.Format("DaxStudio_Trace_SPID_{0}", _sessionId));
                _trace.Filter = GetSessionIdFilter(_sessionId);
                // set default stop time in case trace gets disconnected
                //_trace.StopTime = DateTime.UtcNow.AddHours(24);
                Log.Debug("{class} {method} {event}", "QueryTraceEngineExcel", "GetTrace", "created new trace");
            }
            return(_trace);
        }
        private xlAmo.Trace GetTrace()
        {
            if (_trace == null)
              {

                  _server = new xlAmo.Server();
                  _server.Connect(_connectionString);
                  _trace = _server.Traces.Add( string.Format("DaxStudio_Trace_SPID_{0}", _sessionId));
                  _trace.Filter = GetSessionIdFilter(_sessionId);
                  _trace.OnEvent += OnTraceEventInternal;
              }
              return _trace;
        }
 public void Stop()
 {
     Status = QueryTraceStatus.Stopping;
     if (_trace != null)
     {
         _trace.OnEvent -= OnTraceEventInternal;
         try
         {
             _trace.Drop();
             _trace = null;
             Status = QueryTraceStatus.Stopped;
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.WriteLine(e);
         }
     }
     _traceStarted = false;
 }
        //public void Clear()
        //{
        //    _trace.Events.Clear();
        //}
        public void Start()
        {
            if (_trace != null)
                if (_trace.IsStarted || Status == QueryTraceStatus.Starting )
                    return; // if the trace is already running exit here

            if (Status != QueryTraceStatus.Started)  Status = QueryTraceStatus.Starting;
            _connection = new ADOTabular.ADOTabularConnection(_connectionString, _connectionType);
            _connection.Open();
            _trace = GetTrace();
            SetupTrace(_trace, _eventsToCapture);
            _trace.Start();

            // create timer to "ping" the server with DISCOVER_SESSION requests
            // until the trace events start to fire.
            if (_startingTimer == null)
                _startingTimer = new Timer();
            _startingTimer.Interval = 300;  //TODO - make time interval shorter?
            _startingTimer.Elapsed += OnTimerElapsed;
            _startingTimer.Enabled = true;
            _startingTimer.Start();
            utcPingStart = DateTime.UtcNow;
            // Wait for Trace to become active
        }