protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder,
                                                                      FormattedDatabaseTraceListenerData configurationObject,
                                                                      IConfigurationSource configurationSource,
                                                                      String elementPolicyKeyName)
        {
            List <AdmDropDownListItem> connectionStrings = new List <AdmDropDownListItem>();
            ConnectionStringsSection   connectionStringsSection
                = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");

            if (connectionStringsSection != null)
            {
                foreach (ConnectionStringSettings connectionString in connectionStringsSection.ConnectionStrings)
                {
                    connectionStrings.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                }
            }
            contentBuilder.AddDropDownListPart(Resources.DatabaseTraceListenerDatabasePartName,
                                               DatabaseInstanceNamePropertyName,
                                               connectionStrings,
                                               configurationObject.DatabaseInstanceName);
            contentBuilder.AddEditTextPart(Resources.DatabaseTraceListenerWriteStoreProcPartName,
                                           WriteLogStoredProcNamePropertyName,
                                           configurationObject.WriteLogStoredProcName,
                                           512,
                                           true);
            contentBuilder.AddEditTextPart(Resources.DatabaseTraceListenerAddCategoryStoreProcPartName,
                                           AddCategoryStoredProcNamePropertyName,
                                           configurationObject.AddCategoryStoredProcName,
                                           512,
                                           false);
            AddTraceOptionsPart(contentBuilder, configurationObject.TraceOutputOptions);
            AddFilterPart(contentBuilder, configurationObject.Filter);
            AddFormattersPart(contentBuilder, configurationObject.Formatter, configurationSource);
        }
        /// <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,
                                                                      DataCacheStorageData configurationObject,
                                                                      IConfigurationSource configurationSource,
                                                                      String elementPolicyKeyName)
        {
            List <AdmDropDownListItem> connectionStrings = new List <AdmDropDownListItem>();
            ConnectionStringsSection   connectionStringsSection
                = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");

            if (connectionStringsSection != null)
            {
                foreach (ConnectionStringSettings connectionString in connectionStringsSection.ConnectionStrings)
                {
                    connectionStrings.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                }
            }
            contentBuilder.AddDropDownListPart(Resources.DataCacheStorageDatabaseInstanceNamePartName,
                                               elementPolicyKeyName,
                                               DatabaseInstanceNamePropertyName,
                                               connectionStrings,
                                               configurationObject.DatabaseInstanceName);

            contentBuilder.AddEditTextPart(Resources.DataCacheStoragePartitionNamePartName,
                                           elementPolicyKeyName,
                                           PartitionNamePropertyName,
                                           configurationObject.PartitionName,
                                           255,
                                           true);
        }
        protected override void AddAdministrativeTemplateDirectives(
            AdmContentBuilder contentBuilder,
            DatabaseSettings configurationSection,
            IConfigurationSource configurationSource,
            string sectionKey)
        {
            contentBuilder.StartPolicy(Resources.DatabaseSettingsPolicyName, sectionKey);
            List <AdmDropDownListItem> dropDownListItemList = new List <AdmDropDownListItem>();
            ConnectionStringsSection   section = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");

            if (section != null)
            {
                foreach (ConnectionStringSettings connectionString in (ConfigurationElementCollection)section.ConnectionStrings)
                {
                    dropDownListItemList.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                }
            }
            contentBuilder.AddDropDownListPart(Resources.DatabaseSettingsDefaultDatabasePartName, "defaultDatabase", (IEnumerable <AdmDropDownListItem>)dropDownListItemList, configurationSection.DefaultDatabase);
            contentBuilder.EndPolicy();
            if (configurationSection.ProviderMappings.Count <= 0)
            {
                return;
            }
            contentBuilder.StartCategory(Resources.ProviderMappingsCategoryName);
            foreach (DbProviderMapping providerMapping in configurationSection.ProviderMappings)
            {
                contentBuilder.StartPolicy(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.ProviderMappingPolicyNameTemplate, (object)providerMapping.Name), sectionKey + "\\providerMappings\\" + providerMapping.Name);
                contentBuilder.AddComboBoxPart(Resources.ProviderMappingDatabaseTypePartName, "databaseType", providerMapping.DatabaseType.AssemblyQualifiedName, (int)byte.MaxValue, false, DatabaseSettingsManageabilityProvider.DatabaseTypeNames);
                contentBuilder.EndPolicy();
            }
            contentBuilder.EndCategory();
        }
        /// <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,
                                                                    DatabaseSettings configurationSection,
                                                                    IConfigurationSource configurationSource, String sectionKey)
        {
            contentBuilder.StartPolicy(Resources.DatabaseSettingsPolicyName, sectionKey);
            {
                List <AdmDropDownListItem> connectionStrings = new List <AdmDropDownListItem>();
                ConnectionStringsSection   connectionStringsSection
                    = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");
                if (connectionStringsSection != null)
                {
                    foreach (ConnectionStringSettings connectionString in connectionStringsSection.ConnectionStrings)
                    {
                        connectionStrings.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                    }
                }
                contentBuilder.AddDropDownListPart(Resources.DatabaseSettingsDefaultDatabasePartName,
                                                   DefaultDatabasePropertyName,
                                                   connectionStrings,
                                                   configurationSection.DefaultDatabase);
            }
            contentBuilder.EndPolicy();

            if (configurationSection.ProviderMappings.Count > 0)
            {
                contentBuilder.StartCategory(Resources.ProviderMappingsCategoryName);
                {
                    foreach (DbProviderMapping providerMapping in configurationSection.ProviderMappings)
                    {
                        contentBuilder.StartPolicy(String.Format(CultureInfo.InvariantCulture,
                                                                 Resources.ProviderMappingPolicyNameTemplate,
                                                                 providerMapping.Name),
                                                   sectionKey + @"\" + ProviderMappingsKeyName + @"\" + providerMapping.Name);

                        contentBuilder.AddComboBoxPart(Resources.ProviderMappingDatabaseTypePartName,
                                                       DatabaseTypePropertyName,
                                                       providerMapping.DatabaseType.AssemblyQualifiedName,
                                                       255,
                                                       false,
                                                       DatabaseTypeNames);

                        contentBuilder.EndPolicy();
                    }
                }
                contentBuilder.EndCategory();
            }
        }
        public void CanAddDropDownListPartWithKeyName()
        {
            List<AdmDropDownListItem> items = new List<AdmDropDownListItem>();
            items.Add(new AdmDropDownListItem("1", "1"));
            items.Add(new AdmDropDownListItem("2", "2"));
            items.Add(new AdmDropDownListItem("3", "3"));

            AdmContentBuilder builder = new AdmContentBuilder();

            builder.StartCategory("category");
            builder.StartPolicy("policy", "key");
            builder.AddDropDownListPart("part", "key", "value", items, "1");
            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(AdmDropDownListPart), partsEnumerator.Current.GetType());
            Assert.AreEqual("part", ((AdmDropDownListPart)partsEnumerator.Current).PartName);
            Assert.AreEqual("key", ((AdmDropDownListPart)partsEnumerator.Current).KeyName);
            Assert.AreEqual("value", ((AdmDropDownListPart)partsEnumerator.Current).ValueName);
            Assert.AreEqual("1", ((AdmDropDownListPart)partsEnumerator.Current).DefaultValue);
            IEnumerator<AdmDropDownListItem> itemsEnumerator = ((AdmDropDownListPart)partsEnumerator.Current).Items.GetEnumerator();
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("1", itemsEnumerator.Current.Name);
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("2", itemsEnumerator.Current.Name);
            Assert.IsTrue(itemsEnumerator.MoveNext());
            Assert.AreEqual("3", itemsEnumerator.Current.Name);
            Assert.IsFalse(itemsEnumerator.MoveNext());
        }