コード例 #1
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();
        }
コード例 #2
0
		public IsolatedStorageBackingStore(string storageAreaName, IStorageEncryptionProvider encryptionProvider)
		{
			if (string.IsNullOrEmpty(storageAreaName)) throw new ArgumentException(Resources.ExceptionStorageAreaNullOrEmpty, "storageAreaName");
			this.storageAreaName = storageAreaName;
			this.encryptionProvider = encryptionProvider;
			Initialize();
		}
        private void NullEncryptorTests(string instanceName)
        {
            MockStorageEncryptionProvider.Encrypted = false;
            MockStorageEncryptionProvider.Decrypted = false;

            CacheManagerSettings          settings               = (CacheManagerSettings)TestConfigurationSource.GenerateConfiguration().GetSection(CacheManagerSettings.SectionName);
            CacheStorageData              cacheStorageData       = settings.BackingStores.Get(settings.CacheManagers.Get(instanceName).CacheStorage);
            StorageEncryptionProviderData encryptionProviderData = settings.EncryptionProviders.Get(cacheStorageData.StorageEncryption);

            IStorageEncryptionProvider provider =
                EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>(encryptionProviderData.Name, TestConfigurationSource.GenerateConfiguration());

            Assert.IsNotNull(provider);

            byte[] input     = new byte[] { 0, 1, 2, 3, 4, 5 };
            byte[] encrypted = provider.Encrypt(input);

            Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted");

            Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed");

            byte[] decrypted = provider.Decrypt(encrypted);
            Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted");

            Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed");
            Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2");
        }
コード例 #4
0
 /// <summary>
 /// This is public purely for unit testing purposes and should never be called by application code
 /// </summary>
 /// <param name="database">Database to use for persistence</param>
 /// <param name="databasePartitionName">Partition name in database</param>
 /// <param name="encryptionProvider">Provider used for encryption</param>
 public DataBackingStore(Data.Database database,
                         string databasePartitionName,
                         IStorageEncryptionProvider encryptionProvider)
 {
     this.database           = database;
     partitionName           = databasePartitionName;
     this.encryptionProvider = encryptionProvider;
 }
コード例 #5
0
 /// <summary>
 /// This is public purely for unit testing purposes and should never be called by application code
 /// </summary>
 /// <param name="database">Database to use for persistence</param>
 /// <param name="databasePartitionName">Partition name in database</param>
 /// <param name="encryptionProvider">Provider used for encryption</param>
 public DataBackingStore(Data.Database database,
                         string databasePartitionName,
                         IStorageEncryptionProvider encryptionProvider)
 {
     this.database = database;
     partitionName = databasePartitionName;
     this.encryptionProvider = encryptionProvider;
 }
コード例 #6
0
 public IsolatedStorageCacheItemField(IsolatedStorageFile storage, string fieldName,
                                      string fileSystemLocation, IStorageEncryptionProvider encryptionProvider)
 {
     this.fieldName          = fieldName;
     this.fileSystemLocation = fileSystemLocation;
     this.storage            = storage;
     this.encryptionProvider = encryptionProvider;
 }
コード例 #7
0
 /// <summary>
 /// Instance constructor
 /// </summary>
 /// <param name="storage">IsolatedStorage area to use. May not be null.</param>
 /// <param name="fieldName">Name of the file in which the field value is stored. May not be null.</param>
 /// <param name="fileSystemLocation">Complete path to directory where file specified in fieldName is to be found. May not be null.</param>
 /// <param name="encryptionProvider">Encryption provider</param>
 public IsolatedStorageCacheItemField(IsolatedStorageFile storage, string fieldName,
                                      string fileSystemLocation, IStorageEncryptionProvider encryptionProvider)
 {
     this.fieldName = fieldName;
     this.fileSystemLocation = fileSystemLocation;
     this.storage = storage;
     this.encryptionProvider = encryptionProvider;
 }
コード例 #8
0
        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 IsolatedStorageBackingStore(string storageAreaName, IStorageEncryptionProvider encryptionProvider)
 {
     if (string.IsNullOrEmpty(storageAreaName))
     {
         throw new ArgumentException(Resources.ExceptionStorageAreaNullOrEmpty, "storageAreaName");
     }
     this.storageAreaName    = storageAreaName;
     this.encryptionProvider = encryptionProvider;
     Initialize();
 }
コード例 #10
0
        /// <summary>
        /// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
        /// for reading and writing. This class stores each individual field of the CacheItem into its own
        /// file inside the directory specified by itemDirectoryRoot.
        /// </summary>
        /// <param name="storage">Isolated Storage area to use. May not be null.</param>
        /// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
        /// <param name="encryptionProvider">Encryption provider</param>
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
            storage.CreateDirectory(itemDirectoryRoot);

            keyField = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #11
0
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: ktairov/YellowDrawer
        static void TestReadEncryptionProvider(IStorageProvider provider, IStorageEncryptionProvider encryptionProvider, byte[] iv)
        {
            var path       = "testfolder\\testencryption990.jpeg";
            var file       = provider.GetFile(path);
            var streamRead = file.OpenCryptoRead(encryptionProvider, iv);

            FileStream fs = new FileStream(@"..\..\TestDecryptFile990.jpeg",
                                           FileMode.OpenOrCreate,
                                           FileAccess.Write);

            CopyStream(streamRead, fs);
        }
コード例 #13
0
        public IBackingStore Assemble(IBuilderContext context, CacheStorageData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            IsolatedStorageCacheStorageData castedObjectConfiguration
                = (IsolatedStorageCacheStorageData)objectConfiguration;
            IStorageEncryptionProvider encryptionProvider
                = GetStorageEncryptionProvider(context, castedObjectConfiguration.StorageEncryption, configurationSource, reflectionCache);
            IBackingStore createdObject
                = new IsolatedStorageBackingStore(
                      castedObjectConfiguration.PartitionName,
                      encryptionProvider);

            return(createdObject);
        }
コード例 #14
0
        /// <summary>
        /// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
        /// for reading and writing. This class stores each individual field of the CacheItem into its own
        /// file inside the directory specified by itemDirectoryRoot.
        /// </summary>
        /// <param name="storage">Isolated Storage area to use. May not be null.</param>
        /// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
        /// <param name="encryptionProvider">Encryption provider</param>
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
			if (storage.GetDirectoryNames(itemDirectoryRoot).Length == 0)
			{
				// avoid creating if already exists - work around for partial trust
				storage.CreateDirectory(itemDirectoryRoot);
			}

            keyField = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ktairov/YellowDrawer
        static void TestWriteEncryptionProvider(IStorageProvider provider, IStorageEncryptionProvider encryptionProvider, byte[] iv)
        {
            byte[]     buff     = new byte[0];
            var        fileName = pathToTestFile;
            FileStream fs       = new FileStream(fileName,
                                                 FileMode.Open,
                                                 FileAccess.Read);

            var path = "testfolder\\testencryption990.jpeg";

            provider.DeleteFile(path);
            var file        = provider.CreateFile(path);
            var streamWrite = file.OpenCryptoWrite(encryptionProvider, iv);

            CopyStream(fs, streamWrite);
        }
コード例 #16
0
        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());
        }
コード例 #17
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);
            }
        }
        private CacheItem DoCacheItemRoundTripToStorage(CacheItem itemToStore, bool encrypted)
        {
            IStorageEncryptionProvider encryptionProvider = null;

            if (encrypted)
            {
                encryptionProvider = new MockStorageEncryptionProvider();
            }

            string itemRoot = DirectoryRoot + itemToStore.Key;

            IsolatedStorageCacheItem item = new IsolatedStorageCacheItem(storage, itemRoot, encryptionProvider);

            item.Store(itemToStore);

            IsolatedStorageCacheItem itemToRead = new IsolatedStorageCacheItem(storage, itemRoot, encryptionProvider);

            return(itemToRead.Load());
        }
コード例 #19
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds an <see cref="DataBackingStore"/> based on an instance of <see cref="DataCacheStorageData"/>.
        /// </summary>
        /// <seealso cref="BackingStoreCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="DataCacheStorageData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="DataBackingStore"/>.</returns>
        public IBackingStore Assemble(IBuilderContext context, CacheStorageData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            DataCacheStorageData castedObjectConfiguration
                = (DataCacheStorageData)objectConfiguration;

            Data.Database database
                = (Data.Database)context.HeadOfChain.BuildUp(context, typeof(Data.Database), null, castedObjectConfiguration.DatabaseInstanceName);

            IStorageEncryptionProvider encryptionProvider
                = GetStorageEncryptionProvider(context, castedObjectConfiguration.StorageEncryption, configurationSource, reflectionCache);

            IBackingStore createdObjet
                = new DataBackingStore(
                      database,
                      castedObjectConfiguration.PartitionName,
                      encryptionProvider);

            return(createdObjet);
        }
コード例 #20
0
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            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.GetExpirations()[0].GetType());
        }
コード例 #21
0
        private void NullEncryptorTests(string instanceName)
        {
            MockStorageEncryptionProvider.Encrypted = false;
            MockStorageEncryptionProvider.Decrypted = false;
            CacheManagerSettings settings = (CacheManagerSettings)Context.GetConfiguration(CacheManagerSettings.SectionName);

            StorageEncryptionFactory   factory  = new StorageEncryptionFactory(Context);
            IStorageEncryptionProvider provider = factory.CreateSymmetricProvider(settings.CacheManagers[instanceName].Name);

            Assert.IsNotNull(provider);

            byte[] input     = new byte[] { 0, 1, 2, 3, 4, 5 };
            byte[] encrypted = provider.Encrypt(input);

            Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted");

            Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed");

            byte[] decrypted = provider.Decrypt(encrypted);
            Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted");

            Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed");
            Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2");
        }
コード例 #22
0
 public Stream OpenCryptoWrite(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Encrypt(_blob.OpenWriteAsync().Result, iv));
 }
コード例 #23
0
        /// <summary>
        /// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
        /// for reading and writing. This class stores each individual field of the CacheItem into its own
        /// file inside the directory specified by itemDirectoryRoot.
        /// </summary>
        /// <param name="storage">Isolated Storage area to use. May not be null.</param>
        /// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
        /// <param name="encryptionProvider">Encryption provider</param>
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
            if (storage.GetDirectoryNames(itemDirectoryRoot).Length == 0)
            {
                // avoid creating if already exists - work around for partial trust
                storage.CreateDirectory(itemDirectoryRoot);
            }

            keyField   = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField      = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField        = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField       = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #24
0
        /// <summary>
        /// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
        /// for reading and writing. This class stores each individual field of the CacheItem into its own
        /// file inside the directory specified by itemDirectoryRoot.
        /// </summary>
        /// <param name="storage">Isolated Storage area to use. May not be null.</param>
        /// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
        /// <param name="encryptionProvider">Encryption provider</param>
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
            storage.CreateDirectory(itemDirectoryRoot);

            keyField   = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField      = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField        = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField       = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #25
0
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
            int retriesLeft = MaxRetries;

            while (true)
            {
                try
                {
                    storage.CreateDirectory(itemDirectoryRoot);
                    using (IsolatedStorageFileStream fileStream =
                               new IsolatedStorageFileStream(itemDirectoryRoot + @"\sanity-check.txt", FileMode.Create, FileAccess.Write, FileShare.None, storage))
                    { }
                    break;
                }
                catch (UnauthorizedAccessException)
                {
                    if (retriesLeft-- > 0)
                    {
                        Thread.Sleep(RetryDelayInMilliseconds);
                        continue;
                    }
                    throw;
                }
                catch (DirectoryNotFoundException)
                {
                    if (retriesLeft-- > 0)
                    {
                        Thread.Sleep(RetryDelayInMilliseconds);
                        continue;
                    }
                    throw;
                }
            }
            keyField   = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField      = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField        = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField       = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #26
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();
        }
コード例 #27
0
 public Stream OpenCryptoWrite(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
 public Stream OpenCryptoRead(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Decrypt(_bucket.OpenDownloadStream(_fileInfo.Id), iv));
 }
コード例 #29
0
 public Stream OpenCryptoWrite(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Encrypt(new FileStream(_fileInfo.FullName, FileMode.Open, FileAccess.ReadWrite), iv));
 }
コード例 #30
0
 public Stream OpenCryptoWrite(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Encrypt(_bucket.OpenUploadStream(_fileInfo.Filename), iv));
 }
コード例 #31
0
 public Stream OpenCryptoRead(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Decrypt(_fileInfo.OpenRead(), iv));
 }
コード例 #32
0
ファイル: DataBackingStore.cs プロジェクト: bnantz/NCS-V1-1
        /// <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);
            }
        }
コード例 #33
0
        /// <summary>
        /// Instance constructor. Ensures that the storage location in Isolated Storage is prepared
        /// for reading and writing. This class stores each individual field of the CacheItem into its own
        /// file inside the directory specified by itemDirectoryRoot.
        /// </summary>
        /// <param name="storage">Isolated Storage area to use. May not be null.</param>
        /// <param name="itemDirectoryRoot">Complete path in Isolated Storage where the cache item should be stored. May not be null.</param>
        /// <param name="encryptionProvider">Encryption provider</param>
        public IsolatedStorageCacheItem(IsolatedStorageFile storage, string itemDirectoryRoot, IStorageEncryptionProvider encryptionProvider)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            int retriesLeft = MaxRetries;

            while (true)
            {
                // work around - attempt to write a file in the folder to determine whether delayed io
                // needs to be processed
                // since only a limited number of retries will be attempted, some extreme cases may
                // still fail if file io is deferred long enough.
                // while it's still possible that the deferred IO is still pending when the item that failed
                // to be added is removed by the cleanup code, thus making the cleanup fail,
                // the item should eventually be removed (by the original removal)
                try
                {
                    storage.CreateDirectory(itemDirectoryRoot);

                    // try to write a file
                    // if there is a pending operation or the folder is gone, this should find the problem
                    // before writing an actual field is attempted
                    using (IsolatedStorageFileStream fileStream =
                               new IsolatedStorageFileStream(itemDirectoryRoot + @"\sanity-check.txt", FileMode.Create, FileAccess.Write, FileShare.None, storage))
                    { }
                    break;
                }
                catch (UnauthorizedAccessException)
                {
                    // there are probably pending operations on the directory - retry if allowed
                    if (retriesLeft-- > 0)
                    {
                        Thread.Sleep(RetryDelayInMilliseconds);
                        continue;
                    }

                    throw;
                }
                catch (DirectoryNotFoundException)
                {
                    // a pending deletion on the directory was processed before creating the file
                    // but after attempting to create it - retry if allowed
                    if (retriesLeft-- > 0)
                    {
                        Thread.Sleep(RetryDelayInMilliseconds);
                        continue;
                    }

                    throw;
                }
            }

            keyField   = new IsolatedStorageCacheItemField(storage, "Key", itemDirectoryRoot, encryptionProvider);
            valueField = new IsolatedStorageCacheItemField(storage, "Val", itemDirectoryRoot, encryptionProvider);
            scavengingPriorityField = new IsolatedStorageCacheItemField(storage, "ScPr", itemDirectoryRoot, encryptionProvider);
            refreshActionField      = new IsolatedStorageCacheItemField(storage, "RA", itemDirectoryRoot, encryptionProvider);
            expirationsField        = new IsolatedStorageCacheItemField(storage, "Exp", itemDirectoryRoot, encryptionProvider);
            lastAccessedField       = new IsolatedStorageCacheItemField(storage, "LA", itemDirectoryRoot, encryptionProvider);
        }
コード例 #34
0
 public Stream OpenCryptoWrite(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Encrypt(_fileInfo.OpenWrite(), iv));
 }
コード例 #35
0
 public Stream OpenCryptoRead(IStorageEncryptionProvider encryptionProvider, byte[] iv)
 {
     return(encryptionProvider.Decrypt(_blob.OpenReadAsync().Result, iv));
 }