PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/v2.0/Router/ProjectInstaller.cs

#
C# | 285 lines | 235 code | 43 blank | 7 comment | 32 complexity | 0bc6dae3b9e9da3583cb7a4e21237926 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Configuration.Install;
  6. using System.Resources;
  7. using System.Diagnostics;
  8. using System.Reflection;
  9. using System.IO;
  10. namespace Microsoft.WebSolutionsPlatform.Event
  11. {
  12. [RunInstaller(true)]
  13. public partial class ProjectInstaller : Installer
  14. {
  15. /// <summary>
  16. /// Constructor
  17. /// </summary>
  18. public ProjectInstaller()
  19. {
  20. InitializeComponent();
  21. }
  22. /// <summary>
  23. /// Override 'Uninstall' method of Installer class.
  24. /// </summary>
  25. /// <param name="mySavedState"></param>
  26. public override void Uninstall(IDictionary mySavedState)
  27. {
  28. if (mySavedState == null)
  29. {
  30. Console.WriteLine("Uninstallation Error !");
  31. }
  32. else
  33. {
  34. PerformanceCounterSetup pcSetup = new PerformanceCounterSetup();
  35. pcSetup.Init("uninstall");
  36. base.Uninstall(mySavedState);
  37. }
  38. }
  39. private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
  40. {
  41. string initComplete = Context.Parameters["initComplete"];
  42. if (initComplete == null || initComplete == string.Empty)
  43. {
  44. PerformanceCounterSetup pcSetup = new PerformanceCounterSetup();
  45. pcSetup.Init("install");
  46. WriteOutConfig();
  47. Context.Parameters["initComplete"] = "true";
  48. }
  49. }
  50. private void WriteOutConfig()
  51. {
  52. string targetDir = Context.Parameters["TARGETDIR"];
  53. string wspParent = Context.Parameters["WSPPARENT"];
  54. string wspInternetFacing = Context.Parameters["WSPINTERNETFACING"];
  55. string wspEventQueueSize = Context.Parameters["WSPQUEUESIZE"];
  56. string wspParentUi = Context.Parameters["WSPPARENTUI"];
  57. string wspInternetFacingUi = Context.Parameters["WSPINTERNETFACINGUI"];
  58. string wspEventQueueSizeUi = Context.Parameters["WSPQUEUESIZEUI"];
  59. string configPath = targetDir + "WspEventRouter.exe.config";
  60. if (wspParentUi != string.Empty)
  61. {
  62. wspParent = wspParentUi;
  63. }
  64. if (wspEventQueueSize == string.Empty)
  65. {
  66. wspEventQueueSize = wspEventQueueSizeUi;
  67. }
  68. if (wspInternetFacing == string.Empty)
  69. {
  70. wspInternetFacing = wspInternetFacingUi;
  71. }
  72. using (StreamWriter sw = new StreamWriter(configPath))
  73. {
  74. sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
  75. sw.WriteLine("<configuration>");
  76. sw.WriteLine(" <configSections>");
  77. sw.WriteLine(" <section name=\"eventRouterSettings\" type=\"foo\"/>");
  78. sw.WriteLine(" <section name=\"eventPersistSettings\" type=\"foo2\"/>");
  79. sw.WriteLine(" </configSections>");
  80. sw.WriteLine("");
  81. sw.WriteLine(" <eventRouterSettings>");
  82. sw.WriteLine(" <!-- refreshIncrement should be about 1/3 of what the expirationIncrement is. -->");
  83. sw.WriteLine(" <!-- This setting needs to be consistent across all the machines in the eventing network. -->");
  84. sw.WriteLine(" <subscriptionManagement refreshIncrement=\"3\" expirationIncrement=\"10\"/>");
  85. sw.WriteLine("");
  86. if (wspEventQueueSize == null || wspEventQueueSize == string.Empty)
  87. {
  88. sw.WriteLine(" <localPublish eventQueueName=\"WspEventQueue\" eventQueueSize=\"102400000\" averageEventSize=\"10240\"/>");
  89. }
  90. else
  91. {
  92. sw.WriteLine(" <localPublish eventQueueName=\"WspEventQueue\" eventQueueSize=\"" + wspEventQueueSize + "\" averageEventSize=\"10240\"/>");
  93. }
  94. sw.WriteLine("");
  95. sw.WriteLine(" <!-- These settings control what should happen to an output queue when communications is lost to a parent or child.-->");
  96. sw.WriteLine(" <!-- maxQueueSize is in bytes and maxTimeout is in seconds.-->");
  97. sw.WriteLine(" <!-- When the maxQueueSize is reached or the maxTimeout is reached for a communication that has been lost, the queue is deleted.-->");
  98. sw.WriteLine(" <outputCommunicationQueues maxQueueSize=\"200000000\" maxTimeout=\"600\"/>");
  99. sw.WriteLine("");
  100. sw.WriteLine(" <!-- nic can be an alias which specifies a specific IP address or an IP address. -->");
  101. sw.WriteLine(" <!-- port can be 0 if you don't want to have the router open a listening port to be a parent to other routers. -->");
  102. if (wspInternetFacing == null || wspInternetFacing == string.Empty)
  103. {
  104. sw.WriteLine(" <thisRouter nic=\"\" port=\"1300\" bufferSize=\"1024000\" timeout=\"30000\" />");
  105. }
  106. else
  107. {
  108. sw.WriteLine(" <thisRouter nic=\"\" port=\"0\" bufferSize=\"1024000\" timeout=\"30000\" />");
  109. }
  110. sw.WriteLine("");
  111. if (wspParent == null || wspParent == string.Empty)
  112. {
  113. sw.WriteLine(" <!-- <parentRouter name=\"ParentMachineName\" port=\"1300\" bufferSize=\"1024000\" timeout=\"30000\" /> -->");
  114. }
  115. else
  116. {
  117. sw.WriteLine(" <parentRouter name=\"" + wspParent + "\" port=\"1300\" bufferSize=\"1024000\" timeout=\"30000\" />");
  118. }
  119. sw.WriteLine("");
  120. sw.WriteLine(" </eventRouterSettings>");
  121. sw.WriteLine("");
  122. sw.WriteLine(" <eventPersistSettings>");
  123. sw.WriteLine("");
  124. sw.WriteLine(" <!-- type specifies the EventType to be persisted.-->");
  125. sw.WriteLine(" <!-- localOnly is a boolean which specifies whether only events published on this machine are persisted or if events from the entire network are persisted.-->");
  126. sw.WriteLine(" <!-- maxFileSize specifies the maximum size in bytes that the persisted file should be before it is copied.-->");
  127. sw.WriteLine(" <!-- maxCopyInterval specifies in seconds the longest time interval before the persisted file is copied.-->");
  128. sw.WriteLine(" <!-- fieldTerminator specifies the character used between fields.-->");
  129. sw.WriteLine(" <!-- rowTerminator specifies the character used at the end of each row written.-->");
  130. sw.WriteLine(" <!-- tempFileDirectory is the local directory used for writing out the persisted event serializedEvent.-->");
  131. sw.WriteLine(" <!-- copyToFileDirectory is the final destination of the persisted serializedEvent file. It can be local or remote using a UNC.-->");
  132. sw.WriteLine("");
  133. sw.WriteLine(" <!-- <event type=\"78422526-7B21-4559-8B9A-BC551B46AE34\" localOnly=\"true\" maxFileSize=\"2000000000\" maxCopyInterval=\"60\" fieldTerminator=\",\" rowTerminator=\"\\n\" tempFileDirectory=\"c:\\temp\\WebEvents\\\" copyToFileDirectory=\"c:\\temp\\WebEvents\\log\\\" /> -->");
  134. sw.WriteLine("");
  135. sw.WriteLine(" </eventPersistSettings>");
  136. sw.WriteLine("</configuration>");
  137. }
  138. }
  139. }
  140. internal class PerformanceCounterSetup
  141. {
  142. internal static string categoryName;
  143. internal static string communicationCategoryName;
  144. internal static string categoryHelp;
  145. internal static string communicationCategoryHelp;
  146. internal static string subscriptionQueueSizeName;
  147. internal static string rePublisherQueueSizeName;
  148. internal static string persisterQueueSizeName;
  149. internal static string forwarderQueueSizeName;
  150. internal static string subscriptionEntriesName;
  151. internal static string eventsProcessedName;
  152. internal static string eventsProcessedBytesName;
  153. internal static string baseInstance;
  154. internal static PerformanceCounter subscriptionQueueSize;
  155. internal static PerformanceCounter rePublisherQueueSize;
  156. internal static PerformanceCounter persisterQueueSize;
  157. internal static PerformanceCounter forwarderQueueSize;
  158. internal static PerformanceCounter subscriptionEntries;
  159. internal static PerformanceCounter eventsProcessed;
  160. internal static PerformanceCounter eventsProcessedBytes;
  161. internal void Init(string arg)
  162. {
  163. CounterCreationDataCollection CCDC;
  164. categoryName = "WspEventRouter";
  165. communicationCategoryName = "WspEventRouterCommunication";
  166. categoryHelp = "WspEventRouter counters showing internal performance of the router.";
  167. communicationCategoryHelp = "WspEventRouter counters showing communication queues to other machines";
  168. subscriptionQueueSizeName = "SubscriptionQueueSize";
  169. rePublisherQueueSizeName = "RePublisherQueueSize";
  170. persisterQueueSizeName = "PersisterQueueSize";
  171. forwarderQueueSizeName = "ForwarderQueueSize";
  172. subscriptionEntriesName = "SubscriptionEntries";
  173. eventsProcessedName = "EventsProcessed";
  174. eventsProcessedBytesName = "EventsProcessedBytes";
  175. baseInstance = "WspEventRouter";
  176. if (PerformanceCounterCategory.Exists(categoryName) == true)
  177. {
  178. PerformanceCounterCategory.Delete(categoryName);
  179. }
  180. if (EventLog.SourceExists("WspEventRouter") == true)
  181. {
  182. EventLog.DeleteEventSource("WspEventRouter");
  183. }
  184. if (arg == "uninstall")
  185. {
  186. return;
  187. }
  188. EventLog.CreateEventSource("WspEventRouter", "System");
  189. CCDC = new CounterCreationDataCollection();
  190. CounterCreationData subscriptionQueueCounter = new CounterCreationData();
  191. subscriptionQueueCounter.CounterType = PerformanceCounterType.NumberOfItems32;
  192. subscriptionQueueCounter.CounterName = subscriptionQueueSizeName;
  193. CCDC.Add(subscriptionQueueCounter);
  194. CounterCreationData rePublisherQueueCounter = new CounterCreationData();
  195. rePublisherQueueCounter.CounterType = PerformanceCounterType.NumberOfItems32;
  196. rePublisherQueueCounter.CounterName = rePublisherQueueSizeName;
  197. CCDC.Add(rePublisherQueueCounter);
  198. CounterCreationData persisterQueueCounter = new CounterCreationData();
  199. persisterQueueCounter.CounterType = PerformanceCounterType.NumberOfItems32;
  200. persisterQueueCounter.CounterName = persisterQueueSizeName;
  201. CCDC.Add(persisterQueueCounter);
  202. CounterCreationData subscriptionEntriesCounter = new CounterCreationData();
  203. subscriptionEntriesCounter.CounterType = PerformanceCounterType.NumberOfItems32;
  204. subscriptionEntriesCounter.CounterName = subscriptionEntriesName;
  205. CCDC.Add(subscriptionEntriesCounter);
  206. CounterCreationData eventsProcessedCounter = new CounterCreationData();
  207. eventsProcessedCounter.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
  208. eventsProcessedCounter.CounterName = eventsProcessedName;
  209. CCDC.Add(eventsProcessedCounter);
  210. CounterCreationData eventsProcessedBytesCounter = new CounterCreationData();
  211. eventsProcessedBytesCounter.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
  212. eventsProcessedBytesCounter.CounterName = eventsProcessedBytesName;
  213. CCDC.Add(eventsProcessedBytesCounter);
  214. PerformanceCounterCategory.Create(categoryName, categoryHelp,
  215. PerformanceCounterCategoryType.SingleInstance, CCDC);
  216. subscriptionQueueSize = new PerformanceCounter(categoryName, subscriptionQueueSizeName, string.Empty, false);
  217. rePublisherQueueSize = new PerformanceCounter(categoryName, rePublisherQueueSizeName, string.Empty, false);
  218. persisterQueueSize = new PerformanceCounter(categoryName, persisterQueueSizeName, string.Empty, false);
  219. subscriptionEntries = new PerformanceCounter(categoryName, subscriptionEntriesName, string.Empty, false);
  220. eventsProcessed = new PerformanceCounter(categoryName, eventsProcessedName, string.Empty, false);
  221. eventsProcessedBytes = new PerformanceCounter(categoryName, eventsProcessedBytesName, string.Empty, false);
  222. if (PerformanceCounterCategory.Exists(communicationCategoryName) == false)
  223. {
  224. CCDC = new CounterCreationDataCollection();
  225. CounterCreationData forwarderQueueCounter = new CounterCreationData();
  226. forwarderQueueCounter.CounterType = PerformanceCounterType.NumberOfItems32;
  227. forwarderQueueCounter.CounterName = forwarderQueueSizeName;
  228. CCDC.Add(forwarderQueueCounter);
  229. PerformanceCounterCategory.Create(communicationCategoryName, communicationCategoryHelp,
  230. PerformanceCounterCategoryType.MultiInstance, CCDC);
  231. }
  232. forwarderQueueSize = new PerformanceCounter(communicationCategoryName, forwarderQueueSizeName, baseInstance, false);
  233. subscriptionQueueSize.RawValue = 0;
  234. rePublisherQueueSize.RawValue = 0;
  235. persisterQueueSize.RawValue = 0;
  236. forwarderQueueSize.RawValue = 0;
  237. subscriptionEntries.RawValue = 0;
  238. eventsProcessed.RawValue = 0;
  239. eventsProcessedBytes.RawValue = 0;
  240. }
  241. }
  242. }