Ejemplo n.º 1
0
 internal static AttachmentLink Find(AttachmentId attachmentId, IList <AttachmentLink> attachmentLinks)
 {
     if (attachmentId != null && attachmentLinks != null)
     {
         foreach (AttachmentLink attachmentLink in attachmentLinks)
         {
             if (attachmentId.Equals(attachmentLink.AttachmentId))
             {
                 return(attachmentLink);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 2
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);
        }