/// <summary> /// Display a WixException to the console. /// </summary> /// <param name="errorFileName">Default file name to display in the error.</param> /// <param name="shortAppName">Short app name (usually uppercase and 4 letter or less).</param> /// <param name="we">WixException to display.</param> public virtual void Display(string errorFileName, string shortAppName, WixException we) { if (!(we is WixFatalErrorException)) // don't display anything for fatal error exceptions { Console.WriteLine(this.GenerateMessageString(errorFileName, shortAppName, we)); } }
/// <summary> /// Creates a properly formatted message string. /// </summary> /// <param name="errorFileName">Default file name to display in the error.</param> /// <param name="shortAppName">Short app name (usually uppercase and 4 letter or less).</param> /// <param name="we">WixException to display.</param> /// <returns>Returns the application error code.</returns> protected string GenerateMessageString(string errorFileName, string shortAppName, WixException we) { StringBuilder messageBuilder = new StringBuilder(); ArrayList fileNames = new ArrayList(); if (null != we.SourceLineNumbers && 0 < we.SourceLineNumbers.Count) { bool first = true; foreach (SourceLineNumber sln in we.SourceLineNumbers) { if (sln.HasLineNumber) { if (first) { first = false; errorFileName = String.Format("{0}({1})", sln.FileName, sln.LineNumber); } fileNames.Add(String.Format("{0}: line {1}", sln.FileName, sln.LineNumber)); } else { if (first) { first = false; errorFileName = sln.FileName; } fileNames.Add(sln.FileName); } } } messageBuilder.AppendFormat("{0} : fatal error {1}{2:0000}: {3}", errorFileName, shortAppName, (int)we.Type, we.Message); if (this.sourceTrace) { messageBuilder.Append(Environment.NewLine); messageBuilder.Append(Environment.NewLine); if (0 == fileNames.Count) { messageBuilder.AppendFormat("Source trace unavailable.{0}", Environment.NewLine); } else { messageBuilder.AppendFormat("Source Trace:{0}", Environment.NewLine); foreach (string fileName in fileNames) { messageBuilder.AppendFormat(" at {0}{1}", fileName, Environment.NewLine); } } } return(messageBuilder.ToString()); }
/// <summary> /// Creates a properly formatted message string. /// </summary> /// <param name="errorFileName">Default file name to display in the error.</param> /// <param name="shortAppName">Short app name (usually uppercase and 4 letter or less).</param> /// <param name="we">WixException to display.</param> /// <returns>Returns the application error code.</returns> protected string GenerateMessageString(string errorFileName, string shortAppName, WixException we) { StringBuilder messageBuilder = new StringBuilder(); ArrayList fileNames = new ArrayList(); if (null != we.SourceLineNumbers && 0 < we.SourceLineNumbers.Count) { bool first = true; foreach (SourceLineNumber sln in we.SourceLineNumbers) { if (sln.HasLineNumber) { if (first) { first = false; errorFileName = String.Format("{0}({1})", sln.FileName, sln.LineNumber); } fileNames.Add(String.Format("{0}: line {1}", sln.FileName, sln.LineNumber)); } else { if (first) { first = false; errorFileName = sln.FileName; } fileNames.Add(sln.FileName); } } } messageBuilder.AppendFormat("{0} : fatal error {1}{2:0000}: {3}", errorFileName, shortAppName, (int)we.Type, we.Message); if (this.sourceTrace) { messageBuilder.Append(Environment.NewLine); messageBuilder.Append(Environment.NewLine); if (0 == fileNames.Count) { messageBuilder.AppendFormat("Source trace unavailable.{0}", Environment.NewLine); } else { messageBuilder.AppendFormat("Source Trace:{0}", Environment.NewLine); foreach (string fileName in fileNames) { messageBuilder.AppendFormat(" at {0}{1}", fileName, Environment.NewLine); } } } return messageBuilder.ToString(); }