private Exception HandleSaveException(Exception ex) { // log... FileLog log = LogSet.CreateFileLogger("Simple XML Dump Failure", FileLoggerFlags.Default, new GenericFormatter()); // dump... log.Error("Original error...", ex); // keys... List <object> testKeys = new List <object>(); foreach (object key in Keys) { testKeys.Add(key); } // while... object failKey = null; while (testKeys.Count > 0) { // also, go through and create a document with each value in it and see if you can suss it that way... XmlDocument testDoc = new XmlDocument(); XmlElement root = testDoc.CreateElement("Root"); testDoc.AppendChild(root); foreach (string key in testKeys) { this.SaveValueAsElement(root, key, this.InnerValues[key], SimpleXmlSaveMode.ReplaceExisting); } // out... try { string buf = testDoc.OuterXml; if (buf == null) { throw new InvalidOperationException("'buf' is null."); } if (buf.Length == 0) { throw new InvalidOperationException("'buf' is zero-length."); } // ok... if (failKey == null) { log.Info("OK - fail key was CLR null."); } else { log.InfoFormat("OK - fail key was: {0}", failKey); // value... object failValue = this.InnerValues[failKey]; log.InfoFormat("Fail value was: {0}", failValue); // builder... if (failValue is string) { StringBuilder builder = new StringBuilder(); string failString = (string)failValue; for (int index = 0; index < failString.Length; index++) { if (index > 0 && index % 16 == 0) { builder.Append("\r\n"); } builder.Append(((int)failString[index]).ToString("x")); builder.Append(" "); } // show... log.InfoFormat("Fail value hex dump:\r\n{0}", builder); } } // stop... break; } catch (Exception miniEx) { log.Info(string.Format("Double-check failed ({0}).\r\n-------------------------------------", testKeys.Count), miniEx); } // remove... failKey = testKeys[0]; log.InfoFormat("Key '{0}' removed...", failKey); testKeys.RemoveAt(0); } // dump... return(new InvalidOperationException(string.Format("An error occurred when saving the property bag to XML. A log file was written to: {0}", log.Path), ex)); }
/// <summary> /// Runs the supplied process. /// </summary> /// <param name="process"></param> public void Run(OperationDialogProcess process) { if (process == null) { throw new ArgumentNullException("process"); } // check... if (process.Context == null) { throw new InvalidOperationException("process.Context is null."); } // mbr - 2008-11-27 - if it doesn't have an operation, give it us... if (process.Context.InnerOperation == null || process.Context.DefaultInnerOperationUsed) { process.Context.InnerOperation = this; } // load called? if (!(this.LoadCalled)) { _runOnLoad = process; return; } // thread? if (_thread != null) { throw new InvalidOperationException("A thread is already running."); } // create... _thread = new ThreadUIHelper(this, this); // mbr - 10-05-2007 - changed this to create a log file if we haven't been given one explicitly... if (process.Context.HasInnerLog) { _thread.BoundLog = process.Context.InnerLog; } else { // log... FileLog log = LogSet.CreateFileLogger(process.GetType().Name, FileLoggerFlags.AddDateToFileName | FileLoggerFlags.EnsureNewFile | FileLoggerFlags.OwnFolder); if (log == null) { throw new InvalidOperationException("log is null."); } // set... _thread.BoundLog = log; } // events... _thread.Failed += new System.Threading.ThreadExceptionEventHandler(_thread_Failed); _thread.Succeeded += new ResultEventHandler(_thread_Succeeded); // run... _thread.RunAsync(process, "Run"); }