From 436d85f36af90253450c9712b65d17e3bbc884a1 Mon Sep 17 00:00:00 2001 From: wbrussell Date: Wed, 14 Sep 2016 12:22:27 -0600 Subject: [PATCH] -merge pull request #61 https://github.com/OfficeDev/ews-managed-api/pull/61 --- ComplexProperties/Attachment.cs | 21 ++++++ ComplexProperties/FileAttachment.cs | 47 ++++++++++++- Core/Requests/MultiResponseServiceRequest.cs | 12 +++- Core/ServiceObjects/Folders/Folder.cs | 71 +++++++++++++++++++- Core/ServiceObjects/Items/Item.cs | 31 +++++++++ Microsoft.Exchange.WebServices.Data.csproj | 2 +- 6 files changed, 176 insertions(+), 8 deletions(-) diff --git a/ComplexProperties/Attachment.cs b/ComplexProperties/Attachment.cs index 142bb708..605d4c20 100644 --- a/ComplexProperties/Attachment.cs +++ b/ComplexProperties/Attachment.cs @@ -311,6 +311,19 @@ internal void InternalLoad(BodyType? bodyType, IEnumerable + /// Load the attachment. + /// + /// Type of the body. + /// The additional properties. + internal async System.Threading.Tasks.Task InternalLoadAsync(BodyType? bodyType, IEnumerable additionalProperties) + { + await this.service.GetAttachmentAsync( + this, + bodyType, + additionalProperties); + } + /// /// Validates this instance. /// @@ -326,5 +339,13 @@ public void Load() { this.InternalLoad(null, null); } + + /// + /// Loads the attachment. Calling this method results in a call to EWS. + /// + public async System.Threading.Tasks.Task LoadAsync() + { + await this.InternalLoadAsync(null, null); + } } } \ No newline at end of file diff --git a/ComplexProperties/FileAttachment.cs b/ComplexProperties/FileAttachment.cs index f9611145..b20a73ab 100644 --- a/ComplexProperties/FileAttachment.cs +++ b/ComplexProperties/FileAttachment.cs @@ -201,6 +201,24 @@ public void Load(Stream stream) } } + /// + /// Loads the content of the file attachment into the specified stream. Calling this method results in a call to EWS. + /// + /// The stream to load the content of the attachment into. + public async System.Threading.Tasks.Task LoadAsync(Stream stream) + { + this.loadToStream = stream; + + try + { + await this.LoadAsync(); + } + finally + { + this.loadToStream = null; + } + } + /// /// Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS. /// @@ -224,6 +242,29 @@ public void Load(string fileName) this.contentStream = null; } + /// + /// Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS. + /// + /// The name of the file to load the content of the attachment into. If the file already exists, it is overwritten. + public async System.Threading.Tasks.Task LoadAsync(string fileName) + { + this.loadToStream = new FileStream(fileName, FileMode.Create); + + try + { + await this.LoadAsync(); + } + finally + { + this.loadToStream.Dispose(); + this.loadToStream = null; + } + + this.fileName = fileName; + this.content = null; + this.contentStream = null; + } + /// /// Gets the name of the file the attachment is linked to. /// @@ -258,7 +299,7 @@ internal Stream ContentStream set { this.ThrowIfThisIsNotNew(); - + this.contentStream = value; this.content = null; this.fileName = null; @@ -278,7 +319,7 @@ public byte[] Content internal set { this.ThrowIfThisIsNotNew(); - + this.content = value; this.fileName = null; this.contentStream = null; @@ -290,7 +331,7 @@ internal set /// public bool IsContactPhoto { - get + get { EwsUtilities.ValidatePropertyVersion(this.Service, ExchangeVersion.Exchange2010, "IsContactPhoto"); diff --git a/Core/Requests/MultiResponseServiceRequest.cs b/Core/Requests/MultiResponseServiceRequest.cs index 3853ae3b..ed29785f 100644 --- a/Core/Requests/MultiResponseServiceRequest.cs +++ b/Core/Requests/MultiResponseServiceRequest.cs @@ -23,6 +23,7 @@ * DEALINGS IN THE SOFTWARE. */ + namespace Microsoft.Exchange.WebServices.Data { using System; @@ -99,7 +100,7 @@ internal override object ParseResponse(EwsServiceXmlReader reader) /// Index of the response. /// Service response. internal abstract TResponse CreateServiceResponse(ExchangeService service, int responseIndex); - + /// /// Gets the name of the response message XML element. /// @@ -166,6 +167,15 @@ internal ServiceResponseCollection EndExecute(IAsyncResult asyncResul return serviceResponses; } + /// + /// Executes this request in an async-await fashion. + /// + /// Service response collection promise. + internal async System.Threading.Tasks.Task> ExecuteAsync() + { + return await System.Threading.Tasks.Task.Factory.FromAsync>(this.BeginExecute, this.EndExecute, this); + } + /// /// Gets a value indicating how errors should be handled. /// diff --git a/Core/ServiceObjects/Folders/Folder.cs b/Core/ServiceObjects/Folders/Folder.cs index 60f3d465..019855d5 100644 --- a/Core/ServiceObjects/Folders/Folder.cs +++ b/Core/ServiceObjects/Folders/Folder.cs @@ -58,6 +58,22 @@ public static Folder Bind( return service.BindToFolder(id, propertySet); } + /// + /// Binds to an existing folder, whatever its actual type is, and loads the specified set of properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the folder. + /// The Id of the folder to bind to. + /// The set of properties to load. + /// A Folder instance representing the folder corresponding to the specified Id. + public static async System.Threading.Tasks.Task BindAsync( + ExchangeService service, + FolderId id, + PropertySet propertySet) + { + return await service.BindToFolderAsync(id, propertySet); + } + /// /// Binds to an existing folder, whatever its actual type is, and loads its first class properties. /// Calling this method results in a call to EWS. @@ -73,6 +89,21 @@ public static Folder Bind(ExchangeService service, FolderId id) PropertySet.FirstClassProperties); } + /// + /// Binds to an existing folder, whatever its actual type is, and loads its first class properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the folder. + /// The Id of the folder to bind to. + /// A Folder instance representing the folder corresponding to the specified Id. + public static async System.Threading.Tasks.Task BindAsync(ExchangeService service, FolderId id) + { + return await Folder.BindAsync( + service, + id, + PropertySet.FirstClassProperties); + } + /// /// Binds to an existing folder, whatever its actual type is, and loads the specified set of properties. /// Calling this method results in a call to EWS. @@ -92,6 +123,25 @@ public static Folder Bind( propertySet); } + /// + /// Binds to an existing folder, whatever its actual type is, and loads the specified set of properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the folder. + /// The name of the folder to bind to. + /// The set of properties to load. + /// A Folder instance representing the folder with the specified name. + public static async System.Threading.Tasks.Task BindAsync( + ExchangeService service, + WellKnownFolderName name, + PropertySet propertySet) + { + return await Folder.BindAsync( + service, + new FolderId(name), + propertySet); + } + /// /// Binds to an existing folder, whatever its actual type is, and loads its first class properties. /// Calling this method results in a call to EWS. @@ -107,6 +157,21 @@ public static Folder Bind(ExchangeService service, WellKnownFolderName name) PropertySet.FirstClassProperties); } + /// + /// Binds to an existing folder, whatever its actual type is, and loads its first class properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the folder. + /// The name of the folder to bind to. + /// A Folder instance representing the folder with the specified name. + public static async System.Threading.Tasks.Task BindAsync(ExchangeService service, WellKnownFolderName name) + { + return await Folder.BindAsync( + service, + new FolderId(name), + PropertySet.FirstClassProperties); + } + /// /// Validates this instance. /// @@ -190,7 +255,7 @@ internal override void InternalDelete( { this.ThrowIfThisIsNew(); - this.Service.DeleteFolder( this.Id, deleteMode); + this.Service.DeleteFolder(this.Id, deleteMode); } /// @@ -397,7 +462,7 @@ public FindItemsResults FindItems(SearchFilter searchFilter, ItemView view ServiceResponseCollection> responses = this.InternalFindItems( searchFilter, - view, + view, null /* groupBy */); return responses[0].Results; @@ -449,7 +514,7 @@ public GroupedFindItemsResults FindItems(SearchFilter searchFilter, ItemVi ServiceResponseCollection> responses = this.InternalFindItems( searchFilter, - view, + view, groupBy); return responses[0].GroupedFindResults; diff --git a/Core/ServiceObjects/Items/Item.cs b/Core/ServiceObjects/Items/Item.cs index 19f238f7..023d51d6 100644 --- a/Core/ServiceObjects/Items/Item.cs +++ b/Core/ServiceObjects/Items/Item.cs @@ -78,6 +78,22 @@ public static Item Bind( return service.BindToItem(id, propertySet); } + /// + /// Binds to an existing item, whatever its actual type is, and loads the specified set of properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the item. + /// The Id of the item to bind to. + /// The set of properties to load. + /// An Item instance representing the item corresponding to the specified Id. + public static async System.Threading.Tasks.Task BindAsync( + ExchangeService service, + ItemId id, + PropertySet propertySet) + { + return await service.BindToItemAsync(id, propertySet); + } + /// /// Binds to an existing item, whatever its actual type is, and loads its first class properties. /// Calling this method results in a call to EWS. @@ -93,6 +109,21 @@ public static Item Bind(ExchangeService service, ItemId id) PropertySet.FirstClassProperties); } + /// + /// Binds to an existing item, whatever its actual type is, and loads its first class properties. + /// Calling this method results in a call to EWS. + /// + /// The service to use to bind to the item. + /// The Id of the item to bind to. + /// An Item instance representing the item corresponding to the specified Id. + public static async System.Threading.Tasks.Task BindAsync(ExchangeService service, ItemId id) + { + return await Item.BindAsync( + service, + id, + PropertySet.FirstClassProperties); + } + /// /// Internal method to return the schema associated with this type of object. /// diff --git a/Microsoft.Exchange.WebServices.Data.csproj b/Microsoft.Exchange.WebServices.Data.csproj index f4781e3f..9083920d 100644 --- a/Microsoft.Exchange.WebServices.Data.csproj +++ b/Microsoft.Exchange.WebServices.Data.csproj @@ -15,7 +15,7 @@ 4.0 - v3.5 + v4.5 publish\ true Disk