/// <summary>
        /// <para>Adds to the dictionary configuration data for
        /// the enterpriselibrary.configurationSettings configuration section.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        /// <param name="configurationDictionary">
        /// <para>A <see cref="ConfigurationDictionary"/> to add
        /// configuration data to.</para></param>
        public void BuildContext(IServiceProvider serviceProvider, ConfigurationDictionary configurationDictionary)
        {
            CacheManagerSettingsNode node = GetCacheManagerSettingsNode(serviceProvider);

            if (node != null)
            {
                CacheManagerSettings settings = node.CacheManagerSettings;
                configurationDictionary[CacheManagerSettings.SectionName] = settings;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the caching configuration from an application configuration file.
        /// </summary>
        /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
        /// <param name="rootNode">The <see cref="ConfigurationApplicationNode"/> of the hierarchy.</param>
        /// <param name="section">The caching configuration section or null if no section was found.</param>
        protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
        {
            if (null != section)
            {
                CacheManagerSettingsNodeBuilder builder          = new CacheManagerSettingsNodeBuilder(serviceProvider, (CacheManagerSettings)section);
                CacheManagerSettingsNode        cacheManagerNode = builder.Build();
                SetProtectionProvider(section, cacheManagerNode);

                rootNode.AddNode(cacheManagerNode);
            }
        }
		public CacheManagerSettingsNode Build()
		{
			CacheManagerSettingsNode rootNode = new CacheManagerSettingsNode();
			CacheManagerCollectionNode node = new CacheManagerCollectionNode();
			foreach (CacheManagerData data in cacheManagerSettings.CacheManagers)
			{
				CreateCacheManagerNode(node, data);
			}			
			rootNode.AddNode(node);
			rootNode.DefaultCacheManager = defaultNode;
			return rootNode;
		}
Exemplo n.º 4
0
        /// <summary>
        /// Adds a default cache manager.
        /// </summary>
        protected override void AddDefaultChildNodes()
        {
            base.AddDefaultChildNodes();
            CacheManagerData defaultData          = new CacheManagerData(SR.DefaultCacheManagerName, CacheManagerNode.expirationPollFreq, CacheManagerNode.maxElementsInCache, CacheManagerNode.numberToRemoveWhenScavenging);
            int defaultNodeIdx                    = Nodes.Add(new CacheManagerNode(defaultData));
            CacheManagerSettingsNode settingsNode = Parent as CacheManagerSettingsNode;

            if (settingsNode != null)
            {
                settingsNode.DefaultCacheManager = (CacheManagerNode)Nodes[defaultNodeIdx];
            }
        }
        public CacheManagerSettingsNode Build()
        {
            CacheManagerSettingsNode   rootNode = new CacheManagerSettingsNode();
            CacheManagerCollectionNode node     = new CacheManagerCollectionNode();

            foreach (CacheManagerData data in cacheManagerSettings.CacheManagers)
            {
                CreateCacheManagerNode(node, data);
            }
            rootNode.AddNode(node);
            rootNode.DefaultCacheManager = defaultNode;
            return(rootNode);
        }
Exemplo n.º 6
0
        /// <summary>
        /// <para>Adds the <see cref="CacheManagerSettingsNode"/> to the current application with a default <see cref="CacheManagerNode"/>.</para>
        /// </summary>
        /// <param name="e"><para>An <see cref="EventArgs"/> containing the event data.</para></param>
        protected override void OnExecuted(EventArgs e)
        {
            base.OnExecuted(e);
            CacheManagerSettingsNode node = ChildNode as CacheManagerSettingsNode;

            Debug.Assert(null != node, "The added node should be a CacheManagerSettingsNode");

            CacheManagerCollectionNode cacheManagerCollectionNode = new CacheManagerCollectionNode();

            node.AddNode(cacheManagerCollectionNode);
            int defaultNodeIdx = cacheManagerCollectionNode.AddNode(new CacheManagerNode());

            node.DefaultCacheManager = (CacheManagerNode)cacheManagerCollectionNode.Nodes[defaultNodeIdx];
        }
        /// <summary>
        /// <para>Saves the configuration settings created for the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public void Save(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(CacheManagerSettings.SectionName))
            {
                CacheManagerSettingsNode cacheManagerSettingsNode = GetCacheManagerSettingsNode(serviceProvider);
                CacheManagerSettings     settings = cacheManagerSettingsNode.CacheManagerSettings;
                if (settings != null)
                {
                    try
                    {
                        configurationContext.WriteConfiguration(CacheManagerSettings.SectionName, settings);
                    }
                    catch (InvalidOperationException e)
                    {
                        ServiceHelper.LogError(serviceProvider, cacheManagerSettingsNode, e);
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets a <see cref="ConfigurationSectionInfo"/> object containing the Caching Block's configuration information.
        /// </summary>
        /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
        /// <returns>A <see cref="ConfigurationSectionInfo"/> object containing the Caching Block's configuration information.</returns>
        protected override ConfigurationSectionInfo GetConfigurationSectionInfo(IServiceProvider serviceProvider)
        {
            ConfigurationNode        rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
            CacheManagerSettingsNode node     = null;

            if (rootNode != null)
            {
                node = (CacheManagerSettingsNode)rootNode.Hierarchy.FindNodeByType(rootNode, typeof(CacheManagerSettingsNode));
            }
            CacheManagerSettings cacheSection = null;

            if (node == null)
            {
                cacheSection = null;
            }
            else
            {
                CacheManagerSettingsBuilder builder = new CacheManagerSettingsBuilder(serviceProvider, node);
                cacheSection = builder.Build();
            }
            return(new ConfigurationSectionInfo(node, cacheSection, CacheManagerSettings.SectionName));
        }
 /// <summary>
 /// <para>Opens the configuration settings and registers them with the application.</para>
 /// </summary>
 /// <param name="serviceProvider">
 /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
 /// </param>
 public void Open(IServiceProvider serviceProvider)
 {
     ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);
     if (configurationContext.IsValidSection(CacheManagerSettings.SectionName))
     {
         CacheManagerSettingsNode cacheManagerSettingsNode = null;
         try
         {
             CacheManagerSettings settings = configurationContext.GetConfiguration(CacheManagerSettings.SectionName) as CacheManagerSettings;
             if (settings != null)
             {
                 cacheManagerSettingsNode = new CacheManagerSettingsNode(settings);
                 ConfigurationNode configurationNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
                 configurationNode.Nodes.Add(cacheManagerSettingsNode);
             }
         }
         catch (ConfigurationException e)
         {
             ServiceHelper.LogError(serviceProvider, cacheManagerSettingsNode, e);
         }
     }
 }
        /// <summary>
        /// <para>Opens the configuration settings and registers them with the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public void Open(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(CacheManagerSettings.SectionName))
            {
                CacheManagerSettingsNode cacheManagerSettingsNode = null;
                try
                {
                    CacheManagerSettings settings = configurationContext.GetConfiguration(CacheManagerSettings.SectionName) as CacheManagerSettings;
                    if (settings != null)
                    {
                        cacheManagerSettingsNode = new CacheManagerSettingsNode(settings);
                        ConfigurationNode configurationNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
                        configurationNode.Nodes.Add(cacheManagerSettingsNode);
                    }
                }
                catch (ConfigurationException e)
                {
                    ServiceHelper.LogError(serviceProvider, cacheManagerSettingsNode, e);
                }
            }
        }
Exemplo n.º 11
0
 public CacheManagerSettingsBuilder(IServiceProvider serviceProvider, CacheManagerSettingsNode cacheSettingsNode)
 {
     this.cacheSettingsNode = cacheSettingsNode;
     hierarchy          = ServiceHelper.GetCurrentHierarchy(serviceProvider);
     cacheConfiguration = new CacheManagerSettings();
 }
		public CacheManagerSettingsBuilder(IServiceProvider serviceProvider, CacheManagerSettingsNode cacheSettingsNode) 
		{
			this.cacheSettingsNode = cacheSettingsNode;
			hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider);
			cacheConfiguration = new CacheManagerSettings();
		}