Esempio n. 1
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;

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

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

            STATSTG sTATSTG;

            int i;

            stgEnum.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 = stgEnum.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:
                    UCOMIStream uCOMIStream = stgEnum.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;
                }
            }
        }