private static VersionedId EwsIdToVersionedId(string ewsId, string changeKey, out MailboxId mailboxId) { IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsId, BasicTypes.Item, null); mailboxId = idHeaderInformation.MailboxId; byte[] byteArrayChangeKey; StoreObjectType objectType; WebServiceMailboxSearchGroup.ParseChangeKeyString(changeKey, out byteArrayChangeKey, out objectType); return(VersionedId.Deserialize(idHeaderInformation.StoreIdBytes, byteArrayChangeKey, objectType)); }
private static ExDateTime CreateExDateTime(ExTimeZone timeZone, DateTime dateTime, WebServiceMailboxSearchGroup searchGroup = null) { ExDateTime result = ExDateTime.MinValue; IList <ExDateTime> list = ExDateTime.Create(timeZone, dateTime); if (list.Count > 0) { result = list[0]; } else { Factory.Current.GeneralTracer.TraceDebug <ExTimeZone, DateTime>((long)((searchGroup != null) ? searchGroup.GetHashCode() : 0), "DateTime could not be converted to ExDateTime since call to ExchangeSystem.ExDateTime.Create(ExTimeZone: {0}, DateTime: {1}) return nothing", timeZone, dateTime); } return(result); }
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)); }