private StructuredErrors ConvertToNestedErrors(Exception exception) { StructuredErrors structuredErrors = null; while (exception != null) { StructuredError structuredError = new StructuredError(); LocalizedException ex = exception as LocalizedException; if (ex != null) { structuredError.Code = ex.ErrorCode; structuredError.Info = ex.LocalizedString; } else { structuredError.Code = 0; structuredError.Info = exception.ToString(); } Type type = exception.GetType(); structuredError.Name = type.FullName; structuredError.Guid = type.GUID.ToString("n"); structuredError.Message = exception.Message; structuredError.Source = exception.Source; structuredError.TargetSite = exception.TargetSite.Name; if (structuredErrors == null) { structuredErrors = new StructuredErrors(); } structuredErrors.AddError(structuredError); exception = exception.InnerException; } return(structuredErrors); }
private void GetAttachmentsFromItemByStoreId(StoreSession session, StoreId storeId, List <ModernAttachment> outModernAttachments) { if (session == null || storeId == null || outModernAttachments == null || this.IsAttachmentCountExceeded()) { return; } try { using (Item item = Item.Bind(session, storeId, ItemBindOption.LoadRequiredPropertiesOnly, GetModernAttachmentsCommand.bindItemPropDefs)) { this.perfItemsBoundCount++; if (item.AttachmentCollection != null) { IdAndSession idAndSession = new IdAndSession(item.Id, item.Session); IList <AttachmentHandle> handles = item.AttachmentCollection.GetHandles(); for (int i = 0; i < handles.Count; i++) { AttachmentHandle attachmentHandle = handles[i]; using (Attachment attachment = item.AttachmentCollection.Open(attachmentHandle)) { if (GetModernAttachmentsCommand.Utilities.ShowAttachment(attachment, 100000)) { ModernAttachment modernAttachment = new ModernAttachment(); GetModernAttachmentsCommand.PopulateAttachmentProperties(idAndSession, item, attachment, modernAttachment); GetModernAttachmentsCommand.PopulateItemProperties(idAndSession, item, modernAttachment); modernAttachment.Info = new ModernAttachment.AttachmentInfo(); modernAttachment.Info.Index = i; modernAttachment.Info.Path = new string[] { GetModernAttachmentsCommand.Utilities.FormatParam("ATT.N", attachmentHandle.AttachNumber) }; outModernAttachments.Add(modernAttachment); this.perfAttachmentCount++; } this.perfAttachmentsEnumeratedCount++; } } } } } catch (Exception exception) { StructuredErrors structuredErrors = this.ConvertToNestedErrors(exception); structuredErrors.Path = new string[] { "GetAttachmentsFromItemByStoreId", GetModernAttachmentsCommand.Utilities.FormatParam("storeId", storeId.ToBase64String()) }; this.response.AddError(structuredErrors); } }
private void GetAttachmentsFromEwsItem(BaseItemId baseItemId, ModernAttachmentGroup outGroup) { if (baseItemId == null || outGroup == null) { return; } string itemIdDisplayName = GetModernAttachmentsCommand.Utilities.GetItemIdDisplayName(baseItemId); try { IdAndSession idAndSession = base.IdConverter.ConvertItemIdToIdAndSessionReadOnly(baseItemId); using (Item item = Item.Bind(idAndSession.Session, idAndSession.Id)) { List <ModernAttachment> list = new List <ModernAttachment>(0); this.GetAttachmentsFromItemByStoreId(item.Session, item.Id, list); outGroup.AttachmentGroup = list.ToArray(); outGroup.Path = new string[] { GetModernAttachmentsCommand.Utilities.FormatParam("itemId.DisplayName", itemIdDisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("itemId.Id", baseItemId.GetId()), GetModernAttachmentsCommand.Utilities.FormatParam("itemId.ChangeKey", baseItemId.GetChangeKey()) }; } } catch (Exception exception) { StructuredErrors structuredErrors = this.ConvertToNestedErrors(exception); structuredErrors.Path = new string[] { "GetAttachmentsFromEwsItem", GetModernAttachmentsCommand.Utilities.FormatParam("itemId.DisplayName", itemIdDisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("itemId.Id", baseItemId.GetId()), GetModernAttachmentsCommand.Utilities.FormatParam("itemId.ChangeKey", baseItemId.GetChangeKey()) }; this.response.AddError(structuredErrors); } }
private void GetAttachmentsFromEwsFolder(BaseFolderId baseFolderId, ModernAttachmentGroup outGroup) { if (baseFolderId == null || outGroup == null) { return; } string folderIdDisplayName = GetModernAttachmentsCommand.Utilities.GetFolderIdDisplayName(baseFolderId); try { IdAndSession idAndSession = base.IdConverter.ConvertFolderIdToIdAndSessionReadOnly(baseFolderId); ExDateTime now = ExDateTime.Now; using (Folder folder = Folder.Bind(idAndSession.Session, idAndSession.Id)) { List <ModernAttachment> list = new List <ModernAttachment>(0); SortBy[] sortColumns = this.BuildSortBy(); QueryFilter queryFilter = this.BuildQueryFilter(); using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, queryFilter, sortColumns, GetModernAttachmentsCommand.findItemsQueryPropDefs)) { int itemsOffset = this.request.ItemsOffset; int num = this.request.ItemsToProcessMax; int num2 = itemsOffset + num + 1; object[][] rows = queryResult.GetRows(num2 - 1); this.perfFindItemsDuration = ExDateTime.Now - now; now = ExDateTime.Now; outGroup.ItemsTotal = rows.Length; if (itemsOffset >= rows.Length) { return; } if (num2 > rows.Length) { num2 = rows.Length; } outGroup.ItemsOffsetNext = num2; outGroup.RetrievedLastItem = (num2 == rows.Length); if (rows != null && rows.Length > 0) { this.perfItemsFoundCount += rows.Length; for (int i = itemsOffset; i < num2; i++) { object[] array = rows[i]; StoreId storeId = (StoreId)array[0]; this.GetAttachmentsFromItemByStoreId(idAndSession.Session, storeId, list); outGroup.ItemsProcessed++; } } outGroup.AttachmentsReturned = this.perfAttachmentCount; this.perfBindItemsDuration = ExDateTime.Now - now; outGroup.AttachmentGroup = list.ToArray(); } outGroup.Path = new string[] { GetModernAttachmentsCommand.Utilities.FormatParam("folderId.DisplayName", folderIdDisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("folder.ClassName", folder.ClassName), GetModernAttachmentsCommand.Utilities.FormatParam("folder.DisplayName", folder.DisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("perfItemsFoundCount", this.perfItemsFoundCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfItemsBoundCount", this.perfItemsBoundCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfAttachmentsEnumeratedCount", this.perfAttachmentsEnumeratedCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfAttachmentCount", this.perfAttachmentCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfFindItemsDuration", this.perfFindItemsDuration), GetModernAttachmentsCommand.Utilities.FormatParam("perfBindItemsDuration", this.perfBindItemsDuration) }; } } catch (Exception exception) { StructuredErrors structuredErrors = this.ConvertToNestedErrors(exception); structuredErrors.Path = new string[] { "GetAttachmentsFromEwsFolder", GetModernAttachmentsCommand.Utilities.FormatParam("folderId.DisplayName", folderIdDisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("folderId.DisplayName", folderIdDisplayName), GetModernAttachmentsCommand.Utilities.FormatParam("perfItemsFoundCount", this.perfItemsFoundCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfItemsBoundCount", this.perfItemsBoundCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfAttachmentsEnumeratedCount", this.perfAttachmentsEnumeratedCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfAttachmentCount", this.perfAttachmentCount), GetModernAttachmentsCommand.Utilities.FormatParam("perfFindItemsDuration", this.perfFindItemsDuration), GetModernAttachmentsCommand.Utilities.FormatParam("perfBindItemsDuration", this.perfBindItemsDuration) }; this.response.AddError(structuredErrors); } }