Example #1
0
        internal static PreviewItem[] ExcludeDuplicateItems(PreviewItem[] previewItems)
        {
            if (previewItems == null || previewItems.Length == 0)
            {
                return(previewItems);
            }
            HashSet <UniqueItemHash> hashSet = new HashSet <UniqueItemHash>();
            List <PreviewItem>       list    = new List <PreviewItem>(previewItems.Length);
            int i = 0;

            while (i < previewItems.Length)
            {
                PreviewItem    previewItem = previewItems[i];
                UniqueItemHash itemHash    = previewItem.ItemHash;
                if (itemHash == null)
                {
                    goto IL_42;
                }
                if (!hashSet.Contains(itemHash))
                {
                    hashSet.Add(itemHash);
                    goto IL_42;
                }
IL_49:
                i++;
                continue;
IL_42:
                list.Add(previewItem);
                goto IL_49;
            }
            return(list.ToArray());
        }
Example #2
0
        private string[] GetStringArrayProperty(StorePropertyDefinition propertyDef)
        {
            string property = this.GetProperty <string>(propertyDef, string.Empty);

            if (!string.IsNullOrEmpty(property))
            {
                return(PreviewItem.SplitRecipients(property));
            }
            return(null);
        }
Example #3
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            PreviewItem previewItem = obj as PreviewItem;

            if (previewItem != null)
            {
                return(this.SortValue.CompareTo(previewItem.SortValue));
            }
            throw new ArgumentException("Object is not a PreviewItem");
        }
        private SortedResultPage ConvertToPreviewItems(SearchPreviewItem[] ewsPreviewItems)
        {
            if (ewsPreviewItems == null)
            {
                return(new SortedResultPage(new PreviewItem[0], base.PagingInfo));
            }
            List <PreviewItem> list = new List <PreviewItem>(ewsPreviewItems.Length);

            foreach (SearchPreviewItem searchPreviewItem in ewsPreviewItems)
            {
                try
                {
                    MailboxId   mailboxId;
                    VersionedId value       = WebServiceMailboxSearchGroup.EwsIdToVersionedId(searchPreviewItem.Id.UniqueId, searchPreviewItem.Id.ChangeKey, out mailboxId);
                    MailboxInfo mailboxInfo = this.FindMailboxInfoByAnyIdentifier(searchPreviewItem, searchPreviewItem.Mailbox.MailboxId, mailboxId.MailboxGuid, null);
                    if (mailboxInfo == null)
                    {
                        throw new WebServiceProxyInvalidResponseException(Strings.InvalidUnknownMailboxInPreviewResult(this.Uri.AbsoluteUri, searchPreviewItem.Mailbox.MailboxId, mailboxId.MailboxGuid));
                    }
                    Dictionary <PropertyDefinition, object> dictionary = new Dictionary <PropertyDefinition, object>();
                    dictionary.Add(ItemSchema.Id, value);
                    dictionary.Add(StoreObjectSchema.ParentItemId, StoreId.EwsIdToStoreObjectId(searchPreviewItem.ParentId.UniqueId));
                    dictionary.Add(StoreObjectSchema.ItemClass, searchPreviewItem.ItemClass);
                    dictionary.Add(MessageItemSchema.SenderDisplayName, searchPreviewItem.Sender);
                    dictionary.Add(ItemSchema.DisplayTo, this.GetSemicolonSeparated(searchPreviewItem.ToRecipients));
                    dictionary.Add(ItemSchema.DisplayCc, this.GetSemicolonSeparated(searchPreviewItem.CcRecipients));
                    dictionary.Add(ItemSchema.DisplayBcc, this.GetSemicolonSeparated(searchPreviewItem.BccRecipients));
                    dictionary.Add(StoreObjectSchema.CreationTime, WebServiceMailboxSearchGroup.CreateExDateTime(base.PagingInfo.TimeZone, searchPreviewItem.CreatedTime, this));
                    dictionary.Add(ItemSchema.ReceivedTime, WebServiceMailboxSearchGroup.CreateExDateTime(base.PagingInfo.TimeZone, searchPreviewItem.ReceivedTime, this));
                    dictionary.Add(ItemSchema.SentTime, WebServiceMailboxSearchGroup.CreateExDateTime(base.PagingInfo.TimeZone, searchPreviewItem.SentTime, this));
                    dictionary.Add(ItemSchema.Subject, searchPreviewItem.Subject);
                    dictionary.Add(ItemSchema.Size, (int)searchPreviewItem.Size);
                    dictionary.Add(ItemSchema.Importance, searchPreviewItem.Importance.ToString());
                    dictionary.Add(MessageItemSchema.IsRead, searchPreviewItem.Read);
                    dictionary.Add(ItemSchema.HasAttachment, searchPreviewItem.HasAttachment);
                    if (searchPreviewItem.OwaLink == null)
                    {
                        Factory.Current.GeneralTracer.TraceError <Guid, string, string>((long)this.GetHashCode(), "Correlation Id:{0}. Null OWA URI in item with Id {1} in mailbox {2}", base.ExecutingUser.QueryCorrelationId, searchPreviewItem.Id.UniqueId, searchPreviewItem.Mailbox.PrimarySmtpAddress);
                        throw new WebServiceProxyInvalidResponseException(Strings.InvalidOwaUrlInPreviewResult(string.Format("EDiscoveryError:E002::Mailbox:{0}::Item:{1}::", searchPreviewItem.Mailbox.PrimarySmtpAddress, searchPreviewItem.Subject), this.Uri.AbsoluteUri));
                    }
                    PreviewItem item = new PreviewItem(dictionary, mailboxInfo.MailboxGuid.Equals(Guid.Empty) ? Guid.Parse(mailboxId.MailboxGuid) : mailboxInfo.MailboxGuid, new Uri(searchPreviewItem.OwaLink), this.GetReferenceItem(searchPreviewItem.SortValue), this.GetUniqueItemHash(searchPreviewItem.UniqueHash))
                    {
                        MailboxInfo = mailboxInfo
                    };
                    list.Add(item);
                }
                catch (InvalidIdMalformedException ex)
                {
                    Factory.Current.GeneralTracer.TraceError((long)this.GetHashCode(), "Correlation Id:{0}. Error processing item with Id {1} in mailbox {2}: {3}", new object[]
                    {
                        base.ExecutingUser.QueryCorrelationId,
                        searchPreviewItem.Id.UniqueId,
                        searchPreviewItem.Mailbox.PrimarySmtpAddress,
                        ex.ToString()
                    });
                    throw new WebServiceProxyInvalidResponseException(Strings.InvalidIdInPreviewResult(this.Uri.AbsoluteUri), ex);
                }
                catch (UriFormatException ex2)
                {
                    Factory.Current.GeneralTracer.TraceError((long)this.GetHashCode(), "Correlation Id:{0}. Invalid OWA URI in item with Id {1} in mailbox {2}: {3}", new object[]
                    {
                        base.ExecutingUser.QueryCorrelationId,
                        searchPreviewItem.Id.UniqueId,
                        searchPreviewItem.Mailbox.PrimarySmtpAddress,
                        ex2.ToString()
                    });
                    throw new WebServiceProxyInvalidResponseException(Strings.InvalidOwaUrlInPreviewResult(string.Format("EDiscoveryError:E002::Mailbox:{0}::Item:{1}::", searchPreviewItem.Mailbox.PrimarySmtpAddress, searchPreviewItem.Subject), this.Uri.AbsoluteUri), ex2);
                }
            }
            return(new SortedResultPage(list.ToArray(), base.PagingInfo));
        }
        public void Merge(SortedResultPage newPage)
        {
            if (newPage == null)
            {
                return;
            }
            if (this.pagingInfo == null)
            {
                throw new ArgumentException(Strings.SortedResultNullParameters);
            }
            if (!this.pagingInfo.Equals(newPage.pagingInfo))
            {
                throw new ArgumentException(Strings.InvalidResultMerge);
            }
            int num  = 0;
            int num2 = 0;
            int i    = 0;
            int num3 = this.ResultCount + newPage.ResultCount;

            PreviewItem[] array = new PreviewItem[num3];
            while (i < num3)
            {
                bool flag = false;
                if (num == this.ResultCount)
                {
                    flag = false;
                }
                else if (num2 == newPage.ResultCount)
                {
                    flag = true;
                }
                else if (this.resultRows[num].CompareTo(newPage.resultRows[num2]) <= 0)
                {
                    if (this.pagingInfo.AscendingSort)
                    {
                        flag = true;
                    }
                }
                else if (this.resultRows[num].CompareTo(newPage.resultRows[num2]) > 0 && !this.pagingInfo.AscendingSort)
                {
                    flag = true;
                }
                if (flag)
                {
                    array[i] = this.resultRows[num];
                    num++;
                }
                else
                {
                    array[i] = newPage.resultRows[num2];
                    num2++;
                }
                i++;
            }
            if (this.pagingInfo.ExcludeDuplicates)
            {
                array = Util.ExcludeDuplicateItems(array);
                num3  = array.Length;
            }
            this.resultRows = new PreviewItem[Math.Min(this.pagingInfo.PageSize, num3)];
            if (this.pagingInfo.Direction == PageDirection.Next || num3 < this.pagingInfo.PageSize)
            {
                num = 0;
            }
            else
            {
                num = num3 - this.pagingInfo.PageSize;
            }
            i = 0;
            while (i < Math.Min(this.pagingInfo.PageSize, num3))
            {
                this.resultRows[i] = array[num];
                i++;
                num++;
            }
        }
Example #6
0
        private static PreviewItem[] InternalCreateSearchPreviewItems(MailboxInfo mailboxInfo, object[][] rows, PagingInfo pagingInfo, StoreSession mailboxSession, List <KeyValuePair <int, long> > messageIdPairs, bool usingSearchFolders)
        {
            if (!usingSearchFolders)
            {
                Util.ThrowOnNull(messageIdPairs, "messageIdPairs");
            }
            if (rows.Length == 0 || rows[0].Length != pagingInfo.DataColumns.Count)
            {
                throw new ArgumentException("Invalid result rows");
            }
            List <PreviewItem> list = new List <PreviewItem>(rows.Length);
            StoreId            sentItemsFolderId = null;

            if (!mailboxSession.IsPublicFolderSession)
            {
                sentItemsFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.SentItems);
            }
            Uri owaMailboxItemLink = LinkUtils.GetOwaMailboxItemLink(delegate
            {
            }, mailboxInfo, true);

            for (int i = 0; i < rows.Length; i++)
            {
                object[] array = rows[i];
                Dictionary <PropertyDefinition, object> properties = new Dictionary <PropertyDefinition, object>(4);
                int num = 0;
                foreach (PropertyDefinition key in pagingInfo.DataColumns)
                {
                    properties.Add(key, array[num]);
                    num++;
                }
                ReferenceItem sortValue = null;
                if (!usingSearchFolders)
                {
                    sortValue = new ReferenceItem(pagingInfo.SortBy, properties[pagingInfo.SortColumn], messageIdPairs.Find((KeyValuePair <int, long> x) => x.Key == (int)properties[ItemSchema.DocumentId]).Value);
                }
                else
                {
                    sortValue = new ReferenceItem(pagingInfo.SortBy, properties[pagingInfo.SortColumn], (long)mailboxSession.MailboxGuid.GetHashCode() << 32 | (long)((ulong)((int)properties[ItemSchema.DocumentId])));
                }
                List <PropertyDefinition> list2 = null;
                if (pagingInfo.AdditionalProperties != null && pagingInfo.AdditionalProperties.Count > 0)
                {
                    list2 = new List <PropertyDefinition>(pagingInfo.AdditionalProperties.Count);
                    foreach (ExtendedPropertyInfo extendedPropertyInfo in pagingInfo.AdditionalProperties)
                    {
                        list2.Add(extendedPropertyInfo.XsoPropertyDefinition);
                    }
                }
                PreviewItem item = new PreviewItem(properties, mailboxInfo.MailboxGuid, owaMailboxItemLink, sortValue, Util.CalculateUniqueItemHash(mailboxSession, array, pagingInfo, sentItemsFolderId), list2)
                {
                    MailboxInfo = mailboxInfo
                };
                list.Add(item);
            }
            PreviewItem[] array2 = list.ToArray();
            if (pagingInfo.ExcludeDuplicates)
            {
                array2 = Util.ExcludeDuplicateItems(array2);
            }
            return(array2);
        }