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>();
                }
            }
        }
        private DaxStudioTraceEventArgs CreateTraceEventArg(xlAmo.TraceEventArgs traceEvent)
        {
            long cpuTime;
            long duration;

            // not all events have CpuTime
            try
            {
                cpuTime = traceEvent.CpuTime;
            }
            catch (ArgumentNullException)
            {
                cpuTime = 0;
            }
            // not all events have a duration
            try
            {
                duration = traceEvent.Duration;
            }
            catch (ArgumentNullException)
            {
                duration = 0;
            }

            var dsEvent = new DaxStudioTraceEventArgs(
                traceEvent.EventClass.ToString(),
                traceEvent.EventSubclass.ToString(),
                duration,
                cpuTime,
                traceEvent.TextData);

            return(dsEvent);
        }
        private static DaxStudioTraceEventArgs CreateTraceEventArg(xlAmo.TraceEventArgs traceEvent, string xlsxFile)
        {
            long     cpuTime;
            long     duration;
            DateTime eventTime = DateTime.Now;

            // not all events have CpuTime
            try
            {
                cpuTime = traceEvent.CpuTime;
            }
            catch (ArgumentNullException)
            {
                cpuTime = 0;
            }

            // not all events have a duration
            try
            {
                duration = traceEvent.Duration;
            }
            catch (ArgumentNullException)
            {
                duration = 0;
            }
            try
            {
                eventTime = traceEvent.CurrentTime;
                eventTime = traceEvent.StartTime;
            }
            catch (NullReferenceException) { }
            catch (ArgumentNullException)
            {
                //do nothing - leave whatever value worked DateTime.Now / CurrentTime / StartTime
            }


            var dsEvent = new DaxStudioTraceEventArgs(
                traceEvent.EventClass.ToString(),
                traceEvent.EventSubclass.ToString(),
                duration,
                cpuTime,
                traceEvent.TextData,
                xlsxFile,
                eventTime);

            return(dsEvent);
        }