Example #1
0
        private static bool SearchByTopic(IXSOFactory xsoFactory, IMailboxSession session, ICorePropertyBag persistPropertyBag, ConversationIndexTrackingEx indexTrackingEx, out IStorePropertyBag foundPropertyBag, out bool didConversationIdMatch, out bool didReferencesMatch, params PropertyDefinition[] propsToReturn)
        {
            foundPropertyBag       = null;
            didConversationIdMatch = false;
            didReferencesMatch     = false;
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(persistPropertyBag, "persistPropertyBag");
            Util.ThrowOnNullArgument(propsToReturn, "propsToReturn");
            ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propsToReturn, new PropertyDefinition[]
            {
                ItemSchema.ConversationTopicHash
            });
            string            incomingConversationTopic = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.ConversationTopic);
            ConversationIndex conversationIndex;
            bool           isValidIncomingIndex   = ConversationIndex.TryCreate(persistPropertyBag.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);
            ConversationId incomingConversationId = isValidIncomingIndex ? ConversationId.Create(conversationIndex.Guid) : null;

            if (incomingConversationTopic == null)
            {
                return(false);
            }
            bool              didConversationIdMatchLocal   = false;
            bool              didReferencesMatchLocal       = false;
            int               incomingConversationTopicHash = (int)AllItemsFolderHelper.GetHashValue(incomingConversationTopic);
            Stopwatch         stopwatch        = Stopwatch.StartNew();
            IStorePropertyBag storePropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.ConversationTopicHash, incomingConversationTopicHash, null, delegate(QueryResult queryResult)
            {
                bool flag = queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.ConversationTopicHash, incomingConversationTopicHash));
                if (flag)
                {
                    IStorePropertyBag storePropertyBag2 = null;
                    for (int i = 0; i < 5; i++)
                    {
                        IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(1);
                        if (propertyBags.Length != 1)
                        {
                            break;
                        }
                        int?num = propertyBags[0].TryGetProperty(ItemSchema.ConversationTopicHash) as int?;
                        if (num == null || num.Value != incomingConversationTopicHash)
                        {
                            break;
                        }
                        string foundTopic = propertyBags[0].TryGetProperty(ItemSchema.ConversationTopic) as string;
                        if (ConversationIndex.CompareTopics(incomingConversationTopic, foundTopic))
                        {
                            if (storePropertyBag2 == null)
                            {
                                storePropertyBag2 = propertyBags[0];
                            }
                            ConversationIndex conversationIndex2;
                            bool flag2 = ConversationIndex.TryCreate(propertyBags[0].TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex2);
                            if (flag2)
                            {
                                if (isValidIncomingIndex)
                                {
                                    ConversationId conversationId = ConversationId.Create(conversationIndex2.Guid);
                                    if (conversationId.Equals(incomingConversationId))
                                    {
                                        didConversationIdMatchLocal = true;
                                        return(propertyBags[0]);
                                    }
                                }
                                else if (AggregationByItemClassReferencesSubjectProcessor.MatchMessageIdWithReferences(persistPropertyBag, propertyBags[0]))
                                {
                                    didReferencesMatchLocal = true;
                                    return(propertyBags[0]);
                                }
                            }
                        }
                        if (!queryResult.SeekToCondition(SeekReference.OriginCurrent, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.ConversationTopicHash, incomingConversationTopicHash)))
                        {
                            break;
                        }
                    }
                    if (storePropertyBag2 != null)
                    {
                        return(storePropertyBag2);
                    }
                }
                return(null);
            }, properties);

            stopwatch.Stop();
            if (indexTrackingEx != null)
            {
                indexTrackingEx.Trace("SBT", stopwatch.ElapsedMilliseconds.ToString());
            }
            if (storePropertyBag != null)
            {
                foundPropertyBag       = storePropertyBag;
                didConversationIdMatch = didConversationIdMatchLocal;
                didReferencesMatch     = didReferencesMatchLocal;
                return(true);
            }
            return(false);
        }
Example #2
0
        private static bool FixupMeetingMessage(IXSOFactory xsoFactory, IMailboxSession session, AggregationByItemClassReferencesSubjectProcessor.PropertyDefinitionListConstructorDelegate propertyDefinitionListConstructorDelegate, ICorePropertyBag corePropertyBag, ref ConversationIndex newIndex, ref ConversationIndex.FixupStage stage, out IStorePropertyBag parentItemPropertyBag)
        {
            corePropertyBag.Load(propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                InternalSchema.AppointmentSequenceNumber
            }));
            byte[] array = corePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[];
            if (array == null)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            GlobalObjectId globalObjectId;
            GlobalObjectId globalObjectId3;

            try
            {
                globalObjectId  = new GlobalObjectId(array);
                globalObjectId3 = new GlobalObjectId(array);
            }
            catch (CorruptDataException)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            globalObjectId3.Date = ExDateTime.MinValue;
            string     valueOrDefault          = corePropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);
            bool       isRequest               = ObjectClass.IsMeetingRequest(valueOrDefault);
            object     fixupStage              = null;
            ExDateTime ownerCriticalChangeTime = corePropertyBag.GetValueOrDefault <ExDateTime>(CalendarItemBaseSchema.OwnerCriticalChangeTime, ExDateTime.MaxValue);
            int        sequenceNumber          = corePropertyBag.GetValueOrDefault <int>(InternalSchema.AppointmentSequenceNumber, -1);

            if (sequenceNumber == -1)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            parentItemPropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.CleanGlobalObjectId, globalObjectId3.Bytes, null, delegate(QueryResult queryResult)
            {
                IStorePropertyBag result = null;
                bool flag2 = false;
                while (!flag2)
                {
                    IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(50);
                    flag2 = (propertyBags.Length == 0);
                    IStorePropertyBag[] array2 = propertyBags;
                    int i = 0;
                    while (i < array2.Length)
                    {
                        IStorePropertyBag storePropertyBag = array2[i];
                        VersionedId versionedId            = (VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id);
                        byte[] array3 = (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[]) ?? (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.CleanGlobalObjectId) as byte[]);
                        if (array3 != null && GlobalObjectId.CompareCleanGlobalObjectIds(array3, globalObjectId.Bytes))
                        {
                            GlobalObjectId globalObjectId2 = new GlobalObjectId(array3);
                            if (versionedId.ObjectId.ObjectType == StoreObjectType.MeetingRequest)
                            {
                                ConversationId conversationId = storePropertyBag.TryGetProperty(ConversationItemSchema.ConversationId) as ConversationId;
                                if (conversationId != null)
                                {
                                    if (isRequest)
                                    {
                                        fixupStage = ConversationIndex.FixupStage.M1;
                                        return(storePropertyBag);
                                    }
                                    if (AggregationByItemClassReferencesSubjectProcessor.IsMatchForMeetingResponse(globalObjectId, ownerCriticalChangeTime, sequenceNumber, storePropertyBag))
                                    {
                                        if (globalObjectId.Date != ExDateTime.MinValue && globalObjectId.Date == globalObjectId2.Date)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M3;
                                            return(storePropertyBag);
                                        }
                                        if (globalObjectId.Date == ExDateTime.MinValue)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M2;
                                            return(storePropertyBag);
                                        }
                                        fixupStage = ConversationIndex.FixupStage.M4;
                                        result     = storePropertyBag;
                                    }
                                }
                            }
                            i++;
                            continue;
                        }
                        return(result);
                    }
                }
                return(result);
            }, propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                InternalSchema.AppointmentSequenceNumber,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                ConversationItemSchema.ConversationId
            }));
            if (parentItemPropertyBag == null)
            {
                return(false);
            }
            ConversationIndex conversationIndex;

            if (!ConversationIndex.TryCreate(parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex))
            {
                return(false);
            }
            bool?flag = parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;

            stage = ((flag == null || !flag.Value) ? ConversationIndex.FixupStage.L1 : ((ConversationIndex.FixupStage)fixupStage));
            if (isRequest)
            {
                byte[]            valueOrDefault2 = corePropertyBag.GetValueOrDefault <byte[]>(ItemSchema.ConversationIndex);
                ConversationIndex conversationIndex2;
                if (valueOrDefault2 != null && ConversationIndex.TryCreate(valueOrDefault2, out conversationIndex2))
                {
                    newIndex = conversationIndex.UpdateHeader(conversationIndex2.Components[0]);
                }
                else
                {
                    newIndex = ConversationIndex.Create(conversationIndex.Guid);
                }
            }
            else
            {
                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
            }
            return(true);
        }
Example #3
0
        private static bool SearchByReferences(IXSOFactory xsoFactory, IMailboxSession session, ICorePropertyBag persistPropertyBag, ConversationIndexTrackingEx indexTrackingEx, bool searchByDupedMessage, out IStorePropertyBag foundPropertyBag, params PropertyDefinition[] propsToReturn)
        {
            foundPropertyBag = null;
            Util.ThrowOnNullArgument(propsToReturn, "propsToReturn");
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(persistPropertyBag, "persistPropertyBag");
            List <string> internetIds = new List <string>();

            if (searchByDupedMessage)
            {
                string valueOrDefault = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InternetMessageId, string.Empty);
                if (!string.IsNullOrEmpty(valueOrDefault))
                {
                    internetIds.Add(valueOrDefault);
                }
            }
            string valueOrDefault2 = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InReplyTo, string.Empty);

            if (!string.IsNullOrEmpty(valueOrDefault2))
            {
                internetIds.Add(valueOrDefault2);
            }
            string valueOrDefault3 = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty);

            if (!string.IsNullOrEmpty(valueOrDefault3))
            {
                string[] array = valueOrDefault3.Split(AggregationByItemClassReferencesSubjectProcessor.ReferencesSeparators, StringSplitOptions.RemoveEmptyEntries);
                if (array != null && array.Length > 0)
                {
                    int num = array.Length - 1;
                    for (int i = num; i >= 0; i--)
                    {
                        if (!string.IsNullOrEmpty(array[i]) && !internetIds.Contains(array[i]))
                        {
                            internetIds.Add(array[i]);
                            if (internetIds.Count >= 50)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (internetIds.Count > 0)
            {
                ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propsToReturn, new PropertyDefinition[]
                {
                    ItemSchema.InternetMessageIdHash
                });
                Stopwatch         stopwatch        = Stopwatch.StartNew();
                IStorePropertyBag storePropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.InternetMessageIdHash, delegate(QueryResult queryResult)
                {
                    using (List <string> .Enumerator enumerator = internetIds.GetEnumerator())
                    {
                        IL_A6:
                        while (enumerator.MoveNext())
                        {
                            string text   = enumerator.Current;
                            int hashValue = (int)AllItemsFolderHelper.GetHashValue(text);
                            if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.InternetMessageIdHash, hashValue)))
                            {
                                IStorePropertyBag[] propertyBags;
                                string text2;
                                do
                                {
                                    propertyBags = queryResult.GetPropertyBags(1);
                                    if (propertyBags == null || propertyBags.Length != 1)
                                    {
                                        goto IL_A6;
                                    }
                                    int?num2 = propertyBags[0].TryGetProperty(ItemSchema.InternetMessageIdHash) as int?;
                                    if (num2 == null || num2.Value != hashValue)
                                    {
                                        goto IL_A6;
                                    }
                                    text2 = (propertyBags[0].TryGetProperty(ItemSchema.InternetMessageId) as string);
                                }while (string.IsNullOrEmpty(text2) || !string.Equals(text, text2, StringComparison.OrdinalIgnoreCase));
                                return(propertyBags[0]);
                            }
                        }
                    }
                    return(null);
                }, properties);
                stopwatch.Stop();
                if (indexTrackingEx != null)
                {
                    indexTrackingEx.Trace("SBMID", stopwatch.ElapsedMilliseconds.ToString());
                }
                if (storePropertyBag != null)
                {
                    foundPropertyBag = storePropertyBag;
                    return(true);
                }
            }
            return(false);
        }
        public static void ChunkSmsConversation(IXSOFactory xsoFactory, IMailboxSession session, ConversationIndex conversationIndex, ConversationIndexTrackingEx conversationIndexTrackingEx)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(conversationIndex, "conversationIndex");
            byte[]    conversationIdBytes = ConversationId.Create(conversationIndex.Guid).GetBytes();
            int       conversationIdHash  = (int)AllItemsFolderHelper.GetHashValue(conversationIdBytes);
            Stopwatch stopwatch           = Stopwatch.StartNew();
            List <IStorePropertyBag> list = xsoFactory.RunQueryOnAllItemsFolder <List <IStorePropertyBag> >(session, AllItemsFolderHelper.SupportedSortBy.ConversationIdHash, conversationIdHash, null, delegate(QueryResult queryResult)
            {
                List <IStorePropertyBag> list2 = null;
                bool flag = false;
                while (!flag)
                {
                    IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(10);
                    if (propertyBags == null || propertyBags.Length <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < propertyBags.Length; i++)
                    {
                        int?num2 = propertyBags[i].TryGetProperty(ItemSchema.ConversationIdHash) as int?;
                        if (num2 == null)
                        {
                            break;
                        }
                        if (num2.Value != conversationIdHash)
                        {
                            flag = true;
                            break;
                        }
                        byte[] array = propertyBags[i].TryGetProperty(InternalSchema.MapiConversationId) as byte[];
                        if (array != null && Util.CompareByteArray(conversationIdBytes, array))
                        {
                            if (list2 == null)
                            {
                                list2 = new List <IStorePropertyBag>(10);
                            }
                            list2.Add(propertyBags[i]);
                        }
                    }
                }
                return(list2);
            }, new StorePropertyDefinition[]
            {
                ItemSchema.Id,
                ItemSchema.ConversationIdHash,
                ItemSchema.ReceivedTime,
                InternalSchema.MapiConversationId
            });

            stopwatch.Stop();
            if (conversationIndexTrackingEx != null)
            {
                conversationIndexTrackingEx.Trace("SBSMSCID", stopwatch.ElapsedMilliseconds.ToString());
            }
            if (list == null || list.Count < 79)
            {
                return;
            }
            list.Sort(delegate(IStorePropertyBag x, IStorePropertyBag y)
            {
                ExDateTime?exDateTime  = x.TryGetProperty(ItemSchema.ReceivedTime) as ExDateTime?;
                ExDateTime?exDateTime2 = y.TryGetProperty(ItemSchema.ReceivedTime) as ExDateTime?;
                if (exDateTime == null && exDateTime2 == null)
                {
                    return(0);
                }
                if (exDateTime == null)
                {
                    return(1);
                }
                if (exDateTime2 == null)
                {
                    return(-1);
                }
                return(exDateTime.Value.CompareTo(exDateTime2.Value));
            });
            string str = conversationIndex.Guid.ToString("D").Substring("472e2878-19b1-4ac1-a21a-".Length);
            string text;

            do
            {
                text = Guid.NewGuid().ToString("D").Substring(0, "472e2878-19b1-4ac1-a21a-".Length);
            }while (string.Equals(text, "472e2878-19b1-4ac1-a21a-"));
            ConversationIndex conversationIndex2 = ConversationIndex.Create(new Guid(text + str));
            int num = 0;

            while (num < list.Count && num < 50)
            {
                VersionedId versionedId = (VersionedId)list[num].TryGetProperty(ItemSchema.Id);
                if (versionedId != null)
                {
                    StoreObjectId objectId = versionedId.ObjectId;
                    if (objectId != null)
                    {
                        using (IMessageItem messageItem = xsoFactory.BindToMessage(session, objectId, null))
                        {
                            messageItem.OpenAsReadWrite();
                            messageItem[ItemSchema.ConversationIndex]         = conversationIndex2.ToByteArray();
                            messageItem[ItemSchema.ConversationIndexTracking] = true;
                            messageItem.Save(SaveMode.ResolveConflicts);
                        }
                    }
                }
                num++;
            }
        }