Skip to content

Commit

Permalink
-merge pull request OfficeDev#61 OfficeDev#61
Browse files Browse the repository at this point in the history
  • Loading branch information
wbrussell committed Sep 14, 2016
1 parent f9e8939 commit 436d85f
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 8 deletions.
21 changes: 21 additions & 0 deletions ComplexProperties/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ internal void InternalLoad(BodyType? bodyType, IEnumerable<PropertyDefinitionBas
additionalProperties);
}

/// <summary>
/// Load the attachment.
/// </summary>
/// <param name="bodyType">Type of the body.</param>
/// <param name="additionalProperties">The additional properties.</param>
internal async System.Threading.Tasks.Task InternalLoadAsync(BodyType? bodyType, IEnumerable<PropertyDefinitionBase> additionalProperties)
{
await this.service.GetAttachmentAsync(
this,
bodyType,
additionalProperties);
}

/// <summary>
/// Validates this instance.
/// </summary>
Expand All @@ -326,5 +339,13 @@ public void Load()
{
this.InternalLoad(null, null);
}

/// <summary>
/// Loads the attachment. Calling this method results in a call to EWS.
/// </summary>
public async System.Threading.Tasks.Task LoadAsync()
{
await this.InternalLoadAsync(null, null);
}
}
}
47 changes: 44 additions & 3 deletions ComplexProperties/FileAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ public void Load(Stream stream)
}
}

/// <summary>
/// Loads the content of the file attachment into the specified stream. Calling this method results in a call to EWS.
/// </summary>
/// <param name="stream">The stream to load the content of the attachment into.</param>
public async System.Threading.Tasks.Task LoadAsync(Stream stream)
{
this.loadToStream = stream;

try
{
await this.LoadAsync();
}
finally
{
this.loadToStream = null;
}
}

/// <summary>
/// Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS.
/// </summary>
Expand All @@ -224,6 +242,29 @@ public void Load(string fileName)
this.contentStream = null;
}

/// <summary>
/// Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS.
/// </summary>
/// <param name="fileName">The name of the file to load the content of the attachment into. If the file already exists, it is overwritten.</param>
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;
}

/// <summary>
/// Gets the name of the file the attachment is linked to.
/// </summary>
Expand Down Expand Up @@ -258,7 +299,7 @@ internal Stream ContentStream
set
{
this.ThrowIfThisIsNotNew();

this.contentStream = value;
this.content = null;
this.fileName = null;
Expand All @@ -278,7 +319,7 @@ public byte[] Content
internal set
{
this.ThrowIfThisIsNotNew();

this.content = value;
this.fileName = null;
this.contentStream = null;
Expand All @@ -290,7 +331,7 @@ internal set
/// </summary>
public bool IsContactPhoto
{
get
get
{
EwsUtilities.ValidatePropertyVersion(this.Service, ExchangeVersion.Exchange2010, "IsContactPhoto");

Expand Down
12 changes: 11 additions & 1 deletion Core/Requests/MultiResponseServiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* DEALINGS IN THE SOFTWARE.
*/


namespace Microsoft.Exchange.WebServices.Data
{
using System;
Expand Down Expand Up @@ -99,7 +100,7 @@ internal override object ParseResponse(EwsServiceXmlReader reader)
/// <param name="responseIndex">Index of the response.</param>
/// <returns>Service response.</returns>
internal abstract TResponse CreateServiceResponse(ExchangeService service, int responseIndex);

/// <summary>
/// Gets the name of the response message XML element.
/// </summary>
Expand Down Expand Up @@ -166,6 +167,15 @@ internal ServiceResponseCollection<TResponse> EndExecute(IAsyncResult asyncResul
return serviceResponses;
}

/// <summary>
/// Executes this request in an async-await fashion.
/// </summary>
/// <returns>Service response collection promise.</returns>
internal async System.Threading.Tasks.Task<ServiceResponseCollection<TResponse>> ExecuteAsync()
{
return await System.Threading.Tasks.Task.Factory.FromAsync<ServiceResponseCollection<TResponse>>(this.BeginExecute, this.EndExecute, this);
}

/// <summary>
/// Gets a value indicating how errors should be handled.
/// </summary>
Expand Down
71 changes: 68 additions & 3 deletions Core/ServiceObjects/Folders/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public static Folder Bind(
return service.BindToFolder<Folder>(id, propertySet);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the folder.</param>
/// <param name="id">The Id of the folder to bind to.</param>
/// <param name="propertySet">The set of properties to load.</param>
/// <returns>A Folder instance representing the folder corresponding to the specified Id.</returns>
public static async System.Threading.Tasks.Task<Folder> BindAsync(
ExchangeService service,
FolderId id,
PropertySet propertySet)
{
return await service.BindToFolderAsync<Folder>(id, propertySet);
}

/// <summary>
/// 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.
Expand All @@ -73,6 +89,21 @@ public static Folder Bind(ExchangeService service, FolderId id)
PropertySet.FirstClassProperties);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the folder.</param>
/// <param name="id">The Id of the folder to bind to.</param>
/// <returns>A Folder instance representing the folder corresponding to the specified Id.</returns>
public static async System.Threading.Tasks.Task<Folder> BindAsync(ExchangeService service, FolderId id)
{
return await Folder.BindAsync(
service,
id,
PropertySet.FirstClassProperties);
}

/// <summary>
/// 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.
Expand All @@ -92,6 +123,25 @@ public static Folder Bind(
propertySet);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the folder.</param>
/// <param name="name">The name of the folder to bind to.</param>
/// <param name="propertySet">The set of properties to load.</param>
/// <returns>A Folder instance representing the folder with the specified name.</returns>
public static async System.Threading.Tasks.Task<Folder> BindAsync(
ExchangeService service,
WellKnownFolderName name,
PropertySet propertySet)
{
return await Folder.BindAsync(
service,
new FolderId(name),
propertySet);
}

/// <summary>
/// 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.
Expand All @@ -107,6 +157,21 @@ public static Folder Bind(ExchangeService service, WellKnownFolderName name)
PropertySet.FirstClassProperties);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the folder.</param>
/// <param name="name">The name of the folder to bind to.</param>
/// <returns>A Folder instance representing the folder with the specified name.</returns>
public static async System.Threading.Tasks.Task<Folder> BindAsync(ExchangeService service, WellKnownFolderName name)
{
return await Folder.BindAsync(
service,
new FolderId(name),
PropertySet.FirstClassProperties);
}

/// <summary>
/// Validates this instance.
/// </summary>
Expand Down Expand Up @@ -190,7 +255,7 @@ internal override void InternalDelete(
{
this.ThrowIfThisIsNew();

this.Service.DeleteFolder( this.Id, deleteMode);
this.Service.DeleteFolder(this.Id, deleteMode);
}

/// <summary>
Expand Down Expand Up @@ -397,7 +462,7 @@ public FindItemsResults<Item> FindItems(SearchFilter searchFilter, ItemView view

ServiceResponseCollection<FindItemResponse<Item>> responses = this.InternalFindItems<Item>(
searchFilter,
view,
view,
null /* groupBy */);

return responses[0].Results;
Expand Down Expand Up @@ -449,7 +514,7 @@ public GroupedFindItemsResults<Item> FindItems(SearchFilter searchFilter, ItemVi

ServiceResponseCollection<FindItemResponse<Item>> responses = this.InternalFindItems<Item>(
searchFilter,
view,
view,
groupBy);

return responses[0].GroupedFindResults;
Expand Down
31 changes: 31 additions & 0 deletions Core/ServiceObjects/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ public static Item Bind(
return service.BindToItem<Item>(id, propertySet);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the item.</param>
/// <param name="id">The Id of the item to bind to.</param>
/// <param name="propertySet">The set of properties to load.</param>
/// <returns>An Item instance representing the item corresponding to the specified Id.</returns>
public static async System.Threading.Tasks.Task<Item> BindAsync(
ExchangeService service,
ItemId id,
PropertySet propertySet)
{
return await service.BindToItemAsync<Item>(id, propertySet);
}

/// <summary>
/// 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.
Expand All @@ -93,6 +109,21 @@ public static Item Bind(ExchangeService service, ItemId id)
PropertySet.FirstClassProperties);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="service">The service to use to bind to the item.</param>
/// <param name="id">The Id of the item to bind to.</param>
/// <returns>An Item instance representing the item corresponding to the specified Id.</returns>
public static async System.Threading.Tasks.Task<Item> BindAsync(ExchangeService service, ItemId id)
{
return await Item.BindAsync(
service,
id,
PropertySet.FirstClassProperties);
}

/// <summary>
/// Internal method to return the schema associated with this type of object.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Exchange.WebServices.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand Down

1 comment on commit 436d85f

@wbrussell
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cloned current working master of EWS api and merged in the changes made by the pull request below that never was pulled in to master code. Last commit on main project was 2015! Got to move forward with async implementation for portions of the api. Set target to 4.5 instead of 4.6.

OfficeDev#61

Please sign in to comment.