void DoUpdateConfigurationSectionManageability(IConfigurationAccessor configurationAccessor,
                                                       String sectionName)
        {
            ConfigurationSectionManageabilityProvider manageabilityProvider = manageabilityProviders[sectionName];

            ConfigurationSection section = configurationAccessor.GetSection(sectionName);

            if (section != null)
            {
                IRegistryKey machineKey = null;
                IRegistryKey userKey    = null;

                try
                {
                    LoadPolicyRegistryKeys(sectionName, out machineKey, out userKey);

                    if (!manageabilityProvider
                        .OverrideWithGroupPolicies(section, readGroupPolicies, machineKey, userKey))
                    {
                        configurationAccessor.RemoveSection(sectionName);
                    }
                }
                catch (Exception e)
                {
                    ManageabilityExtensionsLogger.LogException(e, Resources.ExceptionUnexpectedErrorProcessingSection);
                }
                finally
                {
                    ReleasePolicyRegistryKeys(machineKey, userKey);
                }
            }
        }
Example #2
0
        public void UpdateConfigurationManageability(IConfigurationAccessor configurationAccessor)
        {
            using (new GroupPolicyLock())
            {
                foreach (String sectionName in manageabilityProviders.Keys)
                {
                    if (publishedSettingsMapping.ContainsKey(sectionName))
                    {
                        RevokeAll(publishedSettingsMapping[sectionName]);
                    }

                    ConfigurationSectionManageabilityProvider manageabilityProvider = manageabilityProviders[sectionName];

                    ConfigurationSection section = configurationAccessor.GetSection(sectionName);
                    if (section != null)
                    {
                        ICollection <ConfigurationSetting> wmiSettings = new List <ConfigurationSetting>();

                        IRegistryKey machineKey = null;
                        IRegistryKey userKey    = null;

                        try
                        {
                            LoadPolicyRegistryKeys(sectionName, out machineKey, out userKey);

                            if (manageabilityProvider
                                .OverrideWithGroupPoliciesAndGenerateWmiObjects(section,
                                                                                this.readGroupPolicies, machineKey, userKey,
                                                                                generateWmiObjects, wmiSettings))
                            {
                                publishedSettingsMapping[sectionName] = wmiSettings;

                                PublishAll(wmiSettings, sectionName);
                            }
                            else
                            {
                                configurationAccessor.RemoveSection(sectionName);
                            }
                        }
                        catch (Exception e)
                        {
                            ManageabilityExtensionsLogger.LogException(e, Resources.ExceptionUnexpectedErrorProcessingSection);
                        }
                        finally
                        {
                            ReleasePolicyRegistryKeys(machineKey, userKey);
                        }
                    }
                }
            }                   // locks on group policies are released here
        }
        public void NotifyUpdatedSections(IEnumerable <string> sectionsToNotify)
        {
            foreach (string rawSectionName in sectionsToNotify)
            {
                String sectionName = CanonicalizeSectionName(rawSectionName);

                Delegate[] invocationList = null;

                lock (eventHandlersLock)
                {
                    ConfigurationChangedEventHandler callbacks = (ConfigurationChangedEventHandler)eventHandlers[sectionName];
                    if (callbacks == null)
                    {
                        continue;
                    }
                    invocationList = callbacks.GetInvocationList();
                }

                ConfigurationChangedEventArgs eventData = new ConfigurationChangedEventArgs(sectionName);
                foreach (ConfigurationChangedEventHandler callback in invocationList)
                {
                    try
                    {
                        if (callback != null)
                        {
                            callback(this, eventData);
                        }
                    }
                    catch (Exception e)
                    {
                        ManageabilityExtensionsLogger.LogException(e,
                                                                   String.Format(Resources.Culture,
                                                                                 Resources.ExceptionErrorOnCallbackForSectionUpdate,
                                                                                 sectionName,
                                                                                 callback.ToString()));
                    }
                }
            }
        }
 /// <summary>
 /// Logs an error detected while overriding a configuration object with policy values.
 /// </summary>
 /// <param name="exception">The exception representing the error.</param>
 protected virtual void LogExceptionWhileOverriding(Exception exception)
 {
     ManageabilityExtensionsLogger.LogExceptionWhileOverriding(exception);
 }