Example #1
0
        internal static StoreObjectPropertyBag CreatePropertyBag(StoreSession storeSession, StoreObjectId id, ICollection <PropertyDefinition> prefetchPropertyArray)
        {
            MapiProp mapiProp = null;
            StoreObjectPropertyBag storeObjectPropertyBag = null;
            bool flag = false;
            StoreObjectPropertyBag result;

            try
            {
                mapiProp = storeSession.GetMapiProp(id);
                storeObjectPropertyBag = new StoreObjectPropertyBag(storeSession, mapiProp, prefetchPropertyArray);
                flag   = true;
                result = storeObjectPropertyBag;
            }
            finally
            {
                if (!flag)
                {
                    if (storeObjectPropertyBag != null)
                    {
                        storeObjectPropertyBag.Dispose();
                        storeObjectPropertyBag = null;
                    }
                    if (mapiProp != null)
                    {
                        mapiProp.Dispose();
                        mapiProp = null;
                    }
                }
            }
            return(result);
        }
Example #2
0
        internal static StoreObjectPropertyBag CreatePropertyBag(StoreSession storeSession, StoreObjectId id, ICollection <PropertyDefinition> prefetchPropertyArray)
        {
            Util.ThrowOnNullArgument(id, "id");
            MapiProp mapiProp = null;
            StoreObjectPropertyBag storeObjectPropertyBag = null;
            bool flag = false;
            StoreObjectPropertyBag result;

            try
            {
                mapiProp = storeSession.GetMapiProp(id);
                storeObjectPropertyBag = new StoreObjectPropertyBag(storeSession, mapiProp, prefetchPropertyArray);
                flag   = true;
                result = storeObjectPropertyBag;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(storeObjectPropertyBag);
                    Util.DisposeIfPresent(mapiProp);
                }
            }
            return(result);
        }
        public override CalendarItemBase GetEmbeddedItem()
        {
            this.CheckDisposed("GetEmbeddedItem");
            ExTraceGlobals.MeetingMessageTracer.Information <GlobalObjectId>((long)this.GetHashCode(), "Storage.MeetingMessage.GetEmbeddedItem: GOID={0}", this.GlobalObjectId);
            CalendarItemBase calendarItemBase = null;
            bool             flag             = false;
            CalendarItemBase result;

            try
            {
                ItemCreateInfo calendarItemInfo = ItemCreateInfo.CalendarItemInfo;
                calendarItemBase = ItemBuilder.ConstructItem <CalendarItem>(base.Session, base.StoreObjectId, (base.StoreObjectId != null) ? base.Id.ChangeKeyAsByteArray() : null, calendarItemInfo.Schema.AutoloadProperties, delegate
                {
                    AcrPropertyBag acrPropertyBag = null;
                    PersistablePropertyBag persistablePropertyBag = null;
                    bool flag2 = false;
                    StoreObjectId storeObjectId = base.StoreObjectId;
                    PersistablePropertyBag result2;
                    try
                    {
                        if (storeObjectId != null && !storeObjectId.IsFakeId)
                        {
                            persistablePropertyBag = StoreObjectPropertyBag.CreatePropertyBag(base.Session, storeObjectId, InternalSchema.ContentConversionProperties);
                            acrPropertyBag         = new AcrPropertyBag(persistablePropertyBag, AcrProfile.AppointmentProfile, storeObjectId, new ItemBagFactory(base.Session, base.StoreObjectId), null);
                            flag2   = true;
                            result2 = acrPropertyBag;
                        }
                        else
                        {
                            persistablePropertyBag = new StoreObjectPropertyBag(base.Session, base.MapiProp, InternalSchema.ContentConversionProperties, false);
                            flag2   = true;
                            result2 = persistablePropertyBag;
                        }
                    }
                    finally
                    {
                        if (!flag2)
                        {
                            Util.DisposeIfPresent(persistablePropertyBag);
                            Util.DisposeIfPresent(acrPropertyBag);
                        }
                    }
                    return(result2);
                }, calendarItemInfo.Creator, base.CoreObject.Origin, base.CoreObject.ItemLevel);
                flag   = true;
                result = calendarItemBase;
            }
            finally
            {
                if (!flag && calendarItemBase != null)
                {
                    calendarItemBase.Dispose();
                    calendarItemBase = null;
                }
            }
            return(result);
        }
Example #4
0
 internal StoreObjectStream(StoreObjectPropertyBag storePropertyBag, NativeStorePropertyDefinition property, PropertyOpenMode streamOpenMode)
 {
     Util.ThrowOnNullArgument(storePropertyBag, "storePropertyBag");
     Util.ThrowOnNullArgument(property, "property");
     this.storePropertyBag = storePropertyBag;
     this.property         = property;
     this.openMode         = streamOpenMode;
     this.CreateStream();
     this.disposeTracker = this.GetDisposeTracker();
 }
Example #5
0
        internal void ForceReload(params PropertyDefinition[] propsToLoad)
        {
            this.CheckDisposed("ForceReload");
            if (propsToLoad == null)
            {
                throw new ArgumentNullException("propsToLoad");
            }
            StoreObjectPropertyBag storeObjectPropertyBag = (StoreObjectPropertyBag)base.PropertyBag;

            storeObjectPropertyBag.ForceReload(propsToLoad);
        }
Example #6
0
 internal static PropertyError[] MapiPropProblemsToPropertyErrors(StoreSession storeSession, MapiProp mapiProp, PropProblem[] problems)
 {
     PropTag[]     array  = new PropTag[problems.Length];
     PropProblem[] array2 = new PropProblem[problems.Length];
     for (int i = 0; i < problems.Length; i++)
     {
         array[i]  = problems[i].PropTag;
         array2[i] = new PropProblem(i, problems[i].PropTag, problems[i].Scode);
     }
     NativeStorePropertyDefinition[] propertyDefinitions = PropertyTagCache.Cache.PropertyDefinitionsFromPropTags(NativeStorePropertyDefinition.TypeCheckingFlag.DisableTypeCheck, mapiProp, storeSession, array);
     return(StoreObjectPropertyBag.MapiPropProblemsToPropertyErrors(propertyDefinitions, array2));
 }
Example #7
0
        public PersistablePropertyBag CreateStorePropertyBag(PropertyBag propertyBag, ICollection <PropertyDefinition> prefetchProperties)
        {
            byte[]                           entryId = propertyBag.TryGetProperty(InternalSchema.EntryId) as byte[];
            StoreObjectId                    id      = StoreObjectId.FromProviderSpecificId(entryId, StoreObjectType.Unknown);
            StoreObjectPropertyBag           storeObjectPropertyBag = propertyBag as StoreObjectPropertyBag;
            ICollection <PropertyDefinition> prefetchPropertyArray;

            if (storeObjectPropertyBag != null)
            {
                prefetchPropertyArray = ((prefetchProperties != null) ? prefetchProperties.Union(storeObjectPropertyBag.PrefetchPropertyArray) : storeObjectPropertyBag.PrefetchPropertyArray);
            }
            else
            {
                prefetchPropertyArray = prefetchProperties;
            }
            PersistablePropertyBag persistablePropertyBag = ItemBagFactory.CreatePropertyBag(this.storeSession, id, prefetchPropertyArray);

            persistablePropertyBag.ExTimeZone = this.exTimeZone;
            return(persistablePropertyBag);
        }
Example #8
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);
        }
Example #9
0
        internal static PersistablePropertyBag ConstructItemPersistablePropertyBag(StoreSession session, ICollection <PropertyDefinition> propertiesToLoad, bool createAcrPropertyBag, AcrProfile acrProfile, ItemBuilder.MapiMessageCreator mapiMessageCreator)
        {
            MapiMessage            mapiMessage             = null;
            PersistablePropertyBag persistablePropertyBag  = null;
            PersistablePropertyBag persistablePropertyBag2 = null;
            bool flag = false;
            PersistablePropertyBag result;

            try
            {
                mapiMessage            = mapiMessageCreator();
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiMessage, propertiesToLoad);
                PersistablePropertyBag persistablePropertyBag3;
                if (createAcrPropertyBag)
                {
                    persistablePropertyBag2 = new AcrPropertyBag(persistablePropertyBag, acrProfile, null, new RetryBagFactory(session), null);
                    persistablePropertyBag3 = persistablePropertyBag2;
                }
                else
                {
                    persistablePropertyBag3 = persistablePropertyBag;
                }
                flag   = true;
                result = persistablePropertyBag3;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(persistablePropertyBag2);
                    Util.DisposeIfPresent(persistablePropertyBag);
                    Util.DisposeIfPresent(mapiMessage);
                }
            }
            return(result);
        }
Example #10
0
        internal static MailboxStoreObject Bind(StoreSession session, MapiStore mapiStore, ICollection <PropertyDefinition> requestedProperties, bool getMappingSignature, bool overridePropertyList)
        {
            ICollection <PropertyDefinition> collection = InternalSchema.Combine <PropertyDefinition>(overridePropertyList ? new PropertyTagPropertyDefinition[]
            {
                MailboxSchema.MailboxType,
                MailboxSchema.MailboxTypeDetail
            } : MailboxSchema.Instance.AutoloadProperties, requestedProperties);
            PersistablePropertyBag persistablePropertyBag = null;
            CoreMailboxObject      coreMailboxObject      = null;
            MailboxStoreObject     mailboxStoreObject     = null;
            bool flag = false;
            MailboxStoreObject result;

            try
            {
                byte[] array = null;
                if (getMappingSignature)
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                        {
                            array = (rootFolder.GetProp(PropTag.MappingSignature).Value as byte[]);
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                }
                if (array != null)
                {
                    session.MappingSignature = Convert.ToBase64String(array);
                }
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiStore, collection);
                coreMailboxObject      = new CoreMailboxObject(session, persistablePropertyBag, null, null, collection);
                mailboxStoreObject     = new MailboxStoreObject(coreMailboxObject);
                flag   = true;
                result = mailboxStoreObject;
            }
            finally
            {
                if (!flag)
                {
                    if (mailboxStoreObject != null)
                    {
                        mailboxStoreObject.Dispose();
                        mailboxStoreObject = null;
                    }
                    if (coreMailboxObject != null)
                    {
                        coreMailboxObject.Dispose();
                        coreMailboxObject = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(result);
        }
 public static void ValidateStreamIfApplicable(long streamLength, PropertyDefinition propertyDefinition, StoreObjectPropertyBag propertyBag)
 {
     if (ExtendedRuleConditionConstraint.propertyDefinition.Equals(propertyDefinition) && propertyBag != null && propertyBag.MapiPropertyBag != null && propertyBag.MapiPropertyBag.StoreSession != null)
     {
         int extendedRuleSizeLimit = ExtendedRuleConditionConstraint.GetExtendedRuleSizeLimit(propertyBag.MapiPropertyBag.StoreSession);
         if (streamLength > (long)extendedRuleSizeLimit)
         {
             throw new StoragePermanentException(ServerStrings.ExConstraintViolationByteArrayLengthTooLong(propertyDefinition.Name, (long)extendedRuleSizeLimit, streamLength));
         }
     }
 }
Example #12
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);
        }
Example #13
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));
                }
            }
        }
Example #14
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);
        }
Example #15
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);
        }
Example #16
0
 private static void ProcessCopyPropertyProblems(PropProblem[] problems, StoreSession sourceSession, MapiProp source)
 {
     if (problems != null)
     {
         for (int i = 0; i < problems.Length; i++)
         {
             int scode = problems[i].Scode;
             if (scode != -2147221233 && scode != -2147221222)
             {
                 throw PropertyError.ToException(ServerStrings.MapiCopyFailedProperties, StoreObjectPropertyBag.MapiPropProblemsToPropertyErrors(sourceSession, source, problems));
             }
         }
     }
 }
Example #17
0
        internal static CoreItem CoreItemBind(StoreSession session, StoreId storeId, ItemBuilder.MapiMessageCreator mapiMessageCreator, ItemBindOption itemBindOption, ICollection <PropertyDefinition> propertiesToLoad, ref StoreObjectType storeObjectType)
        {
            Util.ThrowOnNullArgument(session, "session");
            EnumValidator.ThrowIfInvalid <ItemBindOption>(itemBindOption);
            Util.ThrowOnNullArgument(propertiesToLoad, "propertiesToLoad");
            bool     flag     = false;
            MapiProp mapiProp = null;
            PersistablePropertyBag persistablePropertyBag = null;
            AcrPropertyBag         acrPropertyBag         = null;
            CoreItem coreItem = null;
            CoreItem result2;

            using (CallbackContext callbackContext = new CallbackContext(session))
            {
                try
                {
                    session.OnBeforeItemChange(ItemChangeOperation.ItemBind, session, storeId, coreItem, callbackContext);
                    StoreObjectId storeObjectId;
                    byte[]        array;
                    StoreId.SplitStoreObjectIdAndChangeKey(storeId, out storeObjectId, out array);
                    session.CheckSystemFolderAccess(storeObjectId);
                    if (storeObjectId != null && !IdConverter.IsMessageId(storeObjectId))
                    {
                        throw new ArgumentException(ServerStrings.ExInvalidItemId);
                    }
                    bool flag2 = false;
                    OccurrenceStoreObjectId occurrenceStoreObjectId = storeObjectId as OccurrenceStoreObjectId;
                    IPropertyBagFactory     propertyBagFactory;
                    if (occurrenceStoreObjectId != null)
                    {
                        persistablePropertyBag = Item.CreateOccurrencePropertyBag(session, occurrenceStoreObjectId, propertiesToLoad);
                        storeObjectType        = StoreObjectType.CalendarItemOccurrence;
                        flag2 = true;
                        propertyBagFactory = new OccurrenceBagFactory(session, occurrenceStoreObjectId);
                    }
                    else
                    {
                        if (mapiMessageCreator != null)
                        {
                            mapiProp = mapiMessageCreator();
                        }
                        else if ((itemBindOption & ItemBindOption.SoftDeletedItem) == ItemBindOption.SoftDeletedItem)
                        {
                            mapiProp = session.GetMapiProp(storeObjectId, OpenEntryFlags.BestAccess | OpenEntryFlags.DeferredErrors | OpenEntryFlags.ShowSoftDeletes);
                        }
                        else
                        {
                            mapiProp = session.GetMapiProp(storeObjectId);
                        }
                        persistablePropertyBag = new StoreObjectPropertyBag(session, mapiProp, propertiesToLoad);
                        StoreObjectType storeObjectType2 = ItemBuilder.ReadStoreObjectTypeFromPropertyBag(persistablePropertyBag);
                        if (storeObjectType2 == storeObjectType)
                        {
                            flag2 = true;
                        }
                        else
                        {
                            storeObjectType = storeObjectType2;
                        }
                        propertyBagFactory = new RetryBagFactory(session);
                        if (storeObjectId != null && storeObjectId.ObjectType != storeObjectType)
                        {
                            storeObjectId = StoreObjectId.FromProviderSpecificId(storeObjectId.ProviderLevelItemId, storeObjectType);
                        }
                    }
                    ItemBuilder.CheckPrivateItem(session, persistablePropertyBag);
                    ItemCreateInfo itemCreateInfo = ItemCreateInfo.GetItemCreateInfo(storeObjectType);
                    if (flag2)
                    {
                        propertiesToLoad = null;
                    }
                    else
                    {
                        propertiesToLoad = ItemBuilder.GetPropertiesToLoad(itemBindOption, itemCreateInfo.Schema, propertiesToLoad);
                    }
                    acrPropertyBag = new AcrPropertyBag(persistablePropertyBag, itemCreateInfo.AcrProfile, storeObjectId, propertyBagFactory, array);
                    coreItem       = new CoreItem(session, acrPropertyBag, storeObjectId, array, Origin.Existing, ItemLevel.TopLevel, propertiesToLoad, itemBindOption);
                    flag           = true;
                    ConflictResolutionResult result = flag ? ConflictResolutionResult.Success : ConflictResolutionResult.Failure;
                    session.OnAfterItemChange(ItemChangeOperation.ItemBind, session, storeId, coreItem, result, callbackContext);
                    result2 = coreItem;
                }
                finally
                {
                    if (!flag)
                    {
                        Util.DisposeIfPresent(coreItem);
                        Util.DisposeIfPresent(acrPropertyBag);
                        Util.DisposeIfPresent(persistablePropertyBag);
                        Util.DisposeIfPresent(mapiProp);
                    }
                }
            }
            return(result2);
        }