Exemple #1
0
        internal MsgStorageWriter OpenAttachedMessageWriter()
        {
            if (this.attachMethod != 5)
            {
                throw new InvalidOperationException(MsgStorageStrings.NotAMessageAttachment);
            }
            ComStorage       comStorage       = null;
            MsgStorageWriter msgStorageWriter = null;

            try
            {
                TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj;
                string          storageName   = Util.PropertyStreamName(attachDataObj);
                MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Message);
                comStorage = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite);
                comStorage.StorageClass = Util.ClassIdMessageAttachment;
                msgStorageWriter        = new MsgStorageWriter(this.owner, comStorage);
            }
            finally
            {
                if (msgStorageWriter == null && comStorage != null)
                {
                    comStorage.Dispose();
                }
            }
            return(msgStorageWriter);
        }
Exemple #2
0
        internal Stream OpenOleAttachmentStream()
        {
            if (this.attachMethod != 6)
            {
                throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment);
            }
            Stream cacheStream = Streams.CreateTemporaryStorageStream();
            MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(cacheStream, 0);

            msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException)
            {
                if (onCloseException != null)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException));
                    return;
                }
                TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj;
                ComStorage comStorage         = null;
                ComStorage comStorage2        = null;
                string storageName            = Util.PropertyStreamName(attachDataObj);
                try
                {
                    cacheStream.Flush();
                    cacheStream.Position     = 0L;
                    comStorage               = ComStorage.OpenStorageOnStream(cacheStream, ComStorage.OpenMode.Read);
                    comStorage2              = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite);
                    comStorage2.StorageClass = Util.ClassIdFileAttachment;
                    ComStorage.CopyStorageContent(comStorage, comStorage2);
                    comStorage2.Flush();
                    MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Storage);
                }
                catch (IOException exc)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc));
                }
                catch (COMException exc2)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc2));
                }
                finally
                {
                    if (comStorage2 != null)
                    {
                        comStorage2.Dispose();
                    }
                    if (comStorage != null)
                    {
                        comStorage.Dispose();
                    }
                    if (cacheStream != null)
                    {
                        cacheStream.Dispose();
                    }
                }
            });
            return(msgStorageWriteStream);
        }