PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Blocks/Logging/Src/Logging/Configuration/Manageability/TraceListeners/MsmqTraceListenerDataManageabilityProvider.cs

#
C# | 209 lines | 114 code | 28 blank | 67 comment | 1 complexity | c6a7d166d770c0f0f1ab73c8a068d9f5 MD5 | raw file
  1. //===============================================================================
  2. // Microsoft patterns & practices Enterprise Library
  3. // Logging Application Block
  4. //===============================================================================
  5. // Copyright Š Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===============================================================================
  11. using System;
  12. using System.Diagnostics;
  13. using System.Globalization;
  14. using System.Messaging;
  15. using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
  16. using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;
  17. using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.Adm;
  18. using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Manageability.Properties;
  19. namespace Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Manageability.TraceListeners
  20. {
  21. /// <summary>
  22. /// Provides an implementation for <see cref="FormattedEventLogTraceListenerData"/> that
  23. /// processes policy overrides, performing appropriate logging of
  24. /// policy processing errors.
  25. /// </summary>
  26. public class MsmqTraceListenerDataManageabilityProvider
  27. : TraceListenerDataManageabilityProvider<MsmqTraceListenerData>
  28. {
  29. /// <summary>
  30. /// The name of the message priority property.
  31. /// </summary>
  32. public const String MessagePriorityPropertyName = "messagePriority";
  33. /// <summary>
  34. /// The name of the queue path property.
  35. /// </summary>
  36. public const String QueuePathPropertyName = "queuePath";
  37. /// <summary>
  38. /// The name of the recoverable property.
  39. /// </summary>
  40. public const String RecoverablePropertyName = "recoverable";
  41. /// <summary>
  42. /// The name of the time to be received property.
  43. /// </summary>
  44. public const String TimeToBeReceivedPropertyName = "timeToBeReceived";
  45. /// <summary>
  46. /// The name of the time to reach the queue property.
  47. /// </summary>
  48. public const String TimeToReachQueuePropertyName = "timeToReachQueue";
  49. /// <summary>
  50. /// The name of the transaction type property.
  51. /// </summary>
  52. public const String TransactionTypePropertyName = "transactionType";
  53. /// <summary>
  54. /// The name of the use authentication property.
  55. /// </summary>
  56. public const String UseAuthenticationPropertyName = "useAuthentication";
  57. /// <summary>
  58. /// The name of the use dead letter queue property.
  59. /// </summary>
  60. public const String UseDeadLetterQueuePropertyName = "useDeadLetterQueue";
  61. /// <summary>
  62. /// The name of the use encryption property.
  63. /// </summary>
  64. public const String UseEncryptionPropertyName = "useEncryption";
  65. /// <summary>
  66. /// Initialize a new instance of the <see cref="MsmqTraceListenerDataManageabilityProvider"/> class.
  67. /// </summary>
  68. public MsmqTraceListenerDataManageabilityProvider()
  69. { }
  70. /// <summary>
  71. /// Adds the ADM parts that represent the properties of
  72. /// a specific instance of the configuration element type managed by the receiver.
  73. /// </summary>
  74. /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param>
  75. /// <param name="configurationObject">The configuration object instance.</param>
  76. /// <param name="configurationSource">The configuration source from where to get additional configuration
  77. /// information, if necessary.</param>
  78. /// <param name="elementPolicyKeyName">The key for the element's policies.</param>
  79. /// <remarks>
  80. /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts.
  81. /// </remarks>
  82. protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder,
  83. MsmqTraceListenerData configurationObject,
  84. IConfigurationSource configurationSource,
  85. String elementPolicyKeyName)
  86. {
  87. contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerQueuePathPartName,
  88. QueuePathPropertyName,
  89. configurationObject.QueuePath,
  90. 255,
  91. true);
  92. contentBuilder.AddDropDownListPartForEnumeration<MessagePriority>(Resources.MsmqTraceListenerPriorityPartName,
  93. MessagePriorityPropertyName,
  94. configurationObject.MessagePriority);
  95. contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerTtbrPartName,
  96. TimeToBeReceivedPropertyName,
  97. Convert.ToString(configurationObject.TimeToBeReceived, CultureInfo.InvariantCulture),
  98. 255,
  99. false);
  100. contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerTtrqPartName,
  101. TimeToReachQueuePropertyName,
  102. Convert.ToString(configurationObject.TimeToReachQueue, CultureInfo.InvariantCulture),
  103. 255,
  104. false);
  105. contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerRecoverablePartName,
  106. RecoverablePropertyName,
  107. configurationObject.Recoverable);
  108. contentBuilder.AddDropDownListPartForEnumeration<MessageQueueTransactionType>(Resources.MsmqTraceListenerTransactionTypePartName,
  109. TransactionTypePropertyName,
  110. configurationObject.TransactionType);
  111. contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseAuthenticationPartName,
  112. UseAuthenticationPropertyName,
  113. configurationObject.UseAuthentication);
  114. contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseDeadLetterQueuePartName,
  115. UseDeadLetterQueuePropertyName,
  116. configurationObject.UseDeadLetterQueue);
  117. contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseEncryptionPartName,
  118. UseEncryptionPropertyName,
  119. configurationObject.UseEncryption);
  120. AddTraceOptionsPart(contentBuilder, elementPolicyKeyName, configurationObject.TraceOutputOptions);
  121. AddFilterPart(contentBuilder, configurationObject.Filter);
  122. AddFormattersPart(contentBuilder, configurationObject.Formatter, configurationSource);
  123. }
  124. TimeSpan GetTimeSpanOverride(IRegistryKey policyKey,
  125. String propertyName)
  126. {
  127. TimeSpan result;
  128. String overrideValue = policyKey.GetStringValue(propertyName);
  129. if (!TimeSpan.TryParse(overrideValue, out result))
  130. {
  131. throw new RegistryAccessException(
  132. String.Format(CultureInfo.CurrentCulture,
  133. Resources.ExceptionErrorValueNotTimeSpan,
  134. policyKey.Name,
  135. propertyName,
  136. overrideValue));
  137. }
  138. return result;
  139. }
  140. /// <summary>
  141. /// Overrides the <paramref name="configurationObject"/>'s properties with the Group Policy values from the
  142. /// registry.
  143. /// </summary>
  144. /// <param name="configurationObject">The configuration object for instances that must be managed.</param>
  145. /// <param name="policyKey">The <see cref="IRegistryKey"/> which holds the Group Policy overrides for the
  146. /// configuration element.</param>
  147. /// <remarks>Subclasses implementing this method must retrieve all the override values from the registry
  148. /// before making modifications to the <paramref name="configurationObject"/> so any error retrieving
  149. /// the override values will cancel policy processing.</remarks>
  150. protected override void OverrideWithGroupPolicies(MsmqTraceListenerData configurationObject,
  151. IRegistryKey policyKey)
  152. {
  153. String formatterOverride = GetFormatterPolicyOverride(policyKey);
  154. MessagePriority? messagePriorityOverride = policyKey.GetEnumValue<MessagePriority>(MessagePriorityPropertyName);
  155. String queuePathOverride = policyKey.GetStringValue(QueuePathPropertyName);
  156. bool? recoverableOverride = policyKey.GetBoolValue(RecoverablePropertyName);
  157. TimeSpan timeToBeReceivedOverride = GetTimeSpanOverride(policyKey, TimeToBeReceivedPropertyName);
  158. TimeSpan timeToReachQueueOverride = GetTimeSpanOverride(policyKey, TimeToReachQueuePropertyName);
  159. TraceOptions? traceOutputOptionsOverride =
  160. GetFlagsEnumOverride<TraceOptions>(policyKey, TraceOutputOptionsPropertyName);
  161. SourceLevels? filterOverride = policyKey.GetEnumValue<SourceLevels>(FilterPropertyName);
  162. MessageQueueTransactionType? transactionTypeOverride =
  163. policyKey.GetEnumValue<MessageQueueTransactionType>(TransactionTypePropertyName);
  164. bool? usedAuthenticationOverride = policyKey.GetBoolValue(UseAuthenticationPropertyName);
  165. bool? useDeadLetterOverride = policyKey.GetBoolValue(UseDeadLetterQueuePropertyName);
  166. bool? useEncryptionOverride = policyKey.GetBoolValue(UseEncryptionPropertyName);
  167. configurationObject.Formatter = formatterOverride;
  168. configurationObject.MessagePriority = messagePriorityOverride.Value;
  169. configurationObject.QueuePath = queuePathOverride;
  170. configurationObject.Recoverable = recoverableOverride.Value;
  171. configurationObject.TimeToReachQueue = timeToReachQueueOverride;
  172. configurationObject.TimeToBeReceived = timeToBeReceivedOverride;
  173. configurationObject.TraceOutputOptions = traceOutputOptionsOverride.Value;
  174. configurationObject.Filter = filterOverride.Value;
  175. configurationObject.TransactionType = transactionTypeOverride.Value;
  176. configurationObject.UseAuthentication = usedAuthenticationOverride.Value;
  177. configurationObject.UseDeadLetterQueue = useDeadLetterOverride.Value;
  178. configurationObject.UseEncryption = useEncryptionOverride.Value;
  179. }
  180. }
  181. }