public void DataTest()
        {
            string           name         = "testName";
            CacheStorageData cacheStorage = new CustomCacheStorageData();

            cacheStorage.Name     = "testCacheStorageName";
            cacheStorage.TypeName = "fakeType";
            int expirationPollFrequencyInSeconds       = 30;
            int maximumElementsInCacheBeforeScavenging = 5;
            int numberToRemoveWhenScavenging           = 8;

            CacheManagerData data = new CacheManagerData();

            data.Name         = name;
            data.CacheStorage = cacheStorage;
            data.ExpirationPollFrequencyInSeconds       = expirationPollFrequencyInSeconds;
            data.MaximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavenging;
            data.NumberToRemoveWhenScavenging           = numberToRemoveWhenScavenging;
            data.CacheStorage = cacheStorage;

            CacheManagerNode node = new CacheManagerNode(data);

            applicationNode.Nodes.Add(node);
            CacheManagerData nodeData = node.CacheManagerData;

            Assert.AreEqual(name, nodeData.Name);
            Assert.AreEqual(expirationPollFrequencyInSeconds, nodeData.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(maximumElementsInCacheBeforeScavenging, nodeData.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(numberToRemoveWhenScavenging, nodeData.NumberToRemoveWhenScavenging);
            Assert.AreEqual(cacheStorage.Name, nodeData.CacheStorage.Name);
            Assert.AreEqual(cacheStorage.TypeName, nodeData.CacheStorage.TypeName);
        }
        public void then_cache_managers_with_empty_backing_store_refere_to_null_backing_store()
        {
            var nullbackingStore           = savedSettings.BackingStores.Where(x => x.GetType() == typeof(CacheStorageData)).First();
            CacheManagerData cacheManager1 = (CacheManagerData)savedSettings.CacheManagers.Where(x => x.Name == "Cache Manager 1").First();

            Assert.AreEqual(nullbackingStore.Name, cacheManager1.CacheStorage);
        }
        public void DataTest()
        {
            string name = "testName";
            CacheStorageData cacheStorage = new CustomCacheStorageData();
            cacheStorage.Name = "testCacheStorageName";
            cacheStorage.TypeName = "fakeType";
            int expirationPollFrequencyInSeconds = 30;
            int maximumElementsInCacheBeforeScavenging = 5;
            int numberToRemoveWhenScavenging = 8;

            CacheManagerData data = new CacheManagerData();
            data.Name = name;
            data.CacheStorage = cacheStorage;
            data.ExpirationPollFrequencyInSeconds = expirationPollFrequencyInSeconds;
            data.MaximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavenging;
            data.NumberToRemoveWhenScavenging = numberToRemoveWhenScavenging;
            data.CacheStorage = cacheStorage;

            CacheManagerNode node = new CacheManagerNode(data);
            applicationNode.Nodes.Add(node);
            CacheManagerData nodeData = node.CacheManagerData;
            Assert.AreEqual(name, nodeData.Name);
            Assert.AreEqual(expirationPollFrequencyInSeconds, nodeData.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(maximumElementsInCacheBeforeScavenging, nodeData.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(numberToRemoveWhenScavenging, nodeData.NumberToRemoveWhenScavenging);
            Assert.AreEqual(cacheStorage.Name, nodeData.CacheStorage.Name);
            Assert.AreEqual(cacheStorage.TypeName, nodeData.CacheStorage.TypeName);
        }
Exemple #4
0
        public void DataTest()
        {
            CacheStorageData cacheStorage = new CustomCacheStorageData();

            cacheStorage.Name = "testCacheStorage";

            CacheManagerDataCollection cacheManagers = new CacheManagerDataCollection();
            CacheManagerData           testManager1  = new CacheManagerData();

            testManager1.Name         = "testName";
            testManager1.CacheStorage = cacheStorage;
            cacheManagers.Add(testManager1);

            CacheManagerSettings data = new CacheManagerSettings();

            data.CacheManagers.Clear();
            data.CacheManagers.AddRange(cacheManagers);

            CacheManagerSettingsNode node = new CacheManagerSettingsNode(data);

            applicationNode.Nodes.Add(node);
            CacheManagerSettings nodeData = node.CacheManagerSettings;

            Assert.AreSame(testManager1, nodeData.CacheManagers[testManager1.Name]);
        }
Exemple #5
0
        public void CacheManagerIsOverridenIfThereAreUserPolicyOverrides()
        {
            CacheManagerData data1 = new CacheManagerData();

            data1.Name         = "cache manager 1";
            data1.CacheStorage = "cache storage";
            data1.ExpirationPollFrequencyInSeconds       = 100;
            data1.MaximumElementsInCacheBeforeScavenging = 200;
            data1.NumberToRemoveWhenScavenging           = 300;
            section.CacheManagers.Add(data1);

            MockRegistryKey userCacheManagersKey = new MockRegistryKey(false);

            userKey.AddSubKey(CacheManagerSettingsManageabilityProvider.CacheManagersKeyName, userCacheManagersKey);
            MockRegistryKey userCacheManager1Key = new MockRegistryKey(false);

            userCacheManagersKey.AddSubKey(data1.Name, userCacheManager1Key);
            userCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerExpirationPollFrequencyInSecondsPropertyName, 160);
            userCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName, 260);
            userCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerNumberToRemoveWhenScavengingPropertyName, 360);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.AreEqual("cache storage", data1.CacheStorage);
            Assert.AreEqual(160, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(260, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(360, data1.NumberToRemoveWhenScavenging);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(userCacheManagersKey, userCacheManager1Key));
        }
Exemple #6
0
        public void CacheManagerIsNotOverridenIfThereArePolicyOverridesForDifferentName()
        {
            CacheManagerData data1 = new CacheManagerData();

            data1.Name         = "cache manager 1";
            data1.CacheStorage = "cache storage";
            data1.ExpirationPollFrequencyInSeconds       = 100;
            data1.MaximumElementsInCacheBeforeScavenging = 200;
            data1.NumberToRemoveWhenScavenging           = 300;
            section.CacheManagers.Add(data1);

            MockRegistryKey machineCacheManagersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.CacheManagersKeyName, machineCacheManagersKey);
            MockRegistryKey machineCacheManager1Key = new MockRegistryKey(false);

            machineCacheManagersKey.AddSubKey("cache manager 2", machineCacheManager1Key);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerExpirationPollFrequencyInSecondsPropertyName, 150);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName, 250);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerNumberToRemoveWhenScavengingPropertyName, 350);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual("cache storage", data1.CacheStorage);
            Assert.AreEqual(100, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(200, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(300, data1.NumberToRemoveWhenScavenging);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machineCacheManagersKey, machineCacheManager1Key));
        }
		private void CreateCacheManagerNode(CacheManagerCollectionNode node, CacheManagerData cacheManagerData)
		{
			CacheManagerNode cacheManagerNode = new CacheManagerNode(cacheManagerData);
			node.AddNode(cacheManagerNode);
			if (cacheManagerNode.Name == cacheManagerSettings.DefaultCacheManager) defaultNode = cacheManagerNode;
			CreateStorageNode(cacheManagerNode, cacheManagerData.CacheStorage);
		}
Exemple #8
0
        public void CacheManagerWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            CacheManagerData data1 = new CacheManagerData();

            data1.Name = "cache manager 1";
            section.CacheManagers.Add(data1);
            CacheManagerData data2 = new CacheManagerData();

            data2.Name = "cache manager 2";
            section.CacheManagers.Add(data2);

            MockRegistryKey machineCacheManagersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.CacheManagersKeyName, machineCacheManagersKey);
            MockRegistryKey machineCacheManager1Key = new MockRegistryKey(false);

            machineCacheManagersKey.AddSubKey("cache manager 1", machineCacheManager1Key);
            machineCacheManager1Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, section.CacheManagers.Count);
            Assert.IsNotNull(section.CacheManagers.Get("cache manager 1"));
            Assert.IsNotNull(section.CacheManagers.Get("cache manager 2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineCacheManagersKey, machineCacheManager1Key));
        }
        /// <summary>
        /// <para>Gets the <see cref="Type"/> of the <see cref="CacheManager"/> for the factory to create.</para>
        /// </summary>
        /// <param name="cacheManagerName">
        /// <para>The name from configuration of the <see cref="CacheManager"/>.</para>
        /// </param>
        /// <returns>
        /// <para>The <see cref="Type"/> of the <see cref="CacheManager"/> to create.</para>
        /// </returns>
        protected override Type GetConfigurationType(string cacheManagerName)
        {
            CachingConfigurationView view             = new CachingConfigurationView(ConfigurationContext);
            CacheManagerData         cacheManagerData = view.GetCacheManagerData(cacheManagerName);

            return(GetType(cacheManagerData.TypeName));
        }
        void IContainerPolicyCreator.CreatePolicies(
            IPolicyList policyList,
            string instanceName,
            ConfigurationElement configurationObject,
            IConfigurationSource configurationSource)
        {
            CacheManagerData castConfigurationObject = (CacheManagerData)configurationObject;
            var cacheManagerName = instanceName;
            var cacheStorageName = castConfigurationObject.CacheStorage;
            var maximumElementsInCacheBeforeScavenging = castConfigurationObject.MaximumElementsInCacheBeforeScavenging;
            var numberToRemoveWhenScavenging           = castConfigurationObject.NumberToRemoveWhenScavenging;
            var expirationPollFrequencyInSeconds       = castConfigurationObject.ExpirationPollFrequencyInSeconds;

            policyList.Set <IBuildPlanPolicy>(
                new DelegateBuildPlanPolicy(
                    context =>
            {
                IBuilderContext backingStoreContext
                    = context.CloneForNewBuild(NamedTypeBuildKey.Make <IBackingStore>(cacheStorageName), null);
                IBackingStore backingStore = (IBackingStore)context.Strategies.ExecuteBuildUp(backingStoreContext);
                CachingInstrumentationProvider instrumentationProvider
                    = CreateInstrumentationProvider(cacheManagerName, configurationSource);
                return(new CacheManagerFactoryHelper().BuildCacheManager(
                           cacheManagerName,
                           backingStore,
                           maximumElementsInCacheBeforeScavenging,
                           numberToRemoveWhenScavenging,
                           expirationPollFrequencyInSeconds,
                           instrumentationProvider));
            }),
                NamedTypeBuildKey.Make <CacheManager>(cacheManagerName));
        }
        private CacheManager CreateCacheManager(string cacheManagerName)
        {
            CacheManager cacheManager = cacheManagers[cacheManagerName] as CacheManager;

            if (cacheManager != null)
            {
                return(cacheManager);
            }

            CachingConfigurationView      view             = new CachingConfigurationView(ConfigurationContext);
            CacheManagerData              cacheManagerData = view.GetCacheManagerData(cacheManagerName);
            CacheCapacityScavengingPolicy scavengingPolicy =
                new CacheCapacityScavengingPolicy(cacheManagerName, view);

            IBackingStore backingStore = backingStoreFactory.CreateBackingStore(cacheManagerName);
            Cache         cache        = new Cache(backingStore, scavengingPolicy);

            ExpirationPollTimer timer          = new ExpirationPollTimer();
            ExpirationTask      expirationTask = CreateExpirationTask(cache);
            ScavengerTask       scavengerTask  = new ScavengerTask(cacheManagerName, view, scavengingPolicy, cache);
            BackgroundScheduler scheduler      = new BackgroundScheduler(expirationTask, scavengerTask);

            cache.Initialize(scheduler);

            scheduler.Start();
            timer.StartPolling(new TimerCallback(scheduler.ExpirationTimeoutExpired), cacheManagerData.ExpirationPollFrequencyInSeconds * 1000);

            cacheManager = new CacheManager(cache, scheduler, timer);
            cacheManagers.Add(cacheManagerName, cacheManager);
            return(cacheManager);
        }
Exemple #12
0
 /// <summary>
 /// Initializes  new instance of the <see cref="CacheManagerNode"/> class with the given settings data.
 /// </summary>
 /// <param name="cacheManagerData">The settings objet to use.</param>
 public CacheManagerNode(CacheManagerData cacheManagerData) : base()
 {
     if (cacheManagerData == null)
     {
         throw new ArgumentNullException("cacheManagerData");
     }
     this.cacheManagerData = cacheManagerData;
 }
Exemple #13
0
 /// <summary>
 /// Initializes  new instance of the <see cref="CacheManagerNode"/> class with the given settings data.
 /// </summary>
 /// <param name="cacheManagerData">The settings objet to use.</param>
 public CacheManagerNode(CacheManagerData cacheManagerData)
     : base()
 {
     if (cacheManagerData == null)
     {
         throw new ArgumentNullException("cacheManagerData");
     }
     this.cacheManagerData = cacheManagerData;
 }
Exemple #14
0
        public void ManageabilityProviderGeneratesProperAdmContent()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(CacheManagerSettings.SectionName, section);

            IsolatedStorageCacheStorageData storage1, storage2;
            CacheManagerData manager1, manager2;
            StorageEncryptionProviderData encryption1;

            section.BackingStores.Add(storage1          = new IsolatedStorageCacheStorageData("storage1", "encryption1", "partition1"));
            section.CacheManagers.Add(manager1          = new CacheManagerData("manager1", 100, 200, 300, "storage1"));
            section.EncryptionProviders.Add(encryption1 = new StorageEncryptionProviderData("encryption1", typeof(object)));
            section.BackingStores.Add(storage2          = new IsolatedStorageCacheStorageData("storage2", "", "partition2"));
            section.CacheManagers.Add(manager2          = new CacheManagerData("manager2", 100, 200, 300, "storage2"));

            MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(IsolatedStorageCacheStorageData), subProvider);
            subProviders.Add(typeof(StorageEncryptionProviderData), subProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(new CacheManagerSettingsManageabilityProvider(subProviders));

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.InvokeAddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            Assert.AreEqual(3, subProvider.configurationObjects.Count);
            Assert.AreSame(storage1, subProvider.configurationObjects[0]);
            Assert.AreSame(encryption1, subProvider.configurationObjects[1]);
            Assert.AreSame(storage2, subProvider.configurationObjects[2]);
            MockAdmContent            content = contentBuilder.GetMockContent();
            IEnumerator <AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();

            Assert.IsTrue(categoriesEnumerator.MoveNext());
            Assert.AreEqual(Resources.CachingSectionCategoryName, categoriesEnumerator.Current.Name);
            IEnumerator <AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();

            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            Assert.AreEqual(Resources.CacheManagersCategoryName, subCategoriesEnumerator.Current.Name);
            IEnumerator <AdmPolicy> cacheManagerPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator();

            Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.AreEqual(String.Format(Resources.CacheManagerPolicyNameTemplate, manager1.Name), cacheManagerPoliciesEnumerator.Current.Name);
            Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.AreEqual(String.Format(Resources.CacheManagerPolicyNameTemplate, manager2.Name), cacheManagerPoliciesEnumerator.Current.Name);
            Assert.IsFalse(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            IEnumerator <AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();

            Assert.IsTrue(sectionPoliciesEnumerator.MoveNext());
            Assert.AreEqual(Resources.CacheManagerSettingsPolicyName, sectionPoliciesEnumerator.Current.Name);
            Assert.IsFalse(sectionPoliciesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
Exemple #15
0
        public void then_file_has_overridden_values()
        {
            FileConfigurationSource source       = new FileConfigurationSource(TargetFile);
            CacheManagerSettings    settings     = (CacheManagerSettings)source.GetSection(CacheManagerSettings.SectionName);
            CacheManagerData        cacheManager = (CacheManagerData)settings.CacheManagers.Get("Cache Manager");

            Assert.AreEqual(1, cacheManager.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(1, cacheManager.NumberToRemoveWhenScavenging);
            Assert.AreEqual(1, cacheManager.ExpirationPollFrequencyInSeconds);
        }
Exemple #16
0
        /// <summary>
        /// Initialize a new instance of the <see cref="CacheManagerNode"/> class with a <see cref="CacheManagerData"/> object.
        /// </summary>
        /// <param name="cacheManagerData">A <see cref="CacheManagerData"/> object.</param>
        public CacheManagerNode(CacheManagerData cacheManagerData)
            : base((cacheManagerData == null) ? Resources.DefaultCacheManagerNodeName : cacheManagerData.Name)
        {
            if (cacheManagerData == null) { throw new ArgumentNullException("cacheManagerData"); }

            this.expirationPollFrequencyInSeconds = cacheManagerData.ExpirationPollFrequencyInSeconds;
            this.maximumElementsInCacheBeforeScavenging = cacheManagerData.MaximumElementsInCacheBeforeScavenging;
            this.numberToRemoveWhenScavenging = cacheManagerData.NumberToRemoveWhenScavenging;
            this.cacheStorageName = cacheManagerData.CacheStorage;
        }
Exemple #17
0
            public ForCacheManagerNamedBuilder(ICachingConfiguration context, string cacheManagerName)
                : base(context)
            {
                cacheManagerData = new CacheManagerData
                {
                    Name = cacheManagerName
                };

                base.CachingSettings.CacheManagers.Add(cacheManagerData);
            }
        /// <summary>
        /// Gets the <see cref="CacheManagerData"/> from configuration for the named <see cref="CacheManager"/>
        /// </summary>
        /// <param name="cacheManagerName">
        /// The name of the <see cref="CacheManager"/>.
        /// </param>
        /// <returns>
        /// A <see cref="CacheManagerData"/> object.
        /// </returns>
        public CacheManagerData GetCacheManagerData(string cacheManagerName)
        {
            CacheManagerSettings configSettings = this.CacheManagerSettings;
            CacheManagerData     data           = configSettings.CacheManagers.Get(cacheManagerName);

            if (data == null)
            {
                throw new ConfigurationErrorsException(string.Format(Resources.Culture, Resources.UnableToFindCacheManagerInstance, cacheManagerName));
            }
            return(data);
        }
Exemple #19
0
        public void CanReadCacheManagerData()
        {
            XmlTextReader    xmlReader               = new XmlTextReader(new StringReader(configurationSection));
            XmlSerializer    xmlSerializer           = new XmlSerializer(typeof(CacheManagerData));
            CacheManagerData objectFromConfiguration = xmlSerializer.Deserialize(xmlReader) as CacheManagerData;

            Assert.AreEqual("InDatabasePersistence", objectFromConfiguration.Name);
            Assert.AreEqual(60, objectFromConfiguration.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(100, objectFromConfiguration.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(10, objectFromConfiguration.NumberToRemoveWhenScavenging);
        }
        /// <summary>
        /// <para>Gets the <see cref="CacheManagerData"/> from configuration for the named <see cref="CacheManager"/></para>
        /// </summary>
        /// <param name="cacheManagerName">
        /// <para>The name of the <see cref="CacheManager"/>.</para>
        /// </param>
        /// <returns>
        /// <para>A <see cref="CacheManagerData"/> object.</para>
        /// </returns>
        public virtual CacheManagerData GetCacheManagerData(string cacheManagerName)
        {
            CacheManagerSettings configSettings = GetCacheManagerSettings();
            CacheManagerData     data           = configSettings.CacheManagers[cacheManagerName];

            if (data == null)
            {
                throw new ConfigurationException(SR.UnableToFindCacheManagerInstance(cacheManagerName));
            }
            return(data);
        }
        /// <summary>
        /// <para>Gets the <see cref="CacheStorageData"/> from configuration for the named <see cref="CacheManager"/></para>
        /// </summary>
        /// <param name="cacheManagerName">
        /// <para>The name of the <see cref="CacheManager"/>.</para>
        /// </param>
        /// <returns>
        /// <para>A <see cref="CacheStorageData"/> object.</para>
        /// </returns>
        public virtual CacheStorageData GetCacheStorageDataForCacheManager(string cacheManagerName)
        {
            CacheManagerData cacheManagerData = GetCacheManagerData(cacheManagerName);
            CacheStorageData cacheStorageData = cacheManagerData.CacheStorage;

            if (cacheStorageData == null)
            {
                throw new ConfigurationException(SR.CannotInstantiateCacheStorage(cacheManagerName));
            }
            return(cacheStorageData);
        }
        private void CreateCacheManagerNode(CacheManagerCollectionNode node, CacheManagerData cacheManagerData)
        {
            CacheManagerNode cacheManagerNode = new CacheManagerNode(cacheManagerData);

            node.AddNode(cacheManagerNode);
            if (cacheManagerNode.Name == cacheManagerSettings.DefaultCacheManager)
            {
                defaultNode = cacheManagerNode;
            }
            CreateStorageNode(cacheManagerNode, cacheManagerData.CacheStorage);
        }
        /// <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 void Setup()
        {
            CustomCacheStorageData customStorageData = new CustomCacheStorageData("Custom Storage", typeof(MockCustomStorageBackingStore));
            CacheManagerData       cacheManagerData  = new CacheManagerData("Default Cache Manager", 10, 10, 10, customStorageData.Name);

            CacheManagerSettings settings = new CacheManagerSettings();

            settings.CacheManagers.Add(cacheManagerData);
            settings.BackingStores.Add(customStorageData);

            registrations = settings.GetRegistrations(null);
        }
        public void Setup()
        {
            IsolatedStorageCacheStorageData isolatedStorageData = new IsolatedStorageCacheStorageData("Isolated Storage", string.Empty, "part");
            CacheManagerData cacheManagerData = new CacheManagerData("Default Cache Manager", 10, 10, 10, isolatedStorageData.Name);

            CacheManagerSettings settings = new CacheManagerSettings();

            settings.CacheManagers.Add(cacheManagerData);
            settings.BackingStores.Add(isolatedStorageData);

            registrations = settings.GetRegistrations(null);
        }
Exemple #26
0
        /// <summary>
        /// Initialize a new instance of the <see cref="CacheManagerNode"/> class with a <see cref="CacheManagerData"/> object.
        /// </summary>
        /// <param name="cacheManagerData">A <see cref="CacheManagerData"/> object.</param>
        public CacheManagerNode(CacheManagerData cacheManagerData)
            : base((cacheManagerData == null) ? Resources.DefaultCacheManagerNodeName : cacheManagerData.Name)
        {
            if (cacheManagerData == null)
            {
                throw new ArgumentNullException("cacheManagerData");
            }

            this.expirationPollFrequencyInSeconds       = cacheManagerData.ExpirationPollFrequencyInSeconds;
            this.maximumElementsInCacheBeforeScavenging = cacheManagerData.MaximumElementsInCacheBeforeScavenging;
            this.numberToRemoveWhenScavenging           = cacheManagerData.NumberToRemoveWhenScavenging;
            this.cacheStorageName = cacheManagerData.CacheStorage;
        }
        public void Setup()
        {
            CacheStorageData cacheStorageData = new CacheStorageData("Null Storage", typeof(NullBackingStore));
            CacheManagerData cacheManagerData = new CacheManagerData("Default Cache Manager", 10, 10, 10, cacheStorageData.Name);

            CacheManagerSettings settings = new CacheManagerSettings();

            settings.CacheManagers.Add(cacheManagerData);
            settings.BackingStores.Add(cacheStorageData);

            settings.DefaultCacheManager = cacheManagerData.Name;

            registrations = settings.GetRegistrations(null);
        }
        bool OverrideWithGroupPoliciesAndGenerateWmiObjectsForCacheManager(CacheManagerDataBase cacheManagerDataBase,
                                                                           bool readGroupPolicies,
                                                                           IRegistryKey machineKey,
                                                                           IRegistryKey userKey,
                                                                           bool generateWmiObjects,
                                                                           ICollection <ConfigurationSetting> wmiSettings)
        {
            if (readGroupPolicies)
            {
                IRegistryKey policyKey = machineKey != null ? machineKey : userKey;
                if (policyKey != null)
                {
                    if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value)
                    {
                        return(false);
                    }
                    try
                    {
                        if (cacheManagerDataBase is CacheManagerData)
                        {
                            CacheManagerData cacheManagerData = (CacheManagerData)cacheManagerDataBase;

                            // cache storage is not overrideable
                            int?expirationPollFrequencyInSecondsOverride
                                = policyKey.GetIntValue(CacheManagerExpirationPollFrequencyInSecondsPropertyName);
                            int?maximumElementsInCacheBeforeScavengingOverride
                                = policyKey.GetIntValue(CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName);
                            int?numberToRemoveWhenScavengingOverride
                                = policyKey.GetIntValue(CacheManagerNumberToRemoveWhenScavengingPropertyName);

                            cacheManagerData.ExpirationPollFrequencyInSeconds       = expirationPollFrequencyInSecondsOverride.Value;
                            cacheManagerData.MaximumElementsInCacheBeforeScavenging = maximumElementsInCacheBeforeScavengingOverride.Value;
                            cacheManagerData.NumberToRemoveWhenScavenging           = numberToRemoveWhenScavengingOverride.Value;
                        }
                    }
                    catch (RegistryAccessException ex)
                    {
                        LogExceptionWhileOverriding(ex);
                    }
                }
            }
            if (generateWmiObjects)
            {
                CacheManagerSettingsWmiMapper.GenerateCacheManagerWmiObjects(cacheManagerDataBase, wmiSettings);
            }

            return(true);
        }
Exemple #29
0
        private void BuildCacheManagers()
        {
            foreach (CacheManagerNode managerNode in hierarchy.FindNodesByType(cacheSettingsNode, typeof(CacheManagerNode)))
            {
                CacheManagerData cacheManagerData      = managerNode.CacheManagerData;
                CacheStorageNode storageNodeForManager = (CacheStorageNode)hierarchy.FindNodeByType(managerNode, typeof(CacheStorageNode));
                cacheManagerData.CacheStorage = (storageNodeForManager == null) ? Resources.NullStorageName : storageNodeForManager.Name;

                if (cacheManagerData.CacheStorage == Resources.NullStorageName && !cacheConfiguration.BackingStores.Contains(Resources.NullStorageName))
                {
                    cacheConfiguration.BackingStores.Add(new CacheStorageData(Resources.NullStorageName, typeof(NullBackingStore)));
                }

                cacheConfiguration.CacheManagers.Add(cacheManagerData);
            }
        }
Exemple #30
0
 public CacheBase()
 {
     if (cacheManager == null)
     {
         DictionaryConfigurationSource internalConfigurationSource = new DictionaryConfigurationSource();
         CacheManagerSettings          settings = new CacheManagerSettings();
         internalConfigurationSource.Add(CacheManagerSettings.SectionName, settings);
         CacheStorageData storageConfig = new CacheStorageData("Null Storage", typeof(NullBackingStore));
         settings.BackingStores.Add(storageConfig);
         CacheManagerData cacheManagerConfig = new CacheManagerData("CustomCache", 60, 1000, 10, storageConfig.Name);
         settings.CacheManagers.Add(cacheManagerConfig);
         settings.DefaultCacheManager = cacheManagerConfig.Name;
         CacheManagerFactory cacheFactory = new CacheManagerFactory(internalConfigurationSource);
         cacheManager = cacheFactory.CreateDefault();
     }
 }
            public static CacheManager Create(string name, IConfigurationSource configurationSource)
            {
                CachingConfigurationView configurationView   = new CachingConfigurationView(configurationSource);
                CacheManagerData         objectConfiguration = configurationView.GetCacheManagerData(name);

                IBackingStore backingStore =
                    EnterpriseLibraryFactory.BuildUp <IBackingStore>(objectConfiguration.CacheStorage, configurationSource);

                return(new MockCacheManagerFactoryHelper().BuildCacheManager(
                           name,
                           backingStore,
                           objectConfiguration.MaximumElementsInCacheBeforeScavenging,
                           objectConfiguration.NumberToRemoveWhenScavenging,
                           objectConfiguration.ExpirationPollFrequencyInSeconds,
                           new CachingInstrumentationProvider()));
            }
        public void DataTest()
        {
            CacheStorageData cacheStorage = new CustomCacheStorageData();
            cacheStorage.Name = "testevtu8entv";
            CacheManagerDataCollection data = new CacheManagerDataCollection();
            CacheManagerData cacheManagerData = new CacheManagerData();
            cacheManagerData.CacheStorage = cacheStorage;
            cacheManagerData.Name = "tesotvetyevt";

            data.Add(cacheManagerData);

            CacheManagerCollectionNode node = new CacheManagerCollectionNode(data);
            applicationNode.Nodes.Add(node);
            CacheManagerDataCollection nodeData = node.CacheManagerDataCollection;

            Assert.AreEqual(data.Count, nodeData.Count);
            Assert.AreEqual(data[cacheManagerData.Name].CacheStorage.Name, nodeData[cacheManagerData.Name].CacheStorage.Name);
        }
        public void CacheManagerIsSingleton()
        {
            CacheStorageData data = new CacheStorageData("storage", typeof(NullBackingStore));

            settings.BackingStores.Add(data);

            CacheManagerData managerData = new CacheManagerData("name", 300, 200, 100, "storage");

            settings.CacheManagers.Add(managerData);

            IServiceLocator container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

            CacheManager createdObject1 = (CacheManager)container.GetInstance <ICacheManager>("name");
            CacheManager createdObject2 = (CacheManager)container.GetInstance <ICacheManager>("name");

            Assert.IsNotNull(createdObject1);
            Assert.AreSame(createdObject1, createdObject2);
        }
Exemple #34
0
        public void CacheManagerIsNotOverridenIfThereAreNoPolicyOverrides()
        {
            CacheManagerData data1 = new CacheManagerData();

            data1.Name         = "cache manager 1";
            data1.CacheStorage = "cache storage";
            data1.ExpirationPollFrequencyInSeconds       = 100;
            data1.MaximumElementsInCacheBeforeScavenging = 200;
            data1.NumberToRemoveWhenScavenging           = 300;
            section.CacheManagers.Add(data1);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual("cache storage", data1.CacheStorage);
            Assert.AreEqual(100, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(200, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(300, data1.NumberToRemoveWhenScavenging);
        }
Exemple #35
0
        private ICacheManager CreateEntLibCacheManager()
        {
            var internalConfigurationSource = new DictionaryConfigurationSource();
            var settings = new CacheManagerSettings();

            internalConfigurationSource.Add(CacheManagerSettings.SectionName, settings);

            var storageConfig = new CacheStorageData("Null Storage", typeof(NullBackingStore));

            settings.BackingStores.Add(storageConfig);

            var cacheManagerConfig = new CacheManagerData("CustomCache", 60, 1000, 10, storageConfig.Name);

            settings.CacheManagers.Add(cacheManagerConfig);
            settings.DefaultCacheManager = cacheManagerConfig.Name;

            return(new CacheManagerFactory(internalConfigurationSource).CreateDefault());
        }
        public void CopyToTest()
        {
            CacheManagerDataCollection collection = new CacheManagerDataCollection();

            CacheManagerData data = new CacheManagerData();
            data.Name = "Cache1";
            CacheManagerData data1 = new CacheManagerData();
            data1.Name = "Cache2";

            collection.Add(data);
            collection.Add(data1);

            CacheManagerData[] array = new CacheManagerData[collection.Count];

            collection.CopyTo(array, 0);

            Assert.AreSame(array[0], data);
            Assert.AreSame(array[1], data1);
        }
        public void CanDeserializeSerializedConfiguration()
        {
            CacheManagerData data1 = new CacheManagerData(name1, pollFrequency1, itemsBeforeScavenge1, itemsToScavenge1, storageName);
            CacheManagerData data2 = new CacheManagerData(name2, pollFrequency2, itemsBeforeScavenge2, itemsToScavenge2, storageName);

            CacheManagerSettings settings = new CacheManagerSettings();
            settings.DefaultCacheManager = name1;

            settings.CacheManagers.Add(data1);
            settings.CacheManagers.Add(data2);

            // needed to save configuration
            settings.BackingStores.Add(new CustomCacheStorageData("foo", typeof(MockCustomStorageBackingStore)));

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[CacheManagerSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            CacheManagerSettings roSettigs = (CacheManagerSettings)configurationSource.GetSection(CacheManagerSettings.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(2, roSettigs.CacheManagers.Count);
            Assert.AreEqual(name1, roSettigs.DefaultCacheManager);

            data1 = (CacheManagerData)roSettigs.CacheManagers.Get(name1);
            Assert.IsNotNull(data1);
            Assert.AreEqual(name1, data1.Name);
            Assert.AreEqual(pollFrequency1, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(itemsBeforeScavenge1, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(itemsToScavenge1, data1.NumberToRemoveWhenScavenging);
            Assert.AreEqual(storageName, data1.CacheStorage);

            data2 = (CacheManagerData)roSettigs.CacheManagers.Get(name2);
            Assert.IsNotNull(data2);
            Assert.AreEqual(name2, data2.Name);
            Assert.AreEqual(pollFrequency2, data2.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(itemsBeforeScavenge2, data2.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(itemsToScavenge2, data2.NumberToRemoveWhenScavenging);
            Assert.AreEqual(storageName, data2.CacheStorage);
        }
        public void DataTest()
        {
            CacheStorageData cacheStorage = new CustomCacheStorageData();
            cacheStorage.Name = "testCacheStorage";

            CacheManagerDataCollection cacheManagers = new CacheManagerDataCollection();
            CacheManagerData testManager1 = new CacheManagerData();
            testManager1.Name = "testName";
            testManager1.CacheStorage = cacheStorage;
            cacheManagers.Add(testManager1);

            CacheManagerSettings data = new CacheManagerSettings();
            data.CacheManagers.Clear();
            data.CacheManagers.AddRange(cacheManagers);

            CacheManagerSettingsNode node = new CacheManagerSettingsNode(data);
            applicationNode.Nodes.Add(node);
            CacheManagerSettings nodeData = node.CacheManagerSettings;

            Assert.AreSame(testManager1, nodeData.CacheManagers[testManager1.Name]);
        }
        public void ManageabilityProviderGeneratesProperAdmContent()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(CacheManagerSettings.SectionName, section);

            IsolatedStorageCacheStorageData storage1, storage2;
            CacheManagerData manager1, manager2;
            StorageEncryptionProviderData encryption1;
            section.BackingStores.Add(storage1 = new IsolatedStorageCacheStorageData("storage1", "encryption1", "partition1"));
            section.CacheManagers.Add(manager1 = new CacheManagerData("manager1", 100, 200, 300, "storage1"));
            section.EncryptionProviders.Add(encryption1 = new StorageEncryptionProviderData("encryption1", typeof(object)));
            section.BackingStores.Add(storage2 = new IsolatedStorageCacheStorageData("storage2", "", "partition2"));
            section.CacheManagers.Add(manager2 = new CacheManagerData("manager2", 100, 200, 300, "storage2"));

            MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(IsolatedStorageCacheStorageData), subProvider);
            subProviders.Add(typeof(StorageEncryptionProviderData), subProvider);
            provider = new CacheManagerSettingsManageabilityProvider(subProviders);

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.AddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            Assert.AreEqual(3, subProvider.configurationObjects.Count);
            Assert.AreSame(storage1, subProvider.configurationObjects[0]);
            Assert.AreSame(encryption1, subProvider.configurationObjects[1]);
            Assert.AreSame(storage2, subProvider.configurationObjects[2]);
            MockAdmContent content = contentBuilder.GetMockContent();
            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            Assert.IsTrue(categoriesEnumerator.MoveNext());
            IEnumerator<AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();
            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            IEnumerator<AdmPolicy> cacheManagerPoliciesEnumerator = subCategoriesEnumerator.Current.Policies.GetEnumerator();
            Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.IsTrue(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.IsFalse(cacheManagerPoliciesEnumerator.MoveNext());
            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            IEnumerator<AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();
            Assert.IsTrue(sectionPoliciesEnumerator.MoveNext());
            Assert.IsFalse(sectionPoliciesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
Exemple #40
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 void CacheManagerIsNotOverridenIfThereArePolicyOverridesForDifferentName()
        {
            CacheManagerData data1 = new CacheManagerData();
            data1.Name = "cache manager 1";
            data1.CacheStorage = "cache storage";
            data1.ExpirationPollFrequencyInSeconds = 100;
            data1.MaximumElementsInCacheBeforeScavenging = 200;
            data1.NumberToRemoveWhenScavenging = 300;
            section.CacheManagers.Add(data1);

            MockRegistryKey machineCacheManagersKey = new MockRegistryKey(false);
            machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.CacheManagersKeyName, machineCacheManagersKey);
            MockRegistryKey machineCacheManager1Key = new MockRegistryKey(false);
            machineCacheManagersKey.AddSubKey("cache manager 2", machineCacheManager1Key);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerExpirationPollFrequencyInSecondsPropertyName, 150);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerMaximumElementsInCacheBeforeScavengingPropertyName, 250);
            machineCacheManager1Key.AddIntValue(CacheManagerSettingsManageabilityProvider.CacheManagerNumberToRemoveWhenScavengingPropertyName, 350);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.AreEqual("cache storage", data1.CacheStorage);
            Assert.AreEqual(100, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(200, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(300, data1.NumberToRemoveWhenScavenging);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machineCacheManagersKey, machineCacheManager1Key));
        }
        public void CacheManagerIsNotOverridenIfThereAreNoPolicyOverrides()
        {
            CacheManagerData data1 = new CacheManagerData();
            data1.Name = "cache manager 1";
            data1.CacheStorage = "cache storage";
            data1.ExpirationPollFrequencyInSeconds = 100;
            data1.MaximumElementsInCacheBeforeScavenging = 200;
            data1.NumberToRemoveWhenScavenging = 300;
            section.CacheManagers.Add(data1);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual("cache storage", data1.CacheStorage);
            Assert.AreEqual(100, data1.ExpirationPollFrequencyInSeconds);
            Assert.AreEqual(200, data1.MaximumElementsInCacheBeforeScavenging);
            Assert.AreEqual(300, data1.NumberToRemoveWhenScavenging);
        }
        public void CacheManagerWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            CacheManagerData data1 = new CacheManagerData();
            data1.Name = "cache manager 1";
            section.CacheManagers.Add(data1);
            CacheManagerData data2 = new CacheManagerData();
            data2.Name = "cache manager 2";
            section.CacheManagers.Add(data2);

            MockRegistryKey machineCacheManagersKey = new MockRegistryKey(false);
            machineKey.AddSubKey(CacheManagerSettingsManageabilityProvider.CacheManagersKeyName, machineCacheManagersKey);
            MockRegistryKey machineCacheManager1Key = new MockRegistryKey(false);
            machineCacheManagersKey.AddSubKey("cache manager 1", machineCacheManager1Key);
            machineCacheManager1Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false);

            provider.OverrideWithGroupPolicies(section, false, machineKey, userKey);

            Assert.AreEqual(2, section.CacheManagers.Count);
            Assert.IsNotNull(section.CacheManagers.Get("cache manager 1"));
            Assert.IsNotNull(section.CacheManagers.Get("cache manager 2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineCacheManagersKey, machineCacheManager1Key));
        }