Exemplo n.º 1
0
        public DaxStudioTraceEventArgs(Microsoft.AnalysisServices.TraceEventArgs e, string powerBIFileName)
        {
            StartTime         = DateTime.Now;
            EventClassName    = e.EventClass.ToString();
            EventSubclassName = e.EventSubclass.ToString();
            Enum.TryParse <DaxStudioTraceEventClass>(EventClassName, out _eventClass);
            Enum.TryParse <DaxStudioTraceEventSubclass>(EventSubclassName, out _eventSubclass);

            TextData = e.TextData;

            /*
             * switch (e.EventClass)
             * {
             *  case TraceEventClass.QueryEnd:
             *      Duration = e.Duration;
             *      DatabaseName = e.DatabaseName;
             *      StartTime = e.StartTime;
             *      NTUserName = e.NTUserName;
             *
             *      break;
             *  case TraceEventClass.VertiPaqSEQueryCacheMatch:
             *      StartTime = e.StartTime;
             *      break;
             *  case TraceEventClass.CommandBegin:
             *
             *  default:
             *      throw new ArgumentException($"No mapping for the event class {e.EventClass.ToString()} was found");
             *
             * }
             */
            if (e.EventClass != TraceEventClass.CommandBegin)
            {
                // not all events have CpuTime
                try
                {
                    CpuTime = e.CpuTime;
                }
                catch (ArgumentNullException)
                {
                    CpuTime = 0;
                }
                // not all events have a duration
                try
                {
                    Duration = e.Duration;
                }
                catch (ArgumentNullException)
                {
                    Duration = 0;
                }
            }

            if (e.NTUserName != null)
            {
                NTUserName = e.NTUserName;
            }

            if (e.DatabaseName != null)
            {
                DatabaseName = e.DatabaseName;
                if (!string.IsNullOrEmpty(powerBIFileName))
                {
                    DatabaseFriendlyName = powerBIFileName;
                }
                else
                {
                    DatabaseFriendlyName = DatabaseName;
                }
            }
            try
            {
                StartTime = e.CurrentTime;
                StartTime = e.StartTime;
            }
            catch (NullReferenceException)
            {
            }

            try
            {
                RequestID = e[TraceColumn.RequestID];
            }
            catch
            { }
        }
        public DaxStudioTraceEventArgs(Microsoft.AnalysisServices.TraceEventArgs e, string powerBiFileName)
        {
            StartTime         = DateTime.Now;
            EventClassName    = e.EventClass.ToString();
            EventSubclassName = e.EventSubclass.ToString();
            Enum.TryParse <DaxStudioTraceEventClass>(EventClassName, out _eventClass);
            Enum.TryParse <DaxStudioTraceEventSubclass>(EventSubclassName, out _eventSubclass);

            TextData             = e.TextData;
            RequestID            = e[TraceColumn.RequestID];
            DatabaseName         = e.DatabaseName;
            DatabaseFriendlyName = !string.IsNullOrEmpty(powerBiFileName)? powerBiFileName : DatabaseName;

            switch (e.EventClass)
            {
            case TraceEventClass.QueryBegin:
                RequestProperties = e.RequestProperties;
                RequestParameters = e.RequestParameters;
                NTUserName        = e.NTUserName;
                StartTime         = e.StartTime;
                break;

            case TraceEventClass.QueryEnd:
                Duration   = e.Duration;
                StartTime  = e.StartTime;
                NTUserName = e.NTUserName;
                EndTime    = e.EndTime;
                CpuTime    = e.CpuTime;
                break;

            case TraceEventClass.DirectQueryEnd:
                Duration  = e.Duration;
                EndTime   = e.EndTime;
                CpuTime   = e.CpuTime;
                StartTime = e.StartTime;
                break;

            case TraceEventClass.VertiPaqSEQueryEnd:
                StartTime  = e.StartTime;
                CpuTime    = e.CpuTime;
                Duration   = e.Duration;
                NTUserName = e.NTUserName;
                break;

            case TraceEventClass.AggregateTableRewriteQuery:
            case TraceEventClass.VertiPaqSEQueryCacheMatch:
                StartTime  = e.CurrentTime;
                NTUserName = e.NTUserName;
                break;

            case TraceEventClass.CommandBegin:
                string s = e[TraceColumn.StartTime] ?? e[TraceColumn.CurrentTime] ?? string.Empty;
                DateTime.TryParse(s, out var startTime);
                StartTime  = startTime;
                NTUserName = e.NTUserName;
                break;

            case TraceEventClass.DiscoverBegin:
            case TraceEventClass.DAXQueryPlan:
                // no additional properties captured, the plan is stored in the text field
                break;

            default:
                throw new ArgumentException($"No mapping for the event class {e.EventClass.ToString()} was found");
            }

            //if (e.EventClass != TraceEventClass.CommandBegin)
            //{
            //    // not all events have CpuTime
            //    try
            //    {
            //        CpuTime = e.CpuTime;
            //    }
            //    catch (ArgumentNullException)
            //    {
            //        CpuTime = 0;
            //    }
            //    // not all events have a duration
            //    try
            //    {
            //        Duration = e.Duration;
            //    }
            //    catch (ArgumentNullException)
            //    {
            //        Duration = 0;
            //    }
            //}

            //if (e.EventClass == TraceEventClass.QueryBegin)
            //{
            //    RequestParameters = e.RequestParameters;
            //    RequestProperties = e.RequestProperties;
            //}

            //if (e.NTUserName != null)
            //    NTUserName = e.NTUserName;

            //if (e.DatabaseName != null)
            //{
            //    DatabaseName = e.DatabaseName;
            //    if (!string.IsNullOrEmpty(powerBIFileName)) DatabaseFriendlyName = powerBIFileName;
            //    else DatabaseFriendlyName = DatabaseName;
            //}
            //try
            //{
            //    StartTime = e.CurrentTime;
            //    StartTime = e.StartTime;
            //}
            //catch (NullReferenceException)
            //{

            //}

            //try
            //{
            //    RequestID = e[TraceColumn.RequestID];
            //}
            //catch
            //{ }
        }