public List <T> ReadObjectChunks(ReadObjectFlags flags)
        {
            if ((flags & ReadObjectFlags.Refresh) != ReadObjectFlags.None)
            {
                this.message.Dispose();
                this.message = null;
            }
            if (this.message == null && !this.OpenMessage())
            {
                return(null);
            }
            List <T> list = new List <T>();
            T        t;

            if ((flags & ReadObjectFlags.LastChunkOnly) == ReadObjectFlags.None)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        PropValue[][] array = attachmentTable.QueryAllRows(null, MoveObjectInfo <T> .AttachmentTagsToLoad);
                        foreach (PropValue[] array3 in array)
                        {
                            int @int = array3[0].GetInt();
                            using (MapiAttach mapiAttach = this.message.OpenAttach(@int))
                            {
                                using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.BestAccess))
                                {
                                    t = MoveObjectInfo <T> .DeserializeFromStream(mapiStream, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);
                                }
                                if (t != null)
                                {
                                    list.Add(t);
                                }
                            }
                        }
                    }
                }
            }
            t = MoveObjectInfo <T> .ReadObjectFromMessage(this.message, (flags & ReadObjectFlags.DontThrowOnCorruptData) == ReadObjectFlags.None);

            if (t != null)
            {
                list.Add(t);
            }
            if (list.Count <= 0)
            {
                return(null);
            }
            return(list);
        }
Beispiel #2
0
        private uint CreateMsgWithAttachement(out byte[] entryId)
        {
            ASCIIEncoding asciiencoding = new ASCIIEncoding();
            uint          @int;

            using (MapiMessage mapiMessage = this.testFolder.CreateMessage())
            {
                PropValue[] props = new PropValue[]
                {
                    new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)),
                    new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)),
                    new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now)
                };
                this.threadExit.CheckStop();
                mapiMessage.SetProps(props);
                int num;
                using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num))
                {
                    string s     = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString);
                    byte[] bytes = asciiencoding.GetBytes(s);
                    using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                    {
                        mapiStream.Write(bytes, 0, bytes.Length);
                        mapiStream.Flush();
                        this.threadExit.CheckStop();
                    }
                    props = new PropValue[]
                    {
                        new PropValue(PropTag.AttachFileName, "CITestSearch.txt"),
                        new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                    };
                    mapiAttach.SetProps(props);
                    mapiAttach.SaveChanges();
                }
                this.threadExit.CheckStop();
                mapiMessage.SaveChanges();
                entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes();
                @int    = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt();
            }
            return(@int);
        }
Beispiel #3
0
        private StoreObjectPropertyBag CreateStorePropertyBag(MapiAttach mapiAttach, ICollection <PropertyDefinition> prefetchPropertyArray)
        {
            StoreObjectPropertyBag storeObjectPropertyBag = null;
            bool flag = false;

            try
            {
                storeObjectPropertyBag = new StoreObjectPropertyBag(this.AttachmentCollection.ContainerItem.Session, mapiAttach, prefetchPropertyArray);
                storeObjectPropertyBag.PrefetchPropertyArray = prefetchPropertyArray;
                storeObjectPropertyBag.ExTimeZone            = this.ExTimeZone;
                flag = true;
            }
            finally
            {
                if (!flag && storeObjectPropertyBag != null)
                {
                    storeObjectPropertyBag.Dispose();
                    storeObjectPropertyBag = null;
                }
            }
            return(storeObjectPropertyBag);
        }
        public void SaveObjectChunks(List <T> chunks, int maxChunks, MoveObjectInfo <T> .GetAdditionalProperties getAdditionalPropertiesCallback)
        {
            if (chunks.Count > maxChunks)
            {
                MrsTracer.Common.Warning("Too many chunks supplied, truncating", new object[0]);
                chunks.RemoveRange(0, chunks.Count - maxChunks);
            }
            bool flag = false;

            if (this.message == null)
            {
                using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, true))
                {
                    this.FolderId = mapiFolder.GetProp(PropTag.EntryId).GetBytes();
                    this.message  = mapiFolder.CreateMessage();
                }
                this.message.SetProps(new PropValue[]
                {
                    new PropValue(PropTag.MessageClass, this.messageClass),
                    new PropValue(PropTag.Subject, this.subject),
                    new PropValue(PropTag.ReplyTemplateID, this.searchKey)
                });
                flag = true;
            }
            if (chunks.Count > 1)
            {
                using (MapiTable attachmentTable = this.message.GetAttachmentTable())
                {
                    if (attachmentTable != null)
                    {
                        int num = attachmentTable.GetRowCount() - (maxChunks - chunks.Count);
                        if (num > 0)
                        {
                            attachmentTable.SetColumns(MoveObjectInfo <T> .AttachmentTagsToLoad);
                            PropValue[][] array = attachmentTable.QueryRows(num);
                            for (int i = 0; i < num; i++)
                            {
                                this.message.DeleteAttach(array[i][0].GetInt());
                            }
                        }
                    }
                }
                for (int j = 0; j < chunks.Count - 1; j++)
                {
                    int num2;
                    using (MapiAttach mapiAttach = this.message.CreateAttach(out num2))
                    {
                        using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                        {
                            MoveObjectInfo <T> .SerializeToStream(chunks[j], mapiStream);
                        }
                        mapiAttach.SetProps(new PropValue[]
                        {
                            new PropValue(PropTag.AttachFileName, string.Format("MOI_Chunk_{0:yyyymmdd_HHmmssfff}", DateTime.UtcNow)),
                            new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                        });
                        mapiAttach.SaveChanges();
                    }
                }
            }
            T obj = chunks[chunks.Count - 1];

            if (getAdditionalPropertiesCallback != null)
            {
                this.message.SetProps(getAdditionalPropertiesCallback(this.store));
            }
            using (MapiStream mapiStream2 = this.message.OpenStream(PropTag.Body, OpenPropertyFlags.Create))
            {
                MoveObjectInfo <T> .SerializeToStream(obj, mapiStream2);
            }
            this.message.SaveChanges();
            if (flag)
            {
                this.MessageId = this.message.GetProp(PropTag.EntryId).GetBytes();
            }
        }
Beispiel #5
0
        public PersistablePropertyBag OpenAttachment(ICollection <PropertyDefinition> prefetchProperties, AttachmentPropertyBag attachmentBag)
        {
            ICollection <PropertyDefinition> attachmentLoadList = this.AttachmentCollection.GetAttachmentLoadList(prefetchProperties, attachmentBag.Schema);
            int                    attachmentNumber             = attachmentBag.AttachmentNumber;
            MapiAttach             mapiAttach             = null;
            StoreObjectPropertyBag storeObjectPropertyBag = null;
            bool                   flag = false;

            try
            {
                StoreSession session = this.AttachmentCollection.ContainerItem.Session;
                bool         flag2   = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiAttach = this.AttachmentCollection.ContainerItem.MapiMessage.OpenAttach(attachmentNumber);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenMapiAttachment({0})", attachmentNumber),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex2, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenMapiAttachment({0})", attachmentNumber),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag2)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                storeObjectPropertyBag = this.CreateStorePropertyBag(mapiAttach, attachmentLoadList);
                byte[] array = ((IDirectPropertyBag)storeObjectPropertyBag).GetValue(InternalSchema.RecordKey) as byte[];
                if (array != null)
                {
                    AttachmentId attachmentId = new AttachmentId(array);
                    if (!attachmentId.Equals(attachmentBag.AttachmentId))
                    {
                        throw new StoragePermanentException(ServerStrings.MapiCannotMatchAttachmentIds(attachmentId.ToBase64String(), attachmentBag.AttachmentId.ToBase64String()));
                    }
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (storeObjectPropertyBag != null)
                    {
                        storeObjectPropertyBag.Dispose();
                        storeObjectPropertyBag = null;
                    }
                    if (mapiAttach != null)
                    {
                        mapiAttach.Dispose();
                        mapiAttach = null;
                    }
                }
            }
            return(storeObjectPropertyBag);
        }
Beispiel #6
0
        internal static void CopySavedMapiAttachment(bool failOnProblems, object thisObject, StoreSession session, MapiAttach source, MapiAttach destination)
        {
            PropProblem[] array = null;
            bool          flag  = false;

            try
            {
                if (session != null)
                {
                    session.BeginMapiCall();
                    session.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                array = source.CopyTo(destination, new PropTag[0]);
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiAttachmentProvider::CopySavedMapiAttachment", new object[0]),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiAttachmentProvider::CopySavedMapiAttachment", new object[0]),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (session != null)
                    {
                        session.EndMapiCall();
                        if (flag)
                        {
                            session.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            if (array != null)
            {
                ExTraceGlobals.StorageTracer.TraceError <int>((long)((thisObject == null) ? 0 : thisObject.GetHashCode()), "MapiAttachmentProvider.CreateNewAttachment: MapiAttach.CopyTo returned scode = {0}", array[0].Scode);
                if (failOnProblems)
                {
                    throw PropertyError.ToException(ServerStrings.ExUnableToCopyAttachments, StoreObjectPropertyBag.MapiPropProblemsToPropertyErrors(null, destination, array));
                }
            }
        }
Beispiel #7
0
        public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew)
        {
            MapiMessage            mapiMessage            = null;
            PersistablePropertyBag persistablePropertyBag = null;
            CoreItem      coreItem      = null;
            bool          flag          = false;
            StoreObjectId storeObjectId = null;

            byte[]    array = null;
            ICoreItem result;

            try
            {
                StoreObjectPropertyBag storeObjectPropertyBag = (StoreObjectPropertyBag)attachmentBag.PersistablePropertyBag;
                MapiAttach             mapiAttach             = (MapiAttach)storeObjectPropertyBag.MapiProp;
                StoreSession           session           = this.AttachmentCollection.ContainerItem.Session;
                OpenPropertyFlags      openPropertyFlags = isNew ? OpenPropertyFlags.Create : (this.AttachmentCollection.IsReadOnly ? OpenPropertyFlags.BestAccess : OpenPropertyFlags.BestAccess);
                openPropertyFlags |= OpenPropertyFlags.DeferredErrors;
                string text   = storeObjectPropertyBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                StoreSession session2 = this.AttachmentCollection.ContainerItem.Session;
                bool         flag2    = false;
                try
                {
                    if (session2 != null)
                    {
                        session2.BeginMapiCall();
                        session2.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiMessage = mapiAttach.OpenEmbeddedMessage(openPropertyFlags);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex, session2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex2, session2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session2 != null)
                        {
                            session2.EndMapiCall();
                            if (flag2)
                            {
                                session2.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiMessage, propertiesToLoad);
                if (!isNew)
                {
                    StoreObjectType storeObjectType = ItemBuilder.ReadStoreObjectTypeFromPropertyBag(persistablePropertyBag);
                    ItemCreateInfo  itemCreateInfo  = ItemCreateInfo.GetItemCreateInfo(storeObjectType);
                    propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(itemCreateInfo.Schema.AutoloadProperties, propertiesToLoad);
                    if (this.AttachmentCollection.IsReadOnly)
                    {
                        StoreId.SplitStoreObjectIdAndChangeKey(StoreObjectId.DummyId, out storeObjectId, out array);
                    }
                    persistablePropertyBag = new AcrPropertyBag(persistablePropertyBag, itemCreateInfo.AcrProfile, storeObjectId, new RetryBagFactory(session), array);
                }
                coreItem = new CoreItem(session, persistablePropertyBag, storeObjectId, array, isNew ? Origin.New : Origin.Existing, ItemLevel.Attached, propertiesToLoad, ItemBindOption.None);
                if (text != null && isNew)
                {
                    coreItem.PropertyBag[InternalSchema.ItemClass] = text;
                }
                flag   = true;
                result = coreItem;
            }
            finally
            {
                if (!flag)
                {
                    if (coreItem != null)
                    {
                        coreItem.Dispose();
                        coreItem = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                    if (mapiMessage != null)
                    {
                        mapiMessage.Dispose();
                        mapiMessage = null;
                    }
                }
            }
            return(result);
        }
Beispiel #8
0
        public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber)
        {
            MapiAttach             mapiAttach             = null;
            PersistablePropertyBag persistablePropertyBag = null;
            bool flag = false;
            int  num  = 0;

            try
            {
                StoreSession session = this.AttachmentCollection.ContainerItem.Session;
                bool         flag2   = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiAttach = this.AttachmentCollection.ContainerItem.MapiMessage.CreateAttach(out num);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex2, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag2)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                attachmentNumber = num;
                if (attachmentToClone != null)
                {
                    MapiAttachmentProvider.CopySavedMapiAttachment(true, this, this.AttachmentCollection.ContainerItem.Session, (MapiAttach)attachmentToClone.PropertyBag.MapiProp, mapiAttach);
                }
                else if (itemToAttach != null)
                {
                    MapiMessage  mapiMessage  = itemToAttach.MapiMessage;
                    MapiMessage  mapiMessage2 = null;
                    StoreSession session2     = this.AttachmentCollection.ContainerItem.Session;
                    bool         flag3        = false;
                    try
                    {
                        if (session2 != null)
                        {
                            session2.BeginMapiCall();
                            session2.BeginServerHealthCall();
                            flag3 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiMessage2 = mapiAttach.OpenEmbeddedMessage(OpenPropertyFlags.Create);
                    }
                    catch (MapiPermanentException ex3)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex3, session2, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                            ex3
                        });
                    }
                    catch (MapiRetryableException ex4)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex4, session2, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                            ex4
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session2 != null)
                            {
                                session2.EndMapiCall();
                                if (flag3)
                                {
                                    session2.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    using (mapiMessage2)
                    {
                        PropProblem[] array    = null;
                        StoreSession  session3 = this.AttachmentCollection.ContainerItem.Session;
                        bool          flag4    = false;
                        try
                        {
                            if (session3 != null)
                            {
                                session3.BeginMapiCall();
                                session3.BeginServerHealthCall();
                                flag4 = true;
                            }
                            if (StorageGlobals.MapiTestHookBeforeCall != null)
                            {
                                StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                            }
                            array = mapiMessage.CopyTo(mapiMessage2, new PropTag[]
                            {
                                (PropTag)InternalSchema.UrlCompName.PropertyTag
                            });
                        }
                        catch (MapiPermanentException ex5)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyFailedProperties, ex5, session3, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex5
                            });
                        }
                        catch (MapiRetryableException ex6)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyFailedProperties, ex6, session3, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex6
                            });
                        }
                        finally
                        {
                            try
                            {
                                if (session3 != null)
                                {
                                    session3.EndMapiCall();
                                    if (flag4)
                                    {
                                        session3.EndServerHealthCall();
                                    }
                                }
                            }
                            finally
                            {
                                if (StorageGlobals.MapiTestHookAfterCall != null)
                                {
                                    StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                                }
                            }
                        }
                        if (array != null)
                        {
                            int num2 = -1;
                            for (int i = 0; i < array.Length; i++)
                            {
                                int scode = array[i].Scode;
                                if (scode == -2147221233 || scode == -2147221222)
                                {
                                    ExTraceGlobals.StorageTracer.TraceDebug <int>((long)this.GetHashCode(), "Storage.MapiAttachmentProvider.AddExisting Item: CopyTo returned ignorable scode = {0}", scode);
                                }
                                else
                                {
                                    ExTraceGlobals.StorageTracer.TraceError <int>((long)this.GetHashCode(), "Storage.MapiAttachmentProvider.AddExisting Item: CopyTo returned fatal scode = {0}", scode);
                                    num2 = i;
                                }
                                if (num2 != -1)
                                {
                                    throw PropertyError.ToException(ServerStrings.ExUnableToCopyAttachments, StoreObjectPropertyBag.MapiPropProblemsToPropertyErrors(null, mapiMessage, array));
                                }
                            }
                        }
                        StoreSession session4 = this.AttachmentCollection.ContainerItem.Session;
                        bool         flag5    = false;
                        try
                        {
                            if (session4 != null)
                            {
                                session4.BeginMapiCall();
                                session4.BeginServerHealthCall();
                                flag5 = true;
                            }
                            if (StorageGlobals.MapiTestHookBeforeCall != null)
                            {
                                StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                            }
                            mapiMessage2.SaveChanges();
                        }
                        catch (MapiPermanentException ex7)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSaveChanges, ex7, session4, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex7
                            });
                        }
                        catch (MapiRetryableException ex8)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSaveChanges, ex8, session4, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("MapiAttachmentProvider::CreateMapiAttachment", new object[0]),
                                ex8
                            });
                        }
                        finally
                        {
                            try
                            {
                                if (session4 != null)
                                {
                                    session4.EndMapiCall();
                                    if (flag5)
                                    {
                                        session4.EndServerHealthCall();
                                    }
                                }
                            }
                            finally
                            {
                                if (StorageGlobals.MapiTestHookAfterCall != null)
                                {
                                    StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                                }
                            }
                        }
                    }
                }
                persistablePropertyBag            = this.CreateStorePropertyBag(mapiAttach, propertiesToLoad);
                persistablePropertyBag.ExTimeZone = this.ExTimeZone;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                    }
                    if (mapiAttach != null)
                    {
                        mapiAttach.Dispose();
                    }
                }
            }
            return(persistablePropertyBag);
        }