Пример #1
0
 private void CrimsonToE2eThreadProc(object o)
 {
     if (o != null && o is InternalCrimsonToE2eConvertingParameter)
     {
         InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter = (InternalCrimsonToE2eConvertingParameter)o;
         if (!string.IsNullOrEmpty(internalCrimsonToE2eConvertingParameter.SourceFileName) && !string.IsNullOrEmpty(internalCrimsonToE2eConvertingParameter.ConvertedFilename))
         {
             FileStream fileStream  = null;
             FileStream fileStream2 = null;
             try
             {
                 fileStream = Utilities.CreateFileStreamHelper(internalCrimsonToE2eConvertingParameter.SourceFileName);
                 if (fileStream.Length > 0)
                 {
                     List <InternalTargetTraceRecord> list = new List <InternalTargetTraceRecord>();
                     fileStream2 = Utilities.CreateFileStreamHelper(internalCrimsonToE2eConvertingParameter.ConvertedFilename, FileMode.Create, FileAccess.Write, FileShare.Read);
                     XmlTextReader xmlTextReader = new XmlTextReader(fileStream, XmlNodeType.Element, null);
                     XmlWriter     xmlWriter     = new XmlTextWriter(fileStream2, Encoding.UTF8);
                     xmlTextReader.WhitespaceHandling = WhitespaceHandling.None;
                     xmlTextReader.MoveToContent();
                     while (InternalReadToXml(xmlTextReader, "Event"))
                     {
                         string text = xmlTextReader.ReadOuterXml();
                         if (!string.IsNullOrEmpty(text))
                         {
                             InternalTargetTraceRecord item = InternalConstructTargetTraceRecordXml(text);
                             list.Add(item);
                         }
                         internalCrimsonToE2eConvertingParameter.Percentage = (int)((double)fileStream.Position / (double)fileStream.Length);
                         internalCrimsonToE2eConvertingParameter.TraceConvertedEvent.Set();
                     }
                     OutputCrimsonToE2EResults(list, xmlWriter);
                     xmlWriter.Flush();
                 }
             }
             catch (LogFileException ex)
             {
                 InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter2 = internalCrimsonToE2eConvertingParameter;
                 internalCrimsonToE2eConvertingParameter2.Exception = new FileConverterException(internalCrimsonToE2eConvertingParameter2.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, ex.Message, ex);
             }
             catch (ArgumentException e)
             {
                 InternalCrimsonToE2eConvertingParameter internalCrimsonToE2eConvertingParameter3 = internalCrimsonToE2eConvertingParameter;
                 internalCrimsonToE2eConvertingParameter3.Exception = new FileConverterException(internalCrimsonToE2eConvertingParameter3.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, SR.GetString("MsgCannotWriteToFile") + internalCrimsonToE2eConvertingParameter.ConvertedFilename + SR.GetString("MsgCannotWriteToFileEnd"), e);
             }
             catch (XmlException ex2)
             {
                 errorReport.ReportErrorToUser(new FileConverterException(internalCrimsonToE2eConvertingParameter.SourceFileName, internalCrimsonToE2eConvertingParameter.ConvertedFilename, SR.GetString("MsgErrorOccursOnConvertCrimson") + ex2.Message + SR.GetString("MsgCannotWriteToFileEnd"), ex2));
             }
             finally
             {
                 Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
                 Utilities.CloseStreamWithoutException(fileStream2, isFlushStream: false);
                 internalCrimsonToE2eConvertingParameter.IsFinished = true;
                 internalCrimsonToE2eConvertingParameter.TraceConvertedEvent.Set();
             }
         }
     }
 }
Пример #2
0
 private bool ContainsUserDataAndTraceRecord(InternalTargetTraceRecord trace, XmlElement elem)
 {
     if (elem.Name == "System.Diagnostics.UserData")
     {
         foreach (XmlElement childNode in elem.ChildNodes)
         {
             if (childNode.Name == "Data" && childNode.InnerXml.Trim().StartsWith("&lt;TraceRecord", StringComparison.Ordinal))
             {
                 trace.isTraceRecord = true;
                 trace.recordText    = childNode.InnerText;
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #3
0
        private void SetupInternalTargetTraceRecordInSystemXmlElement(XmlElement element, InternalTargetTraceRecord trace)
        {
            if (element != null && trace != null)
            {
                switch (element.Name)
                {
                case "EventID":
                    trace.eventID = element.InnerText;
                    break;

                case "Provider":
                    if (element.HasAttribute("Name"))
                    {
                        trace.sourceName = element.Attributes["Name"].Value;
                    }
                    if (element.HasAttribute("Guid"))
                    {
                        trace.guid = element.Attributes["Guid"].Value;
                    }
                    AppendXmlElementToStringBuilder(trace.sbUndefinedXmlInSystemXmlElement, element);
                    break;

                case "Level":
                {
                    byte result = 0;
                    if (byte.TryParse(element.InnerText, out result))
                    {
                        trace.level = MofUtils.ConvertByteToTraceEventType(result);
                    }
                    else
                    {
                        trace.level = (TraceEventType)0;
                    }
                    break;
                }

                case "TimeCreated":
                    if (element.HasAttribute("SystemTime") && !string.IsNullOrEmpty(element.Attributes["SystemTime"].Value))
                    {
                        try
                        {
                            trace.createdDateTime = DateTime.Parse(element.Attributes["SystemTime"].Value, CultureInfo.CurrentUICulture);
                        }
                        catch (FormatException)
                        {
                            trace.createdDateTime = DateTime.MinValue;
                        }
                        catch (ArgumentNullException)
                        {
                            trace.createdDateTime = DateTime.MinValue;
                        }
                    }
                    break;

                case "Correlation":
                    if (element.HasAttribute("ActivityID"))
                    {
                        trace.activityID = element.Attributes["ActivityID"].Value;
                        if (element.HasAttribute("RelatedActivityID"))
                        {
                            trace.relatedActivityID = element.Attributes["RelatedActivityID"].Value;
                        }
                    }
                    break;

                case "Execution":
                    if (element.HasAttribute("ProcessID"))
                    {
                        trace.processID = element.Attributes["ProcessID"].Value;
                    }
                    if (element.HasAttribute("ThreadID"))
                    {
                        trace.threadID = element.Attributes["ThreadID"].Value;
                    }
                    break;

                case "Channel":
                    trace.channel = element.InnerText;
                    break;

                case "Computer":
                    trace.computerName = element.InnerText;
                    break;

                case "Security":
                    if (element.HasAttribute("UserID"))
                    {
                        trace.userSid = element.Attributes["UserID"].Value;
                    }
                    break;

                case "Task":
                case "OpCode":
                case "Keywords":
                case "EventRecordID":
                    AppendXmlElementToStringBuilder(trace.sbUndefinedXmlInSystemXmlElement, element);
                    break;
                }
            }
        }
Пример #4
0
 private void SetupInternalTargetTraceRecordInRenderingInfoXmlElement(XmlElement element, InternalTargetTraceRecord trace)
 {
     if (element != null && trace != null)
     {
         string name = element.Name;
         if (!(name == "Message"))
         {
             if (name == "Level" && !string.IsNullOrEmpty(element.InnerText))
             {
                 TraceEventType traceEventType = TraceEventTypeFromString(element.InnerText);
                 if (traceEventType != 0)
                 {
                     trace.level = traceEventType;
                 }
             }
         }
         else if (!string.IsNullOrEmpty(element.InnerText))
         {
             trace.description = element.InnerText;
         }
     }
 }
Пример #5
0
 private void SetupInternalTargetTraceRecordInOthersXmlElement(XmlElement element, InternalTargetTraceRecord trace)
 {
     if (element != null)
     {
         trace?.sbXmlExt.Append(element.OuterXml);
     }
 }
Пример #6
0
 private void SetupInternalTargetTraceRecordInEventDataXmlElement(XmlElement element, InternalTargetTraceRecord trace)
 {
     if (element != null && trace != null && element.Name == "Data" && element.HasAttribute("name"))
     {
         if (element.Attributes["name"].Value == "Error")
         {
             trace.level = TraceEventType.Error;
         }
         if (!string.IsNullOrEmpty(element.Attributes["name"].Value))
         {
             if (!trace.eventDataSections.ContainsKey(element.Attributes["name"].Value))
             {
                 trace.eventDataSections.Add(element.Attributes["name"].Value, element.InnerText);
             }
             else
             {
                 trace.eventDataSections[element.Attributes["name"].Value] = element.InnerText;
             }
         }
     }
 }
Пример #7
0
 private InternalTargetTraceRecord InternalConstructTargetTraceRecordXml(string xml)
 {
     try
     {
         if (!string.IsNullOrEmpty(xml))
         {
             InternalTargetTraceRecord internalTargetTraceRecord = new InternalTargetTraceRecord();
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.LoadXml(xml);
             XmlElement documentElement = xmlDocument.DocumentElement;
             if (documentElement != null && documentElement.Name == "Event")
             {
                 foreach (XmlElement childNode in documentElement.ChildNodes)
                 {
                     if (childNode.Name == "System")
                     {
                         foreach (XmlElement childNode2 in childNode.ChildNodes)
                         {
                             SetupInternalTargetTraceRecordInSystemXmlElement(childNode2, internalTargetTraceRecord);
                         }
                     }
                     else if (childNode.Name == "EventData")
                     {
                         foreach (XmlElement childNode3 in childNode.ChildNodes)
                         {
                             SetupInternalTargetTraceRecordInEventDataXmlElement(childNode3, internalTargetTraceRecord);
                         }
                     }
                     else if (childNode.Name == "RenderingInfo")
                     {
                         foreach (XmlElement childNode4 in childNode.ChildNodes)
                         {
                             SetupInternalTargetTraceRecordInRenderingInfoXmlElement(childNode4, internalTargetTraceRecord);
                         }
                         internalTargetTraceRecord.sbXmlExt.Append(childNode.OuterXml);
                     }
                     else if (childNode.Name == "UserData")
                     {
                         foreach (XmlElement childNode5 in childNode.ChildNodes)
                         {
                             if (ContainsUserDataAndTraceRecord(internalTargetTraceRecord, childNode5))
                             {
                                 break;
                             }
                         }
                         SetupInternalTargetTraceRecordInOthersXmlElement(childNode, internalTargetTraceRecord);
                     }
                     else
                     {
                         SetupInternalTargetTraceRecordInOthersXmlElement(childNode, internalTargetTraceRecord);
                     }
                 }
             }
             return(internalTargetTraceRecord);
         }
     }
     catch (XmlException)
     {
     }
     return(null);
 }
Пример #8
0
 private void InternalWriterTargetTraceRecord(InternalTargetTraceRecord trace, XmlWriter writer)
 {
     if (trace != null && writer != null)
     {
         try
         {
             writer.WriteStartElement("E2ETraceEvent", "http://schemas.microsoft.com/2004/06/E2ETraceEvent");
             writer.WriteStartElement("System", "http://schemas.microsoft.com/2004/06/windows/eventlog/system");
             writer.WriteStartElement("EventID");
             writer.WriteString((!string.IsNullOrEmpty(trace.eventID)) ? trace.eventID : "0");
             writer.WriteEndElement();
             writer.WriteStartElement("Type");
             writer.WriteString("3");
             writer.WriteEndElement();
             writer.WriteStartElement("SubType");
             writer.WriteAttributeString("Name", trace.level.ToString());
             writer.WriteEndElement();
             writer.WriteStartElement("Level");
             int level = (int)trace.level;
             writer.WriteString(level.ToString(CultureInfo.CurrentCulture));
             writer.WriteEndElement();
             writer.WriteStartElement("TimeCreated");
             writer.WriteAttributeString("SystemTime", trace.createdDateTime.ToString(CultureInfo.CurrentUICulture));
             writer.WriteEndElement();
             writer.WriteStartElement("Source");
             writer.WriteAttributeString("Name", trace.sourceName);
             if (!string.IsNullOrEmpty(trace.guid))
             {
                 writer.WriteAttributeString("Id", trace.guid);
             }
             writer.WriteEndElement();
             writer.WriteStartElement("Correlation");
             writer.WriteAttributeString("ActivityID", trace.activityID);
             if (!string.IsNullOrEmpty(trace.relatedActivityID))
             {
                 writer.WriteAttributeString("RelatedActivityID", trace.relatedActivityID);
             }
             writer.WriteEndElement();
             writer.WriteStartElement("Execution");
             writer.WriteAttributeString("ProcessID", trace.processID);
             writer.WriteAttributeString("ThreadID", trace.threadID);
             writer.WriteEndElement();
             writer.WriteStartElement("Channel");
             writer.WriteString(trace.channel);
             writer.WriteEndElement();
             writer.WriteStartElement("Computer");
             writer.WriteString(trace.computerName);
             writer.WriteEndElement();
             writer.WriteStartElement("Security");
             if (!string.IsNullOrEmpty(trace.userSid))
             {
                 writer.WriteAttributeString("UserSid", trace.userSid);
             }
             writer.WriteEndElement();
             if (trace.sbUndefinedXmlInSystemXmlElement.Length != 0)
             {
                 try
                 {
                     writer.WriteRaw(trace.sbUndefinedXmlInSystemXmlElement.ToString());
                 }
                 catch (Exception e)
                 {
                     ExceptionManager.GeneralExceptionFilter(e);
                 }
             }
             writer.WriteEndElement();
             writer.WriteStartElement("ApplicationData");
             writer.WriteStartElement("TraceData");
             writer.WriteStartElement("DataItem");
             if (trace.isTraceRecord)
             {
                 writer.WriteRaw(trace.recordText);
             }
             else
             {
                 writer.WriteStartElement("TraceRecord", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
                 writer.WriteAttributeString("Severity", trace.level.ToString());
                 writer.WriteStartElement("TraceIdentifier");
                 writer.WriteString("");
                 writer.WriteEndElement();
                 writer.WriteStartElement("Description");
                 writer.WriteString((!string.IsNullOrEmpty(trace.description)) ? trace.description : trace.sourceName);
                 writer.WriteEndElement();
                 if (trace.eventDataSections.Count != 0 || trace.sbXmlExt.Length != 0)
                 {
                     writer.WriteStartElement("ExtendedData");
                     if (trace.eventDataSections.Count != 0)
                     {
                         foreach (string key in trace.eventDataSections.Keys)
                         {
                             writer.WriteStartElement(key);
                             writer.WriteString(trace.eventDataSections[key]);
                             writer.WriteEndElement();
                         }
                     }
                     if (trace.sbXmlExt.Length != 0)
                     {
                         try
                         {
                             writer.WriteRaw(trace.sbXmlExt.ToString());
                         }
                         catch (Exception e2)
                         {
                             ExceptionManager.GeneralExceptionFilter(e2);
                         }
                     }
                     writer.WriteEndElement();
                 }
                 writer.WriteEndElement();
             }
             writer.WriteEndElement();
             writer.WriteEndElement();
             writer.WriteEndElement();
             writer.WriteEndElement();
         }
         catch (InvalidOperationException)
         {
         }
         catch (ArgumentException)
         {
         }
     }
 }