示例#1
0
 internal static void SetTableFilter(StoreSession session, MapiProp propertyReference, MapiTable mapiTable, QueryFilter queryFilter)
 {
     if (queryFilter != null)
     {
         Restriction restriction = FilterRestrictionConverter.CreateRestriction(session, session.ExTimeZone, propertyReference, queryFilter);
         object      thisObject  = null;
         bool        flag        = false;
         try
         {
             if (session != null)
             {
                 session.BeginMapiCall();
                 session.BeginServerHealthCall();
                 flag = true;
             }
             if (StorageGlobals.MapiTestHookBeforeCall != null)
             {
                 StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
             }
             mapiTable.Restrict(restriction);
         }
         catch (MapiPermanentException ex)
         {
             throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateRestriction, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
             {
                 string.Format("Folder::SetTableFilter. Failed to set a restriction.", new object[0]),
                 ex
             });
         }
         catch (MapiRetryableException ex2)
         {
             throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateRestriction, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
             {
                 string.Format("Folder::SetTableFilter. Failed to set a restriction.", new object[0]),
                 ex2
             });
         }
         finally
         {
             try
             {
                 if (session != null)
                 {
                     session.EndMapiCall();
                     if (flag)
                     {
                         session.EndServerHealthCall();
                     }
                 }
             }
             finally
             {
                 if (StorageGlobals.MapiTestHookAfterCall != null)
                 {
                     StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                 }
             }
         }
     }
 }
示例#2
0
        private static object GetMapiValueFromValue(StoreSession session, ExTimeZone timeZone, object value)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(timeZone, "timeZone");
            if (value is PropertyError)
            {
                throw new ArgumentException(string.Format("We should never need to translate a PropertyError into mapi.net, because it makes no sense to set an error. PropertyError found = {0}.", value));
            }
            QueryFilter queryFilter = value as QueryFilter;

            if (queryFilter != null)
            {
                return(FilterRestrictionConverter.CreateRestriction(session, timeZone, session.Mailbox.MapiStore, queryFilter));
            }
            RuleAction[] array = value as RuleAction[];
            if (array != null)
            {
                RuleAction[] array2 = new RuleAction[array.Length];
                for (int i = 0; i < array2.Length; i++)
                {
                    array2[i] = RuleActionConverter.ConvertRuleAction(session, timeZone, array[i]);
                }
                return(array2);
            }
            return(ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(timeZone, value));
        }
示例#3
0
        public bool TryGetQueryFilter(out QueryFilter filter)
        {
            MailboxSession mailboxSession = base.Session as MailboxSession;

            if (mailboxSession == null)
            {
                throw new InvalidOperationException(ServerStrings.ExOutlookSearchFolderDoesNotHaveMailboxSession);
            }
            VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(mailboxSession, (Guid)this[InternalSchema.OutlookSearchFolderClsId]);

            if (versionedId == null)
            {
                filter = null;
                return(false);
            }
            bool result;

            using (MessageItem messageItem = MessageItem.Bind(mailboxSession, versionedId))
            {
                bool        flag;
                StoreId[]   array;
                Restriction restriction = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out flag, out array);
                filter = FilterRestrictionConverter.CreateFilter(mailboxSession, mailboxSession.Mailbox.MapiStore, restriction, true);
                result = true;
            }
            return(result);
        }
示例#4
0
 internal override void RegisterFilterTranslation()
 {
     FilterRestrictionConverter.RegisterFilterTranslation(this, typeof(ComparisonFilter));
     FilterRestrictionConverter.RegisterFilterTranslation(this, typeof(ExistsFilter));
 }
示例#5
0
        internal static object GetValueFromPropValue(StoreSession storeSession, ExTimeZone exTimeZone, StorePropertyDefinition propertyDefinition, PropValue propertyValue)
        {
            if (propertyValue.IsError())
            {
                int num = propertyValue.GetErrorValue();
                if (num == -2147220732 && (propertyDefinition.SpecifiedWith == PropertyTypeSpecifier.GuidId || propertyDefinition.SpecifiedWith == PropertyTypeSpecifier.GuidString))
                {
                    num = -2147221233;
                }
                return(MapiPropertyBag.CreatePropertyError(num, propertyDefinition));
            }
            PropType propType = propertyValue.PropTag.ValueType();

            if (propType == PropType.Restriction)
            {
                if (storeSession == null)
                {
                    throw new NotSupportedException("PT_RESTRICTION is not supported when we do not have a session. This very likely is an attachment.");
                }
                return(FilterRestrictionConverter.CreateFilter(storeSession, storeSession.Mailbox.MapiStore, (Restriction)propertyValue.Value, false));
            }
            else
            {
                if (propertyValue.Value == null)
                {
                    return(MapiPropertyBag.CreatePropertyError(-2147221233, propertyDefinition));
                }
                if (propType == PropType.Actions)
                {
                    if (storeSession == null)
                    {
                        throw new NotSupportedException("RuleAction type not supported without a session.");
                    }
                    RuleAction[] array  = (RuleAction[])propertyValue.Value;
                    RuleAction[] array2 = new RuleAction[array.Length];
                    for (int i = 0; i < array2.Length; i++)
                    {
                        array2[i] = RuleActionConverter.ConvertRuleAction(storeSession, exTimeZone, array[i]);
                    }
                    return(array2);
                }
                else if (propType == PropType.SysTime)
                {
                    DateTime dateTime = (DateTime)propertyValue.Value;
                    if (ExDateTime.IsValidDateTime(dateTime))
                    {
                        return(new ExDateTime(exTimeZone, dateTime));
                    }
                    return(MapiPropertyBag.CreatePropertyError(-2147221221, propertyDefinition));
                }
                else
                {
                    if (propType == PropType.SysTimeArray)
                    {
                        DateTime[] array3 = (DateTime[])propertyValue.Value;
                        foreach (DateTime dateTime2 in array3)
                        {
                            if (!ExDateTime.IsValidDateTime(dateTime2))
                            {
                                return(MapiPropertyBag.CreatePropertyError(-2147221221, propertyDefinition));
                            }
                        }
                        return(ExTimeZoneHelperForMigrationOnly.ToExDateTimeArray(exTimeZone, array3));
                    }
                    return(propertyValue.Value);
                }
            }
        }
示例#6
0
        protected SynchronizerProviderBase(CoreFolder folder, SynchronizerConfigFlags flags, QueryFilter filter, StorageIcsState initialState, PropertyDefinition[] includeProperties, PropertyDefinition[] excludeProperties, short[] unspecifiedIncludeProperties, short[] unspecifiedExcludeProperties, int fastTransferBlockSize)
        {
            this.folder = folder;
            bool flag = false;

            try
            {
                PersistablePropertyBag persistablePropertyBag = CoreObject.GetPersistablePropertyBag(this.folder);
                Restriction            restriction            = null;
                if (filter != null)
                {
                    restriction = FilterRestrictionConverter.CreateRestriction(folder.Session, persistablePropertyBag.ExTimeZone, persistablePropertyBag.MapiProp, filter);
                }
                ICollection <PropTag> includePropertyTags = null;
                if (includeProperties != null && includeProperties.Length > 0)
                {
                    includePropertyTags = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiFolder, this.folder.Session, true, includeProperties);
                }
                ICollection <PropTag> excludePropertyTags = null;
                if (excludeProperties != null && excludeProperties.Length > 0)
                {
                    excludePropertyTags = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiFolder, this.folder.Session, true, excludeProperties);
                }
                SynchronizerProviderBase.ReconstituteProperties(unspecifiedIncludeProperties, ref includePropertyTags);
                SynchronizerProviderBase.ReconstituteProperties(unspecifiedExcludeProperties, ref excludePropertyTags);
                StoreSession session    = this.folder.Session;
                object       thisObject = this.folder;
                bool         flag2      = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    this.MapiCreateSynchronizer(flags, restriction, initialState, includePropertyTags, excludePropertyTags, fastTransferBlockSize);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.CannotCreateSynchronizerEx(base.GetType()), ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("SynchronizerProviderBase..ctor. Failed to create/configure MapiSynchronizerEx.", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.CannotCreateSynchronizerEx(base.GetType()), ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("SynchronizerProviderBase..ctor. Failed to create/configure MapiSynchronizerEx.", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag2)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    base.Dispose();
                }
            }
        }
示例#7
0
        private void WriteOutlookSearchFolderDefinitionBlob(MessageItem message, SearchFolderCriteria criteria)
        {
            Restriction restriction = FilterRestrictionConverter.CreateRestriction(base.Session, base.PropertyBag.ExTimeZone, base.MapiProp, criteria.SearchQuery);

            OutlookSearchFolder.WriteOutlookSearchFolderDefinitionBlob(message, restriction, criteria.DeepTraversal, criteria.FolderScope);
        }
示例#8
0
        public static StoreObjectId Recreate(MailboxSession session, Guid searchFolderClsId)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (searchFolderClsId == Guid.Empty)
            {
                throw new ArgumentException("Guid is empty", "searchFolderClsId");
            }
            using (Folder folder = Folder.Bind(session, DefaultFolderType.SearchFolders))
            {
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[]
                {
                    InternalSchema.OutlookSearchFolderClsId
                }))
                {
                    for (;;)
                    {
                        object[][] rows = queryResult.GetRows(10000);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (rows[i][0] is Guid && ((Guid)rows[i][0]).Equals(searchFolderClsId))
                            {
                                goto Block_9;
                            }
                        }
                        if (rows.Length <= 0)
                        {
                            goto Block_11;
                        }
                    }
Block_9:
                    throw new ObjectExistedException(ServerStrings.ExSearchFolderAlreadyExists(searchFolderClsId));
                    Block_11 :;
                }
            }
            VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(session, searchFolderClsId);

            if (versionedId == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ExSearchFolderNoAssociatedItem(searchFolderClsId));
            }
            StoreObjectId objectId;

            using (MessageItem messageItem = MessageItem.Bind(session, versionedId))
            {
                bool                 deepTraversal;
                StoreId[]            folderScope;
                Restriction          restriction          = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out deepTraversal, out folderScope);
                QueryFilter          searchQuery          = FilterRestrictionConverter.CreateFilter(session, session.Mailbox.MapiStore, restriction, true);
                SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(searchQuery, folderScope);
                searchFolderCriteria.DeepTraversal = deepTraversal;
                string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.DisplayName, string.Empty);
                using (OutlookSearchFolder outlookSearchFolder = OutlookSearchFolder.Create(session, valueOrDefault))
                {
                    outlookSearchFolder[InternalSchema.OutlookSearchFolderClsId] = searchFolderClsId;
                    FolderSaveResult folderSaveResult = outlookSearchFolder.Save();
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));
                    }
                    outlookSearchFolder.Load(null);
                    outlookSearchFolder.ApplyContinuousSearch(searchFolderCriteria);
                    objectId = outlookSearchFolder.Id.ObjectId;
                }
            }
            return(objectId);
        }
        private bool EnsureMapiManifest(MailboxSyncWatermark minWatermark, int numOperations, Dictionary <ISyncItemId, ServerManifestEntry> newServerManifest)
        {
            MemoryStream memoryStream = null;
            MapiFolder   mapiFolder   = this.folder.MapiFolder;

            if (this.manifest != null)
            {
                if (MailboxSyncProvider.IcsStateEquals(this.icsState, minWatermark.IcsState))
                {
                    if (this.extraServerManifestEntry != null)
                    {
                        if (numOperations == 0)
                        {
                            return(true);
                        }
                        newServerManifest.Add(this.extraServerManifestEntry.Id, this.extraServerManifestEntry);
                        if (this.extraServerManifestEntry.Watermark != null)
                        {
                            minWatermark.ChangeNumber = ((MailboxSyncWatermark)this.extraServerManifestEntry.Watermark).ChangeNumber;
                        }
                        this.SyncLogger.Information <ISyncItemId>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Adding cached change, id = {0}", this.extraServerManifestEntry.Id);
                        this.extraServerManifestEntry = null;
                    }
                    this.icsCallback.Bind(minWatermark, numOperations, newServerManifest);
                    this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Reusing ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
                    return(false);
                }
                this.manifest.Dispose();
                this.manifest = null;
                this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Tossed old ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
            }
            try
            {
                memoryStream     = ((minWatermark.IcsState == null) ? new MemoryStream() : new MemoryStream(minWatermark.IcsState));
                this.manifest    = mapiFolder.CreateExportManifest();
                this.icsCallback = new IcsCallback(this, newServerManifest, numOperations, minWatermark);
                Restriction restriction = (this.icsPropertyGroupFilter == null) ? null : FilterRestrictionConverter.CreateRestriction(this.folder.Session, this.folder.Session.ExTimeZone, this.folder.MapiFolder, this.icsPropertyGroupFilter);
                this.manifest.Configure(this.GetConfigFlags(), restriction, memoryStream, this.icsCallback, IcsCallback.PropTags);
                this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Created new ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
            }
            finally
            {
                Util.DisposeIfPresent(memoryStream);
            }
            return(false);
        }
示例#10
0
 internal override void RegisterFilterTranslation()
 {
     FilterRestrictionConverter.RegisterFilterTranslation(this, typeof(OrFilter));
     FilterRestrictionConverter.RegisterFilterTranslation(this, typeof(NotFilter));
 }
示例#11
0
 internal override void RegisterFilterTranslation()
 {
     FilterRestrictionConverter.RegisterFilterTranslation(this, typeof(SinglePropertyFilter));
 }
        protected ManifestProviderBase(CoreFolder folder, ManifestConfigFlags flags, QueryFilter filter, StorageIcsState initialState, PropertyDefinition[] includeProperties, PropertyDefinition[] excludeProperties)
        {
            this.folder         = folder;
            this.disposeTracker = this.GetDisposeTracker();
            bool flag = false;

            try
            {
                PersistablePropertyBag persistablePropertyBag = CoreObject.GetPersistablePropertyBag(this.folder);
                Restriction            restriction            = null;
                if (filter != null)
                {
                    restriction = FilterRestrictionConverter.CreateRestriction(folder.Session, persistablePropertyBag.ExTimeZone, persistablePropertyBag.MapiProp, filter);
                }
                ICollection <PropTag> includePropertyTags = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiFolder, this.Session, true, includeProperties);
                ICollection <PropTag> excludePropertyTags = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiFolder, this.Session, true, excludeProperties);
                StoreSession          session             = this.Session;
                object thisObject = this.folder;
                bool   flag2      = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    this.mapiManifest = this.MapiCreateManifest(flags, restriction, initialState, includePropertyTags, excludePropertyTags);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.CannotCreateManifestEx(base.GetType()), ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("ManifestProviderBase..ctor. Failed to create/configure HierarchyManifestEx.", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.CannotCreateManifestEx(base.GetType()), ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("ManifestProviderBase..ctor. Failed to create/configure HierarchyManifestEx.", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag2)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    base.Dispose();
                }
            }
        }