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/ExchangeService.cs b/Core/ExchangeService.cs index cdc22cd3..91d87c38 100644 --- a/Core/ExchangeService.cs +++ b/Core/ExchangeService.cs @@ -188,6 +188,31 @@ private ServiceResponseCollection InternalFindFolders( return request.Execute(); } + /// + /// Finds folders. + /// + /// The parent folder ids. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of folders returned. + /// Indicates the type of error handling should be done. + /// Collection of service responses. + private async System.Threading.Tasks.Task> InternalFindFoldersAsync( + IEnumerable parentFolderIds, + SearchFilter searchFilter, + FolderView view, + ServiceErrorHandling errorHandlingMode) + { + FindFolderRequest request = new FindFolderRequest(this, errorHandlingMode); + + request.ParentFolderIds.AddRange(parentFolderIds); + request.SearchFilter = searchFilter; + request.View = view; + + return await request.ExecuteAsync(); + } + /// /// Obtains a list of folders by searching the sub-folders of the specified folder. /// @@ -212,6 +237,30 @@ public FindFoldersResults FindFolders(FolderId parentFolderId, SearchFilter sear return responses[0].Results; } + /// + /// Obtains a list of folders by searching the sub-folders of the specified folder. + /// + /// The Id of the folder in which to search for folders. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of folders returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task FindFoldersAsync(FolderId parentFolderId, SearchFilter searchFilter, FolderView view) + { + EwsUtilities.ValidateParam(parentFolderId, "parentFolderId"); + EwsUtilities.ValidateParam(view, "view"); + EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter"); + + ServiceResponseCollection responses = await this.InternalFindFoldersAsync( + new FolderId[] { parentFolderId }, + searchFilter, + view, + ServiceErrorHandling.ThrowOnError); + + return responses[0].Results; + } + /// /// Obtains a list of folders by searching the sub-folders of the specified folder. /// @@ -232,6 +281,26 @@ public FindFoldersResults FindFolders(FolderId parentFolderId, FolderView view) return responses[0].Results; } + /// + /// Obtains a list of folders by searching the sub-folders of the specified folder. + /// + /// The Id of the folder in which to search for folders. + /// The view controlling the number of folders returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task FindFoldersAsync(FolderId parentFolderId, FolderView view) + { + EwsUtilities.ValidateParam(parentFolderId, "parentFolderId"); + EwsUtilities.ValidateParam(view, "view"); + + ServiceResponseCollection responses = await this.InternalFindFoldersAsync( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + view, + ServiceErrorHandling.ThrowOnError); + + return responses[0].Results; + } + /// /// Obtains a list of folders by searching the sub-folders of the specified folder. /// @@ -246,6 +315,20 @@ public FindFoldersResults FindFolders(WellKnownFolderName parentFolderName, Sear return this.FindFolders(new FolderId(parentFolderName), searchFilter, view); } + /// + /// Obtains a list of folders by searching the sub-folders of the specified folder. + /// + /// The name of the folder in which to search for folders. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of folders returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task FindFoldersAsync(WellKnownFolderName parentFolderName, SearchFilter searchFilter, FolderView view) + { + return await this.FindFoldersAsync(new FolderId(parentFolderName), searchFilter, view); + } + /// /// Obtains a list of folders by searching the sub-folders of the specified folder. /// @@ -257,6 +340,17 @@ public FindFoldersResults FindFolders(WellKnownFolderName parentFolderName, Fold return this.FindFolders(new FolderId(parentFolderName), view); } + /// + /// Obtains a list of folders by searching the sub-folders of the specified folder. + /// + /// The name of the folder in which to search for folders. + /// The view controlling the number of folders returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task FindFoldersAsync(WellKnownFolderName parentFolderName, FolderView view) + { + return await this.FindFoldersAsync(new FolderId(parentFolderName), view); + } + /// /// Load specified properties for a folder. /// @@ -297,6 +391,26 @@ 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 +437,32 @@ 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 +483,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 +523,26 @@ 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. /// @@ -889,6 +1069,45 @@ internal ServiceResponseCollection> FindItems( return request.Execute(); } + /// + /// Finds items. + /// + /// The type of the item. + /// The parent folder ids. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// query string to be used for indexed search. + /// The view controlling the number of items returned. + /// The group by. + /// Indicates the type of error handling should be done. + /// Service response collection. + internal async System.Threading.Tasks.Task>> FindItemsAsync( + IEnumerable parentFolderIds, + SearchFilter searchFilter, + string queryString, + ViewBase view, + Grouping groupBy, + ServiceErrorHandling errorHandlingMode) + where TItem : Item + { + EwsUtilities.ValidateParamCollection(parentFolderIds, "parentFolderIds"); + EwsUtilities.ValidateParam(view, "view"); + EwsUtilities.ValidateParamAllowNull(groupBy, "groupBy"); + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter"); + + FindItemRequest request = new FindItemRequest(this, errorHandlingMode); + + request.ParentFolderIds.AddRange(parentFolderIds); + request.SearchFilter = searchFilter; + request.QueryString = queryString; + request.View = view; + request.GroupBy = groupBy; + + return await request.ExecuteAsync(); + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -911,6 +1130,28 @@ public FindItemsResults FindItems(FolderId parentFolderId, string queryStr return responses[0].Results; } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// the search string to be used for indexed search, if any. + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(FolderId parentFolderId, string queryString, ViewBase view) + { + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + + ServiceResponseCollection> responses = await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + queryString, + view, + null, /* groupBy */ + ServiceErrorHandling.ThrowOnError); + + return responses[0].Results; + } + /// /// Obtains a list of items by searching the contents of a specific folder. /// Along with conversations, a list of highlight terms are returned. @@ -942,6 +1183,37 @@ public FindItemsResults FindItems(FolderId parentFolderId, string queryStr return responses[0].Results; } + /// + /// Obtains a list of items by searching the contents of a specific folder. + /// Along with conversations, a list of highlight terms are returned. + /// Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// the search string to be used for indexed search, if any. + /// Flag indicating if highlight terms should be returned in the response + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(FolderId parentFolderId, string queryString, bool returnHighlightTerms, ViewBase view) + { + FolderId[] parentFolderIds = new FolderId[] { parentFolderId }; + + EwsUtilities.ValidateParamCollection(parentFolderIds, "parentFolderIds"); + EwsUtilities.ValidateParam(view, "view"); + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + EwsUtilities.ValidateParamAllowNull(returnHighlightTerms, "returnHighlightTerms"); + EwsUtilities.ValidateMethodVersion(this, ExchangeVersion.Exchange2013, "FindItems"); + + FindItemRequest request = new FindItemRequest(this, ServiceErrorHandling.ThrowOnError); + + request.ParentFolderIds.AddRange(parentFolderIds); + request.QueryString = queryString; + request.ReturnHighlightTerms = returnHighlightTerms; + request.View = view; + + ServiceResponseCollection> responses = await request.ExecuteAsync(); + return responses[0].Results; + } + /// /// Obtains a list of items by searching the contents of a specific folder. /// Along with conversations, a list of highlight terms are returned. @@ -976,6 +1248,40 @@ public GroupedFindItemsResults FindItems(FolderId parentFolderId, string q return responses[0].GroupedFindResults; } + /// + /// Obtains a list of items by searching the contents of a specific folder. + /// Along with conversations, a list of highlight terms are returned. + /// Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// the search string to be used for indexed search, if any. + /// Flag indicating if highlight terms should be returned in the response + /// The view controlling the number of items returned. + /// The group by clause. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(FolderId parentFolderId, string queryString, bool returnHighlightTerms, ViewBase view, Grouping groupBy) + { + FolderId[] parentFolderIds = new FolderId[] { parentFolderId }; + + EwsUtilities.ValidateParamCollection(parentFolderIds, "parentFolderIds"); + EwsUtilities.ValidateParam(view, "view"); + EwsUtilities.ValidateParam(groupBy, "groupBy"); + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + EwsUtilities.ValidateParamAllowNull(returnHighlightTerms, "returnHighlightTerms"); + EwsUtilities.ValidateMethodVersion(this, ExchangeVersion.Exchange2013, "FindItems"); + + FindItemRequest request = new FindItemRequest(this, ServiceErrorHandling.ThrowOnError); + + request.ParentFolderIds.AddRange(parentFolderIds); + request.QueryString = queryString; + request.ReturnHighlightTerms = returnHighlightTerms; + request.View = view; + request.GroupBy = groupBy; + + ServiceResponseCollection> responses = await request.ExecuteAsync(); + return responses[0].GroupedFindResults; + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1000,6 +1306,30 @@ public FindItemsResults FindItems(FolderId parentFolderId, SearchFilter se return responses[0].Results; } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(FolderId parentFolderId, SearchFilter searchFilter, ViewBase view) + { + EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter"); + + ServiceResponseCollection> responses = await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + searchFilter, + null, /* queryString */ + view, + null, /* groupBy */ + ServiceErrorHandling.ThrowOnError); + + return responses[0].Results; + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1019,6 +1349,25 @@ public FindItemsResults FindItems(FolderId parentFolderId, ViewBase view) return responses[0].Results; } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(FolderId parentFolderId, ViewBase view) + { + ServiceResponseCollection> responses = await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + null, /* queryString */ + view, + null, /* groupBy */ + ServiceErrorHandling.ThrowOnError); + + return responses[0].Results; + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1031,6 +1380,18 @@ public FindItemsResults FindItems(WellKnownFolderName parentFolderName, st return this.FindItems(new FolderId(parentFolderName), queryString, view); } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The name of the folder in which to search for items. + /// query string to be used for indexed search + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(WellKnownFolderName parentFolderName, string queryString, ViewBase view) + { + return await this.FindItemsAsync(new FolderId(parentFolderName), queryString, view); + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1048,6 +1409,23 @@ public FindItemsResults FindItems(WellKnownFolderName parentFolderName, Se view); } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The name of the folder in which to search for items. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(WellKnownFolderName parentFolderName, SearchFilter searchFilter, ViewBase view) + { + return await this.FindItemsAsync( + new FolderId(parentFolderName), + searchFilter, + view); + } + /// /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1062,27 +1440,99 @@ public FindItemsResults FindItems(WellKnownFolderName parentFolderName, Vi view); } + /// + /// Obtains a list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The name of the folder in which to search for items. + /// The view controlling the number of items returned. + /// An object representing the results of the search operation. + public async System.Threading.Tasks.Task> FindItemsAsync(WellKnownFolderName parentFolderName, ViewBase view) + { + return await this.FindItemsAsync( + new FolderId(parentFolderName), + (SearchFilter)null, + view); + } + + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// query string to be used for indexed search + /// The view controlling the number of items returned. + /// The group by clause. + /// A list of items containing the contents of the specified folder. + public GroupedFindItemsResults FindItems( + FolderId parentFolderId, + string queryString, + ViewBase view, + Grouping groupBy) + { + EwsUtilities.ValidateParam(groupBy, "groupBy"); + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + + ServiceResponseCollection> responses = this.FindItems( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + queryString, + view, + groupBy, + ServiceErrorHandling.ThrowOnError); + + return responses[0].GroupedFindResults; + } + + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// query string to be used for indexed search + /// The view controlling the number of items returned. + /// The group by clause. + /// A list of items containing the contents of the specified folder. + public async System.Threading.Tasks.Task> FindItemsAsync( + FolderId parentFolderId, + string queryString, + ViewBase view, + Grouping groupBy) + { + EwsUtilities.ValidateParam(groupBy, "groupBy"); + EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + + ServiceResponseCollection> responses = await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + queryString, + view, + groupBy, + ServiceErrorHandling.ThrowOnError); + + return responses[0].GroupedFindResults; + } + /// /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// /// The Id of the folder in which to search for items. - /// query string to be used for indexed search + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection /// The view controlling the number of items returned. /// The group by clause. /// A list of items containing the contents of the specified folder. public GroupedFindItemsResults FindItems( FolderId parentFolderId, - string queryString, + SearchFilter searchFilter, ViewBase view, Grouping groupBy) { EwsUtilities.ValidateParam(groupBy, "groupBy"); - EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); + EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter"); ServiceResponseCollection> responses = this.FindItems( new FolderId[] { parentFolderId }, - null, /* searchFilter */ - queryString, + searchFilter, + null, /* queryString */ view, groupBy, ServiceErrorHandling.ThrowOnError); @@ -1100,7 +1550,7 @@ public GroupedFindItemsResults FindItems( /// The view controlling the number of items returned. /// The group by clause. /// A list of items containing the contents of the specified folder. - public GroupedFindItemsResults FindItems( + public async System.Threading.Tasks.Task> FindItemsAsync( FolderId parentFolderId, SearchFilter searchFilter, ViewBase view, @@ -1109,7 +1559,7 @@ public GroupedFindItemsResults FindItems( EwsUtilities.ValidateParam(groupBy, "groupBy"); EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter"); - ServiceResponseCollection> responses = this.FindItems( + ServiceResponseCollection> responses = await this.FindItemsAsync( new FolderId[] { parentFolderId }, searchFilter, null, /* queryString */ @@ -1145,6 +1595,31 @@ public GroupedFindItemsResults FindItems( return responses[0].GroupedFindResults; } + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// The view controlling the number of items returned. + /// The group by clause. + /// A list of items containing the contents of the specified folder. + public async System.Threading.Tasks.Task> FindItemsAsync( + FolderId parentFolderId, + ViewBase view, + Grouping groupBy) + { + EwsUtilities.ValidateParam(groupBy, "groupBy"); + + ServiceResponseCollection> responses = await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + null, /* searchFilter */ + null, /* queryString */ + view, + groupBy, + ServiceErrorHandling.ThrowOnError); + + return responses[0].GroupedFindResults; + } + /// /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1172,6 +1647,33 @@ internal ServiceResponseCollection> FindItems( ServiceErrorHandling.ThrowOnError); } + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The Id of the folder in which to search for items. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of items returned. + /// The group by clause. + /// Type of item. + /// A list of items containing the contents of the specified folder. + internal async System.Threading.Tasks.Task>> FindItemsAsync( + FolderId parentFolderId, + SearchFilter searchFilter, + ViewBase view, + Grouping groupBy) + where TItem : Item + { + return await this.FindItemsAsync( + new FolderId[] { parentFolderId }, + searchFilter, + null, /* queryString */ + view, + groupBy, + ServiceErrorHandling.ThrowOnError); + } + /// /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1195,6 +1697,29 @@ public GroupedFindItemsResults FindItems( groupBy); } + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The name of the folder in which to search for items. + /// query string to be used for indexed search + /// The view controlling the number of items returned. + /// The group by clause. + /// A collection of grouped items representing the contents of the specified. + public async System.Threading.Tasks.Task> FindItemsAsync( + WellKnownFolderName parentFolderName, + string queryString, + ViewBase view, + Grouping groupBy) + { + EwsUtilities.ValidateParam(groupBy, "groupBy"); + + return await this.FindItemsAsync( + new FolderId(parentFolderName), + queryString, + view, + groupBy); + } + /// /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1218,6 +1743,29 @@ public GroupedFindItemsResults FindItems( groupBy); } + /// + /// Obtains a grouped list of items by searching the contents of a specific folder. Calling this method results in a call to EWS. + /// + /// The name of the folder in which to search for items. + /// The search filter. Available search filter classes + /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and + /// SearchFilter.SearchFilterCollection + /// The view controlling the number of items returned. + /// The group by clause. + /// A collection of grouped items representing the contents of the specified. + public async System.Threading.Tasks.Task> FindItemsAsync( + WellKnownFolderName parentFolderName, + SearchFilter searchFilter, + ViewBase view, + Grouping groupBy) + { + return await this.FindItemsAsync( + new FolderId(parentFolderName), + searchFilter, + view, + groupBy); + } + /// /// Obtains a list of appointments by searching the contents of a specific folder. Calling this method results in a call to EWS. /// @@ -1308,6 +1856,29 @@ 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 +1944,26 @@ 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 +1990,32 @@ 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. /// @@ -1734,7 +2351,7 @@ public GetUserPhotoResults GetUserPhoto(string emailAddress, string userPhotoSiz /// An IAsyncResult that references the asynchronous request. public IAsyncResult BeginGetUserPhoto( AsyncCallback callback, - object state, + object state, string emailAddress, string userPhotoSize, string entityTag) @@ -1810,6 +2427,33 @@ 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 +2473,25 @@ 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 +2517,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 +2560,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. /// @@ -2006,7 +2712,7 @@ public NameResolutionCollection ResolveName( returnContactDetails, contactDataPropertySet); } - + /// /// Finds contacts in the Global Address List that have names that match the one passed as a parameter. /// Calling this method results in a call to EWS. @@ -3453,7 +4159,7 @@ public FindConversationResults FindConversation(ViewBase view, FolderId folderId EwsUtilities.ValidateParamAllowNull(queryString, "queryString"); EwsUtilities.ValidateParam(returnHighlightTerms, "returnHighlightTerms"); EwsUtilities.ValidateParam(folderId, "folderId"); - + EwsUtilities.ValidateMethodVersion( this, ExchangeVersion.Exchange2013, // This method is only applicable for Exchange2013 @@ -5405,7 +6111,7 @@ public int GetUnifiedGroupUnseenCount(string groupMailboxSmtpAddress, DateTime l GetUnifiedGroupUnseenCountRequest request = new GetUnifiedGroupUnseenCountRequest( this, lastVisitedTimeUtc, UnifiedGroupIdentityType.SmtpAddress, groupMailboxSmtpAddress); - + request.AnchorMailbox = groupMailboxSmtpAddress; return request.Execute().UnseenCount; 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 2381628e..837d83c8 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 d7675a1e..275701ea 100644 --- a/Microsoft.Exchange.WebServices.Data.csproj +++ b/Microsoft.Exchange.WebServices.Data.csproj @@ -1,5 +1,5 @@ - + Debug AnyCPU @@ -15,7 +15,7 @@ 4.0 - v3.5 + v4.6 publish\ true Disk