public static string GetXml(NativeMethods.EventTrace trace)
        {
            EventKey eventKey = default(EventKey);

            eventKey.Guid    = trace.Header.Guid;
            eventKey.Type    = trace.Header.Type;
            eventKey.Version = trace.Header.Version;
            eventKey.Level   = trace.Header.Level;
            EventSchema eventSchema = GetEventSchema(eventKey);

            return(GetXml(trace, eventSchema));
        }
        private void EventCallback(ref NativeMethods.EventTrace et)
        {
            string text = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                text = MofUtils.GetXml(et);
                if (!string.IsNullOrEmpty(text))
                {
                    processor(new TraceEntry(text));
                }
            }
            catch (Exception e)
            {
                ExceptionManager.GeneralExceptionFilter(e);
                processor(new TraceEntry(null));
            }
        }
        public static string GetXml(NativeMethods.EventTrace trace, EventSchema es)
        {
            StringBuilder stringBuilder = new StringBuilder(string.Empty);

            stringBuilder.Append("<E2ETraceEvent xmlns=\"");
            stringBuilder.Append("http://schemas.microsoft.com/2004/06/E2ETraceEvent");
            stringBuilder.Append("\">");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("  <System xmlns=\"");
            stringBuilder.Append("http://schemas.microsoft.com/2004/06/windows/eventlog/system");
            stringBuilder.Append("\">");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("    <EventID>0</EventID>");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("    <Type>3</Type>");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("    <SubType>");
            stringBuilder.Append(trace.Header.Type.ToString(CultureInfo.InvariantCulture));
            stringBuilder.Append("</SubType>");
            stringBuilder.Append(Environment.NewLine);
            TraceEventType traceEventType = (TraceEventType)0;

            traceEventType = ConvertByteToTraceEventType(trace.Header.Level);
            StringBuilder stringBuilder2   = stringBuilder;
            CultureInfo   invariantCulture = CultureInfo.InvariantCulture;

            object[] obj = new object[1];
            uint     num = (uint)traceEventType;

            obj[0] = num.ToString(CultureInfo.InvariantCulture);
            stringBuilder2.Append(string.Format(invariantCulture, "    <Level>{0}</Level>", obj));
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("    <Version>0</Version>");
            stringBuilder.Append(Environment.NewLine);
            DateTime dateTime = DateTime.FromFileTime(trace.Header.TimeStamp);

            stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <TimeCreated SystemTime=\"{0}\"/>", new object[1]
            {
                dateTime.ToString("o", CultureInfo.InvariantCulture)
            }));
            stringBuilder.Append(Environment.NewLine);
            byte[] array = new byte[trace.MofLength];
            if (trace.MofLength != 0 && trace.MofData != IntPtr.Zero)
            {
                Marshal.Copy(trace.MofData, array, 0, (int)trace.MofLength);
            }
            int           pos               = 0;
            StringBuilder stringBuilder3    = new StringBuilder(string.Empty);
            string        activityId        = GuidNull;
            string        relatedActivityId = string.Empty;

            if (es == null)
            {
                stringBuilder3.Append(string.Format(CultureInfo.InvariantCulture, "    <Length>{0}</Length>", new object[1]
                {
                    trace.MofLength.ToString(CultureInfo.InvariantCulture)
                }) + Environment.NewLine);
            }
            else
            {
                for (int i = 1; i <= es.WmiDataTypes.Count; i++)
                {
                    if (!es.WmiDataTypes.ContainsKey(i) || array.GetUpperBound(0) == 0)
                    {
                        stringBuilder3.Append(string.Format(CultureInfo.InvariantCulture, "    <Length>{0}</Length>", new object[1]
                        {
                            trace.MofLength.ToString(CultureInfo.InvariantCulture)
                        }) + Environment.NewLine);
                        stringBuilder3.Append(string.Format(CultureInfo.InvariantCulture, "    <Error>Key {0} is missing from {1}: MOF does not match the trace</Error>", new object[2]
                        {
                            i.ToString(CultureInfo.InvariantCulture),
                            es.ManagementClass.ClassPath.ToString()
                        }) + Environment.NewLine);
                    }
                    GetXmlFromWmiDataType(stringBuilder3, es.WmiDataTypes[i], trace.MofData, array, ref pos, ref activityId, ref relatedActivityId);
                }
            }
            if (es == null)
            {
                stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Source Name=\"{0}\" ID=\"{1}\"/>", new object[2]
                {
                    trace.Header.Guid.ToString("B", CultureInfo.InvariantCulture),
                    trace.Header.Guid.ToString("B", CultureInfo.InvariantCulture)
                }));
                stringBuilder.Append(Environment.NewLine);
            }
            else
            {
                string text = es.ManagementClass.ClassPath.ToString();
                int    num2 = text.IndexOf(':');
                if (num2 > 0)
                {
                    text = text.Substring(num2 + 1);
                }
                stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Source Name=\"{0}\" ID=\"{1}\"/>", new object[2]
                {
                    text,
                    trace.Header.Guid.ToString("B")
                }));
                stringBuilder.Append(Environment.NewLine);
            }
            stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Correlation ActivityID=\"{0}\"", new object[1]
            {
                activityId
            }));
            if (!string.IsNullOrEmpty(relatedActivityId))
            {
                stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, " RelatedActivityID=\"{0}\"", new object[1]
                {
                    relatedActivityId
                }));
            }
            stringBuilder.Append("/>");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Execution ProcessID=\"{0}\" ThreadID=\"{1}\"/>", new object[2]
            {
                trace.Header.ProcessId.ToString(CultureInfo.InvariantCulture),
                trace.Header.ThreadId.ToString(CultureInfo.InvariantCulture)
            }));
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Channel />"));
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append(string.Format(CultureInfo.InvariantCulture, "    <Computer />"));
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("  </System>");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("  <ApplicationData>");
            stringBuilder.Append(Environment.NewLine);
            string value = stringBuilder3.ToString().Trim();

            if (!string.IsNullOrEmpty(value))
            {
                stringBuilder.Append("  <TraceData>");
                stringBuilder.Append(Environment.NewLine);
                stringBuilder.Append("  <DataItem>");
                stringBuilder.Append(Environment.NewLine);
                stringBuilder.Append(value);
                stringBuilder.Append("  ");
                stringBuilder.Append("  </DataItem>");
                stringBuilder.Append(Environment.NewLine);
                stringBuilder.Append("  </TraceData>");
                stringBuilder.Append(Environment.NewLine);
            }
            stringBuilder.Append("  </ApplicationData>");
            stringBuilder.Append(Environment.NewLine);
            stringBuilder.Append("</E2ETraceEvent>");
            stringBuilder.Append(Environment.NewLine);
            return(stringBuilder.ToString());
        }