protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition) { string actualCode = expectedCode; CError.WriteLine("***Exception"); CError.WriteLineIgnore(e.ToString()); CError.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber"); CError.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition"); CError.Compare(actualCode, expectedCode, "ec" + e.Message); }
protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition) { string actualCode = expectedCode; CError.WriteLine("***Exception"); CError.WriteLineIgnore(e.ToString()); CError.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber"); CError.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition"); CError.Compare(actualCode, expectedCode, "ec" + e.Message); }
private void CompareException(XmlException e, string ec, Exception inner, int ln, int lp) { CError.WriteLine(e); CError.Compare((object)e.InnerException, (object)inner, "InnerException"); CError.Compare(e.LineNumber, ln, "LineNumber"); CError.Compare(e.LinePosition, lp, "LinePosition"); string s1 = e.StackTrace; Type t = e.GetType(); Exception e2 = e.GetBaseException(); int i = e.GetHashCode(); CError.Compare(!String.IsNullOrEmpty(e.Message), "Message"); string s3 = e.ToString(); }
private void CompareException(XmlException e, string ec, Exception inner, int ln, int lp) { CError.WriteLine(e); CError.Compare((object)e.InnerException, (object)inner, "InnerException"); CError.Compare(e.LineNumber, ln, "LineNumber"); CError.Compare(e.LinePosition, lp, "LinePosition"); string s1 = e.StackTrace; Type t = e.GetType(); Exception e2 = e.GetBaseException(); int i = e.GetHashCode(); CError.Compare(!String.IsNullOrEmpty(e.Message), "Message"); string s3 = e.ToString(); }
private static string RepairXmlFile(string xmlFile, XmlException xmlException) { var message = "There was an error loading this XML file! Do you wish to attempt a repair?"; #if DEBUG message += xmlException.ToString(); #endif DialogResult response = MessageBox.Show(message, "Error loading XML", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (response == DialogResult.Yes) { string safeFile = Path.GetTempFileName(); using (StreamReader inputReader = new StreamReader(xmlFile)) { using (StreamWriter outputWriter = File.AppendText(safeFile)) { string currentLine; while (null != (currentLine = inputReader.ReadLine())) { var replacedSpecialChars = Regex.Replace(currentLine, "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]", string.Empty); var fixedConspirator = replacedSpecialChars.Replace("</conspirator>", "</conspirator_hfid>"); if (fixedConspirator.Contains("<interrogator_hfid>")) { var fixedInterrogator = fixedConspirator.Replace("</convicted_hfid>", "</interrogator_hfid>"); outputWriter.WriteLine(fixedInterrogator); } else { outputWriter.WriteLine(fixedConspirator); } } outputWriter.Close(); } inputReader.Close(); } //DialogResult overwrite = // MessageBox.Show( // "Repair completed. Would you like to overwrite the original file with the repaired version? (Note: No effect if opened from an archive)", // "Repair Completed", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //if (overwrite == DialogResult.Yes) //{ // File.Delete(xmlFile); // File.Copy(safeFile, xmlFile); // return xmlFile; //} return(safeFile); } return(null); }
public static IEnumerable <TraceData> ReadTracesFromFile(string path) { var xr = XmlTextReader.Create(path, new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment }); xr.Read(); do { if (xr.NodeType == XmlNodeType.Element && xr.Name.Equals("E2ETraceEvent")) { var xdr = xr.ReadSubtree(); xdr.Read(); XElement xd = null; XmlException xe = null; try { xd = (XElement)XDocument.ReadFrom(xdr); } catch (XmlException e) { xe = e; } if (xe == null) { var traceData = ParseTraceData(xd); if (traceData.HasValue) { yield return(traceData.Value); } } else { var exceptionInfo = new TraceData(); exceptionInfo.Content = new XElement("Exception"); exceptionInfo.Content.Value = xe.ToString(); yield return(exceptionInfo); break; } } } while (xr.ReadToNextSibling("E2ETraceEvent")); }
private void ReportExceptionForETW(XmlException exception) { using (IETWTracer etwTracer = PSETWTracerFactory.GetETWTracer(PSKeyword.Serializer)) etwTracer.AnalyticChannel.WriteError(PSEventId.Serializer_XmlExceptionWhenDeserializing, PSOpcode.Exception, PSTask.Serialization, (object)exception.LineNumber, (object)exception.LinePosition, (object)exception.ToString()); }
private static void ReportExceptionForETW(XmlException exception) { PSEtwLog.LogAnalyticError(PSEventId.Serializer_XmlExceptionWhenDeserializing, PSOpcode.Exception, PSTask.Serialization, PSKeyword.Serializer | PSKeyword.UseAlwaysAnalytic, new object[] { exception.LineNumber, exception.LinePosition, exception.ToString() }); }