Exemple #1
0
        public static CalendarGroupEntry BindFromCalendarFolder(MailboxSession session, StoreObjectId calendarFolderObjectId)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(calendarFolderObjectId, "calendarFolderObjectId");
            if (calendarFolderObjectId.ObjectType != StoreObjectType.CalendarFolder && calendarFolderObjectId.ObjectType != StoreObjectType.Folder)
            {
                throw new ArgumentException("StoreObject is not a calendar folder.", "calendarFolderObjectId");
            }
            VersionedId groupEntryIdFromFolderId = CalendarGroupEntry.GetGroupEntryIdFromFolderId(session, calendarFolderObjectId);

            if (groupEntryIdFromFolderId == null)
            {
                if (calendarFolderObjectId.Equals(session.GetDefaultFolderId(DefaultFolderType.Calendar)))
                {
                    using (CalendarGroup calendarGroup = CalendarGroup.Bind(session, FolderTreeData.MyFoldersClassId))
                    {
                        ReadOnlyCollection <CalendarGroupEntryInfo> childCalendars = calendarGroup.GetChildCalendars();
                        foreach (CalendarGroupEntryInfo calendarGroupEntryInfo in childCalendars)
                        {
                            LocalCalendarGroupEntryInfo localCalendarGroupEntryInfo = calendarGroupEntryInfo as LocalCalendarGroupEntryInfo;
                            if (localCalendarGroupEntryInfo != null && calendarFolderObjectId.Equals(localCalendarGroupEntryInfo.CalendarId))
                            {
                                return(CalendarGroupEntry.Bind(session, calendarGroupEntryInfo.Id, null));
                            }
                        }
                    }
                }
                throw new ObjectNotFoundException(ServerStrings.ExItemNotFound);
            }
            return(CalendarGroupEntry.Bind(session, groupEntryIdFromFolderId, null));
        }
Exemple #2
0
        private void CheckAccessOnAuditFolders(MailboxSession mailboxSession, StoreObjectId folderId, IDumpsterItemOperations dumpster, bool checkAncestorFolders)
        {
            StoreObjectId auditsFolderId         = dumpster.AuditsFolderId;
            StoreObjectId adminAuditLogsFolderId = dumpster.AdminAuditLogsFolderId;

            if (folderId.Equals(auditsFolderId))
            {
                throw new AccessDeniedException(ServerStrings.ExAuditsUpdateDenied);
            }
            if (folderId.Equals(adminAuditLogsFolderId))
            {
                throw new AccessDeniedException(ServerStrings.ExAdminAuditLogsUpdateDenied);
            }
            if (dumpster.IsAuditFolder(folderId))
            {
                throw new AccessDeniedException((auditsFolderId != null) ? ServerStrings.ExAuditsUpdateDenied : ServerStrings.ExAdminAuditLogsUpdateDenied);
            }
            if (checkAncestorFolders && (folderId.Equals(dumpster.RecoverableItemsRootFolderId) || folderId.Equals(mailboxSession.GetDefaultFolderId(DefaultFolderType.Configuration))))
            {
                if (auditsFolderId != null)
                {
                    throw new AccessDeniedException(ServerStrings.ExAuditsUpdateDenied);
                }
                if (adminAuditLogsFolderId != null)
                {
                    throw new AccessDeniedException(ServerStrings.ExAdminAuditLogsUpdateDenied);
                }
            }
        }
Exemple #3
0
 public bool IsDumpsterFolder(MailboxSession sessionWithBestAccess, StoreObjectId folderId)
 {
     this.CheckDisposed("IsDumpsterFolder");
     if (folderId == null)
     {
         return(false);
     }
     this.CheckFolderInitState(sessionWithBestAccess);
     return(folderId.Equals(this.recoverableItemsRootFolderId) || folderId.Equals(this.recoverableItemsDeletionsFolderId) || folderId.Equals(this.recoverableItemsVersionsFolderId) || folderId.Equals(this.recoverableItemsPurgesFolderId) || folderId.Equals(this.recoverableItemsDiscoveryHoldsFolderId) || folderId.Equals(this.calendarLoggingFolderId) || folderId.Equals(this.recoverableItemsMigratedMessagesFolderId) || folderId.Equals(this.auditsFolderId) || folderId.Equals(this.adminAuditLogsFolderId));
 }
Exemple #4
0
        public CowClientOperationSensitivity SkipGroupOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, FolderChangeOperationFlags flags, StoreSession sourceSession, StoreSession destinationSession, StoreObjectId sourceFolderId, StoreObjectId destinationFolderId, ICollection <StoreObjectId> itemIds, bool onBeforeNotification, bool onDumpster, CallbackContext callbackContext)
        {
            EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
            EnumValidator.ThrowIfInvalid <FolderChangeOperationFlags>(flags, "flags");
            MailboxSession mailboxSession = sourceSession as MailboxSession;

            if (mailboxSession == null)
            {
                return(CowClientOperationSensitivity.Skip);
            }
            if (onBeforeNotification && (COWTriggerAction.Copy == operation || COWTriggerAction.HardDelete == operation || COWTriggerAction.Move == operation || COWTriggerAction.MoveToDeletedItems == operation || COWTriggerAction.SoftDelete == operation))
            {
                StoreObjectId auditsFolderId         = dumpster.AuditsFolderId;
                StoreObjectId adminAuditLogsFolderId = dumpster.AdminAuditLogsFolderId;
                if (settings.CurrentFolderId != null && (COWTriggerAction.HardDelete != operation || LogonType.SystemService != sourceSession.LogonType || !settings.IsMrmAction()))
                {
                    this.CheckAccessOnAuditFolders(mailboxSession, settings.CurrentFolderId, dumpster, false);
                }
                if (itemIds != null)
                {
                    foreach (StoreObjectId storeObjectId in itemIds)
                    {
                        if (storeObjectId != null)
                        {
                            if (storeObjectId.IsMessageId)
                            {
                                if (settings.CurrentFolderId == null && (COWTriggerAction.HardDelete != operation || LogonType.SystemService != sourceSession.LogonType || !settings.IsMrmAction()))
                                {
                                    StoreObjectId parentIdFromMessageId = IdConverter.GetParentIdFromMessageId(storeObjectId);
                                    if (parentIdFromMessageId.Equals(auditsFolderId))
                                    {
                                        throw new AccessDeniedException(ServerStrings.ExAuditsUpdateDenied);
                                    }
                                    if (parentIdFromMessageId.Equals(adminAuditLogsFolderId))
                                    {
                                        throw new AccessDeniedException(ServerStrings.ExAdminAuditLogsUpdateDenied);
                                    }
                                    if (dumpster.IsAuditFolder(parentIdFromMessageId))
                                    {
                                        throw new AccessDeniedException((auditsFolderId != null) ? ServerStrings.ExAuditsUpdateDenied : ServerStrings.ExAdminAuditLogsUpdateDenied);
                                    }
                                }
                            }
                            else if (storeObjectId.IsFolderId)
                            {
                                this.CheckAccessOnAuditFolders(mailboxSession, storeObjectId, dumpster, true);
                            }
                        }
                    }
                }
            }
            return(CowClientOperationSensitivity.Skip);
        }
        public List <IConversationTreeNode> GetInFolderItemsForConversation(ConversationId conversationId)
        {
            this.CheckDisposed("GetInFolderItemsForConversation");
            if (conversationId == null)
            {
                return(null);
            }
            List <IConversationTreeNode> list = null;
            Conversation conversation         = Conversation.Load((MailboxSession)this.folder.Session, conversationId, MailboxSyncProvider.conversationPrefetchProperties);

            if (conversation == null)
            {
                return(list);
            }
            list = new List <IConversationTreeNode>(conversation.ConversationTree.Count);
            StoreObjectId objectId = this.folder.Id.ObjectId;

            foreach (IConversationTreeNode conversationTreeNode in conversation.ConversationTree)
            {
                StoreObjectId id = (StoreObjectId)conversationTreeNode.StorePropertyBags[0].TryGetProperty(StoreObjectSchema.ParentItemId);
                if (objectId.Equals(id))
                {
                    list.Add(conversationTreeNode);
                }
            }
            return(list);
        }
Exemple #6
0
        private bool IsDeletedFolder(IStorePropertyBag folder, ContactFoldersEnumerator.DeletedItemsFolderEnumerationState deletedItemsFolderEnumerationState)
        {
            if (deletedItemsFolderEnumerationState.IsAlreadyEnumerated)
            {
                return(false);
            }
            object obj = folder.TryGetProperty(FolderSchema.FolderHierarchyDepth);

            if (!(obj is int) || (int)obj < 0)
            {
                return(false);
            }
            int           num      = (int)obj;
            StoreObjectId objectId = ((VersionedId)folder.TryGetProperty(FolderSchema.Id)).ObjectId;

            if (deletedItemsFolderEnumerationState.NotEnumeratedYet)
            {
                if (objectId.Equals(this.DeletedItemsFolderId))
                {
                    deletedItemsFolderEnumerationState.MarkDeletedItemsFolderEncountered(num);
                }
                return(false);
            }
            if (num == deletedItemsFolderEnumerationState.DeletedItemsFolderDepth)
            {
                deletedItemsFolderEnumerationState.MarkDeletedItemsFolderEnumerationDone();
                return(false);
            }
            return(true);
        }
Exemple #7
0
 public static bool IsDumpsterFolder(MailboxSession session, StoreObjectId folderId)
 {
     Util.ThrowOnNullArgument(session, "session");
     if (folderId == null)
     {
         return(false);
     }
     foreach (DefaultFolderType defaultFolderType in DumpsterFolderHelper.dumpsterFoldersTypes)
     {
         if (folderId.Equals(session.GetDefaultFolderId(defaultFolderType)))
         {
             return(true);
         }
     }
     return(folderId.Equals(session.GetDefaultFolderId(DefaultFolderType.RecoverableItemsDiscoveryHolds)) || folderId.Equals(session.GetDefaultFolderId(DefaultFolderType.RecoverableItemsMigratedMessages)) || DumpsterFolderHelper.IsAuditFolder(session, folderId));
 }
Exemple #8
0
        public static bool IsAuditFolder(MailboxSession session, StoreObjectId folderId)
        {
            Util.ThrowOnNullArgument(session, "session");
            if (folderId == null)
            {
                return(false);
            }
            StoreObjectId auditsFolder     = null;
            StoreObjectId adminAuditFolder = null;

            session.BypassAuditsFolderAccessChecking(delegate
            {
                auditsFolder     = session.GetAuditsFolderId();
                adminAuditFolder = session.GetAdminAuditLogsFolderId();
            });
            return(folderId.Equals(auditsFolder) || folderId.Equals(adminAuditFolder));
        }
Exemple #9
0
        public void RecordClientOperation(StoreObjectId folderId, ChangeType change, Folder folder)
        {
            EnumValidator.ThrowIfInvalid <ChangeType>(change, "change");
            ExTraceGlobals.SyncTracer.Information <StoreObjectId, ChangeType>((long)this.GetHashCode(), "Storage.FolderHierarchySync.RecordClientOperation. ItemId = {0}, ChangeType = {1}", folderId, change);
            if (folderId == null)
            {
                throw new ArgumentNullException("folderId");
            }
            if (folder != null && !folderId.Equals(folder.Id.ObjectId))
            {
                throw new ArgumentException(ServerStrings.ExFolderDoesNotMatchFolderId);
            }
            if (change != ChangeType.Add && change != ChangeType.Change && change != ChangeType.Delete)
            {
                throw new ArgumentOutOfRangeException("change");
            }
            if ((change == ChangeType.Add || change == ChangeType.Change) && folder == null)
            {
                throw new ArgumentNullException("folder", ServerStrings.ExInvalidNullParameterForChangeTypes("folder", "ChangeType.Add, ChangeType.Change"));
            }
            switch (change)
            {
            case ChangeType.Add:
                if (this.ClientState.ContainsKey(folderId))
                {
                    throw new ArgumentException(ServerStrings.ExFolderAlreadyExistsInClientState);
                }
                break;

            case ChangeType.Change:
            case ChangeType.Delete:
                if (!this.ClientState.ContainsKey(folderId))
                {
                    throw new ArgumentException(ServerStrings.ExFolderNotFoundInClientState);
                }
                break;
            }
            switch (change)
            {
            case ChangeType.Add:
            case ChangeType.Change:
            {
                FolderStateEntry value = new FolderStateEntry(folder.ParentId, folder.GetValueOrDefault <byte[]>(InternalSchema.ChangeKey), this.changeTrackingDelegate(this.storeSession, folder.StoreObjectId, null));
                this.ClientState[folderId] = value;
                return;
            }

            case (ChangeType)3:
                break;

            case ChangeType.Delete:
                this.ClientState.Remove(folderId);
                break;

            default:
                return;
            }
        }
Exemple #10
0
        internal override bool EnsureIsValid(DefaultFolderContext context, Folder folder)
        {
            if (!base.EnsureIsValid(context, folder.PropertyBag))
            {
                return(false);
            }
            StoreObjectId storeObjectId = context[this.parentFolderType];

            return(storeObjectId == null || storeObjectId.Equals(folder.ParentId));
        }
Exemple #11
0
 public bool SkipItemOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, COWTriggerActionState state, StoreSession session, StoreObjectId itemId, CoreItem item, bool onBeforeNotification, bool onDumpster, bool success, CallbackContext callbackContext)
 {
     EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
     EnumValidator.ThrowIfInvalid <COWTriggerActionState>(state, "state");
     if (onBeforeNotification && COWTriggerAction.Update == operation)
     {
         if (settings.CurrentFolderId != null)
         {
             if (settings.CurrentFolderId.Equals(dumpster.AuditsFolderId))
             {
                 throw new AccessDeniedException(ServerStrings.ExAuditsUpdateDenied);
             }
             if (settings.CurrentFolderId.Equals(dumpster.AdminAuditLogsFolderId))
             {
                 throw new AccessDeniedException(ServerStrings.ExAdminAuditLogsUpdateDenied);
             }
             if (dumpster.IsAuditFolder(settings.CurrentFolderId))
             {
                 throw new AccessDeniedException((dumpster.AuditsFolderId != null) ? ServerStrings.ExAuditsUpdateDenied : ServerStrings.ExAdminAuditLogsUpdateDenied);
             }
         }
         else if (itemId != null)
         {
             StoreObjectId parentIdFromMessageId = IdConverter.GetParentIdFromMessageId(itemId);
             if (parentIdFromMessageId.Equals(dumpster.AuditsFolderId))
             {
                 throw new AccessDeniedException(ServerStrings.ExAuditsUpdateDenied);
             }
             if (parentIdFromMessageId.Equals(dumpster.AdminAuditLogsFolderId))
             {
                 throw new AccessDeniedException(ServerStrings.ExAdminAuditLogsUpdateDenied);
             }
             if (dumpster.IsAuditFolder(settings.CurrentFolderId))
             {
                 throw new AccessDeniedException((dumpster.AuditsFolderId != null) ? ServerStrings.ExAuditsUpdateDenied : ServerStrings.ExAdminAuditLogsUpdateDenied);
             }
         }
     }
     return(true);
 }
        internal DefaultFolderType IsDefaultFolderType(StoreId folderId)
        {
            StoreObjectId storeObjectId = StoreId.GetStoreObjectId(folderId);

            for (int i = 0; i < DefaultFolderInfo.DefaultFolderTypeCount; i++)
            {
                StoreObjectId folderId2 = this.defaultFolders[i].FolderId;
                if (!this.defaultFolders[i].IsIdInitialized)
                {
                    this.defaultFolders[i].InitializeFolderId();
                    folderId2 = this.defaultFolders[i].FolderId;
                }
                if (folderId2 != null && storeObjectId.Equals(folderId2))
                {
                    return((DefaultFolderType)i);
                }
            }
            return(DefaultFolderType.None);
        }
Exemple #13
0
 public CowClientOperationSensitivity SkipGroupOperation(COWSettings settings, IDumpsterItemOperations dumpster, COWTriggerAction operation, FolderChangeOperationFlags flags, StoreSession sourceSession, StoreSession destinationSession, StoreObjectId sourceFolderId, StoreObjectId destinationFolderId, ICollection <StoreObjectId> itemIds, bool onBeforeNotification, bool onDumpster, CallbackContext callbackContext)
 {
     EnumValidator.ThrowIfInvalid <COWTriggerAction>(operation, "operation");
     EnumValidator.ThrowIfInvalid <FolderChangeOperationFlags>(flags, "flags");
     Util.ThrowOnNullArgument(settings, "settings");
     Util.ThrowOnNullArgument(sourceSession, "sourceSession");
     Util.ThrowOnNullArgument(dumpster, "dumpster");
     if (onDumpster)
     {
         ExTraceGlobals.CalendarLoggingTracer.Information <string>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since the operation is on dumpster", sourceSession.UserLegacyDN);
         return(CowClientOperationSensitivity.Skip);
     }
     if (!onBeforeNotification)
     {
         ExTraceGlobals.CalendarLoggingTracer.Information <string>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since we are only interested in on-before notifications", sourceSession.UserLegacyDN);
         return(CowClientOperationSensitivity.Skip);
     }
     if (!CalendarLoggingHelper.ShouldLog(operation))
     {
         ExTraceGlobals.CalendarLoggingTracer.Information <string, COWTriggerAction>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since the trigger action {1} is not interesting", sourceSession.UserLegacyDN, operation);
         return(CowClientOperationSensitivity.Skip);
     }
     if (DumpsterFolderHelper.IsAuditFolder(callbackContext.SessionWithBestAccess, sourceFolderId))
     {
         ExTraceGlobals.CalendarLoggingTracer.Information <string>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since the operation is on audit folder", sourceSession.UserLegacyDN);
         return(CowClientOperationSensitivity.Skip);
     }
     if (!settings.IsCalendarLoggingEnabled())
     {
         ExTraceGlobals.CalendarLoggingTracer.Information <string>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since calendar logging is disabled for this user", sourceSession.UserLegacyDN);
         return(CowClientOperationSensitivity.Skip);
     }
     if (!DumpsterFolderHelper.IsDumpsterFolder(callbackContext.SessionWithBestAccess, sourceFolderId))
     {
         return(CowClientOperationSensitivity.Capture);
     }
     if (operation == COWTriggerAction.HardDelete && !sourceFolderId.Equals(dumpster.CalendarLoggingFolderId))
     {
         return(CowClientOperationSensitivity.Capture);
     }
     ExTraceGlobals.CalendarLoggingTracer.Information <string>((long)sourceSession.GetHashCode(), "Skipping calendar COW group operation for user {0}, since we are not interested in hard deletes in calendar logging folder", sourceSession.UserLegacyDN);
     return(CowClientOperationSensitivity.Skip);
 }
 private void ThrowIfCopyMovePrereqsFail(MailboxSession destinationSession, StoreObjectId destinationFolderId, bool isCopy)
 {
     Util.ThrowOnNullArgument(destinationFolderId, "destinationFolderId");
     if (destinationFolderId.ObjectType != StoreObjectType.CalendarFolder)
     {
         throw new ArgumentException("Destination folder must be a calendar folder", "destinationFolderId");
     }
     if (!(base.Session is MailboxSession))
     {
         throw new InvalidOperationException("Only mailbox sessions are supported");
     }
     if (base.ParentId.Equals(destinationFolderId))
     {
         throw new ArgumentException("The destination folder must be different from the source folder.", "destinationFolderId");
     }
     if (!this.IsInThePast)
     {
         throw new FutureMeetingException("Only meetings in the past can be copied or moved");
     }
     if (isCopy)
     {
         StoreObjectId defaultFolderId = ((MailboxSession)base.Session).GetDefaultFolderId(DefaultFolderType.Calendar);
         if (base.ParentId.Equals(defaultFolderId) || destinationFolderId.Equals(defaultFolderId))
         {
             throw new PrimaryCalendarFolderException("Copy is not allowed to/from the primary calendar");
         }
     }
     using (CalendarFolder calendarFolder = CalendarFolder.Bind(destinationSession, destinationFolderId))
     {
         IList list = CalendarCorrelationMatch.FindMatches(calendarFolder, base.GlobalObjectId, null);
         if (list.Count > 0)
         {
             throw new CalendarItemExistsException("There is already a calendar item with this GOID in the destination folder");
         }
     }
 }
        internal static string GetFolderPathForFolderId(MailboxSession session, StoreObjectId folderId)
        {
            StringBuilder stringBuilder = new StringBuilder(128);
            StoreObjectId storeObjectId = folderId;
            int           num           = 0;
            int           num2          = 10;

            while (storeObjectId != null && num < num2)
            {
                using (Folder folder = Folder.Bind(session, storeObjectId))
                {
                    num++;
                    if (stringBuilder.Length == 0)
                    {
                        stringBuilder.Append(folder.DisplayName);
                    }
                    else
                    {
                        stringBuilder.Insert(0, "\\");
                        stringBuilder.Insert(0, folder.DisplayName);
                    }
                    num++;
                    if (folder.ParentId != null && storeObjectId.Equals(folder.ParentId))
                    {
                        break;
                    }
                    storeObjectId = folder.ParentId;
                }
            }
            if (num >= num2)
            {
                ExTraceGlobals.SessionTracer.TraceWarning <int, string, string>((long)session.GetHashCode(), "AnalysisGroupData.GetFolderPathForFolderId hit the max {0} folder depth for folder if {1}, path {2}.", num, folderId.ToString(), stringBuilder.ToString());
                stringBuilder.Insert(0, "...\\");
            }
            return(stringBuilder.ToString());
        }
Exemple #16
0
        public static Participant[] ExpandDeep(StoreSession storeSession, StoreObjectId distributionListId, bool shouldAddNonExistPDL)
        {
            Dictionary <StoreObjectId, Participant> dictionary = new Dictionary <StoreObjectId, Participant>();
            Queue <StoreObjectId> queue = new Queue <StoreObjectId>();
            List <Participant>    list  = new List <Participant>();

            queue.Enqueue(distributionListId);
            while (queue.Count > 0)
            {
                StoreObjectId    storeObjectId    = queue.Dequeue();
                DistributionList distributionList = null;
                try
                {
                    distributionList = DistributionList.Bind(storeSession, storeObjectId);
                }
                catch (ObjectNotFoundException arg)
                {
                    if (storeSession.ItemBinder != null)
                    {
                        Item item = storeSession.ItemBinder.BindItem(storeObjectId, IdConverter.IsFromPublicStore(storeObjectId), IdConverter.GetParentIdFromMessageId(storeObjectId));
                        distributionList = (item as DistributionList);
                        if (item != null && distributionList == null)
                        {
                            item.Dispose();
                        }
                    }
                    if (distributionList == null)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <ObjectNotFoundException>(0L, "DistributionList::ExpandDeep. A PDL member in PDL doesn't exist. Ignore it and continue to expand other members. Exception = {0}.", arg);
                        if (shouldAddNonExistPDL && dictionary.ContainsKey(storeObjectId))
                        {
                            list.Add(new Participant(dictionary[storeObjectId].DisplayName, null, "MAPIPDL"));
                        }
                    }
                }
                if (distributionList != null)
                {
                    using (distributionList)
                    {
                        foreach (DistributionListMember distributionListMember in distributionList)
                        {
                            if (!(distributionListMember.Participant == null))
                            {
                                if (distributionListMember.IsDistributionList() == true && distributionListMember.Participant.Origin is StoreParticipantOrigin && distributionListMember.Participant.ValidationStatus == ParticipantValidationStatus.NoError)
                                {
                                    StoreObjectId originItemId = ((StoreParticipantOrigin)distributionListMember.Participant.Origin).OriginItemId;
                                    if (!dictionary.ContainsKey(originItemId) && !originItemId.Equals(distributionListId))
                                    {
                                        queue.Enqueue(originItemId);
                                        dictionary.Add(originItemId, distributionListMember.Participant);
                                    }
                                }
                                else
                                {
                                    list.Add(distributionListMember.Participant);
                                }
                            }
                        }
                    }
                }
            }
            return(list.ToArray());
        }
Exemple #17
0
        private COWProcessorState InspectNotification(COWTriggerAction operation, StoreSession session, CoreItem item, bool onBeforeNotification, bool onDumpster)
        {
            if (onDumpster)
            {
                return(COWProcessorState.DoNotProcess);
            }
            if (operation != COWTriggerAction.Create)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: not an Create operation.");
                return(COWProcessorState.DoNotProcess);
            }
            if (!onBeforeNotification)
            {
                return(COWProcessorState.DoNotProcess);
            }
            if (item == null)
            {
                return(COWProcessorState.Unknown);
            }
            if (item.Id != null)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: ItemId is non-null, so this is not a new item. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            MailboxSession mailboxSession = session as MailboxSession;

            if (mailboxSession == null)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: not a mailbox session. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            int?num = mailboxSession.Mailbox.TryGetProperty(MailboxSchema.MailboxTypeDetail) as int?;

            if (num == null)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: mailbox type not found. Try to inspect later.");
                return(COWProcessorState.Unknown);
            }
            if (!StoreSession.IsGroupMailbox(num.Value))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: Mailbox isn't a GroupMailbox. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            string valueOrDefault = item.PropertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, string.Empty);

            if (string.IsNullOrEmpty(valueOrDefault))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: item class not found. Try to inspect later.");
                return(COWProcessorState.Unknown);
            }
            if (!ObjectClass.IsMessage(valueOrDefault, false))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: item class is not a message. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            if (ObjectClass.IsMeetingForwardNotification(valueOrDefault))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: item class is meeting forward notification. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            if (ObjectClass.IsMeetingResponse(valueOrDefault))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: item class is meeting response. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            bool flag  = ClientInfo.OWA.IsMatch(mailboxSession.ClientInfoString);
            bool flag2 = ClientInfo.HubTransport.IsMatch(mailboxSession.ClientInfoString);

            if (!flag && !flag2)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: This isn't either a post or a delivery. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            StoreObjectId storeObjectId = item.PropertyBag.TryGetProperty(StoreObjectSchema.ParentItemId) as StoreObjectId;

            if (storeObjectId == null)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: parent folder id not found. Try to inspect later.");
                return(COWProcessorState.Unknown);
            }
            StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox);

            if (defaultFolderId == null)
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: inbox folder id not found. Try to inspect later.");
                return(COWProcessorState.Unknown);
            }
            if (!storeObjectId.Equals(defaultFolderId))
            {
                COWGroupMessageWSPublishing.Tracer.TraceDebug((long)this.GetHashCode(), "COWGroupMessageWSPublishing.InspectNotification: This message isn't located on the inbox folder. Do not process.");
                return(COWProcessorState.DoNotProcess);
            }
            return(COWProcessorState.ProcessAfterSave);
        }
        public static SearchFolder CreateOrOpenOwaFilteredViewSearchFolder(MailboxSession mailboxSession, OwaSearchContext searchContext, StoreId searchFoldersRootId, SearchFolderCriteria searchFolderCriteria, bool flushStaleFolders = true)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <OwaViewFilter>(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] Create or open the specified filtered view: {0}", searchContext.ViewFilter);
            SearchFolder searchFolder = null;
            bool         flag         = true;

            searchContext.ViewFilterActions = ViewFilterActions.None;
            try
            {
                searchContext.ClientSearchFolderIdentity = OwaFilterState.GetOwaFilteredViewSearchFolderName(mailboxSession, searchContext);
                if (searchContext.SearchFolderId == null && OwaFilterState.FilterToLinkPropertyDefinitionsMap.ContainsKey(searchContext.ViewFilter))
                {
                    StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox);
                    if (defaultFolderId.Equals(searchContext.FolderIdToSearch))
                    {
                        searchContext.SearchFolderId = OwaFilterState.GetLinkedFolderIdForFilteredView(mailboxSession, searchContext.FolderIdToSearch, searchContext.ViewFilter);
                    }
                }
                if (searchContext.SearchFolderId != null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.BindToExisting;
                    searchFolder = OwaFilterState.BindAndUpdateExistingFilteredViewSearchFolder(mailboxSession, searchContext);
                }
                if (searchFolder == null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.FindExisting;
                    searchFolder = OwaFilterState.GetFilteredView(mailboxSession, searchContext, searchFoldersRootId, flushStaleFolders);
                }
                if (searchContext.IsSearchFailed && searchFolder != null)
                {
                    ExTraceGlobals.StorageTracer.TraceError <string, StoreId>(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] deleting search folder: {0} using searchContext.SearchFolderId: {1}", searchContext.ClientSearchFolderIdentity, searchContext.SearchFolderId);
                    searchContext.ViewFilterActions |= ViewFilterActions.DeleteInvalidSearchFolder;
                    mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                    {
                        searchContext.SearchFolderId
                    });
                    searchContext.SearchFolderId = null;
                    searchContext.IsSearchFailed = false;
                    searchFolder.Dispose();
                    searchFolder = null;
                }
                if (searchFolder == null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.CreateFilter;
                    searchFolder = OwaFilterState.CreateAndUpdateFilteredViewSearchFolder(mailboxSession, searchContext, searchFoldersRootId, searchFolderCriteria);
                }
                ExTraceGlobals.StorageTracer.TraceDebug(0L, string.Format("{0}_{1}", searchContext.ClientSearchFolderIdentity, (int)searchContext.ViewFilterActions));
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] Creating/Opening of dynamic search folder failed. Setting search folder to null and disposing it");
                    if (searchFolder != null)
                    {
                        searchFolder.Dispose();
                        searchFolder = null;
                    }
                }
            }
            return(searchFolder);
        }
        private static SearchFolder GetFilteredView(MailboxSession mailboxSession, OwaSearchContext searchContext, StoreId searchFoldersRootId, bool flushStaleFolders)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <OwaViewFilter>(0L, "[OwaFilterState::GetFilteredView] Get the specified filtered view: {0}", searchContext.ViewFilter);
            StoreObjectId  defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox);
            OwaFilterState newFilterState  = new OwaFilterState(searchContext.FolderIdToSearch, searchContext.ViewFilter, searchContext.FromFilter);
            int            num             = 0;
            StoreObjectId  storeObjectId   = null;
            List <StoreId> list            = new List <StoreId>();
            SearchFolder   result          = null;

            using (Folder folder = Folder.Bind(mailboxSession, searchFoldersRootId))
            {
                List <object[]> list2 = new List <object[]>();
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, OwaFilterState.FolderQueryProperties))
                {
                    list2 = OwaFilterState.FetchRowsFromQueryResult(queryResult, 10000);
                }
                int        num2  = OwaFilterState.FilterSearchFolderPropertyIndexes[FolderSchema.Id];
                int        num3  = OwaFilterState.FilterSearchFolderPropertyIndexes[FolderSchema.SearchFolderAllowAgeout];
                int        num4  = OwaFilterState.FilterSearchFolderPropertyIndexes[StoreObjectSchema.LastModifiedTime];
                int        num5  = OwaFilterState.FilterSearchFolderPropertyIndexes[OwaFilteredViewProperties.FilteredViewLabel];
                ExDateTime other = ExDateTime.MaxValue;
                for (int i = 0; i < list2.Count; i++)
                {
                    OwaFilterState owaFilterState = OwaFilterState.ParseFromPropertyValue(list2[i][num5]);
                    if (owaFilterState != null)
                    {
                        if (OwaFilterState.AreEqual(newFilterState, owaFilterState))
                        {
                            searchContext.ViewFilterActions |= ViewFilterActions.FilterFound;
                            searchContext.SearchFolderId     = (list2[i][num2] as VersionedId).ObjectId;
                            result = OwaFilterState.BindAndUpdateExistingFilteredViewSearchFolder(mailboxSession, searchContext);
                            break;
                        }
                        if (list2[i][num3] is bool && (bool)list2[i][num3])
                        {
                            if (!owaFilterState.IsCurrentVersion && flushStaleFolders)
                            {
                                list.Add((StoreId)list2[i][num2]);
                            }
                            else
                            {
                                num++;
                                ExDateTime exDateTime = ExDateTime.MinValue;
                                if (!(list2[i][num4] is PropertyError))
                                {
                                    exDateTime = (ExDateTime)list2[i][num4];
                                }
                                if (exDateTime.CompareTo(other) < 0)
                                {
                                    StoreObjectId objectId = (list2[i][num2] as VersionedId).ObjectId;
                                    if (!defaultFolderId.Equals(owaFilterState.SourceFolderId))
                                    {
                                        other         = exDateTime;
                                        storeObjectId = objectId;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (num >= searchContext.MaximumTemporaryFilteredViewPerUser && flushStaleFolders && storeObjectId != null)
            {
                ExTraceGlobals.StorageTracer.TraceDebug <int>(0L, "[OwaFilterState::GetFilteredView] Delete LRU filtered view search folder at hitting max filtered views: {0}", searchContext.MaximumTemporaryFilteredViewPerUser);
                list.Add(storeObjectId);
            }
            if (list.Count > 0)
            {
                ExTraceGlobals.StorageTracer.TraceDebug(0L, "[OwaFilterState::GetFilteredView] deleting LRU / non current version of filtered views count: " + list.Count);
                mailboxSession.Delete(DeleteItemFlags.HardDelete, list.ToArray());
            }
            return(result);
        }
Exemple #20
0
 private static void UnsetStaleReminders(DefaultFolderContext context, SearchFolder reminders)
 {
     ExTraceGlobals.DefaultFoldersTracer.TraceDebug(-1L, "RemindersSearchFolderValidation::UnsetStaleReminders.");
     using (QueryResult queryResult = reminders.ItemQuery(ItemQueryType.None, null, new SortBy[]
     {
         new SortBy(InternalSchema.ReminderIsSet, SortOrder.Descending),
         new SortBy(InternalSchema.ReminderNextTime, SortOrder.Descending)
     }, new PropertyDefinition[]
     {
         InternalSchema.ItemId,
         InternalSchema.ParentItemId,
         InternalSchema.ReminderIsSet
     }))
     {
         ExDateTime now         = ExDateTime.GetNow(context.Session.ExTimeZone);
         StoreId[]  folderScope = RemindersSearchFolderValidation.CreateRemindersQueryForO11(context).FolderScope;
         queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.LessThan, InternalSchema.ReminderNextTime, now));
         bool       flag = false;
         object[][] rows;
         while (!flag && (rows = queryResult.GetRows(2147483647)).Length > 0)
         {
             foreach (object[] array2 in rows)
             {
                 bool flag2;
                 if (Util.TryConvertTo <bool>(array2[2], out flag2) && !flag2)
                 {
                     flag = true;
                     break;
                 }
                 StoreObjectId storeObjectId = PropertyBag.CheckPropertyValue <StoreObjectId>(StoreObjectSchema.ParentItemId, array2[1]);
                 bool          flag3         = false;
                 foreach (StoreId id in folderScope)
                 {
                     if (storeObjectId.Equals(id))
                     {
                         flag3 = true;
                         break;
                     }
                 }
                 if (!flag3)
                 {
                     try
                     {
                         VersionedId storeId = PropertyBag.CheckPropertyValue <VersionedId>(ItemSchema.Id, array2[0]);
                         using (Item item = Item.Bind(context.Session, storeId))
                         {
                             if (item.Reminder != null)
                             {
                                 item.Reminder.IsSet = false;
                                 item.Save(SaveMode.NoConflictResolution);
                             }
                         }
                     }
                     catch (StoragePermanentException arg)
                     {
                         ExTraceGlobals.DefaultFoldersTracer.TraceDebug <object, StoragePermanentException>(-1L, "RemindersSearchFolderValidation::UnsetStaleReminders. Unable to unset a stale reminder of the item {0}: {1}", array2[0], arg);
                     }
                     catch (StorageTransientException arg2)
                     {
                         ExTraceGlobals.DefaultFoldersTracer.TraceDebug <object, StorageTransientException>(-1L, "RemindersSearchFolderValidation::UnsetStaleReminders. Unable to unset a stale reminder of the item {0}: {1}", array2[0], arg2);
                     }
                 }
             }
         }
     }
 }
Exemple #21
0
 public bool CheckMatch(string configName, StoreObjectId folderId)
 {
     return(string.Equals(configName, this.configName, StringComparison.OrdinalIgnoreCase) && folderId.Equals(this.folderId));
 }