PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Microsoft.Sdc.BiztalkDocumenter/Microsoft.Sdc.BiztalkDocumenter.Core/Documenter.cs

#
C# | 173 lines | 135 code | 21 blank | 17 comment | 14 complexity | c3950d000dfa50bd24163f76fd72d653 MD5 | raw file
  1. namespace Microsoft.Services.Tools.BiztalkDocumenter
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.IO;
  6. using System.Reflection;
  7. using Microsoft.Services.Tools.BiztalkDocumenter.Publishers;
  8. using Microsoft.Services.Tools.BizTalkOM;
  9. using Microsoft.Services.Tools.BizTalkOM.Diagnostics;
  10. using Microsoft.Win32;
  11. /// <summary>
  12. /// Summary description for Documenter.
  13. /// </summary>
  14. public class Documenter
  15. {
  16. public bool ShowOutput = true;
  17. public string Server = string.Empty;
  18. public string ResourceFolder = string.Empty;
  19. public string CustomDescriptionsFileName = string.Empty;
  20. public string ConfigFrameworkFileName = string.Empty;
  21. public string UserName = string.Empty;
  22. public string Password = string.Empty;
  23. public string Database = string.Empty;
  24. public string RulesServer = string.Empty;
  25. public string RulesDatabase = string.Empty;
  26. public ArrayList Applications;
  27. public bool IncludeReferences = true;
  28. public string OutputDir = @"C:\Temp";
  29. public string ReportName = @"";
  30. public PublishType PublishType;
  31. public IPublisher Publisher = null;
  32. public bool DocumentRules = false;
  33. public event UpdatePercentageComplete PercentageDocumentationComplete;
  34. /// <summary>
  35. ///
  36. /// </summary>
  37. public Documenter()
  38. {
  39. SetDefaults();
  40. }
  41. public void SetDefaults()
  42. {
  43. this.Applications = new ArrayList();
  44. RegistryKey bizTalkKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BizTalk Server\3.0");
  45. string btsInstallDirectory = (string)bizTalkKey.GetValue("InstallPath", @"C:\Program Files\Microsoft BizTalk Server 2006\");
  46. string privateBinPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
  47. privateBinPath += String.Format(";{0}", Path.Combine(btsInstallDirectory, @"Tracking\Control"));
  48. AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = privateBinPath;
  49. RegistryKey bizTalkAdminKey = bizTalkKey.OpenSubKey(@"Administration");
  50. RegistryKey bizTalkRulesKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\BusinessRules\3.0");
  51. this.Server = (string)bizTalkAdminKey.GetValue("MgmtDBServer", Environment.MachineName);
  52. this.Database = (string)bizTalkAdminKey.GetValue("MgmtDBName", "BizTalkMgmtDb");
  53. this.RulesServer = (string)bizTalkRulesKey.GetValue("DatabaseServer", Environment.MachineName);
  54. this.RulesDatabase = (string)bizTalkRulesKey.GetValue("DatabaseName", "BizTalkRuleEngineDb");
  55. this.OutputDir = Path.GetTempPath();
  56. this.ReportName = "BizTalk Documentation - " + this.Server;
  57. this.PublishType = PublishType.EntireConfiguration;
  58. //this.Publisher = new CompiledHelpPublisher();
  59. bizTalkKey.Close();
  60. bizTalkAdminKey.Close();
  61. bizTalkRulesKey.Close();
  62. try
  63. {
  64. AppDomain.CurrentDomain.Load(@"Microsoft.BizTalk.XLangView");
  65. Assembly.LoadFrom(Path.Combine(btsInstallDirectory, @"Tracking\Control") + @"\Microsoft.BizTalk.XLangView.dll");
  66. }
  67. catch (Exception)
  68. {
  69. }
  70. }
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. public void GenerateDocumentation()
  75. {
  76. try
  77. {
  78. if (this.Publisher == null)
  79. {
  80. throw new ApplicationException("Error initialising documentation publisher");
  81. }
  82. this.Publisher.PercentageDocumentationComplete += new UpdatePercentageComplete(Publisher_PercentageDocumentationComplete);
  83. //============================================
  84. // Prepare the environment for the doc run
  85. //============================================
  86. if (!Publisher.Prepare())
  87. {
  88. return;
  89. }
  90. Publisher_PercentageDocumentationComplete(10);
  91. BizTalkInstallation bi = new BizTalkInstallation();
  92. if (string.Compare("localhost", this.Server, true) == 0 ||
  93. string.Compare("(local)", this.Server, true) == 0 ||
  94. string.Compare(".", this.Server, true) == 0)
  95. {
  96. this.Server = Environment.GetEnvironmentVariable("COMPUTERNAME");
  97. }
  98. bi.Server = this.Server;
  99. bi.MgmtDatabaseName = this.Database;
  100. bi.RulesServer = this.RulesServer;
  101. bi.RulesDatabase = this.RulesDatabase;
  102. if (this.PublishType == PublishType.SpecificApplication)
  103. {
  104. bi.LoadConfig(this.Applications, this.IncludeReferences);
  105. }
  106. else
  107. {
  108. bi.LoadConfig();
  109. }
  110. this.Publisher.Publish(bi, this.PublishType, this.ResourceFolder, this.OutputDir, this.ReportName, this.DocumentRules);
  111. bi = null;
  112. if (this.ShowOutput)
  113. {
  114. this.Publisher.ShowOutput();
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. TraceManager.SmartTrace.TraceError(ex);
  120. Console.WriteLine(ex.ToString());
  121. throw;
  122. }
  123. finally
  124. {
  125. //============================================
  126. // And cleanup - Done!
  127. //============================================
  128. if (this.Publisher != null)
  129. {
  130. this.Publisher.Cleanup();
  131. }
  132. }
  133. return;
  134. }
  135. /// <summary>
  136. ///
  137. /// </summary>
  138. /// <param name="percentage"></param>
  139. private void Publisher_PercentageDocumentationComplete(int percentage)
  140. {
  141. if (this.PercentageDocumentationComplete != null)
  142. {
  143. this.PercentageDocumentationComplete(percentage);
  144. }
  145. return;
  146. }
  147. }
  148. }