PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 99 lines | 91 code | 7 blank | 1 comment | 9 complexity | 8647734eaa4fd1b65105794e23d3bd26 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 StartApplicationCommand : Command
  10. {
  11. public StartApplicationCommand(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(
  24. CommandResources.ResourceID.StartApplication, new object[] { applicationName, server, database });
  25. base.WriteLogEntry(LogEntryType.Information, formattedString);
  26. explorer = new BtsCatalogExplorer();
  27. explorer.ConnectionString = ParameterHelper.GetConnectionString(server, database);
  28. Microsoft.BizTalk.ExplorerOM.Application application = explorer.Applications[applicationName];
  29. if (application == null)
  30. {
  31. throw new ApplicationException("Unable to find application named " + applicationName);
  32. }
  33. application.Start(Microsoft.BizTalk.ExplorerOM.ApplicationStartOption.StartAll);
  34. explorer.SaveChanges();
  35. formattedString = CommandResources.GetFormattedString(
  36. CommandResources.ResourceID.StartApplicationSuccess, new object[] { applicationName });
  37. base.WriteLogEntry(LogEntryType.Information, formattedString);
  38. base.commandResult = new CommandResult();
  39. }
  40. catch (Exception exception)
  41. {
  42. if (explorer != null)
  43. {
  44. try
  45. {
  46. explorer.DiscardChanges();
  47. }
  48. catch (Exception)
  49. {
  50. }
  51. }
  52. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exception.ToString(), new object[0]);
  53. base.WriteLogEntry(LogEntryType.Error, exception.Message);
  54. base.commandResult = new CommandResult(exception);
  55. if (((exception is OutOfMemoryException) || (exception is ExecutionEngineException)) || (exception is StackOverflowException))
  56. {
  57. throw;
  58. }
  59. }
  60. finally
  61. {
  62. if (explorer != null)
  63. {
  64. explorer.Dispose();
  65. explorer = null;
  66. }
  67. }
  68. }
  69. protected override CommandLineArgDescriptorList GetParameterDescriptors()
  70. {
  71. CommandLineArgDescriptor[] collection = new CommandLineArgDescriptor[] {
  72. new CommandLineArgDescriptor(true, "ApplicationName", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_RequiredApplicationName), CommandLineArgDescriptor.ArgumentType.String, 1, 1),
  73. new CommandLineArgDescriptor(true, "Server", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Server), CommandLineArgDescriptor.ArgumentType.String),
  74. new CommandLineArgDescriptor(true, "Database", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Database), CommandLineArgDescriptor.ArgumentType.String) };
  75. CommandLineArgDescriptorList list = new CommandLineArgDescriptorList();
  76. list.AddRange(collection);
  77. return list;
  78. }
  79. public override void Validate()
  80. {
  81. ParameterHelper.ValidateServerDatabase(base.Args);
  82. ParameterHelper.ValidateApplicationName(base.Args);
  83. }
  84. public override string Name
  85. {
  86. get
  87. {
  88. return "StartApp";
  89. }
  90. }
  91. }
  92. }