PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/BTSControl/Microsoft.BizTalk.ApplicationDeployment.CommandLine/Program.cs

#
C# | 189 lines | 167 code | 9 blank | 13 comment | 18 complexity | f91c937f05d085a4284d08525bd4f9c0 MD5 | raw file
  1. namespace Microsoft.BizTalk.ApplicationDeployment.CommandLine
  2. {
  3. using Microsoft.BizTalk.ApplicationDeployment;
  4. //using Microsoft.BizTalk.Internal;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.Specialized;
  8. using System.Diagnostics;
  9. using System.Globalization;
  10. using System.Reflection;
  11. internal sealed class Program
  12. {
  13. private int errors;
  14. private int warnings;
  15. public Program()
  16. {
  17. Console.CancelKeyPress += new ConsoleCancelEventHandler(Program.Console_CancelKeyPress);
  18. }
  19. private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
  20. {
  21. using (new Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer(MethodBase.GetCurrentMethod()))
  22. {
  23. string format = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CancelKeyPress);
  24. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Warning)))
  25. {
  26. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(format, new object[0]);
  27. Console.WriteLine(format);
  28. }
  29. }
  30. }
  31. public static int Main(string[] args)
  32. {
  33. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.Program_UnhandledException);
  34. using (new Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer(MethodBase.GetCurrentMethod()))
  35. {
  36. Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer.TraceAssembly();
  37. Program program = new Program();
  38. return program.Run(args);
  39. }
  40. }
  41. private static void Program_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  42. {
  43. //new WatsonReportGenerator().WatsonExceptionHandler(sender, e);
  44. if (!e.IsTerminating)
  45. {
  46. Exception exceptionObject = e.ExceptionObject as Exception;
  47. if (exceptionObject != null)
  48. {
  49. string format = "FATAL ERROR: An unhandled exception occurred in a thread pool or finalizer thread.";
  50. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(format, new object[0]);
  51. Console.WriteLine(format);
  52. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exceptionObject.ToString(), new object[0]);
  53. Console.WriteLine(exceptionObject.ToString());
  54. }
  55. }
  56. else
  57. {
  58. string str2 = "FATAL ERROR: An unhandled exception occurred in a managed thread.";
  59. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(str2, new object[0]);
  60. Console.WriteLine(str2);
  61. }
  62. }
  63. private int Run(string[] args)
  64. {
  65. try
  66. {
  67. NameValueCollection nameValueArgs = CommandLineParser.Parse(args);
  68. WriteHeader();
  69. CommandLineHelper.TraceWriteArguments(args, nameValueArgs);
  70. if (CommandLineHelper.ArgSpecified(nameValueArgs, "Debug"))
  71. {
  72. nameValueArgs.Remove("Debug");
  73. CommandLineHelper.ConsoleWriteArguments(nameValueArgs);
  74. }
  75. Command command = CommandFactory.Create(nameValueArgs);
  76. bool flag2 = CommandLineHelper.ArgSpecified(nameValueArgs, "?") || CommandLineHelper.ArgSpecified(nameValueArgs, "Help");
  77. if ((nameValueArgs.Count == 0) || flag2)
  78. {
  79. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
  80. {
  81. //if (command is AddResourceCommand)
  82. //{
  83. // command.ValidateArgs();
  84. //}
  85. command.WriteUsage();
  86. goto Label_02F4;
  87. }
  88. }
  89. if (command is HelpCommand)
  90. {
  91. command.Execute();
  92. this.errors += command.Result.ErrorCount;
  93. this.warnings += command.Result.WarningCount;
  94. this.WriteCommandSummary();
  95. return this.errors;
  96. }
  97. List<CommandLineArgumentException> list = command.ValidateArgs();
  98. if (list.Count > 0)
  99. {
  100. foreach (CommandLineArgumentException exception in list)
  101. {
  102. this.errors += (exception.Severity == TraceLevel.Error) ? 1 : 0;
  103. this.warnings += (exception.Severity == TraceLevel.Warning) ? 1 : 0;
  104. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(exception.Severity)))
  105. {
  106. Console.WriteLine(exception.Severity.ToString() + ": " + exception.Message);
  107. Console.WriteLine(string.Empty);
  108. continue;
  109. }
  110. }
  111. }
  112. if (this.errors == 0)
  113. {
  114. command.Execute();
  115. this.errors += command.Result.ErrorCount;
  116. this.warnings += command.Result.WarningCount;
  117. this.WriteCommandSummary();
  118. }
  119. else
  120. {
  121. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
  122. {
  123. command.WriteUsageHint();
  124. }
  125. }
  126. }
  127. catch (Exception exception2)
  128. {
  129. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exception2.ToString(), new object[0]);
  130. this.errors++;
  131. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Error)))
  132. {
  133. Console.WriteLine(exception2.Message);
  134. }
  135. if (((exception2 is OutOfMemoryException) || (exception2 is ExecutionEngineException)) || (exception2 is StackOverflowException))
  136. {
  137. throw;
  138. }
  139. }
  140. finally
  141. {
  142. string formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandCompleted, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
  143. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Empty, new object[0]);
  144. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(formattedString, new object[0]);
  145. }
  146. Label_02F4:
  147. return this.errors;
  148. }
  149. private void WriteCommandSummary()
  150. {
  151. string formattedString;
  152. if (this.errors > 0)
  153. {
  154. formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandResultFailed, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
  155. }
  156. else
  157. {
  158. formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandResultSucceeded, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
  159. }
  160. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
  161. {
  162. Console.WriteLine(string.Empty);
  163. Console.WriteLine(formattedString);
  164. Console.WriteLine(string.Empty);
  165. }
  166. }
  167. private static void WriteHeader()
  168. {
  169. using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
  170. {
  171. string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
  172. string formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.HeaderDescription, new object[] { fileVersion });
  173. string str3 = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.HeaderCopyright);
  174. Console.WriteLine(formattedString);
  175. Console.WriteLine(str3);
  176. Console.WriteLine(string.Empty);
  177. }
  178. }
  179. }
  180. }