Esempio n. 1
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);
        }
        /// <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);
        }
        /// <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);
        }
        /// <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);
        }
        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);
        }
Esempio n. 6
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);
        }