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);
		}
        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);
        }
Example #3
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;
 }
Example #4
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 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 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());
        }
        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));
        }
        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);
        }
Example #13
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];
     }
 }