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);
		}
        private void CreateStorageNode(CacheManagerNode cacheManagerNode, string cacheStorageName)
        {
            if (string.IsNullOrEmpty(cacheStorageName))
            {
                return;
            }

            CacheStorageData cacheStorageData = cacheManagerSettings.BackingStores.Get(cacheStorageName);

            if (null == cacheStorageData)
            {
                LogError(cacheManagerNode, string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionNoStorageProviderDefined, cacheStorageName));
                return;
            }
            if (cacheStorageData.Type == typeof(NullBackingStore))
            {
                return;                                                                // special case
            }
            ConfigurationNode storageNode = NodeCreationService.CreateNodeByDataType(cacheStorageData.GetType(), new object[] { cacheStorageData });

            if (null == storageNode)
            {
                LogNodeMapError(cacheManagerNode, cacheStorageData.GetType());
                return;
            }
            cacheManagerNode.AddNode(storageNode);
            CreateEncryptionNode(storageNode, cacheStorageData.StorageEncryption);
        }
        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 OpenAndSaveConfiguration()
		{
			ApplicationNode.Hierarchy.Load();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);
			ApplicationNode.Hierarchy.Open();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);

			CacheManagerSettingsNode rootNode = (CacheManagerSettingsNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(CacheManagerSettingsNode));
			Assert.IsNotNull(rootNode);
			Assert.AreEqual("ShortInMemoryPersistence", rootNode.DefaultCacheManager.Name);

			Assert.AreEqual(1, Hierarchy.FindNodesByType(ApplicationNode, typeof(CacheManagerSettingsNode)).Count);
			Assert.AreEqual(2, Hierarchy.FindNodesByType(ApplicationNode, typeof(CacheManagerNode)).Count);
			Assert.AreEqual(1, Hierarchy.FindNodesByType(ApplicationNode, typeof(CacheStorageNode)).Count);			

			Hierarchy.Load();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);
			Hierarchy.Open();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);
			CacheManagerCollectionNode cacheManagerCollectionNode = (CacheManagerCollectionNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(CacheManagerCollectionNode));
			
			CacheManagerNode cacheManagerNode = new CacheManagerNode();
			cacheManagerCollectionNode.AddNode(cacheManagerNode);
			AddDataCacheStorageCommand cmd = new AddDataCacheStorageCommand(ServiceProvider);
			cmd.Execute(cacheManagerNode);
			DataCacheStorageNode dataNode = (DataCacheStorageNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(DataCacheStorageNode));
			ConnectionStringSettingsNode connectNode = (ConnectionStringSettingsNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(ConnectionStringSettingsNode));
			dataNode.DatabaseInstance= connectNode;
			dataNode.PartitionName = "foo";

			Assert.AreEqual(1, Hierarchy.FindNodesByType(ApplicationNode, typeof(DatabaseSectionNode)).Count);

			Hierarchy.Save();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);

			Hierarchy.Load();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);
			Hierarchy.Open();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);

			Assert.AreEqual(1, Hierarchy.FindNodesByType(ApplicationNode, typeof(DataCacheStorageNode)).Count);

			dataNode = (DataCacheStorageNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(DataCacheStorageNode));
			Assert.AreEqual(dataNode.DatabaseInstance.Name, connectNode.Name);
			Assert.AreEqual(dataNode.PartitionName, "foo");

			DatabaseSectionNode databaseSectionNode = (DatabaseSectionNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(DatabaseSectionNode));
			databaseSectionNode.Remove();

			dataNode.Remove();
			Hierarchy.Save();
			Assert.AreEqual(0, ErrorLogService.ConfigurationErrorCount);
		}	
        public void EnsureDatabaseSettingsAreAddedOnNewNode()
        {
            AddCacheManagerSettingsNodeCommand cacheCmd = new AddCacheManagerSettingsNodeCommand(ServiceProvider);
            cacheCmd.Execute(Hierarchy.RootNode);

            CacheManagerCollectionNode cacheManagerCollectionNode = (CacheManagerCollectionNode)Hierarchy.FindNodeByType(ApplicationNode, typeof(CacheManagerCollectionNode));
            CacheManagerNode cacheManagerNode = new CacheManagerNode();
            cacheManagerCollectionNode.AddNode(cacheManagerNode);
            AddDataCacheStorageCommand cmd = new AddDataCacheStorageCommand(ServiceProvider);
            cmd.Execute(cacheManagerNode);

            Assert.IsNotNull(Hierarchy.FindNodeByType(ApplicationNode, typeof(DatabaseSectionNode)));
        }
		private void CreateStorageNode(CacheManagerNode cacheManagerNode,string cacheStorageName)
		{
			if (string.IsNullOrEmpty(cacheStorageName)) return;

			CacheStorageData cacheStorageData = cacheManagerSettings.BackingStores.Get(cacheStorageName);
			if (null == cacheStorageData) 
			{
				LogError(cacheManagerNode, string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionNoStorageProviderDefined, cacheStorageName));
				return;
			}
			if (cacheStorageData.Type == typeof(NullBackingStore)) return; // special case
			ConfigurationNode storageNode = NodeCreationService.CreateNodeByDataType(cacheStorageData.GetType(), new object[] { cacheStorageData });
			if (null == storageNode)
			{
				LogNodeMapError(cacheManagerNode, cacheStorageData.GetType());
				return;
			}
			cacheManagerNode.AddNode(storageNode);
			CreateEncryptionNode(storageNode, cacheStorageData.StorageEncryption);						
		}
        public void NodeTest()
        {
            int absoluteExpiration = 72;
            CacheManagerNode cacheManager = new CacheManagerNode();
            int slidingExpiration = 13;

            CachingStoreProviderNode node = new CachingStoreProviderNode();
            GeneratedApplicationNode.Nodes.Add(node);
            Assert.AreEqual(SR.SecurityInstance, node.Name);

            node.AbsoluteExpiration = absoluteExpiration;
            Assert.AreEqual(absoluteExpiration, node.AbsoluteExpiration);

            node.CacheManager = cacheManager;
            Assert.AreEqual(cacheManager, node.CacheManager);

            node.SlidingExpiration = slidingExpiration;
            Assert.AreEqual(slidingExpiration, node.SlidingExpiration);

            CachingStoreProviderData data = (CachingStoreProviderData)node.SecurityCacheProviderData;
            Assert.AreEqual(absoluteExpiration, data.AbsoluteExpiration);
            Assert.AreEqual(cacheManager.Name, data.CacheManager);
            Assert.AreEqual(slidingExpiration, data.SlidingExpiration);
        }
 private void OnCacheManagerNodeRemoved(object sender, ConfigurationNodeChangedEventArgs e)
 {
     this.cacheManagerNode = null;
 }
Esempio n. 9
0
 private void OnCacheManagerNodeRemoved(object sender, ConfigurationNodeChangedEventArgs e)
 {
     this.cacheManagerNode = null;
 }