コード例 #1
0
 public void Run(Action <ICommandRuntime> start, Action shutdown)
 {
     try
     {
         Console.ResetColor();
         Console.Title = _displayName;
         if (_showLogo)
         {
             Console.ForegroundColor = ConsoleColor.White;
             Console.WriteLine(_displayName + " version " + typeof(ConsoleHost).Assembly.GetFileVersion());
             Console.WriteLine();
             Console.ResetColor();
         }
         start(this);
         Console.ResetColor();
         shutdown();
         Console.ResetColor();
     }
     catch (Exception ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(new string('-', 79));
         Console.WriteLine("Error: " + ex.GetErrorSummary());
         Console.WriteLine(new string('-', 79));
         Console.ForegroundColor = ConsoleColor.Gray;
         Console.WriteLine("See the log files for more information.");
         Console.Write("At: ");
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.ResetColor();
         ExceptionKnowledgeBaseEntry entry;
         if (ExceptionKnowledgeBase.TryInterpret(ex, out entry))
         {
             Console.ForegroundColor = ConsoleColor.White;
             Console.WriteLine(new string('=', 79));
             Console.WriteLine(entry.Summary);
             if (entry.HelpText != null)
             {
                 Console.WriteLine(new string('-', 79));
                 if (entry.HelpText != null)
                 {
                     Console.WriteLine(entry.HelpText);
                 }
             }
             Console.WriteLine(new string('=', 79));
             Console.ResetColor();
         }
         _log.FatalException(ex.Message, ex);
         throw;
     }
 }
コード例 #2
0
 private void RunService()
 {
     try
     {
         _execute();
     }
     catch (Exception ex)
     {
         ExceptionKnowledgeBaseEntry entry;
         if (ExceptionKnowledgeBase.TryInterpret(ex, out entry))
         {
             string str = entry.ToString();
             _log.ErrorException(str, ex);
             throw new Exception(str, ex);
         }
         _log.ErrorException(ex.Message, ex);
         throw;
     }
 }