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()); }
private UniqueItemHash GetUniqueItemHash(string hash) { UniqueItemHash result; try { result = UniqueItemHash.Parse(hash); } catch (ArgumentException innerException) { throw new WebServiceProxyInvalidResponseException(Strings.InvalidItemHashInPreviewResult(this.Uri.AbsoluteUri), innerException); } return(result); }
private static UniqueItemHash CalculateUniqueItemHash(StoreSession mailboxSession, object[] row, PagingInfo pagingInfo, StoreId sentItemsFolderId) { UniqueItemHash result = null; Dictionary <PropertyDefinition, object> dictionary = new Dictionary <PropertyDefinition, object>(4); int num = 0; foreach (PropertyDefinition key in pagingInfo.DataColumns) { dictionary.Add(key, row[num]); num++; } object obj = null; object obj2 = null; object obj3 = null; object obj4 = null; object obj5 = null; object obj6 = null; object obj7 = null; dictionary.TryGetValue(ItemSchema.Id, out obj); dictionary.TryGetValue(StoreObjectSchema.ParentItemId, out obj2); dictionary.TryGetValue(ItemSchema.InternetMessageId, out obj3); dictionary.TryGetValue(ItemSchema.ConversationId, out obj4); dictionary.TryGetValue(ItemSchema.ConversationTopic, out obj5); dictionary.TryGetValue(ItemSchema.BodyTag, out obj6); dictionary.TryGetValue(StoreObjectSchema.ItemClass, out obj7); if (obj != null && obj2 != null && obj3 != null && obj4 != null && obj5 != null) { StoreId storeId = (StoreId)obj; string internetMsgId = obj3 as string; string text = obj5 as string; StoreId storeId2 = obj2 as StoreId; bool flag = storeId2 != null && sentItemsFolderId != null && storeId2.Equals(sentItemsFolderId); if (obj6 == null && !flag && ObjectClass.IsMessage(obj7 as string, false)) { using (Item item = Item.Bind(mailboxSession, storeId)) { if (item.Body != null) { obj6 = item.Body.CalculateBodyTag(); } } } byte[] array = obj6 as byte[]; result = new UniqueItemHash(internetMsgId, text ?? string.Empty, (array != null) ? BodyTagInfo.FromByteArray(array) : null, flag); } return(result); }
private Dictionary <UniqueItemHash, List <IStorePropertyBag> > AggregateDuplicates(IEnumerable <IStorePropertyBag> propertyBags) { StoreObjectId defaultFolderId = this.MailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox); StoreObjectId defaultFolderId2 = this.MailboxSession.GetDefaultFolderId(DefaultFolderType.SentItems); Dictionary <UniqueItemHash, List <IStorePropertyBag> > dictionary = new Dictionary <UniqueItemHash, List <IStorePropertyBag> >(); foreach (IStorePropertyBag storePropertyBag in propertyBags) { StoreObjectId storeObjectId = storePropertyBag.TryGetProperty(StoreObjectSchema.ParentItemId) as StoreObjectId; UniqueItemHash key = UniqueItemHash.Create(storePropertyBag, storeObjectId.Equals(defaultFolderId2)); if (dictionary.ContainsKey(key)) { if (storeObjectId.Equals(defaultFolderId)) { dictionary[key].Insert(0, storePropertyBag); } else if (storeObjectId.Equals(defaultFolderId2)) { StoreObjectId storeObjectId2 = dictionary[key][0].TryGetProperty(StoreObjectSchema.ParentItemId) as StoreObjectId; if (storeObjectId2.Equals(defaultFolderId)) { dictionary[key].Insert(1, storePropertyBag); } else { dictionary[key].Insert(0, storePropertyBag); } } else { dictionary[key].Add(storePropertyBag); } } else { dictionary.Add(key, new List <IStorePropertyBag> { storePropertyBag }); } } return(dictionary); }
private ItemId PopulateItemIdFromItemExtendedPropertyValues(ExtendedPropertyType[] extendedProperties) { string id = null; string parentFolder = null; string primaryItemId = null; uint size = 0U; string subject = null; int documentId = 0; string text = null; string sender = null; string senderSmtpAddress = null; DateTime minValue = DateTime.MinValue; DateTime minValue2 = DateTime.MinValue; string importance = null; bool isRead = false; string text2 = null; BodyTagInfo btInfo = null; bool sentItems = false; if (extendedProperties != null) { foreach (ExtendedPropertyType extendedPropertyType in extendedProperties) { if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertySetId, Constants.MailboxItemIdPropertyIdSet, StringComparison.OrdinalIgnoreCase) == 0) { if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ItemIdExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ItemIdExtendedProperty.PropertyType) { id = (string)extendedPropertyType.Item; } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ParentFolderIdExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ParentFolderIdExtendedProperty.PropertyType) { parentFolder = (string)extendedPropertyType.Item; } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.PrimaryItemIdExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.PrimaryItemIdExtendedProperty.PropertyType) { primaryItemId = (string)extendedPropertyType.Item; } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ItemSizeExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ItemSizeExtendedProperty.PropertyType) { uint.TryParse(extendedPropertyType.Item as string, out size); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.DocumentIdExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.DocumentIdExtendedProperty.PropertyType) { int.TryParse(extendedPropertyType.Item as string, out documentId); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.SubjectExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.SubjectExtendedProperty.PropertyType) { subject = MailboxItemIdList.DecodeDataFromEws((string)extendedPropertyType.Item); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.SenderExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.SenderExtendedProperty.PropertyType) { sender = MailboxItemIdList.DecodeDataFromEws((string)extendedPropertyType.Item); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.SenderSmtpAddressExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.SenderExtendedProperty.PropertyType) { senderSmtpAddress = MailboxItemIdList.DecodeDataFromEws((string)extendedPropertyType.Item); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ReceivedTimeExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ReceivedTimeExtendedProperty.PropertyType) { DateTime.TryParse(extendedPropertyType.Item as string, out minValue); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.SentTimeExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.SentTimeExtendedProperty.PropertyType) { DateTime.TryParse(extendedPropertyType.Item as string, out minValue2); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ImportanceExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ImportanceExtendedProperty.PropertyType) { importance = (string)extendedPropertyType.Item; } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.IsReadExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.IsReadExtendedProperty.PropertyType) { bool.TryParse(extendedPropertyType.Item as string, out isRead); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.InternetMessageIdExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.InternetMessageIdExtendedProperty.PropertyType) { text = (string)extendedPropertyType.Item; } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.ConversationTopicExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.ConversationTopicExtendedProperty.PropertyType) { text2 = MailboxItemIdList.DecodeDataFromEws((string)extendedPropertyType.Item); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.IsSentItemsExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.IsSentItemsExtendedProperty.PropertyType) { sentItems = bool.Parse((string)extendedPropertyType.Item); } else if (string.Compare(extendedPropertyType.ExtendedFieldURI.PropertyName, MailboxItemIdList.BodyTagInfoExtendedProperty.PropertyName, StringComparison.OrdinalIgnoreCase) == 0 && extendedPropertyType.ExtendedFieldURI.PropertyType == MailboxItemIdList.BodyTagInfoExtendedProperty.PropertyType) { string s = (string)extendedPropertyType.Item; byte[] byteArray = Convert.FromBase64String(s); btInfo = BodyTagInfo.FromByteArray(byteArray); } } } string uniqueHash = null; if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2)) { uniqueHash = new UniqueItemHash(text, text2, btInfo, sentItems).ToString(); } return(new ItemId { Id = id, ParentFolder = parentFolder, PrimaryItemId = primaryItemId, Size = size, Subject = subject, DocumentId = documentId, InternetMessageId = text, Sender = sender, SenderSmtpAddress = senderSmtpAddress, ReceivedTime = minValue, SentTime = minValue2, Importance = importance, IsRead = isRead, UniqueHash = uniqueHash, SourceId = this.sourcePrimarySmtpAddress }); } return(null); }
private ExtendedPropertyType[] CreateItemExtendedPropertyValuesFromItemId(ItemId itemId) { List <ExtendedPropertyType> list = new List <ExtendedPropertyType>(10); if (!string.IsNullOrEmpty(itemId.Id)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ItemIdExtendedProperty, Item = itemId.Id }); } if (!string.IsNullOrEmpty(itemId.ParentFolder)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ParentFolderIdExtendedProperty, Item = itemId.ParentFolder }); } if (!string.IsNullOrEmpty(itemId.PrimaryItemId)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.PrimaryItemIdExtendedProperty, Item = itemId.PrimaryItemId }); } if (itemId.Size != 0U) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ItemSizeExtendedProperty, Item = itemId.Size.ToString() }); } if (!string.IsNullOrEmpty(itemId.Subject)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.SubjectExtendedProperty, Item = MailboxItemIdList.EncodeDataForEws(itemId.Subject) }); } if (itemId.DocumentId != 0) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.DocumentIdExtendedProperty, Item = itemId.DocumentId.ToString() }); } if (!string.IsNullOrEmpty(itemId.Sender)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.SenderExtendedProperty, Item = MailboxItemIdList.EncodeDataForEws(itemId.Sender) }); } if (!string.IsNullOrEmpty(itemId.SenderSmtpAddress)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.SenderSmtpAddressExtendedProperty, Item = MailboxItemIdList.EncodeDataForEws(itemId.SenderSmtpAddress) }); } if (itemId.ReceivedTime != DateTime.MinValue) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ReceivedTimeExtendedProperty, Item = itemId.ReceivedTime.ToString() }); } if (itemId.SentTime != DateTime.MinValue) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.SentTimeExtendedProperty, Item = itemId.SentTime.ToString() }); } if (!string.IsNullOrEmpty(itemId.Importance)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ImportanceExtendedProperty, Item = itemId.Importance }); } list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.IsReadExtendedProperty, Item = itemId.IsRead.ToString() }); if (!string.IsNullOrEmpty(itemId.UniqueHash)) { UniqueItemHash uniqueItemHash = UniqueItemHash.Parse(itemId.UniqueHash); if (!string.IsNullOrEmpty(uniqueItemHash.InternetMessageId)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.InternetMessageIdExtendedProperty, Item = uniqueItemHash.InternetMessageId }); } if (!string.IsNullOrEmpty(uniqueItemHash.ConversationTopic)) { list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.ConversationTopicExtendedProperty, Item = MailboxItemIdList.EncodeDataForEws(uniqueItemHash.ConversationTopic) }); } list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.IsSentItemsExtendedProperty, Item = uniqueItemHash.IsSentItems.ToString() }); if (uniqueItemHash.BodyTagInfo != null) { byte[] inArray = uniqueItemHash.BodyTagInfo.ToByteArray(); string item = Convert.ToBase64String(inArray); list.Add(new ExtendedPropertyType { ExtendedFieldURI = MailboxItemIdList.BodyTagInfoExtendedProperty, Item = item }); } } return(list.ToArray()); }
public override void Process(IList <SearchSource> item) { Recorder.Trace(4L, TraceType.InfoTrace, "CompleteSourceLookup.Process Item:", item); Guid guid = new Guid("aca47e7e-5bb8-43ed-976a-f3158f6d4df7"); List <PreviewItem> list = new List <PreviewItem>(); List <MailboxStatistics> list2 = new List <MailboxStatistics>(); SearchMailboxesInputs searchMailboxesInputs = base.Context.TaskContext as SearchMailboxesInputs; Uri baseUri = new Uri("http://local/"); StoreId value = new VersionedId(new byte[] { 3, 1, 2, 3, 3, 1, 2, 3, byte.MaxValue }); UniqueItemHash itemHash = new UniqueItemHash(string.Empty, string.Empty, null, false); PagingInfo pagingInfo = ((SearchMailboxesInputs)base.Executor.Context.Input).PagingInfo; ReferenceItem sortValue = new ReferenceItem(pagingInfo.SortBy, ExDateTime.Now, 0L); Dictionary <PropertyDefinition, object> properties = new Dictionary <PropertyDefinition, object> { { ItemSchema.Id, value } }; foreach (SearchSource searchSource in item) { if (searchSource.MailboxInfo != null && (searchSource.MailboxInfo.MailboxGuid != Guid.Empty || searchSource.MailboxInfo.IsRemoteMailbox)) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (searchSource.MailboxInfo != null && searchSource.MailboxInfo.MailboxGuid != Guid.Empty) { Dictionary <string, string> dictionary2 = dictionary; string key = "Name"; string value2; if ((value2 = searchSource.OriginalReferenceId) == null) { value2 = (searchSource.MailboxInfo.DisplayName ?? string.Empty); } dictionary2[key] = value2; dictionary["Smtp"] = (searchSource.MailboxInfo.PrimarySmtpAddress.ToString() ?? string.Empty); dictionary["DN"] = (searchSource.MailboxInfo.LegacyExchangeDN ?? string.Empty); } if (searchMailboxesInputs != null) { dictionary["Lang"] = (searchMailboxesInputs.Language ?? string.Empty); dictionary["Config"] = (searchMailboxesInputs.SearchConfigurationId ?? string.Empty); } Uri owaLink = LinkUtils.AppendQueryString(baseUri, dictionary); Recorder.Trace(4L, TraceType.InfoTrace, new object[] { "CompleteSourceLookup.Process Found:", searchSource.ReferenceId, "MailboxInfo:", searchSource.MailboxInfo }); list.Add(new PreviewItem(properties, (searchSource.MailboxInfo.MailboxGuid != Guid.Empty) ? searchSource.MailboxInfo.MailboxGuid : guid, owaLink, sortValue, itemHash) { MailboxInfo = searchSource.MailboxInfo }); list2.Add(new MailboxStatistics(searchSource.MailboxInfo, 0UL, new ByteQuantifiedSize(0UL))); } } SortedResultPage resultPage = new SortedResultPage(list.ToArray(), pagingInfo); ISearchResult searchResult = new ResultAggregator(resultPage, null, 0UL, new ByteQuantifiedSize(0UL), null, null, list2); base.Executor.EnqueueNext(new SearchMailboxesResults(item) { SearchResult = searchResult }); }
public PreviewItem(Dictionary <PropertyDefinition, object> properties, Guid mailboxGuid, Uri owaLink, ReferenceItem sortValue, UniqueItemHash itemHash, List <PropertyDefinition> additionalProperties) : base(properties) { Util.ThrowOnNull(sortValue, "sortValue"); if (mailboxGuid == Guid.Empty) { throw new ArgumentException("Invalid mailbox guid"); } this.owaLink = owaLink; this.sortValue = sortValue; this.mailboxGuid = mailboxGuid; this.itemHash = itemHash; this.additionalPropertyValues = Util.GetSelectedAdditionalPropertyValues(properties, additionalProperties); }
public PreviewItem(Dictionary <PropertyDefinition, object> properties, Guid mailboxGuid, Uri owaLink, ReferenceItem sortValue, UniqueItemHash itemHash) : this(properties, mailboxGuid, owaLink, sortValue, itemHash, null) { }