Example #1
0
        /// <summary>
        /// Opens a Storage using the specified opener.
        /// </summary>
        /// <param name="name">The name of the substorage.</param>
        /// <param name="mode">The Storagemode to open the substorage.</param>
        /// <param name="writable">Whether to open the storage as writable.  If
        /// the parent storage is readonly, the substorage cannot be opened
        /// as writable (InvalidoperationException will be thrown).</param>
        /// <param name="opener">The IStorageOpener to use to open the storage.</param>
        /// <param name="created">Out parameter indicated whether the storage was created (or opened)</param>
        /// <returns>The Storage.</returns>
        internal static IStorage OpenStorage(string name, StorageMode mode, bool writable, IStorageOpener opener)
        {
            IStorage storage = null;

            try
            {
                switch (mode)
                {
                case (StorageMode.Create):
                    opener.CreateStorage(name, out storage);
                    break;

                case (StorageMode.Open):
                    if (!opener.OpenStorage(name, writable, out storage))
                    {
                        throw new COMException("StorageName does not exist", STG_E.FILENOTFOUND);
                    }
                    break;

                case (StorageMode.OpenOrCreate):
                    if (!opener.OpenStorage(name, writable, out storage))
                    {
                        opener.CreateStorage(name, out storage);
                    }
                    break;
                }
            }
            catch (COMException e)
            {
                ThrowStorageException(e);
            }
            return(storage);
        }
Example #2
0
        /// <summary>
        /// Opens a Storage using the specified opener.
        /// </summary>
        /// <param name="name">The name of the substorage.</param>
        /// <param name="mode">The Storagemode to open the substorage.</param>
        /// <param name="writable">Whether to open the storage as writable.  If
        /// the parent storage is readonly, the substorage cannot be opened
        /// as writable (InvalidoperationException will be thrown).</param>
        /// <param name="opener">The IStorageOpener to use to open the storage.</param>
        /// <param name="created">Out parameter indicated whether the storage was created (or opened)</param>
        /// <returns>The Storage.</returns>
        internal static IStorage OpenStorage(string name, StorageMode mode, bool writable, IStorageOpener opener)
        {
            IStorage storage = null;
            try
            {
                switch (mode)
                {
                    case (StorageMode.Create):
                        opener.CreateStorage(name, out storage);
                        break;

                    case (StorageMode.Open):
                        if (!opener.OpenStorage(name, writable, out storage))
                        {
                            throw new COMException("StorageName does not exist", STG_E.FILENOTFOUND);
                        }
                        break;

                    case (StorageMode.OpenOrCreate):
                        if (!opener.OpenStorage(name, writable, out storage))
                        {
                            opener.CreateStorage(name, out storage);
                        }
                        break;
                }
            }
            catch (COMException e)
            {
                ThrowStorageException(e);
            }
            return storage;
        }