PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 97 lines | 89 code | 7 blank | 1 comment | 9 complexity | 4195ab74033a07be25aed2328b5d4dae MD5 | raw file
  1. namespace Microsoft.BizTalk.ApplicationDeployment.CommandLine
  2. {
  3. using Microsoft.BizTalk.ApplicationDeployment;
  4. using Microsoft.BizTalk.ExplorerOM;
  5. using Microsoft.BizTalk.Log;
  6. using System;
  7. using System.Collections.Specialized;
  8. using System.IO;
  9. internal sealed class FullStopApplicationCommand : Command
  10. {
  11. public FullStopApplicationCommand(NameValueCollection nameValueArgs) : base(nameValueArgs)
  12. {
  13. }
  14. public override void Execute()
  15. {
  16. BtsCatalogExplorer explorer = null;
  17. try
  18. {
  19. this.Validate();
  20. string applicationName = base.Args["ApplicationName"];
  21. string server = base.Args["Server"];
  22. string database = base.Args["Database"];
  23. string formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.FullStopApplication, new object[] { applicationName, server, database });
  24. base.WriteLogEntry(LogEntryType.Information, formattedString);
  25. explorer = new BtsCatalogExplorer();
  26. explorer.ConnectionString = ParameterHelper.GetConnectionString(server, database);
  27. Microsoft.BizTalk.ExplorerOM.Application application = explorer.Applications[applicationName];
  28. if (application == null)
  29. {
  30. throw new ApplicationException("Unable to find application named " + applicationName);
  31. }
  32. application.Stop(Microsoft.BizTalk.ExplorerOM.ApplicationStopOption.StopAll);
  33. explorer.SaveChanges();
  34. formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.FullStopApplicationSuccess, new object[] { applicationName });
  35. base.WriteLogEntry(LogEntryType.Information, formattedString);
  36. base.commandResult = new CommandResult();
  37. }
  38. catch (Exception exception)
  39. {
  40. if (explorer != null)
  41. {
  42. try
  43. {
  44. explorer.DiscardChanges();
  45. }
  46. catch (Exception)
  47. {
  48. }
  49. }
  50. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exception.ToString(), new object[0]);
  51. base.WriteLogEntry(LogEntryType.Error, exception.Message);
  52. base.commandResult = new CommandResult(exception);
  53. if (((exception is OutOfMemoryException) || (exception is ExecutionEngineException)) || (exception is StackOverflowException))
  54. {
  55. throw;
  56. }
  57. }
  58. finally
  59. {
  60. if (explorer != null)
  61. {
  62. explorer.Dispose();
  63. explorer = null;
  64. }
  65. }
  66. }
  67. protected override CommandLineArgDescriptorList GetParameterDescriptors()
  68. {
  69. CommandLineArgDescriptor[] collection = new CommandLineArgDescriptor[] {
  70. new CommandLineArgDescriptor(true, "ApplicationName", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_RequiredApplicationName), CommandLineArgDescriptor.ArgumentType.String, 1, 1),
  71. new CommandLineArgDescriptor(true, "Server", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Server), CommandLineArgDescriptor.ArgumentType.String),
  72. new CommandLineArgDescriptor(true, "Database", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Database), CommandLineArgDescriptor.ArgumentType.String) };
  73. CommandLineArgDescriptorList list = new CommandLineArgDescriptorList();
  74. list.AddRange(collection);
  75. return list;
  76. }
  77. public override void Validate()
  78. {
  79. ParameterHelper.ValidateServerDatabase(base.Args);
  80. ParameterHelper.ValidateApplicationName(base.Args);
  81. }
  82. public override string Name
  83. {
  84. get
  85. {
  86. return "FullStopApp";
  87. }
  88. }
  89. }
  90. }