Example #1
0
 public void SetContainerConfiguration(AbstractConfiguration configuration, string name, int index)
 {
     if (m_Configurations.Contains(configuration))
     {
         return;
     }
     if (m_ContainerConfiguration == configuration)
     {
         SetContainerConfigurationIndex(index);
         var currentContainerName = GetNameForConfiguration(m_ContainerConfiguration);
         if (currentContainerName != name)
         {
             m_NamedConfigurations.Remove(currentContainerName);
             m_NamedConfigurations[name] = configuration;
         }
     }
     else
     {
         m_ContainerConfigurationChanged = true;
         UnregisterEventHandlers(m_ContainerConfiguration);
         m_ContainerConfiguration = configuration;
         m_Configurations.Remove(m_ContainerConfiguration);
         AddConfigurationAtIndex(configuration, name, index);
     }
 }
Example #2
0
        public override sealed void Clear()
        {
            RaiseConfigurationChangedEvent(new ConfigurationEventArgs(ConfigurationEventType.Clear, true));
            foreach (var configuration in m_Configurations)
            {
                UnregisterEventHandlers(configuration);
            }
            m_Configurations.Clear();
            m_NamedConfigurations.Clear();

            // recreate the in memory configuration
            UnregisterEventHandlers(m_ContainerConfiguration);
            m_ContainerConfiguration = new ConcurrentDictionaryConfiguration();
            m_ContainerConfiguration.ListDelimiter            = ListDelimiter;
            m_ContainerConfiguration.DelimiterParsingDisabled = DelimiterParsingDisabled;
            RegisterEventHandlers(m_ContainerConfiguration);
            m_Configurations.Add(m_ContainerConfiguration);

            UnregisterEventHandlers(m_OverrideProperties);
            m_OverrideProperties = new ConcurrentDictionaryConfiguration();
            m_OverrideProperties.ListDelimiter            = ListDelimiter;
            m_OverrideProperties.DelimiterParsingDisabled = DelimiterParsingDisabled;
            RegisterEventHandlers(m_OverrideProperties);

            RaiseConfigurationChangedEvent(new ConfigurationEventArgs(ConfigurationEventType.Clear, false));
            m_ContainerConfigurationChanged = false;
            Invalidate();
        }
Example #3
0
 private static void RemoveDefaultConfiguration()
 {
     lock (m_ClassLock)
     {
         if (m_Instance == null || m_CustomConfigurationInstalled)
         {
             return;
         }
         var defaultConfig = (ConcurrentCompositeConfiguration)m_Instance;
         // Stop loading of the configuration
         var defaultFileConfig = (DynamicUrlConfiguration)defaultConfig.GetConfiguration(UrlConfigName);
         if (defaultFileConfig != null)
         {
             defaultFileConfig.StopLoading();
         }
         // Find the listener and remove it so that DynamicProperty will no longer receives
         // callback from the default configuration source
         var dynamicPropertyEventHandler =
             defaultConfig.ConfigurationChangedEventHandlers.FirstOrDefault(handler => handler.Method.DeclaringType == typeof(DynamicProperty));
         if (dynamicPropertyEventHandler != null)
         {
             defaultConfig.ConfigurationChanged -= dynamicPropertyEventHandler;
         }
         m_Instance = null;
     }
 }
Example #4
0
 internal static void SetDirect(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_Instance != null)
         {
             // Transfer properties which are not in conflict with new configuration
             foreach (var key in m_Instance.Keys)
             {
                 var value = m_Instance.GetProperty(key);
                 if (value != null && !config.ContainsKey(key))
                 {
                     config.SetProperty(key, value);
                 }
             }
             // Transfer listeners
             foreach (var handler in m_Instance.ConfigurationChangedEventHandlers)
             {
                 if (handler.Method.DeclaringType == typeof(DynamicProperty))
                 {
                     // No need to transfer the fast property listener as it should be set later
                     // with the new configuration
                     continue;
                 }
                 config.ConfigurationChanged += handler;
             }
         }
         RemoveDefaultConfiguration();
         m_Instance = config;
         m_CustomConfigurationInstalled = true;
     }
 }
Example #5
0
 /// <summary>
 /// Creates a ConcurrentCompositeConfiguration with a specified <em>container configuration</em>,
 /// and then adds the given collection of configurations.
 /// </summary>
 /// <param name="containerConfiguration">container configuration to use</param>
 /// <param name="configurations">the collection of configurations to add</param>
 public ConcurrentCompositeConfiguration(AbstractConfiguration containerConfiguration, IEnumerable <IConfiguration> configurations)
     : this(containerConfiguration)
 {
     if (configurations != null)
     {
         foreach (var configuration in configurations)
         {
             AddConfiguration(configuration);
         }
     }
 }
Example #6
0
 /// <summary>
 /// Get the current system wide configuration. If there has not been set, it will return a default
 /// <see cref="ConcurrentCompositeConfiguration"/> which contains a SystemConfiguration from Apache Commons
 /// Configuration and a <see cref="DynamicUrlConfiguration"/>
 /// </summary>
 /// <returns></returns>
 public static AbstractConfiguration GetConfigInstance()
 {
     if (m_Instance == null)
     {
         lock (typeof(ConfigurationManager))
         {
             if (m_Instance == null)
             {
                 m_Instance = CreateDefaultConfigInstance();
             }
         }
     }
     return(m_Instance);
 }
 /// <summary>
 /// Get the current system wide configuration. If there has not been set, it will return a default
 /// <see cref="ConcurrentCompositeConfiguration"/> which contains a SystemConfiguration from Apache Commons
 /// Configuration and a <see cref="DynamicUrlConfiguration"/>
 /// </summary>
 /// <returns></returns>
 public static AbstractConfiguration GetConfigInstance()
 {
     if (m_Instance == null)
     {
         lock (typeof(ConfigurationManager))
         {
             if (m_Instance == null)
             {
                 m_Instance = CreateDefaultConfigInstance();
             }
         }
     }
     return m_Instance;
 }
Example #8
0
 /// <summary>
 /// Install the system wide configuration with the ConfigurationManager. This will also install
 /// the configuration with the <see cref="DynamicPropertyFactory"/> by calling <see cref="DynamicPropertyFactory.InitWithConfigurationSource"/>.
 /// This call can be made only once, otherwise IllegalStateException will be thrown.
 /// </summary>
 /// <param name="config"></param>
 public static void Install(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_CustomConfigurationInstalled)
         {
             throw new InvalidOperationException("A non-default configuration is already installed");
         }
         SetDirect(config);
         if (DynamicPropertyFactory.BackingConfigurationSource != config)
         {
             DynamicPropertyFactory.InitWithConfigurationSource(config);
         }
     }
 }
 /// <summary>
 /// Install the system wide configuration with the ConfigurationManager. This will also install 
 /// the configuration with the <see cref="DynamicPropertyFactory"/> by calling <see cref="DynamicPropertyFactory.InitWithConfigurationSource"/>.
 /// This call can be made only once, otherwise IllegalStateException will be thrown.
 /// </summary>
 /// <param name="config"></param>
 public static void Install(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_CustomConfigurationInstalled)
         {
             throw new InvalidOperationException("A non-default configuration is already installed");
         }
         SetDirect(config);
         if (DynamicPropertyFactory.BackingConfigurationSource != config)
         {
             DynamicPropertyFactory.InitWithConfigurationSource(config);
         }
     }
 }
Example #10
0
 /// <summary>
 /// Creates a ConcurrentCompositeConfiguration object with a specified <em>container  configuration</em>.
 /// This configuration will store any changes made by <see cref="IConfiguration.SetProperty"/>
 /// and <see cref="IConfiguration.AddProperty"/>
 /// </summary>
 /// <param name="containerConfiguration"></param>
 public ConcurrentCompositeConfiguration(AbstractConfiguration containerConfiguration)
 {
     m_Configurations.Clear();
     m_ContainerConfiguration = containerConfiguration;
 }
 /// <summary>
 /// Creates a ConcurrentCompositeConfiguration object with a specified <em>container  configuration</em>.
 /// This configuration will store any changes made by <see cref="IConfiguration.SetProperty"/>
 /// and <see cref="IConfiguration.AddProperty"/>
 /// </summary>
 /// <param name="containerConfiguration"></param>
 public ConcurrentCompositeConfiguration(AbstractConfiguration containerConfiguration)
 {
     m_Configurations.Clear();
     m_ContainerConfiguration = containerConfiguration;
 }
        public override sealed void Clear()
        {
            RaiseConfigurationChangedEvent(new ConfigurationEventArgs(ConfigurationEventType.Clear, true));
            foreach (var configuration in m_Configurations)
            {
                UnregisterEventHandlers(configuration);
            }
            m_Configurations.Clear();
            m_NamedConfigurations.Clear();

            // recreate the in memory configuration
            UnregisterEventHandlers(m_ContainerConfiguration);
            m_ContainerConfiguration = new ConcurrentDictionaryConfiguration();
            m_ContainerConfiguration.ListDelimiter = ListDelimiter;
            m_ContainerConfiguration.DelimiterParsingDisabled = DelimiterParsingDisabled;
            RegisterEventHandlers(m_ContainerConfiguration);
            m_Configurations.Add(m_ContainerConfiguration);

            UnregisterEventHandlers(m_OverrideProperties);
            m_OverrideProperties = new ConcurrentDictionaryConfiguration();
            m_OverrideProperties.ListDelimiter = ListDelimiter;
            m_OverrideProperties.DelimiterParsingDisabled = DelimiterParsingDisabled;
            RegisterEventHandlers(m_OverrideProperties);

            RaiseConfigurationChangedEvent(new ConfigurationEventArgs(ConfigurationEventType.Clear, false));
            m_ContainerConfigurationChanged = false;
            Invalidate();
        }
 public void SetContainerConfiguration(AbstractConfiguration configuration, string name, int index)
 {
     if (m_Configurations.Contains(configuration))
     {
         return;
     }
     if (m_ContainerConfiguration == configuration)
     {
         SetContainerConfigurationIndex(index);
         var currentContainerName = GetNameForConfiguration(m_ContainerConfiguration);
         if (currentContainerName != name)
         {
             m_NamedConfigurations.Remove(currentContainerName);
             m_NamedConfigurations[name] = configuration;
         }
     }
     else
     {
         m_ContainerConfigurationChanged = true;
         UnregisterEventHandlers(m_ContainerConfiguration);
         m_ContainerConfiguration = configuration;
         m_Configurations.Remove(m_ContainerConfiguration);
         AddConfigurationAtIndex(configuration, name, index);
     }
 }
 /// <summary>
 /// Creates a ConcurrentCompositeConfiguration with a specified <em>container configuration</em>,
 /// and then adds the given collection of configurations.
 /// </summary>
 /// <param name="containerConfiguration">container configuration to use</param>
 /// <param name="configurations">the collection of configurations to add</param>
 public ConcurrentCompositeConfiguration(AbstractConfiguration containerConfiguration, IEnumerable<IConfiguration> configurations)
     : this(containerConfiguration)
 {
     if (configurations != null)
     {
         foreach (var configuration in configurations)
         {
             AddConfiguration(configuration);
         }
     }
 }
 private static void RemoveDefaultConfiguration()
 {
     lock (m_ClassLock)
     {
         if (m_Instance == null || m_CustomConfigurationInstalled)
         {
             return;
         }
         var defaultConfig = (ConcurrentCompositeConfiguration)m_Instance;
         // Stop loading of the configuration
         var defaultFileConfig = (DynamicUrlConfiguration)defaultConfig.GetConfiguration(UrlConfigName);
         if (defaultFileConfig != null)
         {
             defaultFileConfig.StopLoading();
         }
         // Find the listener and remove it so that DynamicProperty will no longer receives 
         // callback from the default configuration source
         var dynamicPropertyEventHandler =
             defaultConfig.ConfigurationChangedEventHandlers.FirstOrDefault(handler => handler.Method.DeclaringType == typeof(DynamicProperty));
         if (dynamicPropertyEventHandler != null)
         {
             defaultConfig.ConfigurationChanged -= dynamicPropertyEventHandler;
         }
         m_Instance = null;
     }
 }
 internal static void SetDirect(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_Instance != null)
         {
             // Transfer properties which are not in conflict with new configuration
             foreach (var key in m_Instance.Keys)
             {
                 var value = m_Instance.GetProperty(key);
                 if (value != null && !config.ContainsKey(key))
                 {
                     config.SetProperty(key, value);
                 }
             }
             // Transfer listeners
             foreach (var handler in m_Instance.ConfigurationChangedEventHandlers)
             {
                 if (handler.Method.DeclaringType == typeof(DynamicProperty))
                 {
                     // No need to transfer the fast property listener as it should be set later
                     // with the new configuration
                     continue;
                 }
                 config.ConfigurationChanged += handler;
             }
         }
         RemoveDefaultConfiguration();
         m_Instance = config;
         m_CustomConfigurationInstalled = true;
     }
 }