From f9e8939c661867836bc67cd23c010008e2aca0ac Mon Sep 17 00:00:00 2001 From: wbrussell Date: Wed, 14 Sep 2016 12:18:46 -0600 Subject: [PATCH] -manually move async code from pull request #61 exchangeservice.cs to current master version. (only moved items that prevented compile) https://github.com/OfficeDev/ews-managed-api/pull/61 --- Core/ExchangeService.cs | 243 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/Core/ExchangeService.cs b/Core/ExchangeService.cs index 2f5ff9a3..e61cdabc 100644 --- a/Core/ExchangeService.cs +++ b/Core/ExchangeService.cs @@ -297,6 +297,25 @@ internal Folder BindToFolder(FolderId folderId, PropertySet propertySet) return responses[0].Folder; } + /// + /// Binds to a folder. + /// + /// The folder id. + /// The property set. + /// Folder + internal async System.Threading.Tasks.Task BindToFolderAsync(FolderId folderId, PropertySet propertySet) + { + EwsUtilities.ValidateParam(folderId, "folderId"); + EwsUtilities.ValidateParam(propertySet, "propertySet"); + + ServiceResponseCollection responses = await this.InternalBindToFoldersAsync( + new[] { folderId }, + propertySet, + ServiceErrorHandling.ThrowOnError + ); + + return responses[0].Folder; + } /// /// Binds to folder. /// @@ -323,6 +342,33 @@ internal TFolder BindToFolder(FolderId folderId, PropertySet propertySe } } + + /// + /// Binds to folder. + /// + /// The type of the folder. + /// The folder id. + /// The property set. + /// Folder + internal async System.Threading.Tasks.Task BindToFolderAsync(FolderId folderId, PropertySet propertySet) + where TFolder : Folder + { + Folder result = await this.BindToFolderAsync(folderId, propertySet); + + if (result is TFolder) + { + return (TFolder)result; + } + else + { + throw new ServiceLocalException( + string.Format( + Strings.FolderTypeNotCompatible, + result.GetType().Name, + typeof(TFolder).Name)); + } + } + /// /// Binds to multiple folders in a single call to EWS. /// @@ -343,6 +389,26 @@ public ServiceResponseCollection BindToFolders( ); } + /// + /// Binds to multiple folders in a single call to EWS. + /// + /// The Ids of the folders to bind to. + /// The set of properties to load. + /// A ServiceResponseCollection providing results for each of the specified folder Ids. + public async System.Threading.Tasks.Task> BindToFoldersAsync( + IEnumerable folderIds, + PropertySet propertySet) + { + EwsUtilities.ValidateParamCollection(folderIds, "folderIds"); + EwsUtilities.ValidateParam(propertySet, "propertySet"); + + return await this.InternalBindToFoldersAsync( + folderIds, + propertySet, + ServiceErrorHandling.ReturnErrors + ); + } + /// /// Binds to multiple folders in a single call to EWS. /// @@ -363,6 +429,25 @@ private ServiceResponseCollection InternalBindToFolders( return request.Execute(); } + /// + /// Binds to multiple folders in a single call to EWS. + /// + /// The Ids of the folders to bind to. + /// The set of properties to load. + /// Type of error handling to perform. + /// A ServiceResponseCollection providing results for each of the specified folder Ids. + private async System.Threading.Tasks.Task> InternalBindToFoldersAsync( + IEnumerable folderIds, + PropertySet propertySet, + ServiceErrorHandling errorHandling) + { + GetFolderRequest request = new GetFolderRequest(this, errorHandling); + + request.FolderIds.AddRange(folderIds); + request.PropertySet = propertySet; + + return await request.ExecuteAsync(); + } /// /// Deletes a folder. Calling this method results in a call to EWS. /// @@ -1308,6 +1393,28 @@ private ServiceResponseCollection InternalBindToItems( return request.Execute(); } + /// + /// Binds to multiple items in a single call to EWS. + /// + /// The Ids of the items to bind to. + /// The set of properties to load. + /// The SmtpAddress of mailbox that hosts all items we need to bind to + /// Type of error handling to perform. + /// A ServiceResponseCollection providing results for each of the specified item Ids. + private async System.Threading.Tasks.Task> InternalBindToItemsAsync( + IEnumerable itemIds, + PropertySet propertySet, + string anchorMailbox, + ServiceErrorHandling errorHandling) + { + GetItemRequest request = new GetItemRequest(this, errorHandling); + + request.ItemIds.AddRange(itemIds); + request.PropertySet = propertySet; + request.AnchorMailbox = anchorMailbox; + + return await request.ExecuteAsync(); + } /// /// Binds to multiple items in a single call to EWS. /// @@ -1373,6 +1480,25 @@ internal Item BindToItem(ItemId itemId, PropertySet propertySet) return responses[0].Item; } + /// + /// Binds to item. + /// + /// The item id. + /// The property set. + /// Item. + internal async System.Threading.Tasks.Task BindToItemAsync(ItemId itemId, PropertySet propertySet) + { + EwsUtilities.ValidateParam(itemId, "itemId"); + EwsUtilities.ValidateParam(propertySet, "propertySet"); + + ServiceResponseCollection responses = await this.InternalBindToItemsAsync( + new ItemId[] { itemId }, + propertySet, + null, /* anchorMailbox */ + ServiceErrorHandling.ThrowOnError); + + return responses[0].Item; + } /// /// Binds to item. /// @@ -1399,6 +1525,31 @@ internal TItem BindToItem(ItemId itemId, PropertySet propertySet) } } + /// + /// Binds to item. + /// + /// The type of the item. + /// The item id. + /// The property set. + /// Item + internal async System.Threading.Tasks.Task BindToItemAsync(ItemId itemId, PropertySet propertySet) + where TItem : Item + { + Item result = await this.BindToItemAsync(itemId, propertySet); + + if (result is TItem) + { + return (TItem)result; + } + else + { + throw new ServiceLocalException( + string.Format( + Strings.ItemTypeNotCompatible, + result.GetType().Name, + typeof(TItem).Name)); + } + } /// /// Deletes multiple items in a single call to EWS. /// @@ -1810,6 +1961,34 @@ private ServiceResponseCollection InternalGetAttachments( return request.Execute(); } + + /// + /// Gets an attachment. + /// + /// The attachments. + /// Type of the body. + /// The additional properties. + /// Type of error handling to perform. + /// Service response collection. + private async System.Threading.Tasks.Task> InternalGetAttachmentsAsync( + IEnumerable attachments, + BodyType? bodyType, + IEnumerable additionalProperties, + ServiceErrorHandling errorHandling) + { + GetAttachmentRequest request = new GetAttachmentRequest(this, errorHandling); + + request.Attachments.AddRange(attachments); + request.BodyType = bodyType; + + if (additionalProperties != null) + { + request.AdditionalProperties.AddRange(additionalProperties); + } + + return await request.ExecuteAsync(); + } + /// /// Gets attachments. /// @@ -1829,6 +2008,27 @@ public ServiceResponseCollection GetAttachments( ServiceErrorHandling.ReturnErrors); } + + /// + /// Gets attachments. + /// + /// The attachments. + /// Type of the body. + /// The additional properties. + /// Service response collection. + public async System.Threading.Tasks.Task> GetAttachmentsAsync( + Attachment[] attachments, + BodyType? bodyType, + IEnumerable additionalProperties) + { + return await this.InternalGetAttachmentsAsync( + attachments, + bodyType, + additionalProperties, + ServiceErrorHandling.ReturnErrors); + } + + /// /// Gets attachments. /// @@ -1854,6 +2054,31 @@ public ServiceResponseCollection GetAttachments( return request.Execute(); } + /// + /// Gets attachments. + /// + /// The attachment ids. + /// Type of the body. + /// The additional properties. + /// Service response collection. + public async System.Threading.Tasks.Task> GetAttachmentsAsync( + string[] attachmentIds, + BodyType? bodyType, + IEnumerable additionalProperties) + { + GetAttachmentRequest request = new GetAttachmentRequest(this, ServiceErrorHandling.ReturnErrors); + + request.AttachmentIds.AddRange(attachmentIds); + request.BodyType = bodyType; + + if (additionalProperties != null) + { + request.AdditionalProperties.AddRange(additionalProperties); + } + + return await request.ExecuteAsync(); + } + /// /// Gets an attachment. /// @@ -1872,6 +2097,24 @@ internal void GetAttachment( ServiceErrorHandling.ThrowOnError); } + /// + /// Gets an attachment. + /// + /// The attachment. + /// Type of the body. + /// The additional properties. + internal async System.Threading.Tasks.Task GetAttachmentAsync( + Attachment attachment, + BodyType? bodyType, + IEnumerable additionalProperties) + { + await this.InternalGetAttachmentsAsync( + new Attachment[] { attachment }, + bodyType, + additionalProperties, + ServiceErrorHandling.ThrowOnError); + } + /// /// Creates attachments. ///