Exemple #1
0
        private void OnTraceEventInternal(object sender, xlAmo.TraceEventArgs e)
        {
            // we are using CommandBegin as a "heartbeat" to check if the trace
            // has started capturing events
            if (!_traceStarted)
            {
                Log.Debug("{class} {mothod} Pending TraceEvent: {eventClass}", "QueryTraceEngineExcel", "OnTraceEventInternal", e.EventClass.ToString());
                StopTimer();
                _traceStarted = true;
                _connection.Close(false);
                _connection.Dispose();
                _connection = null;
                Status      = QueryTraceStatus.Started;
                TraceStarted?.Invoke(this, null);

                var f = new System.IO.FileInfo(_trace.Parent.Name);
                _friendlyServerName = f.Name;
            }
            else
            {
                Log.Debug("{class} {method} TraceEvent: {eventClass}", "QueryTraceEngineExcel", "OnTraceEventInternal", e.EventClass.ToString());
                //OnTraceEvent(e);
                _capturedEvents.Add(CreateTraceEventArg(e, _friendlyServerName));
                if (e.EventClass == xlAmo.TraceEventClass.QueryEnd)
                {
                    // Raise an event with the captured events
                    TraceCompleted?.Invoke(this, _capturedEvents);
                    // reset the captured events collection
                    _capturedEvents = new List <DaxStudioTraceEventArgs>();
                }
            }
        }
Exemple #2
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;
            }
        }
        private void Start()
        {
            try
            {
                Log.Verbose("{class} {method} {message}", "QueryTraceEngine", "Start", "entering");
                if (_trace != null)
                {
                    if (_trace.IsStarted || Status == QueryTraceStatus.Starting || Status == QueryTraceStatus.Started)
                    {
                        return; // exit here if trace is already started
                    }
                }
                if (Status != QueryTraceStatus.Started)
                {
                    Status = QueryTraceStatus.Starting;
                }
                Log.Verbose("{class} {method} {event}", "QueryTraceEngine", "Start", "Connecting to: " + _connectionString);
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                ConfigureTrace(_connectionString, _connectionType, _sessionId, _applicationName, _databaseName, _filterForCurrentSession);
                _connection = new ADOTabular.ADOTabularConnection(_connectionString, _connectionType);
                try
                {
                    _connection.Open();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "{class} {method} {message}", "QueryTraceEngine", "Start (connection.open catch)", ex.Message);
                    // try again?
                    _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();
                }

                _startingTimer.Interval = 500;
                _startingTimer.Elapsed += OnTimerElapsed;
                _startingTimer.Enabled  = true;
                _startingTimer.Start();
                utcPingStart = DateTime.UtcNow;
                // Wait for Trace to become active
                Log.Verbose("{class} {method} {message}", "QueryTraceEngine", "Start", "exiting");
            }
            catch (Exception ex)
            {
                RaiseError(ex);
                //Log.Error("{class} {method} {message}","QueryTraceEngine" , "Start", ex.Message);
            }
        }