private static void AddBlockSettingsPolicy( AdmContentBuilder contentBuilder, String sectionKey, LoggingSettings configurationSection) { contentBuilder.StartPolicy(Resources.LoggingSettingsPolicyName, sectionKey); { contentBuilder.AddDropDownListPartForNamedElementCollection <TraceSourceData>( Resources.LoggingSettingsDefaultCategoryPartName, DefaultCategoryPropertyName, configurationSection.TraceSources, configurationSection.DefaultCategory, false); contentBuilder.AddCheckboxPart(Resources.LoggingSettingsLogWarningPartName, LogWarningOnNoMatchPropertyName, configurationSection.LogWarningWhenNoCategoriesMatch); contentBuilder.AddCheckboxPart(Resources.LoggingSettingsEnableTracingPartName, TracingEnabledPropertyName, configurationSection.TracingEnabled); contentBuilder.AddCheckboxPart(Resources.LoggingSettingsRevertImpersonationPartName, RevertImpersonationPropertyName, configurationSection.RevertImpersonation); } contentBuilder.EndPolicy(); }
/// <summary> /// Adds the ADM parts that represent the properties of /// a specific instance of the configuration element type managed by the receiver. /// </summary> /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param> /// <param name="configurationObject">The configuration object instance.</param> /// <param name="configurationSource">The configuration source from where to get additional configuration /// information, if necessary.</param> /// <param name="elementPolicyKeyName">The key for the element's policies.</param> /// <remarks> /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts. /// </remarks> protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder, MsmqTraceListenerData configurationObject, IConfigurationSource configurationSource, String elementPolicyKeyName) { contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerQueuePathPartName, QueuePathPropertyName, configurationObject.QueuePath, 255, true); contentBuilder.AddDropDownListPartForEnumeration <MessagePriority>(Resources.MsmqTraceListenerPriorityPartName, MessagePriorityPropertyName, configurationObject.MessagePriority); contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerTtbrPartName, TimeToBeReceivedPropertyName, Convert.ToString(configurationObject.TimeToBeReceived, CultureInfo.InvariantCulture), 255, false); contentBuilder.AddEditTextPart(Resources.MsmqTraceListenerTtrqPartName, TimeToReachQueuePropertyName, Convert.ToString(configurationObject.TimeToReachQueue, CultureInfo.InvariantCulture), 255, false); contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerRecoverablePartName, RecoverablePropertyName, configurationObject.Recoverable); contentBuilder.AddDropDownListPartForEnumeration <MessageQueueTransactionType>(Resources.MsmqTraceListenerTransactionTypePartName, TransactionTypePropertyName, configurationObject.TransactionType); contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseAuthenticationPartName, UseAuthenticationPropertyName, configurationObject.UseAuthentication); contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseDeadLetterQueuePartName, UseDeadLetterQueuePropertyName, configurationObject.UseDeadLetterQueue); contentBuilder.AddCheckboxPart(Resources.MsmqTraceListenerUseEncryptionPartName, UseEncryptionPropertyName, configurationObject.UseEncryption); AddTraceOptionsPart(contentBuilder, elementPolicyKeyName, configurationObject.TraceOutputOptions); AddFilterPart(contentBuilder, configurationObject.Filter); AddFormattersPart(contentBuilder, configurationObject.Formatter, configurationSource); }
/// <summary> /// Adds a new drop down list part to the current policy with items representing an enumeration's values. /// </summary> /// <typeparam name="TEnum">The enumeration type.</typeparam> /// <param name="contentBuilder">The content builder.</param> /// <param name="keyName">The registry key for the part, to override its policy's key.</param> /// <param name="defaultValue">The default value for the new part.</param> /// <exception cref="InvalidOperationException">when there is no current policy.</exception> protected static void AddCheckboxPartsForFlagsEnumeration <TEnum>(AdmContentBuilder contentBuilder, String keyName, TEnum defaultValue) where TEnum : struct { var values = Enum.GetValues(typeof(TEnum)).OfType <TEnum>().Select(v => (ulong)Convert.ToUInt64(v)).ToArray(); var names = Enum.GetNames(typeof(TEnum)); var selectedValues = new List <int>(); var value = (ulong)Convert.ToUInt64(defaultValue); var index = values.Length - 1; while (index >= 0) { var currentValue = values[index]; if (index == 0 && currentValue == 0) { break; } if ((value & currentValue) == currentValue) { value -= currentValue; selectedValues.Add(index); } index--; } for (int i = (values[0] == 0 ? 1 : 0); i < names.Length; i++) { contentBuilder.AddCheckboxPart(names[i], keyName, names[i], selectedValues.Contains(i), true, false); } }
private static void AddTraceSourcePolicy( TraceSourceData traceSourceData, String traceSourceName, String parentKey, AdmContentBuilder contentBuilder, LoggingSettings configurationSection) { String traceSourceKey = parentKey + @"\" + traceSourceName; contentBuilder.StartPolicy(String.Format(CultureInfo.InvariantCulture, Resources.TraceSourcePolicyNameTemplate, traceSourceName), traceSourceKey); { contentBuilder.AddDropDownListPartForEnumeration <SourceLevels>(Resources.TraceSourceDefaultLevelPartName, SourceDefaultLevelPropertyName, traceSourceData.DefaultLevel); contentBuilder.AddTextPart(Resources.TraceSourceListenersPartName); String traceSourceListenersKey = traceSourceKey + @"\" + SourceTraceListenersPropertyName; foreach (TraceListenerData traceListener in configurationSection.TraceListeners) { contentBuilder.AddCheckboxPart(traceListener.Name, traceSourceListenersKey, traceListener.Name, traceSourceData.TraceListeners.Contains(traceListener.Name), true, false); } } contentBuilder.EndPolicy(); }
/// <summary> /// Adds the ADM parts that represent the properties of /// a specific instance of the configuration element type managed by the receiver. /// </summary> /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param> /// <param name="configurationObject">The configuration object instance.</param> /// <param name="configurationSource">The configuration source from where to get additional configuration /// information, if necessary.</param> /// <param name="elementPolicyKeyName">The key for the element's policies.</param> /// <remarks> /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts. /// </remarks> protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder, CategoryFilterData configurationObject, IConfigurationSource configurationSource, String elementPolicyKeyName) { contentBuilder.AddDropDownListPartForEnumeration <CategoryFilterMode>(Resources.CategoryFilterFilterModePartName, CategoryFilterModePropertyName, configurationObject.CategoryFilterMode); contentBuilder.AddTextPart(Resources.CategoryFilterCategoriesPartName); LoggingSettings configurationSection = configurationSource.GetSection(LoggingSettings.SectionName) as LoggingSettings; String logFilterCategoriesKeyName = elementPolicyKeyName + @"\" + CategoryFiltersKeyName; foreach (TraceSourceData category in configurationSection.TraceSources) { contentBuilder.AddCheckboxPart(category.Name, logFilterCategoriesKeyName, category.Name, configurationObject.CategoryFilters.Contains(category.Name), true, false); } }
/// <summary> /// Adds the ADM instructions that describe the policies that can be used to override the configuration /// information represented by a configuration section. /// </summary> /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param> /// <param name="configurationSection">The configuration section instance.</param> /// <param name="configurationSource">The configuration source from where to get additional configuration /// information, if necessary.</param> /// <param name="sectionKey">The root key for the section's policies.</param> protected override void AddAdministrativeTemplateDirectives(AdmContentBuilder contentBuilder, InstrumentationConfigurationSection configurationSection, IConfigurationSource configurationSource, String sectionKey) { contentBuilder.StartPolicy(Resources.InstrumentationSectionPolicyName, sectionKey); { contentBuilder.AddCheckboxPart(Resources.InstrumentationSectionEventLoggingEnabledPartName, EventLoggingEnabledPropertyName, configurationSection.EventLoggingEnabled); contentBuilder.AddCheckboxPart(Resources.InstrumentationSectionPerformanceCountersEnabledPartName, PerformanceCountersEnabledPropertyName, configurationSection.PerformanceCountersEnabled); } contentBuilder.EndPolicy(); }
/// <summary> /// Adds the ADM parts that represent the properties of /// a specific instance of the configuration element type managed by the receiver. /// </summary> /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param> /// <param name="configurationObject">The configuration object instance.</param> /// <param name="configurationSource">The configuration source from where to get additional configuration /// information, if necessary.</param> /// <param name="elementPolicyKeyName">The key for the element's policies.</param> /// <remarks> /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts. /// </remarks> protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder, LogEnabledFilterData configurationObject, IConfigurationSource configurationSource, String elementPolicyKeyName) { contentBuilder.AddCheckboxPart(Resources.LogEnabledFilterEnabledPartName, EnabledPropertyName, configurationObject.Enabled); }
/// <summary> /// Adds the ADM parts that represent the properties of /// a specific instance of the configuration element type managed by the receiver. /// </summary> /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param> /// <param name="configurationObject">The configuration object instance.</param> /// <param name="configurationSource">The configuration source from where to get additional configuration /// information, if necessary.</param> /// <param name="elementPolicyKeyName">The key for the element's policies.</param> /// <remarks> /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts. /// </remarks> protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder, HashAlgorithmProviderData configurationObject, IConfigurationSource configurationSource, string elementPolicyKeyName) { contentBuilder.AddCheckboxPart(Resources.HashAlgorithmProviderSaltEnabledPartName, SaltEnabledPropertyName, configurationObject.SaltEnabled); }
protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder, KeyedHashAlgorithmProviderData configurationObject, IConfigurationSource configurationSource, String elementPolicyKeyName) { contentBuilder.AddCheckboxPart(Resources.KeyedHashAlgorithmProviderSaltEnabledPartName, SaltEnabledPropertyName, configurationObject.SaltEnabled); contentBuilder.AddEditTextPart(Resources.KeyedHashAlgorithmProviderKeyFileNamePartName, ProtectedKeyFilenamePropertyName, configurationObject.ProtectedKeyFilename, 255, true); contentBuilder.AddDropDownListPartForEnumeration <DataProtectionScope>(Resources.KeyedHashAlgorithmProviderKeyProtectionScopePartName, ProtectedKeyProtectionScopePropertyName, configurationObject.ProtectedKeyProtectionScope); }
public void AddCheckBoxWithLongValueNameThrows() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); String valueName = stringBuilder.ToString(); Assert.IsTrue(valueName.Length > 255); AdmContentBuilder builder = new AdmContentBuilder(); builder.StartCategory("category"); builder.StartPolicy("policy", "key"); ; builder.AddCheckboxPart("policy", valueName, true, true, false); }
public void AddCheckBoxWithInvalidValueNameThrows() { AdmContentBuilder builder = new AdmContentBuilder(); builder.StartCategory("category"); builder.StartPolicy("policy", "key"); ; builder.AddCheckboxPart("policy", "invalid\"value", true, true, false); }
public void CanAddCheckboxPartWithValueOnAndOff() { AdmContentBuilder builder = new AdmContentBuilder(); builder.StartCategory("category"); builder.StartPolicy("policy", "key"); ; builder.AddCheckboxPart("part", "value", true, true, false); builder.EndPolicy(); builder.EndCategory(); AdmContent content = builder.GetContent(); IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator(); categoriesEnumerator.MoveNext(); IEnumerator<AdmPolicy> policiesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator(); policiesEnumerator.MoveNext(); IEnumerator<AdmPart> partsEnumerator = policiesEnumerator.Current.Parts.GetEnumerator(); Assert.IsTrue(partsEnumerator.MoveNext()); Assert.AreSame(typeof(AdmCheckboxPart), partsEnumerator.Current.GetType()); Assert.AreEqual("part", ((AdmCheckboxPart)partsEnumerator.Current).PartName); Assert.AreEqual(null, ((AdmCheckboxPart)partsEnumerator.Current).KeyName); Assert.AreEqual("value", ((AdmCheckboxPart)partsEnumerator.Current).ValueName); Assert.AreEqual(true, ((AdmCheckboxPart)partsEnumerator.Current).CheckedByDefault); Assert.AreEqual(true, ((AdmCheckboxPart)partsEnumerator.Current).ValueForOn); Assert.AreEqual(false, ((AdmCheckboxPart)partsEnumerator.Current).ValueForOff); }