コード例 #1
0
        public static ComStorage CreateFileStorage(string filename, ComStorage.OpenMode openMode)
        {
            Util.ThrowOnNullArgument(filename, "filename");
            ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes);
            object     obj = null;
            ComStorage result;

            try
            {
                Guid iidistorage = Interop.IIDIStorage;
                int  num         = Interop.StgCreateStorageEx(filename, (uint)openMode, 0, 0U, IntPtr.Zero, IntPtr.Zero, ref iidistorage, out obj);
                if (num != 0)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename), num);
                }
                Interop.IStorage storage = obj as Interop.IStorage;
                if (storage == null)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename));
                }
                obj    = null;
                result = new ComStorage(storage);
            }
            finally
            {
                if (obj != null)
                {
                    Marshal.ReleaseComObject(obj);
                }
            }
            return(result);
        }
コード例 #2
0
        public static ComStorage CreateStorageOnStream(Stream stream, ComStorage.OpenMode openMode)
        {
            Util.ThrowOnNullArgument(stream, "stream");
            ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes);
            ComStorage comStorage = null;

            Interop.IStorage storage = null;
            try
            {
                LockBytesOnStream lockBytes = new LockBytesOnStream(stream);
                int num = Interop.StgCreateDocfileOnILockBytes(lockBytes, (uint)openMode, 0, out storage);
                if (num != 0)
                {
                    throw new MsgStorageException(MsgStorageErrorCode.CreateStorageOnStreamFailed, MsgStorageStrings.FailedCreateStorage("ILockBytes"), num);
                }
                comStorage = new ComStorage(storage);
            }
            finally
            {
                if (comStorage == null && storage != null)
                {
                    Marshal.ReleaseComObject(storage);
                }
            }
            return(comStorage);
        }
コード例 #3
0
        /// <summary>
        /// Opens a sub storage. Call this if an enumerated file object is of type storage
        /// </summary>
        /// <param name="parentStorage">parent storage of the sub storage file</param>
        /// <param name="storageName">name of the storage</param>
        /// <returns>Returns a reference to the sub storage</returns>
        public Interop.IStorage OpenSubStorage(Interop.IStorage parentStorage, string storageName)
        {
            if (parentStorage == null)
            {
                parentStorage = storage;
            }

            Interop.IStorage retObject = null;

            STATSTG sTATSTG;

            sTATSTG.pwcsName = storageName;
            sTATSTG.type     = 1;

            try
            {
                Interop.IStorage iStorage = parentStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0);

                retObject = iStorage;
            }
            catch (Exception ex)
            {
                retObject = null;

                Trace.WriteLine("ITStorageWrapper.OpenSubStorage() - Failed for storage '" + storageName + "'");
                Trace.Indent();
                Trace.WriteLine("Exception: " + ex.Message);
                Trace.Unindent();
            }

            return(retObject);
        }
コード例 #4
0
        /// <summary>
        /// Enumerates an Interop.IStorage object and creates the internal file object collection
        /// </summary>
        /// <param name="BasePath">Sets the base url for the storage files</param>
        /// <param name="enumStorage">storage to enumerate</param>
        protected void EnumIStorageObject(Interop.IStorage enumStorage, string BasePath)
        {
            Interop.IEnumSTATSTG iEnumSTATSTG;

            System.Runtime.InteropServices.ComTypes.STATSTG sTATSTG;

            int i;

            enumStorage.EnumElements(0, IntPtr.Zero, 0, out iEnumSTATSTG);
            iEnumSTATSTG.Reset();
            while (iEnumSTATSTG.Next(1, out sTATSTG, out i) == (int)Interop.S_OK)
            {
                if (i == 0)
                {
                    break;
                }

                FileObject newFileObj = new FileObject();
                newFileObj.FileType = sTATSTG.type;
                switch (sTATSTG.type)
                {
                case 1:
                    Interop.IStorage iStorage = enumStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0);
                    if (iStorage != null)
                    {
                        string str = String.Concat(BasePath, sTATSTG.pwcsName.ToString());
                        newFileObj.FileStorage = iStorage;
                        newFileObj.FilePath    = BasePath;
                        newFileObj.FileName    = sTATSTG.pwcsName.ToString();
                        foCollection.Add(newFileObj);
                        EnumIStorageObject(iStorage, str);
                    }
                    break;

                case 2:
                    System.Runtime.InteropServices.ComTypes.IStream uCOMIStream = enumStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0);
                    newFileObj.FilePath   = BasePath;
                    newFileObj.FileName   = sTATSTG.pwcsName.ToString();
                    newFileObj.FileStream = uCOMIStream;
                    foCollection.Add(newFileObj);
                    break;

                case 4:
                    Debug.WriteLine("Ignoring IProperty type ...");
                    break;

                case 3:
                    Debug.WriteLine("Ignoring ILockBytes type ...");
                    break;

                default:
                    Debug.WriteLine("Unknown object type ...");
                    break;
                }
            }
        }
コード例 #5
0
 public ComStorage OpenStorage(string storageName, ComStorage.OpenMode mode)
 {
     this.CheckDisposed("ComStorage::OpenStorage");
     Util.ThrowOnNullArgument(storageName, "storageName");
     ComStorage.CheckOpenMode(mode, "mode", ComStorage.validOpenModes);
     Interop.IStorage iOpenStorage = null;
     Util.InvokeComCall(MsgStorageErrorCode.FailedOpenSubstorage, delegate
     {
         this.iStorage.OpenStorage(storageName, null, (uint)mode, IntPtr.Zero, 0U, out iOpenStorage);
     });
     return(new ComStorage(iOpenStorage));
 }
コード例 #6
0
        /// <summary>
        /// Opens an UCOMIStream and returns the associated file object
        /// </summary>
        /// <param name="parentStorage">storage used to open the stream</param>
        /// <param name="fileName">filename of the stream</param>
        /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns>
        public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName)
        {
            if (parentStorage == null)
            {
                parentStorage = storage;
            }

            FileObject retObject = null;

            STATSTG sTATSTG;

            sTATSTG.pwcsName = fileName;
            sTATSTG.type     = 2;

            try
            {
                retObject = new FileObject();

                UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0);

                if (uCOMIStream != null)
                {
                    retObject.FileType   = sTATSTG.type;
                    retObject.FilePath   = "";
                    retObject.FileName   = sTATSTG.pwcsName.ToString();
                    retObject.FileStream = uCOMIStream;
                }
                else
                {
                    retObject = null;
                }
            }
            catch (Exception ex)
            {
                retObject = null;

                Trace.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'");
                Trace.Indent();
                Trace.WriteLine("Exception: " + ex.Message);
                Trace.Unindent();
            }

            return(retObject);
        }
コード例 #7
0
 private ComStorage(Interop.IStorage iStorage)
 {
     this.iStorage   = iStorage;
     this.isDisposed = false;
 }
コード例 #8
0
 /// <summary>
 /// Enumerates an IStorage object and creates the file object collection
 /// </summary>
 /// <param name="stgEnum">IStorage to enumerate</param>
 public override void EnumIStorageObject(Interop.IStorage stgEnum)
 {
     base.EnumIStorageObject(storage);
 }
コード例 #9
0
 /// <summary>
 /// Enumerates an Interop.IStorage object and creates the internal file object collection
 /// </summary>
 /// <param name="stgEnum">Interop.IStorage to enumerate</param>
 public virtual void EnumIStorageObject(Interop.IStorage stgEnum)
 {
     EnumIStorageObject(stgEnum, "");
 }
コード例 #10
0
ファイル: Interop.cs プロジェクト: YHZX2013/exchange_diff
 public static extern int StgCreateDocfileOnILockBytes([MarshalAs(UnmanagedType.Interface)][In] Interop.ILockBytes lockBytes, [In] uint grfMode, [In] int reserved, [MarshalAs(UnmanagedType.Interface)] out Interop.IStorage newStorage);
コード例 #11
0
ファイル: Interop.cs プロジェクト: YHZX2013/exchange_diff
 public static extern int StgOpenStorageOnILockBytes([MarshalAs(UnmanagedType.Interface)][In] Interop.ILockBytes lockBytes, [In] IntPtr pStgPriority, [In] uint grfMode, [In] IntPtr snbExclude, [In] uint reserved, [MarshalAs(UnmanagedType.Interface)] out Interop.IStorage newStorage);