/// <summary>
        /// Initializes a new instance of the <see cref="IsolatedStorageBackingStore"/> class given the configuration data
        /// </summary>
        /// <param name="configurationView">An <see cref="CachingConfigurationView"></see> object</param>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof(CachingConfigurationView));

            CachingConfigurationView        cachingConfigurationView  = (CachingConfigurationView)configurationView;
            IsolatedStorageCacheStorageData isoStoreConfigurationData = (IsolatedStorageCacheStorageData)cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager);

            if (isoStoreConfigurationData.PartitionName == null)
            {
                throw new ConfigurationException(SR.IsolatedStoreAreaNameNullException(isoStoreConfigurationData.Name));
            }

            if (isoStoreConfigurationData.PartitionName.Length == 0)
            {
                throw new ConfigurationException(SR.IsolatedStoreAreaNameEmptyException(isoStoreConfigurationData.Name));
            }

            this.storageAreaName = isoStoreConfigurationData.PartitionName;

            if (isoStoreConfigurationData.StorageEncryption != null)
            {
                StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext);
                this.encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager);
            }

            Initialize();
        }
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];
            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.Expirations[0].GetType());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsolatedStorageBackingStore"/> class given the configuration data
        /// </summary>
        /// <param name="configurationView">An <see cref="CachingConfigurationView"></see> object</param>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof (CachingConfigurationView));

            CachingConfigurationView cachingConfigurationView = (CachingConfigurationView) configurationView;
            IsolatedStorageCacheStorageData isoStoreConfigurationData = (IsolatedStorageCacheStorageData) cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager);

            if (isoStoreConfigurationData.PartitionName == null)
            {
                throw new ConfigurationException(SR.IsolatedStoreAreaNameNullException(isoStoreConfigurationData.Name));
            }

            if (isoStoreConfigurationData.PartitionName.Length == 0)
            {
                throw new ConfigurationException(SR.IsolatedStoreAreaNameEmptyException(isoStoreConfigurationData.Name));
            }

            this.storageAreaName = isoStoreConfigurationData.PartitionName;

            if (isoStoreConfigurationData.StorageEncryption != null)
            {
                StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext);
                this.encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager);
            }

            Initialize();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataBackingStore"/> class
        /// with the specified configuration information.
        /// </summary>
        /// <param name="configurationView">A <see cref="CachingConfigurationView"></see> object</param>
        /// <exception cref="System.Configuration.ConfigurationException">Reflects any failures to read configuration information</exception>
        /// <remarks>Other exceptions thrown depend on the implementation of the underlying database.</remarks>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof (CachingConfigurationView));

            CachingConfigurationView cachingConfigurationView = (CachingConfigurationView) configurationView;
            DataCacheStorageData dataConfiguration = (DataCacheStorageData) cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager);
            partitionName = dataConfiguration.PartitionName;
            DatabaseProviderFactory dataFactory = new DatabaseProviderFactory(cachingConfigurationView.ConfigurationContext);
            database = dataFactory.CreateDatabase(dataConfiguration.DatabaseInstanceName);
            if (dataConfiguration.StorageEncryption != null)
            {
                StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext);
                encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager);
            }
        }