From 1c547cb8eca2dc16d57c9067df6afafaf2fa6e2e Mon Sep 17 00:00:00 2001 From: Michael Bisbjerg Date: Fri, 24 Nov 2017 21:21:08 +0100 Subject: [PATCH 1/2] Add async variants to all methods Fixes #231 --- TMDbLib/Client/TMDbClient.cs | 3 +- TMDbLib/Client/TMDbClientAccount.cs | 56 ++++----- TMDbLib/Client/TMDbClientAuthentication.cs | 25 ++-- TMDbLib/Client/TMDbClientCertifications.cs | 18 +-- TMDbLib/Client/TMDbClientChanges.cs | 21 ++-- TMDbLib/Client/TMDbClientCollections.cs | 17 +-- TMDbLib/Client/TMDbClientCompanies.cs | 17 +-- TMDbLib/Client/TMDbClientCredit.cs | 11 +- TMDbLib/Client/TMDbClientDiscover.cs | 5 +- TMDbLib/Client/TMDbClientFind.cs | 5 +- TMDbLib/Client/TMDbClientGenres.cs | 25 ++-- TMDbLib/Client/TMDbClientGuestSessions.cs | 27 ++--- TMDbLib/Client/TMDbClientJobs.cs | 5 +- TMDbLib/Client/TMDbClientKeywords.cs | 15 +-- TMDbLib/Client/TMDbClientLists.cs | 33 +++--- TMDbLib/Client/TMDbClientMovies.cs | 129 +++++++++++---------- TMDbLib/Client/TMDbClientNetworks.cs | 5 +- TMDbLib/Client/TMDbClientPeople.cs | 53 ++++----- TMDbLib/Client/TMDbClientReviews.cs | 7 +- TMDbLib/Client/TMDbClientSearch.cs | 51 ++++---- TMDbLib/Client/TMDbClientTimezones.cs | 5 +- TMDbLib/Client/TMDbClientTvEpisodes.cs | 45 +++---- TMDbLib/Client/TMDbClientTvSeasons.cs | 33 +++--- TMDbLib/Client/TMDbClientTvShows.cs | 105 ++++++++--------- TMDbLib/Objects/Discover/DiscoverBase.cs | 11 +- TMDbLib/Rest/RestRequest.cs | 33 +++--- 26 files changed, 394 insertions(+), 366 deletions(-) diff --git a/TMDbLib/Client/TMDbClient.cs b/TMDbLib/Client/TMDbClient.cs index 11a1fa22..c5d838e7 100644 --- a/TMDbLib/Client/TMDbClient.cs +++ b/TMDbLib/Client/TMDbClient.cs @@ -8,6 +8,7 @@ using RestClient = TMDbLib.Rest.RestClient; using RestRequest = TMDbLib.Rest.RestRequest; using System.Net; +using System.Threading; namespace TMDbLib.Client { @@ -165,7 +166,7 @@ private void AddSessionId(RestRequest req, SessionType targetType = SessionType. public void GetConfig() { - TMDbConfig config = _client.Create("configuration").ExecuteGet().Result; + TMDbConfig config = _client.Create("configuration").ExecuteGet(CancellationToken.None).Result; if (config == null) throw new Exception("Unable to retrieve configuration"); diff --git a/TMDbLib/Client/TMDbClientAccount.cs b/TMDbLib/Client/TMDbClientAccount.cs index c24bf4bb..b991d00e 100644 --- a/TMDbLib/Client/TMDbClientAccount.cs +++ b/TMDbLib/Client/TMDbClientAccount.cs @@ -1,5 +1,6 @@ using TMDbLib.Utilities; using System.Globalization; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Account; using TMDbLib.Objects.Authentication; @@ -18,19 +19,20 @@ public partial class TMDbClient /// The type of media to influence /// The id of the movie/tv show to influence /// True if you want the specified movie to be marked as favorite, false if not + /// Cancellation token /// True if the the movie's favorite status was successfully updated, false if not /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task AccountChangeFavoriteStatusAsync(MediaType mediaType, int mediaId, bool isFavorite) + public async Task AccountChangeFavoriteStatusAsync(MediaType mediaType, int mediaId, bool isFavorite, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); - RestRequest request = _client.Create("account/{accountId}/favorite") ; + RestRequest request = _client.Create("account/{accountId}/favorite"); request.AddUrlSegment("accountId", ActiveAccount.Id.ToString(CultureInfo.InvariantCulture)); request.SetBody(new { media_type = mediaType.GetDescription(), media_id = mediaId, favorite = isFavorite }); AddSessionId(request, SessionType.UserSession); - PostReply response = await request.ExecutePost().ConfigureAwait(false); + PostReply response = await request.ExecutePost(cancellationToken).ConfigureAwait(false); // status code 1 = "Success" - Returned when adding a movie as favorite for the first time // status code 13 = "The item/record was deleted successfully" - When removing an item as favorite, no matter if it exists or not @@ -47,16 +49,16 @@ public async Task AccountChangeFavoriteStatusAsync(MediaType mediaType, in /// True if the the movie's status on the watchlist was successfully updated, false if not /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task AccountChangeWatchlistStatusAsync(MediaType mediaType, int mediaId, bool isOnWatchlist) + public async Task AccountChangeWatchlistStatusAsync(MediaType mediaType, int mediaId, bool isOnWatchlist, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); - RestRequest request = _client.Create("account/{accountId}/watchlist"); + RestRequest request = _client.Create("account/{accountId}/watchlist"); request.AddUrlSegment("accountId", ActiveAccount.Id.ToString(CultureInfo.InvariantCulture)); request.SetBody(new { media_type = mediaType.GetDescription(), media_id = mediaId, watchlist = isOnWatchlist }); AddSessionId(request, SessionType.UserSession); - PostReply response = await request.ExecutePost().ConfigureAwait(false); + PostReply response = await request.ExecutePost(cancellationToken).ConfigureAwait(false); // status code 1 = "Success" // status code 13 = "The item/record was deleted successfully" - When removing an item from the watchlist, no matter if it exists or not @@ -69,14 +71,14 @@ public async Task AccountChangeWatchlistStatusAsync(MediaType mediaType, i /// /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task AccountGetDetailsAsync() + public async Task AccountGetDetailsAsync(CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); RestRequest request = _client.Create("account"); AddSessionId(request, SessionType.UserSession); - AccountDetails response = await request.ExecuteGet().ConfigureAwait(false); + AccountDetails response = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } @@ -90,9 +92,9 @@ public async Task> AccountGetFavoriteMoviesAsync( int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.FavoriteMovies).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.FavoriteMovies, cancellationToken).ConfigureAwait(false); } /// @@ -104,9 +106,9 @@ public async Task> AccountGetFavoriteTvAsync( int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.FavoriteTv).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.FavoriteTv, cancellationToken).ConfigureAwait(false); } /// @@ -115,7 +117,7 @@ public async Task> AccountGetFavoriteTvAsync( /// /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task> AccountGetListsAsync(int page = 1, string language = null) + public async Task> AccountGetListsAsync(int page = 1, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -132,7 +134,7 @@ public async Task> AccountGetListsAsync(int page = if (!string.IsNullOrWhiteSpace(language)) request.AddQueryString("language", language); - SearchContainer response = await request.ExecuteGet>().ConfigureAwait(false); + SearchContainer response = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return response; } @@ -146,9 +148,9 @@ public async Task> AccountGetMovieWatchlistAsync( int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.MovieWatchlist).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.MovieWatchlist, cancellationToken).ConfigureAwait(false); } /// @@ -160,9 +162,9 @@ public async Task> AccountGetRatedMoviesA int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedMovies).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedMovies, cancellationToken).ConfigureAwait(false); } /// @@ -174,9 +176,9 @@ public async Task> AccountGetRatedTvShow int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedTvEpisodes).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedTvEpisodes, cancellationToken).ConfigureAwait(false); } /// @@ -188,9 +190,9 @@ public async Task> AccountGetRatedTvShowsAsync( int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedTv).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.RatedTv, cancellationToken).ConfigureAwait(false); } /// @@ -202,16 +204,16 @@ public async Task> AccountGetTvWatchlistAsync( int page = 1, AccountSortBy sortBy = AccountSortBy.Undefined, SortOrder sortOrder = SortOrder.Undefined, - string language = null) + string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.TvWatchlist).ConfigureAwait(false); + return await GetAccountList(page, sortBy, sortOrder, language, AccountListsMethods.TvWatchlist, cancellationToken).ConfigureAwait(false); } - private async Task> GetAccountList(int page, AccountSortBy sortBy, SortOrder sortOrder, string language, AccountListsMethods method) + private async Task> GetAccountList(int page, AccountSortBy sortBy, SortOrder sortOrder, string language, AccountListsMethods method, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); - RestRequest request = _client.Create("account/{accountId}/" + method.GetDescription()); + RestRequest request = _client.Create("account/{accountId}/" + method.GetDescription()); request.AddUrlSegment("accountId", ActiveAccount.Id.ToString(CultureInfo.InvariantCulture)); AddSessionId(request, SessionType.UserSession); @@ -228,7 +230,7 @@ private async Task> GetAccountList(int page, AccountSortBy if (!string.IsNullOrWhiteSpace(language)) request.AddParameter("language", language); - SearchContainer response = await request.ExecuteGet>().ConfigureAwait(false); + SearchContainer response = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return response; } diff --git a/TMDbLib/Client/TMDbClientAuthentication.cs b/TMDbLib/Client/TMDbClientAuthentication.cs index b128c351..f9001142 100644 --- a/TMDbLib/Client/TMDbClientAuthentication.cs +++ b/TMDbLib/Client/TMDbClientAuthentication.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using System.Net; +using System.Threading; using TMDbLib.Objects.Authentication; using TMDbLib.Rest; @@ -8,24 +9,24 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task AuthenticationCreateGuestSessionAsync() + public async Task AuthenticationCreateGuestSessionAsync(CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create("authentication/guest_session/new"); //{ // DateFormat = "yyyy-MM-dd HH:mm:ss UTC" //}; - RestResponse response = await request.ExecuteGet().ConfigureAwait(false); + RestResponse response = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } - public async Task AuthenticationGetUserSessionAsync(string initialRequestToken) + public async Task AuthenticationGetUserSessionAsync(string initialRequestToken, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create("authentication/session/new"); request.AddParameter("request_token", initialRequestToken); - RestResponse response = await request.ExecuteGet().ConfigureAwait(false); + RestResponse response = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.Unauthorized) throw new UnauthorizedAccessException(); @@ -38,18 +39,18 @@ public async Task AuthenticationGetUserSessionAsync(string initialR /// /// A valid TMDb username /// The passoword for the provided login - public async Task AuthenticationGetUserSessionAsync(string username, string password) + public async Task AuthenticationGetUserSessionAsync(string username, string password, CancellationToken cancellationToken = default(CancellationToken)) { - Token token = await AuthenticationRequestAutenticationTokenAsync().ConfigureAwait(false); - await AuthenticationValidateUserTokenAsync(token.RequestToken, username, password).ConfigureAwait(false); - return await AuthenticationGetUserSessionAsync(token.RequestToken).ConfigureAwait(false); + Token token = await AuthenticationRequestAutenticationTokenAsync(cancellationToken).ConfigureAwait(false); + await AuthenticationValidateUserTokenAsync(token.RequestToken, username, password, cancellationToken).ConfigureAwait(false); + return await AuthenticationGetUserSessionAsync(token.RequestToken, cancellationToken).ConfigureAwait(false); } - public async Task AuthenticationRequestAutenticationTokenAsync() + public async Task AuthenticationRequestAutenticationTokenAsync(CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create("authentication/token/new"); - RestResponse response = await request.ExecuteGet().ConfigureAwait(false); + RestResponse response = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); Token token = response; token.AuthenticationCallback = response.GetHeader("Authentication-Callback"); @@ -57,7 +58,7 @@ public async Task AuthenticationRequestAutenticationTokenAsync() return token; } - public async Task AuthenticationValidateUserTokenAsync(string initialRequestToken, string username, string password) + public async Task AuthenticationValidateUserTokenAsync(string initialRequestToken, string username, string password, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create("authentication/token/validate_with_login"); request.AddParameter("request_token", initialRequestToken); @@ -67,7 +68,7 @@ public async Task AuthenticationValidateUserTokenAsync(string initialRequestToke RestResponse response; try { - response = await request.ExecuteGet().ConfigureAwait(false); + response = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); } catch (AggregateException ex) { diff --git a/TMDbLib/Client/TMDbClientCertifications.cs b/TMDbLib/Client/TMDbClientCertifications.cs index 4d931ea2..8267acee 100644 --- a/TMDbLib/Client/TMDbClientCertifications.cs +++ b/TMDbLib/Client/TMDbClientCertifications.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.Certifications; using TMDbLib.Rest; @@ -6,19 +7,20 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetMovieCertificationsAsync() + public async Task GetMovieCertificationsAsync(CancellationToken cancellationToken = default(CancellationToken)) { - RestRequest req = _client.Create("certification/movie/list"); + RestRequest req = _client.Create("certification/movie/list"); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); - return resp;} + return resp; + } - public async Task GetTvCertificationsAsync() + public async Task GetTvCertificationsAsync(CancellationToken cancellationToken = default(CancellationToken)) { - RestRequest req = _client.Create("certification/tv/list"); + RestRequest req = _client.Create("certification/tv/list"); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientChanges.cs b/TMDbLib/Client/TMDbClientChanges.cs index f2a7d9a0..bfd8bcbe 100644 --- a/TMDbLib/Client/TMDbClientChanges.cs +++ b/TMDbLib/Client/TMDbClientChanges.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Changes; using TMDbLib.Objects.General; @@ -8,7 +9,7 @@ namespace TMDbLib.Client { public partial class TMDbClient { - private async Task GetChanges(string type, int page = 0, DateTime? startDate = null, DateTime? endDate = null) where T : new() + private async Task GetChanges(string type, int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("{type}/changes"); req.AddUrlSegment("type", type); @@ -20,7 +21,7 @@ public partial class TMDbClient if (endDate != null) req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } @@ -32,9 +33,9 @@ public partial class TMDbClient /// You can then use the movie changes API to get the actual data that has been changed. (.GetMovieChangesAsync) /// /// the change log system to support this was changed on October 5, 2012 and will only show movies that have been edited since. - public async Task> GetChangesMoviesAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null) + public async Task> GetChangesMoviesAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetChanges>("movie", page, startDate, endDate).ConfigureAwait(false); + return await GetChanges>("movie", page, startDate, endDate, cancellationToken).ConfigureAwait(false); } /// @@ -44,9 +45,9 @@ public async Task> GetChangesMoviesAsync(int pa /// You can then use the person changes API to get the actual data that has been changed.(.GetPersonChangesAsync) /// /// the change log system to support this was changed on October 5, 2012 and will only show people that have been edited since. - public async Task> GetChangesPeopleAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null) + public async Task> GetChangesPeopleAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetChanges>("person", page, startDate, endDate).ConfigureAwait(false); + return await GetChanges>("person", page, startDate, endDate, cancellationToken).ConfigureAwait(false); } /// @@ -59,9 +60,9 @@ public async Task> GetChangesPeopleAsync(int pa /// the change log system to properly support TV was updated on May 13, 2014. /// You'll likely only find the edits made since then to be useful in the change log system. /// - public async Task> GetChangesTvAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null) - { - return await GetChanges>("tv", page, startDate, endDate).ConfigureAwait(false); - } + public async Task> GetChangesTvAsync(int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return await GetChanges>("tv", page, startDate, endDate, cancellationToken).ConfigureAwait(false); + } } } \ No newline at end of file diff --git a/TMDbLib/Client/TMDbClientCollections.cs b/TMDbLib/Client/TMDbClientCollections.cs index 6a4c3bac..e8d122ee 100644 --- a/TMDbLib/Client/TMDbClientCollections.cs +++ b/TMDbLib/Client/TMDbClientCollections.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Collections; using TMDbLib.Objects.General; @@ -10,12 +11,12 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetCollectionAsync(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined) + public async Task GetCollectionAsync(int collectionId, CollectionMethods extraMethods = CollectionMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetCollectionAsync(collectionId, DefaultLanguage, extraMethods).ConfigureAwait(false); + return await GetCollectionAsync(collectionId, DefaultLanguage, extraMethods, cancellationToken).ConfigureAwait(false); } - public async Task GetCollectionAsync(int collectionId, string language, CollectionMethods extraMethods = CollectionMethods.Undefined) + public async Task GetCollectionAsync(int collectionId, string language, CollectionMethods extraMethods = CollectionMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("collection/{collectionId}"); req.AddUrlSegment("collectionId", collectionId.ToString()); @@ -36,17 +37,17 @@ public async Task GetCollectionAsync(int collectionId, string langua //req.DateFormat = "yyyy-MM-dd"; - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task GetCollectionImagesAsync(int collectionId, string language = null) + public async Task GetCollectionImagesAsync(int collectionId, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetCollectionMethod(collectionId, CollectionMethods.Images, language).ConfigureAwait(false); + return await GetCollectionMethod(collectionId, CollectionMethods.Images, language, cancellationToken).ConfigureAwait(false); } - private async Task GetCollectionMethod(int collectionId, CollectionMethods collectionMethod, string language = null) where T : new() + private async Task GetCollectionMethod(int collectionId, CollectionMethods collectionMethod, string language = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("collection/{collectionId}/{method}"); req.AddUrlSegment("collectionId", collectionId.ToString()); @@ -55,7 +56,7 @@ public async Task GetCollectionImagesAsync(int collectionId, strin if (language != null) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientCompanies.cs b/TMDbLib/Client/TMDbClientCompanies.cs index aebc01ff..cdc8498c 100644 --- a/TMDbLib/Client/TMDbClientCompanies.cs +++ b/TMDbLib/Client/TMDbClientCompanies.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Companies; using TMDbLib.Objects.General; @@ -11,7 +12,7 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetCompanyAsync(int companyId, CompanyMethods extraMethods = CompanyMethods.Undefined) + public async Task GetCompanyAsync(int companyId, CompanyMethods extraMethods = CompanyMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("company/{companyId}"); req.AddUrlSegment("companyId", companyId.ToString()); @@ -28,12 +29,12 @@ public async Task GetCompanyAsync(int companyId, CompanyMethods extraMe //req.DateFormat = "yyyy-MM-dd"; - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - private async Task GetCompanyMethod(int companyId, CompanyMethods companyMethod, int page = 0, string language = null) where T : new() + private async Task GetCompanyMethod(int companyId, CompanyMethods companyMethod, int page = 0, string language = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("company/{companyId}/{method}"); req.AddUrlSegment("companyId", companyId.ToString()); @@ -45,19 +46,19 @@ public async Task GetCompanyAsync(int companyId, CompanyMethods extraMe if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetCompanyMoviesAsync(int companyId, int page = 0) + public async Task> GetCompanyMoviesAsync(int companyId, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetCompanyMoviesAsync(companyId, DefaultLanguage, page).ConfigureAwait(false); + return await GetCompanyMoviesAsync(companyId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetCompanyMoviesAsync(int companyId, string language, int page = 0) + public async Task> GetCompanyMoviesAsync(int companyId, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetCompanyMethod>(companyId, CompanyMethods.Movies, page, language).ConfigureAwait(false); + return await GetCompanyMethod>(companyId, CompanyMethods.Movies, page, language, cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/TMDbLib/Client/TMDbClientCredit.cs b/TMDbLib/Client/TMDbClientCredit.cs index 132b120f..1846529f 100644 --- a/TMDbLib/Client/TMDbClientCredit.cs +++ b/TMDbLib/Client/TMDbClientCredit.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.Credit; using TMDbLib.Rest; @@ -6,12 +7,12 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetCreditsAsync(string id) + public async Task GetCreditsAsync(string id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetCreditsAsync(id, DefaultLanguage).ConfigureAwait(false); + return await GetCreditsAsync(id, DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task GetCreditsAsync(string id, string language) + public async Task GetCreditsAsync(string id, string language, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("credit/{id}"); @@ -20,7 +21,7 @@ public async Task GetCreditsAsync(string id, string language) req.AddUrlSegment("id", id); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientDiscover.cs b/TMDbLib/Client/TMDbClientDiscover.cs index 7c032700..ec2f0a87 100644 --- a/TMDbLib/Client/TMDbClientDiscover.cs +++ b/TMDbLib/Client/TMDbClientDiscover.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Discover; using TMDbLib.Objects.General; @@ -17,7 +18,7 @@ public DiscoverMovie DiscoverMoviesAsync() return new DiscoverMovie(this); } - internal async Task> DiscoverPerformAsync(string endpoint, string language, int page, SimpleNamedValueCollection parameters) + internal async Task> DiscoverPerformAsync(string endpoint, string language, int page, SimpleNamedValueCollection parameters, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create(endpoint); @@ -30,7 +31,7 @@ internal async Task> DiscoverPerformAsync(string endpoint, foreach (KeyValuePair pair in parameters) request.AddParameter(pair.Key, pair.Value); - RestResponse> response = await request.ExecuteGet>().ConfigureAwait(false); + RestResponse> response = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return response; } diff --git a/TMDbLib/Client/TMDbClientFind.cs b/TMDbLib/Client/TMDbClientFind.cs index 8a9ed11b..69c59a9a 100644 --- a/TMDbLib/Client/TMDbClientFind.cs +++ b/TMDbLib/Client/TMDbClientFind.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Find; using TMDbLib.Rest; @@ -18,7 +19,7 @@ public partial class TMDbClient /// The source the specified id belongs to /// The id of the object you wish to located /// A list of all objects in TMDb that matched your id - public async Task FindAsync(FindExternalSource source, string id) + public async Task FindAsync(FindExternalSource source, string id, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("find/{id}"); @@ -30,7 +31,7 @@ public async Task FindAsync(FindExternalSource source, string id) req.AddParameter("external_source", source.GetDescription()); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientGenres.cs b/TMDbLib/Client/TMDbClientGenres.cs index 996882b6..003019cb 100644 --- a/TMDbLib/Client/TMDbClientGenres.cs +++ b/TMDbLib/Client/TMDbClientGenres.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.General; using TMDbLib.Objects.Genres; @@ -9,12 +10,12 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task> GetGenreMoviesAsync(int genreId, int page = 0, bool? includeAllMovies = null) + public async Task> GetGenreMoviesAsync(int genreId, int page = 0, bool? includeAllMovies = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetGenreMoviesAsync(genreId, DefaultLanguage, page, includeAllMovies).ConfigureAwait(false); + return await GetGenreMoviesAsync(genreId, DefaultLanguage, page, includeAllMovies, cancellationToken).ConfigureAwait(false); } - public async Task> GetGenreMoviesAsync(int genreId, string language, int page = 0, bool? includeAllMovies = null) + public async Task> GetGenreMoviesAsync(int genreId, string language, int page = 0, bool? includeAllMovies = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("genre/{genreId}/movies"); req.AddUrlSegment("genreId", genreId.ToString()); @@ -28,17 +29,17 @@ public async Task> GetGenreMoviesAsync(int ge if (includeAllMovies.HasValue) req.AddParameter("include_all_movies", includeAllMovies.Value ? "true" : "false"); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetMovieGenresAsync() + public async Task> GetMovieGenresAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieGenresAsync(DefaultLanguage).ConfigureAwait(false); + return await GetMovieGenresAsync(DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieGenresAsync(string language) + public async Task> GetMovieGenresAsync(string language, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("genre/movie/list"); @@ -46,17 +47,17 @@ public async Task> GetMovieGenresAsync(string language) if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return (await resp.GetDataObject().ConfigureAwait(false)).Genres; } - public async Task> GetTvGenresAsync() + public async Task> GetTvGenresAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvGenresAsync(DefaultLanguage).ConfigureAwait(false); + return await GetTvGenresAsync(DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task> GetTvGenresAsync(string language) + public async Task> GetTvGenresAsync(string language, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("genre/tv/list"); @@ -64,7 +65,7 @@ public async Task> GetTvGenresAsync(string language) if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return (await resp.GetDataObject().ConfigureAwait(false)).Genres; } diff --git a/TMDbLib/Client/TMDbClientGuestSessions.cs b/TMDbLib/Client/TMDbClientGuestSessions.cs index b9c151a9..633eaa85 100644 --- a/TMDbLib/Client/TMDbClientGuestSessions.cs +++ b/TMDbLib/Client/TMDbClientGuestSessions.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.General; using TMDbLib.Objects.Search; @@ -9,12 +10,12 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task> GetGuestSessionRatedMoviesAsync(int page = 0) + public async Task> GetGuestSessionRatedMoviesAsync(int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetGuestSessionRatedMoviesAsync(DefaultLanguage, page).ConfigureAwait(false); + return await GetGuestSessionRatedMoviesAsync(DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetGuestSessionRatedMoviesAsync(string language, int page = 0) + public async Task> GetGuestSessionRatedMoviesAsync(string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -28,17 +29,17 @@ public async Task> GetGuestSessionRatedMo AddSessionId(request, SessionType.GuestSession, ParameterType.UrlSegment); - RestResponse> resp = await request.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetGuestSessionRatedTvAsync(int page = 0) + public async Task> GetGuestSessionRatedTvAsync(int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetGuestSessionRatedTvAsync(DefaultLanguage, page).ConfigureAwait(false); + return await GetGuestSessionRatedTvAsync(DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetGuestSessionRatedTvAsync(string language, int page = 0) + public async Task> GetGuestSessionRatedTvAsync(string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -52,17 +53,17 @@ public async Task> GetGuestSessionRatedT AddSessionId(request, SessionType.GuestSession, ParameterType.UrlSegment); - RestResponse> resp = await request.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetGuestSessionRatedTvEpisodesAsync(int page = 0) + public async Task> GetGuestSessionRatedTvEpisodesAsync(int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetGuestSessionRatedTvEpisodesAsync(DefaultLanguage, page).ConfigureAwait(false); + return await GetGuestSessionRatedTvEpisodesAsync(DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetGuestSessionRatedTvEpisodesAsync(string language, int page = 0) + public async Task> GetGuestSessionRatedTvEpisodesAsync(string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -76,7 +77,7 @@ public async Task> GetGuestSessionRatedTvEp AddSessionId(request, SessionType.GuestSession, ParameterType.UrlSegment); - RestResponse> resp = await request.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await request.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientJobs.cs b/TMDbLib/Client/TMDbClientJobs.cs index b36f6953..4f664cee 100644 --- a/TMDbLib/Client/TMDbClientJobs.cs +++ b/TMDbLib/Client/TMDbClientJobs.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.General; using TMDbLib.Objects.Jobs; @@ -12,11 +13,11 @@ public partial class TMDbClient /// Retrieves a list of departments and positions within /// /// Valid jobs and their departments - public async Task> GetJobsAsync() + public async Task> GetJobsAsync(CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("job/list"); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return (await response.GetDataObject().ConfigureAwait(false)).Jobs; } diff --git a/TMDbLib/Client/TMDbClientKeywords.cs b/TMDbLib/Client/TMDbClientKeywords.cs index 5508927f..ed4853ae 100644 --- a/TMDbLib/Client/TMDbClientKeywords.cs +++ b/TMDbLib/Client/TMDbClientKeywords.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.General; using TMDbLib.Objects.Search; using TMDbLib.Rest; @@ -7,22 +8,22 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetKeywordAsync(int keywordId) + public async Task GetKeywordAsync(int keywordId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("keyword/{keywordId}"); req.AddUrlSegment("keywordId", keywordId.ToString()); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetKeywordMoviesAsync(int keywordId, int page = 0) + public async Task> GetKeywordMoviesAsync(int keywordId, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetKeywordMoviesAsync(keywordId, DefaultLanguage, page).ConfigureAwait(false); + return await GetKeywordMoviesAsync(keywordId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetKeywordMoviesAsync(int keywordId, string language, int page = 0) + public async Task> GetKeywordMoviesAsync(int keywordId, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("keyword/{keywordId}/movies"); req.AddUrlSegment("keywordId", keywordId.ToString()); @@ -34,7 +35,7 @@ public async Task> GetKeywordMoviesAsync(int if (page >= 1) req.AddParameter("page", page.ToString()); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientLists.cs b/TMDbLib/Client/TMDbClientLists.cs index 558d2cb2..c9b0c00e 100644 --- a/TMDbLib/Client/TMDbClientLists.cs +++ b/TMDbLib/Client/TMDbClientLists.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.General; @@ -13,7 +14,7 @@ public partial class TMDbClient /// Retrieve a list by it's id /// /// The id of the list you want to retrieve - public async Task GetListAsync(string listId) + public async Task GetListAsync(string listId, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(listId)) throw new ArgumentNullException(nameof(listId)); @@ -21,7 +22,7 @@ public async Task GetListAsync(string listId) RestRequest req = _client.Create("list/{listId}"); req.AddUrlSegment("listId", listId); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } @@ -31,7 +32,7 @@ public async Task GetListAsync(string listId) /// /// Id of the list to check in /// Id of the movie to check for in the list - public async Task GetListIsMoviePresentAsync(string listId, int movieId) + public async Task GetListIsMoviePresentAsync(string listId, int movieId, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(listId)) throw new ArgumentNullException(nameof(listId)); @@ -43,7 +44,7 @@ public async Task GetListIsMoviePresentAsync(string listId, int movieId) req.AddUrlSegment("listId", listId); req.AddParameter("movie_id", movieId.ToString()); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return (await response.GetDataObject().ConfigureAwait(false)).ItemPresent; } @@ -56,9 +57,9 @@ public async Task GetListIsMoviePresentAsync(string listId, int movieId) /// True if the method was able to add the movie to the list, will retrun false in case of an issue or when the movie was already added to the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task ListAddMovieAsync(string listId, int movieId) + public async Task ListAddMovieAsync(string listId, int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await ManipulateMediaListAsync(listId, movieId, "add_item").ConfigureAwait(false); + return await ManipulateMediaListAsync(listId, movieId, "add_item", cancellationToken).ConfigureAwait(false); } /// @@ -68,7 +69,7 @@ public async Task ListAddMovieAsync(string listId, int movieId) /// True if the method was able to remove the movie from the list, will retrun false in case of an issue or when the movie was not present in the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task ListClearAsync(string listId) + public async Task ListClearAsync(string listId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -80,7 +81,7 @@ public async Task ListClearAsync(string listId) request.AddParameter("confirm", "true"); AddSessionId(request, SessionType.UserSession); - RestResponse response = await request.ExecutePost().ConfigureAwait(false); + RestResponse response = await request.ExecutePost(cancellationToken).ConfigureAwait(false); // Status code 12 = "The item/record was updated successfully" PostReply item = await response.GetDataObject().ConfigureAwait(false); @@ -97,7 +98,7 @@ public async Task ListClearAsync(string listId) /// Optional language that might indicate the language of the content in the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task ListCreateAsync(string name, string description = "", string language = null) + public async Task ListCreateAsync(string name, string description = "", string language = null, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -122,7 +123,7 @@ public async Task ListCreateAsync(string name, string description = "", req.SetBody(new { name = name, description = description }); } - RestResponse response = await req.ExecutePost().ConfigureAwait(false); + RestResponse response = await req.ExecutePost(cancellationToken).ConfigureAwait(false); return (await response.GetDataObject().ConfigureAwait(false)).ListId; } @@ -133,7 +134,7 @@ public async Task ListCreateAsync(string name, string description = "", /// A list id that is owned by the user associated with the current session id /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task ListDeleteAsync(string listId) + public async Task ListDeleteAsync(string listId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -144,7 +145,7 @@ public async Task ListDeleteAsync(string listId) req.AddUrlSegment("listId", listId); AddSessionId(req, SessionType.UserSession); - RestResponse response = await req.ExecuteDelete().ConfigureAwait(false); + RestResponse response = await req.ExecuteDelete(cancellationToken).ConfigureAwait(false); // Status code 13 = success PostReply item = await response.GetDataObject().ConfigureAwait(false); @@ -161,12 +162,12 @@ public async Task ListDeleteAsync(string listId) /// True if the method was able to remove the movie from the list, will retrun false in case of an issue or when the movie was not present in the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task ListRemoveMovieAsync(string listId, int movieId) + public async Task ListRemoveMovieAsync(string listId, int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await ManipulateMediaListAsync(listId, movieId, "remove_item").ConfigureAwait(false); + return await ManipulateMediaListAsync(listId, movieId, "remove_item", cancellationToken).ConfigureAwait(false); } - private async Task ManipulateMediaListAsync(string listId, int movieId, string method) + private async Task ManipulateMediaListAsync(string listId, int movieId, string method, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -184,7 +185,7 @@ private async Task ManipulateMediaListAsync(string listId, int movieId, st req.SetBody(new { media_id = movieId }); - RestResponse response = await req.ExecutePost().ConfigureAwait(false); + RestResponse response = await req.ExecutePost(cancellationToken).ConfigureAwait(false); // Status code 12 = "The item/record was updated successfully" // Status code 13 = "The item/record was deleted successfully" diff --git a/TMDbLib/Client/TMDbClientMovies.cs b/TMDbLib/Client/TMDbClientMovies.cs index cb92b166..bd42d15d 100644 --- a/TMDbLib/Client/TMDbClientMovies.cs +++ b/TMDbLib/Client/TMDbClientMovies.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using System.Net; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.Changes; @@ -24,7 +25,7 @@ public partial class TMDbClient /// The id of the movie to get the account states for /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task GetMovieAccountStateAsync(int movieId) + public async Task GetMovieAccountStateAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -33,34 +34,34 @@ public async Task GetMovieAccountStateAsync(int movieId) req.AddUrlSegment("method", MovieMethods.AccountStates.GetDescription()); AddSessionId(req, SessionType.UserSession); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return await response.GetDataObject().ConfigureAwait(false); } - public async Task GetMovieAlternativeTitlesAsync(int movieId) + public async Task GetMovieAlternativeTitlesAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieAlternativeTitlesAsync(movieId, DefaultCountry).ConfigureAwait(false); + return await GetMovieAlternativeTitlesAsync(movieId, DefaultCountry, cancellationToken).ConfigureAwait(false); } - public async Task GetMovieAlternativeTitlesAsync(int movieId, string country) + public async Task GetMovieAlternativeTitlesAsync(int movieId, string country, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.AlternativeTitles, country: country).ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.AlternativeTitles, country: country, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetMovieAsync(int movieId, MovieMethods extraMethods = MovieMethods.Undefined) + public async Task GetMovieAsync(int movieId, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieAsync(movieId, DefaultLanguage, extraMethods).ConfigureAwait(false); + return await GetMovieAsync(movieId, DefaultLanguage, extraMethods, cancellationToken).ConfigureAwait(false); } - public async Task GetMovieAsync(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined) + public async Task GetMovieAsync(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieAsync(imdbId, DefaultLanguage, extraMethods).ConfigureAwait(false); + return await GetMovieAsync(imdbId, DefaultLanguage, extraMethods, cancellationToken).ConfigureAwait(false); } - public async Task GetMovieAsync(int movieId, string language, MovieMethods extraMethods = MovieMethods.Undefined) + public async Task GetMovieAsync(int movieId, string language, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieAsync(movieId.ToString(CultureInfo.InvariantCulture), language, extraMethods).ConfigureAwait(false); + return await GetMovieAsync(movieId.ToString(CultureInfo.InvariantCulture), language, extraMethods, cancellationToken).ConfigureAwait(false); } /// @@ -72,7 +73,7 @@ public async Task GetMovieAsync(int movieId, string language, MovieMethod /// The reqed movie or null if it could not be found /// Requires a valid user session when specifying the extra method 'AccountStates' flag /// Thrown when the current client object doens't have a user session assigned, see remarks. - public async Task GetMovieAsync(string imdbId, string language, MovieMethods extraMethods = MovieMethods.Undefined) + public async Task GetMovieAsync(string imdbId, string language, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { if (extraMethods.HasFlag(MovieMethods.AccountStates)) RequireSessionId(SessionType.UserSession); @@ -95,7 +96,7 @@ public async Task GetMovieAsync(string imdbId, string language, MovieMeth if (appends != string.Empty) req.AddParameter("append_to_response", appends); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); // No data to patch up so return if (response == null) return null; @@ -130,36 +131,36 @@ public async Task GetMovieAsync(string imdbId, string language, MovieMeth return item; } - public async Task> GetMovieChangesAsync(int movieId, DateTime? startDate = null, DateTime? endDate = null) + public async Task> GetMovieChangesAsync(int movieId, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) { - ChangesContainer changesContainer = await GetMovieMethod(movieId, MovieMethods.Changes, startDate: startDate, endDate: endDate, dateFormat: "yyyy-MM-dd HH:mm:ss UTC").ConfigureAwait(false); + ChangesContainer changesContainer = await GetMovieMethod(movieId, MovieMethods.Changes, startDate: startDate, endDate: endDate, dateFormat: "yyyy-MM-dd HH:mm:ss UTC", cancellationToken: cancellationToken).ConfigureAwait(false); return changesContainer.Changes; } - public async Task GetMovieCreditsAsync(int movieId) + public async Task GetMovieCreditsAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.Credits).ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.Credits, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetMovieImagesAsync(int movieId) + public async Task GetMovieImagesAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieImagesAsync(movieId, DefaultLanguage).ConfigureAwait(false); + return await GetMovieImagesAsync(movieId, DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task GetMovieImagesAsync(int movieId, string language) + public async Task GetMovieImagesAsync(int movieId, string language, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.Images, language: language).ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetMovieKeywordsAsync(int movieId) + public async Task GetMovieKeywordsAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.Keywords).ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.Keywords, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetMovieLatestAsync() + public async Task GetMovieLatestAsync( CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("movie/latest"); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); Movie item = await resp.GetDataObject().ConfigureAwait(false); @@ -170,29 +171,29 @@ public async Task GetMovieLatestAsync() return item; } - public async Task> GetMovieListsAsync(int movieId, int page = 0) + public async Task> GetMovieListsAsync(int movieId, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieListsAsync(movieId, DefaultLanguage, page).ConfigureAwait(false); + return await GetMovieListsAsync(movieId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieListsAsync(int movieId, string language, int page = 0) + public async Task> GetMovieListsAsync(int movieId, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(movieId, MovieMethods.Lists, page: page, language: language).ConfigureAwait(false); + return await GetMovieMethod>(movieId, MovieMethods.Lists, page: page, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieRecommendationsAsync(int id, int page = 0) + public async Task> GetMovieRecommendationsAsync(int id, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieRecommendationsAsync(id, DefaultLanguage, page).ConfigureAwait(false); + return await GetMovieRecommendationsAsync(id, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieRecommendationsAsync(int id, string language, int page = 0) + public async Task> GetMovieRecommendationsAsync(int id, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(id, MovieMethods.Recommendations, language: language, page: page).ConfigureAwait(false); + return await GetMovieMethod>(id, MovieMethods.Recommendations, language: language, page: page, cancellationToken: cancellationToken).ConfigureAwait(false); } private async Task GetMovieMethod(int movieId, MovieMethods movieMethod, string dateFormat = null, string country = null, - string language = null, int page = 0, DateTime? startDate = null, DateTime? endDate = null) where T : new() + string language = null, int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("movie/{movieId}/{method}"); req.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture)); @@ -211,12 +212,12 @@ private async Task GetMovieMethod(int movieId, MovieMethods movieMethod, s if (endDate != null) req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } - public async Task> GetMovieNowPlayingListAsync(string language = null, int page = 0, string region = null) + public async Task> GetMovieNowPlayingListAsync(string language = null, int page = 0, string region = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("movie/now_playing"); @@ -227,12 +228,12 @@ public async Task> GetMovieNowPlayingListA if (region != null) req.AddParameter("region", region); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetMoviePopularListAsync(string language = null, int page = 0, string region = null) + public async Task> GetMoviePopularListAsync(string language = null, int page = 0, string region = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("movie/popular"); @@ -243,42 +244,42 @@ public async Task> GetMoviePopularListAsync(string if (region != null) req.AddParameter("region", region); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetMovieReleaseDatesAsync(int movieId) + public async Task> GetMovieReleaseDatesAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(movieId, MovieMethods.ReleaseDates).ConfigureAwait(false); + return await GetMovieMethod>(movieId, MovieMethods.ReleaseDates, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetMovieReleasesAsync(int movieId) + public async Task GetMovieReleasesAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.Releases, dateFormat: "yyyy-MM-dd").ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.Releases, dateFormat: "yyyy-MM-dd", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieReviewsAsync(int movieId, int page = 0) + public async Task> GetMovieReviewsAsync(int movieId, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieReviewsAsync(movieId, DefaultLanguage, page).ConfigureAwait(false); + return await GetMovieReviewsAsync(movieId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieReviewsAsync(int movieId, string language, int page = 0) + public async Task> GetMovieReviewsAsync(int movieId, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(movieId, MovieMethods.Reviews, page: page, language: language).ConfigureAwait(false); + return await GetMovieMethod>(movieId, MovieMethods.Reviews, page: page, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieSimilarAsync(int movieId, int page = 0) + public async Task> GetMovieSimilarAsync(int movieId, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieSimilarAsync(movieId, DefaultLanguage, page).ConfigureAwait(false); + return await GetMovieSimilarAsync(movieId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieSimilarAsync(int movieId, string language, int page = 0) + public async Task> GetMovieSimilarAsync(int movieId, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(movieId, MovieMethods.Similar, page: page, language: language, dateFormat: "yyyy-MM-dd").ConfigureAwait(false); + return await GetMovieMethod>(movieId, MovieMethods.Similar, page: page, language: language, dateFormat: "yyyy-MM-dd", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieTopRatedListAsync(string language = null, int page = 0, string region = null) + public async Task> GetMovieTopRatedListAsync(string language = null, int page = 0, string region = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("movie/top_rated"); @@ -289,17 +290,17 @@ public async Task> GetMovieTopRatedListAsync(string if (region != null) req.AddParameter("region", region); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task GetMovieTranslationsAsync(int movieId) + public async Task GetMovieTranslationsAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod(movieId, MovieMethods.Translations).ConfigureAwait(false); + return await GetMovieMethod(movieId, MovieMethods.Translations, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetMovieUpcomingListAsync(string language = null, int page = 0, string region = null) + public async Task> GetMovieUpcomingListAsync(string language = null, int page = 0, string region = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("movie/upcoming"); @@ -310,17 +311,17 @@ public async Task> GetMovieUpcomingListAsy if (region != null) req.AddParameter("region", region); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetMovieVideosAsync(int movieId) + public async Task> GetMovieVideosAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetMovieMethod>(movieId, MovieMethods.Videos).ConfigureAwait(false); + return await GetMovieMethod>(movieId, MovieMethods.Videos, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task MovieRemoveRatingAsync(int movieId) + public async Task MovieRemoveRatingAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -328,7 +329,7 @@ public async Task MovieRemoveRatingAsync(int movieId) req.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture)); AddSessionId(req); - RestResponse response = await req.ExecuteDelete().ConfigureAwait(false); + RestResponse response = await req.ExecuteDelete(cancellationToken).ConfigureAwait(false); // status code 13 = "The item/record was deleted successfully." PostReply item = await response.GetDataObject().ConfigureAwait(false); @@ -345,7 +346,7 @@ public async Task MovieRemoveRatingAsync(int movieId) /// True if the the movie's rating was successfully updated, false if not /// Requires a valid guest or user session /// Thrown when the current client object doens't have a guest or user session assigned. - public async Task MovieSetRatingAsync(int movieId, double rating) + public async Task MovieSetRatingAsync(int movieId, double rating, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -355,7 +356,7 @@ public async Task MovieSetRatingAsync(int movieId, double rating) req.SetBody(new { value = rating }); - RestResponse response = await req.ExecutePost().ConfigureAwait(false); + RestResponse response = await req.ExecutePost(cancellationToken).ConfigureAwait(false); // status code 1 = "Success" // status code 12 = "The item/record was updated successfully" - Used when an item was previously rated by the user diff --git a/TMDbLib/Client/TMDbClientNetworks.cs b/TMDbLib/Client/TMDbClientNetworks.cs index d45ad338..dda219f7 100644 --- a/TMDbLib/Client/TMDbClientNetworks.cs +++ b/TMDbLib/Client/TMDbClientNetworks.cs @@ -1,4 +1,5 @@ using System.Globalization; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.TvShows; using TMDbLib.Rest; @@ -11,12 +12,12 @@ public partial class TMDbClient /// Retrieves a network by it's TMDb id. A network is a distributer of media content ex. HBO, AMC /// /// The id of the network object to retrieve - public async Task GetNetworkAsync(int networkId) + public async Task GetNetworkAsync(int networkId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("network/{networkId}"); req.AddUrlSegment("networkId", networkId.ToString(CultureInfo.InvariantCulture)); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } diff --git a/TMDbLib/Client/TMDbClientPeople.cs b/TMDbLib/Client/TMDbClientPeople.cs index 024fd9ed..dc2bf5a1 100644 --- a/TMDbLib/Client/TMDbClientPeople.cs +++ b/TMDbLib/Client/TMDbClientPeople.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Changes; using TMDbLib.Objects.General; @@ -12,19 +13,19 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetLatestPersonAsync() + public async Task GetLatestPersonAsync( CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("person/latest"); // TODO: Dateformat? //req.DateFormat = "yyyy-MM-dd"; - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task GetPersonAsync(int personId, PersonMethods extraMethods = PersonMethods.Undefined) + public async Task GetPersonAsync(int personId, PersonMethods extraMethods = PersonMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("person/{personId}"); req.AddUrlSegment("personId", personId.ToString()); @@ -42,7 +43,7 @@ public async Task GetPersonAsync(int personId, PersonMethods extraMethod // TODO: Dateformat? //req.DateFormat = "yyyy-MM-dd"; - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); Person item = await resp.GetDataObject().ConfigureAwait(false); @@ -62,23 +63,23 @@ public async Task GetPersonAsync(int personId, PersonMethods extraMethod return item; } - public async Task> GetPersonChangesAsync(int personId, DateTime? startDate = null, DateTime? endDate = null) + public async Task> GetPersonChangesAsync(int personId, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) { - ChangesContainer changesContainer = await GetPersonMethod(personId, PersonMethods.Changes, startDate: startDate, endDate: endDate, dateFormat: "yyyy-MM-dd HH:mm:ss UTC").ConfigureAwait(false); + ChangesContainer changesContainer = await GetPersonMethod(personId, PersonMethods.Changes, startDate: startDate, endDate: endDate, dateFormat: "yyyy-MM-dd HH:mm:ss UTC", cancellationToken: cancellationToken).ConfigureAwait(false); return changesContainer.Changes; } - public async Task GetPersonExternalIdsAsync(int personId) + public async Task GetPersonExternalIdsAsync(int personId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMethod(personId, PersonMethods.ExternalIds).ConfigureAwait(false); + return await GetPersonMethod(personId, PersonMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetPersonImagesAsync(int personId) + public async Task GetPersonImagesAsync(int personId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMethod(personId, PersonMethods.Images).ConfigureAwait(false); + return await GetPersonMethod(personId, PersonMethods.Images, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetPersonListAsync(PersonListType type, int page = 0) + public async Task> GetPersonListAsync(PersonListType type, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req; switch (type) @@ -96,13 +97,13 @@ public async Task> GetPersonListAsync(PersonListTy // TODO: Dateformat? //req.DateFormat = "yyyy-MM-dd"; - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } private async Task GetPersonMethod(int personId, PersonMethods personMethod, string dateFormat = null, string country = null, string language = null, - int page = 0, DateTime? startDate = null, DateTime? endDate = null) where T : new() + int page = 0, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("person/{personId}/{method}"); req.AddUrlSegment("personId", personId.ToString()); @@ -125,39 +126,39 @@ private async Task GetPersonMethod(int personId, PersonMethods personMetho if (endDate != null) req.AddParameter("endDate", endDate.Value.ToString("yyyy-MM-dd")); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task GetPersonMovieCreditsAsync(int personId) + public async Task GetPersonMovieCreditsAsync(int personId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMovieCreditsAsync(personId, DefaultLanguage).ConfigureAwait(false); + return await GetPersonMovieCreditsAsync(personId, DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task GetPersonMovieCreditsAsync(int personId, string language) + public async Task GetPersonMovieCreditsAsync(int personId, string language, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMethod(personId, PersonMethods.MovieCredits, language: language).ConfigureAwait(false); + return await GetPersonMethod(personId, PersonMethods.MovieCredits, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetPersonTaggedImagesAsync(int personId, int page) + public async Task> GetPersonTaggedImagesAsync(int personId, int page, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonTaggedImagesAsync(personId, DefaultLanguage, page).ConfigureAwait(false); + return await GetPersonTaggedImagesAsync(personId, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetPersonTaggedImagesAsync(int personId, string language, int page) + public async Task> GetPersonTaggedImagesAsync(int personId, string language, int page, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMethod>(personId, PersonMethods.TaggedImages, language: language, page: page).ConfigureAwait(false); + return await GetPersonMethod>(personId, PersonMethods.TaggedImages, language: language, page: page, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetPersonTvCreditsAsync(int personId) + public async Task GetPersonTvCreditsAsync(int personId, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonTvCreditsAsync(personId, DefaultLanguage).ConfigureAwait(false); + return await GetPersonTvCreditsAsync(personId, DefaultLanguage, cancellationToken).ConfigureAwait(false); } - public async Task GetPersonTvCreditsAsync(int personId, string language) + public async Task GetPersonTvCreditsAsync(int personId, string language, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetPersonMethod(personId, PersonMethods.TvCredits, language: language).ConfigureAwait(false); + return await GetPersonMethod(personId, PersonMethods.TvCredits, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/TMDbLib/Client/TMDbClientReviews.cs b/TMDbLib/Client/TMDbClientReviews.cs index 8fd30b5c..694329db 100644 --- a/TMDbLib/Client/TMDbClientReviews.cs +++ b/TMDbLib/Client/TMDbClientReviews.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.Reviews; using TMDbLib.Rest; @@ -6,7 +7,7 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetReviewAsync(string reviewId) + public async Task GetReviewAsync(string reviewId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest request = _client.Create("review/{reviewId}"); request.AddUrlSegment("reviewId", reviewId); @@ -14,7 +15,7 @@ public async Task GetReviewAsync(string reviewId) // TODO: Dateformat? //request.DateFormat = "yyyy-MM-dd"; - RestResponse resp = await request.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await request.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } diff --git a/TMDbLib/Client/TMDbClientSearch.cs b/TMDbLib/Client/TMDbClientSearch.cs index 591a1083..8070f94a 100644 --- a/TMDbLib/Client/TMDbClientSearch.cs +++ b/TMDbLib/Client/TMDbClientSearch.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Objects.General; using TMDbLib.Objects.Search; using TMDbLib.Rest; @@ -7,32 +8,32 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task> SearchCollectionAsync(string query, int page = 0) + public async Task> SearchCollectionAsync(string query, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchCollectionAsync(query, DefaultLanguage, page).ConfigureAwait(false); + return await SearchCollectionAsync(query, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> SearchCollectionAsync(string query, string language, int page = 0) + public async Task> SearchCollectionAsync(string query, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("collection", query, page, language).ConfigureAwait(false); + return await SearchMethod>("collection", query, page, language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> SearchCompanyAsync(string query, int page = 0) + public async Task> SearchCompanyAsync(string query, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("company", query, page).ConfigureAwait(false); + return await SearchMethod>("company", query, page, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> SearchKeywordAsync(string query, int page = 0) + public async Task> SearchKeywordAsync(string query, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("keyword", query, page).ConfigureAwait(false); + return await SearchMethod>("keyword", query, page, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> SearchListAsync(string query, int page = 0, bool includeAdult = false) + public async Task> SearchListAsync(string query, int page = 0, bool includeAdult = false, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("list", query, page, includeAdult: includeAdult).ConfigureAwait(false); + return await SearchMethod>("list", query, page, includeAdult: includeAdult, cancellationToken: cancellationToken).ConfigureAwait(false); } - private async Task SearchMethod(string method, string query, int page, string language = null, bool? includeAdult = null, int year = 0, string dateFormat = null) where T : new() + private async Task SearchMethod(string method, string query, int page, string language = null, bool? includeAdult = null, int year = 0, string dateFormat = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("search/{method}"); req.AddUrlSegment("method", method); @@ -53,39 +54,39 @@ public async Task> SearchListAsync(string query, int //if (dateFormat != null) // req.DateFormat = dateFormat; - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> SearchMovieAsync(string query, int page = 0, bool includeAdult = false, int year = 0) + public async Task> SearchMovieAsync(string query, int page = 0, bool includeAdult = false, int year = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMovieAsync(query, DefaultLanguage, page, includeAdult, year).ConfigureAwait(false); + return await SearchMovieAsync(query, DefaultLanguage, page, includeAdult, year, cancellationToken).ConfigureAwait(false); } - public async Task> SearchMovieAsync(string query, string language, int page = 0, bool includeAdult = false, int year = 0) + public async Task> SearchMovieAsync(string query, string language, int page = 0, bool includeAdult = false, int year = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("movie", query, page, language, includeAdult, year, "yyyy-MM-dd").ConfigureAwait(false); + return await SearchMethod>("movie", query, page, language, includeAdult, year, "yyyy-MM-dd", cancellationToken).ConfigureAwait(false); } - public async Task> SearchMultiAsync(string query, int page = 0, bool includeAdult = false, int year = 0) + public async Task> SearchMultiAsync(string query, int page = 0, bool includeAdult = false, int year = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMultiAsync(query, DefaultLanguage, page, includeAdult, year).ConfigureAwait(false); + return await SearchMultiAsync(query, DefaultLanguage, page, includeAdult, year, cancellationToken).ConfigureAwait(false); } - public async Task> SearchMultiAsync(string query, string language, int page = 0, bool includeAdult = false, int year = 0) + public async Task> SearchMultiAsync(string query, string language, int page = 0, bool includeAdult = false, int year = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("multi", query, page, language, includeAdult, year, "yyyy-MM-dd").ConfigureAwait(false); + return await SearchMethod>("multi", query, page, language, includeAdult, year, "yyyy-MM-dd", cancellationToken).ConfigureAwait(false); } - public async Task> SearchPersonAsync(string query, int page = 0, bool includeAdult = false) + public async Task> SearchPersonAsync(string query, int page = 0, bool includeAdult = false, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("person", query, page, includeAdult: includeAdult).ConfigureAwait(false); + return await SearchMethod>("person", query, page, includeAdult: includeAdult, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> SearchTvShowAsync(string query, int page = 0) + public async Task> SearchTvShowAsync(string query, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await SearchMethod>("tv", query, page).ConfigureAwait(false); + return await SearchMethod>("tv", query, page, cancellationToken: cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/TMDbLib/Client/TMDbClientTimezones.cs b/TMDbLib/Client/TMDbClientTimezones.cs index ca56b705..bf24d812 100644 --- a/TMDbLib/Client/TMDbClientTimezones.cs +++ b/TMDbLib/Client/TMDbClientTimezones.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Timezones; using TMDbLib.Rest; @@ -18,11 +19,11 @@ public partial class TMDbClient /// The source the specified id belongs to /// The id of the object you wish to located /// A list of all objects in TMDb that matched your id - public async Task GetTimezonesAsync() + public async Task GetTimezonesAsync(CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("timezones/list"); - RestResponse>>> resp = await req.ExecuteGet>>>().ConfigureAwait(false); + RestResponse>>> resp = await req.ExecuteGet>>>(cancellationToken).ConfigureAwait(false); List>> item = await resp.GetDataObject().ConfigureAwait(false); diff --git a/TMDbLib/Client/TMDbClientTvEpisodes.cs b/TMDbLib/Client/TMDbClientTvEpisodes.cs index e6dace52..29702556 100644 --- a/TMDbLib/Client/TMDbClientTvEpisodes.cs +++ b/TMDbLib/Client/TMDbClientTvEpisodes.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.Changes; @@ -13,7 +14,7 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetTvEpisodeAccountStateAsync(int tvShowId, int seasonNumber, int episodeNumber) + public async Task GetTvEpisodeAccountStateAsync(int tvShowId, int seasonNumber, int episodeNumber, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -24,8 +25,8 @@ public async Task GetTvEpisodeAccountStateAsync(int tvSho req.AddUrlSegment("method", TvEpisodeMethods.AccountStates.GetDescription()); AddSessionId(req, SessionType.UserSession); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); - + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); + return await response.GetDataObject().ConfigureAwait(false); } @@ -37,7 +38,7 @@ public async Task GetTvEpisodeAccountStateAsync(int tvSho /// The episode number of the episode you want to retrieve. /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es - public async Task GetTvEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods extraMethods = TvEpisodeMethods.Undefined, string language = null) + public async Task GetTvEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods extraMethods = TvEpisodeMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { if (extraMethods.HasFlag(TvEpisodeMethods.AccountStates)) RequireSessionId(SessionType.UserSession); @@ -64,7 +65,7 @@ public async Task GetTvEpisodeAsync(int tvShowId, int seasonNumber, i if (appends != string.Empty) req.AddParameter("append_to_response", appends); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); TvEpisode item = await resp.GetDataObject().ConfigureAwait(false); @@ -84,16 +85,16 @@ public async Task GetTvEpisodeAsync(int tvShowId, int seasonNumber, i if (item.ExternalIds != null) item.ExternalIds.Id = item.Id ?? 0; - + return item; } - public async Task GetTvEpisodeChangesAsync(int episodeId) + public async Task GetTvEpisodeChangesAsync(int episodeId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("tv/episode/{id}/changes"); req.AddUrlSegment("id", episodeId.ToString(CultureInfo.InvariantCulture)); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } @@ -105,9 +106,9 @@ public async Task GetTvEpisodeChangesAsync(int episodeId) /// The season number of the season the episode belongs to. Note use 0 for specials. /// The episode number of the episode you want to retrieve information for. /// If specified the api will attempt to return a localized result. ex: en,it,es - public async Task GetTvEpisodeCreditsAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null) + public async Task GetTvEpisodeCreditsAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Credits, dateFormat: "yyyy-MM-dd", language: language).ConfigureAwait(false); + return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Credits, dateFormat: "yyyy-MM-dd", language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -116,9 +117,9 @@ public async Task GetTvEpisodeCreditsAsync(int tvShowId, /// The TMDb id of the target tv show. /// The season number of the season the episode belongs to. Note use 0 for specials. /// The episode number of the episode you want to retrieve information for. - public async Task GetTvEpisodeExternalIdsAsync(int tvShowId, int seasonNumber, int episodeNumber) + public async Task GetTvEpisodeExternalIdsAsync(int tvShowId, int seasonNumber, int episodeNumber, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.ExternalIds).ConfigureAwait(false); + return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -131,12 +132,12 @@ public async Task GetTvEpisodeExternalIdsAsync(int tvShowI /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// - public async Task GetTvEpisodeImagesAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null) + public async Task GetTvEpisodeImagesAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Images, language: language).ConfigureAwait(false); + return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - private async Task GetTvEpisodeMethod(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods tvShowMethod, string dateFormat = null, string language = null) where T : new() + private async Task GetTvEpisodeMethod(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods tvShowMethod, string dateFormat = null, string language = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("tv/{id}/season/{season_number}/episode/{episode_number}/{method}"); req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture)); @@ -153,17 +154,17 @@ public async Task GetTvEpisodeImagesAsync(int tvShowId, int seasonN if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } - public async Task> GetTvEpisodeVideosAsync(int tvShowId, int seasonNumber, int episodeNumber) + public async Task> GetTvEpisodeVideosAsync(int tvShowId, int seasonNumber, int episodeNumber, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvEpisodeMethod>(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Videos).ConfigureAwait(false); + return await GetTvEpisodeMethod>(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Videos, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TvEpisodeRemoveRatingAsync(int tvShowId, int seasonNumber, int episodeNumber) + public async Task TvEpisodeRemoveRatingAsync(int tvShowId, int seasonNumber, int episodeNumber, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -174,7 +175,7 @@ public async Task TvEpisodeRemoveRatingAsync(int tvShowId, int seasonNumbe AddSessionId(req); - RestResponse response = await req.ExecuteDelete().ConfigureAwait(false); + RestResponse response = await req.ExecuteDelete(cancellationToken).ConfigureAwait(false); // status code 13 = "The item/record was deleted successfully." PostReply item = await response.GetDataObject().ConfigureAwait(false); @@ -183,7 +184,7 @@ public async Task TvEpisodeRemoveRatingAsync(int tvShowId, int seasonNumbe return item.StatusCode == 13; } - public async Task TvEpisodeSetRatingAsync(int tvShowId, int seasonNumber, int episodeNumber, double rating) + public async Task TvEpisodeSetRatingAsync(int tvShowId, int seasonNumber, int episodeNumber, double rating, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -196,7 +197,7 @@ public async Task TvEpisodeSetRatingAsync(int tvShowId, int seasonNumber, req.SetBody(new { value = rating }); - RestResponse response = await req.ExecutePost().ConfigureAwait(false); + RestResponse response = await req.ExecutePost(cancellationToken).ConfigureAwait(false); // status code 1 = "Success" // status code 12 = "The item/record was updated successfully" - Used when an item was previously rated by the user diff --git a/TMDbLib/Client/TMDbClientTvSeasons.cs b/TMDbLib/Client/TMDbClientTvSeasons.cs index 43978b4b..cbf21501 100644 --- a/TMDbLib/Client/TMDbClientTvSeasons.cs +++ b/TMDbLib/Client/TMDbClientTvSeasons.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.Changes; @@ -14,7 +15,7 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task> GetTvSeasonAccountStateAsync(int tvShowId, int seasonNumber) + public async Task> GetTvSeasonAccountStateAsync(int tvShowId, int seasonNumber, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -24,7 +25,7 @@ public async Task> GetTvSeasonA req.AddUrlSegment("method", TvEpisodeMethods.AccountStates.GetDescription()); AddSessionId(req, SessionType.UserSession); - RestResponse> response = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> response = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return await response.GetDataObject().ConfigureAwait(false); } @@ -37,7 +38,7 @@ public async Task> GetTvSeasonA /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es /// The requested season for the specified tv show - public async Task GetTvSeasonAsync(int tvShowId, int seasonNumber, TvSeasonMethods extraMethods = TvSeasonMethods.Undefined, string language = null) + public async Task GetTvSeasonAsync(int tvShowId, int seasonNumber, TvSeasonMethods extraMethods = TvSeasonMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { if (extraMethods.HasFlag(TvSeasonMethods.AccountStates)) RequireSessionId(SessionType.UserSession); @@ -63,7 +64,7 @@ public async Task GetTvSeasonAsync(int tvShowId, int seasonNumber, TvS if (appends != string.Empty) req.AddParameter("append_to_response", appends); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); TvSeason item = await response.GetDataObject().ConfigureAwait(false); @@ -89,12 +90,12 @@ public async Task GetTvSeasonAsync(int tvShowId, int seasonNumber, TvS return item; } - public async Task GetTvSeasonChangesAsync(int seasonId) + public async Task GetTvSeasonChangesAsync(int seasonId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("tv/season/{id}/changes"); req.AddUrlSegment("id", seasonId.ToString(CultureInfo.InvariantCulture)); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } @@ -105,9 +106,9 @@ public async Task GetTvSeasonChangesAsync(int seasonId) /// The TMDb id of the target tv show. /// The season number of the season you want to retrieve information for. Note use 0 for specials. /// If specified the api will attempt to return a localized result. ex: en,it,es - public async Task GetTvSeasonCreditsAsync(int tvShowId, int seasonNumber, string language = null) + public async Task GetTvSeasonCreditsAsync(int tvShowId, int seasonNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Credits, dateFormat: "yyyy-MM-dd", language: language).ConfigureAwait(false); + return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Credits, dateFormat: "yyyy-MM-dd", language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -115,9 +116,9 @@ public async Task GetTvSeasonCreditsAsync(int tvShowId, int seasonNumbe /// /// The TMDb id of the target tv show. /// The season number of the season you want to retrieve information for. Note use 0 for specials. - public async Task GetTvSeasonExternalIdsAsync(int tvShowId, int seasonNumber) + public async Task GetTvSeasonExternalIdsAsync(int tvShowId, int seasonNumber, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.ExternalIds).ConfigureAwait(false); + return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -129,12 +130,12 @@ public async Task GetTvSeasonExternalIdsAsync(int tvShowId, /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// - public async Task GetTvSeasonImagesAsync(int tvShowId, int seasonNumber, string language = null) + public async Task GetTvSeasonImagesAsync(int tvShowId, int seasonNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Images, language: language).ConfigureAwait(false); + return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - private async Task GetTvSeasonMethod(int tvShowId, int seasonNumber, TvSeasonMethods tvShowMethod, string dateFormat = null, string language = null) where T : new() + private async Task GetTvSeasonMethod(int tvShowId, int seasonNumber, TvSeasonMethods tvShowMethod, string dateFormat = null, string language = null, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("tv/{id}/season/{season_number}/{method}"); req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture)); @@ -149,14 +150,14 @@ public async Task GetTvSeasonImagesAsync(int tvShowId, int seasonN if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return response; } - public async Task> GetTvSeasonVideosAsync(int tvShowId, int seasonNumber, string language = null) + public async Task> GetTvSeasonVideosAsync(int tvShowId, int seasonNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvSeasonMethod>(tvShowId, seasonNumber, TvSeasonMethods.Videos, language: language).ConfigureAwait(false); + return await GetTvSeasonMethod>(tvShowId, seasonNumber, TvSeasonMethods.Videos, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/TMDbLib/Client/TMDbClientTvShows.cs b/TMDbLib/Client/TMDbClientTvShows.cs index cf83e74c..a116db98 100644 --- a/TMDbLib/Client/TMDbClientTvShows.cs +++ b/TMDbLib/Client/TMDbClientTvShows.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Linq; +using System.Threading; using System.Threading.Tasks; using TMDbLib.Objects.Authentication; using TMDbLib.Objects.Changes; @@ -15,11 +16,11 @@ namespace TMDbLib.Client { public partial class TMDbClient { - public async Task GetLatestTvShowAsync() + public async Task GetLatestTvShowAsync( CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("tv/latest"); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } @@ -30,7 +31,7 @@ public async Task GetLatestTvShowAsync() /// The id of the tv show to get the account states for /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. - public async Task GetTvShowAccountStateAsync(int tvShowId) + public async Task GetTvShowAccountStateAsync(int tvShowId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.UserSession); @@ -39,14 +40,14 @@ public async Task GetTvShowAccountStateAsync(int tvShowId) req.AddUrlSegment("method", TvShowMethods.AccountStates.GetDescription()); AddSessionId(req, SessionType.UserSession); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return await response.GetDataObject().ConfigureAwait(false); } - public async Task> GetTvShowAlternativeTitlesAsync(int id) + public async Task> GetTvShowAlternativeTitlesAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.AlternativeTitles).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.AlternativeTitles, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -56,7 +57,7 @@ public async Task> GetTvShowAlternativeTitlesA /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es /// The requested Tv Show - public async Task GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null) + public async Task GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { if (extraMethods.HasFlag(TvShowMethods.AccountStates)) RequireSessionId(SessionType.UserSession); @@ -81,7 +82,7 @@ public async Task GetTvShowAsync(int id, TvShowMethods extraMethods = Tv if (appends != string.Empty) req.AddParameter("append_to_response", appends); - RestResponse response = await req.ExecuteGet().ConfigureAwait(false); + RestResponse response = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); TvShow item = await response.GetDataObject().ConfigureAwait(false); @@ -99,14 +100,14 @@ public async Task GetTvShowAsync(int id, TvShowMethods extraMethods = Tv return item; } - public async Task GetTvShowChangesAsync(int id) + public async Task GetTvShowChangesAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod(id, TvShowMethods.Changes).ConfigureAwait(false); + return await GetTvShowMethod(id, TvShowMethods.Changes, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowContentRatingsAsync(int id) + public async Task> GetTvShowContentRatingsAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.ContentRatings).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.ContentRatings, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -114,18 +115,18 @@ public async Task> GetTvShowContentRatingsAsync(i /// /// The TMDb id of the target tv show. /// If specified the api will attempt to return a localized result. ex: en,it,es - public async Task GetTvShowCreditsAsync(int id, string language = null) + public async Task GetTvShowCreditsAsync(int id, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod(id, TvShowMethods.Credits, dateFormat: "yyyy-MM-dd", language: language).ConfigureAwait(false); + return await GetTvShowMethod(id, TvShowMethods.Credits, "yyyy-MM-dd", language, cancellationToken: cancellationToken).ConfigureAwait(false); } /// /// Returns an object that contains all known exteral id's for the tv show related to the specified TMDB id. /// /// The TMDb id of the target tv show. - public async Task GetTvShowExternalIdsAsync(int id) + public async Task GetTvShowExternalIdsAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod(id, TvShowMethods.ExternalIds).ConfigureAwait(false); + return await GetTvShowMethod(id, TvShowMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); } /// @@ -136,17 +137,17 @@ public async Task GetTvShowExternalIdsAsync(int id) /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// - public async Task GetTvShowImagesAsync(int id, string language = null) + public async Task GetTvShowImagesAsync(int id, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod(id, TvShowMethods.Images, language: language).ConfigureAwait(false); + return await GetTvShowMethod(id, TvShowMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowKeywordsAsync(int id) + public async Task> GetTvShowKeywordsAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.Keywords).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.Keywords, cancellationToken: cancellationToken).ConfigureAwait(false); } - private async Task> GetTvShowListAsync(int page, string language, string tvShowListType) + private async Task> GetTvShowListAsync(int page, string language, string tvShowListType, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("tv/" + tvShowListType); @@ -157,7 +158,7 @@ private async Task> GetTvShowListAsync(int page, strin if (page >= 1) req.AddParameter("page", page.ToString()); - RestResponse> response = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> response = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return response; } @@ -169,9 +170,9 @@ private async Task> GetTvShowListAsync(int page, strin /// Page /// Only relevant for list type AiringToday /// - public async Task> GetTvShowListAsync(TvShowListType list, int page = 0, string timezone = null) + public async Task> GetTvShowListAsync(TvShowListType list, int page = 0, string timezone = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowListAsync(list, DefaultLanguage, page, timezone).ConfigureAwait(false); + return await GetTvShowListAsync(list, DefaultLanguage, page, timezone, cancellationToken).ConfigureAwait(false); } /// @@ -182,7 +183,7 @@ public async Task> GetTvShowListAsync(TvShowListType l /// Page /// Only relevant for list type AiringToday /// - public async Task> GetTvShowListAsync(TvShowListType list, string language, int page = 0, string timezone = null) + public async Task> GetTvShowListAsync(TvShowListType list, string language, int page = 0, string timezone = null, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("tv/{method}"); req.AddUrlSegment("method", list.GetDescription()); @@ -197,12 +198,12 @@ public async Task> GetTvShowListAsync(TvShowListType l if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse> resp = await req.ExecuteGet>().ConfigureAwait(false); + RestResponse> resp = await req.ExecuteGet>(cancellationToken).ConfigureAwait(false); return resp; } - private async Task GetTvShowMethod(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, int page = 0) where T : new() + private async Task GetTvShowMethod(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) where T : new() { RestRequest req = _client.Create("tv/{id}/{method}"); req.AddUrlSegment("id", id.ToString(CultureInfo.InvariantCulture)); @@ -219,7 +220,7 @@ public async Task> GetTvShowListAsync(TvShowListType l if (!string.IsNullOrWhiteSpace(language)) req.AddParameter("language", language); - RestResponse resp = await req.ExecuteGet().ConfigureAwait(false); + RestResponse resp = await req.ExecuteGet(cancellationToken).ConfigureAwait(false); return resp; } @@ -231,41 +232,41 @@ public async Task> GetTvShowListAsync(TvShowListType l /// Returns the basic information about a tv show. /// For additional data use the main GetTvShowAsync method using the tv show id as parameter. /// - public async Task> GetTvShowPopularAsync(int page = -1, string language = null) + public async Task> GetTvShowPopularAsync(int page = -1, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowListAsync(page, language, "popular").ConfigureAwait(false); + return await GetTvShowListAsync(page, language, "popular", cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowSimilarAsync(int id, int page = 0) + public async Task> GetTvShowSimilarAsync(int id, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowSimilarAsync(id, DefaultLanguage, page).ConfigureAwait(false); + return await GetTvShowSimilarAsync(id, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowSimilarAsync(int id, string language, int page = 0) + public async Task> GetTvShowSimilarAsync(int id, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.Similar, language: language, page: page).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.Similar, language: language, page: page, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowRecommendationsAsync(int id, int page = 0) + public async Task> GetTvShowRecommendationsAsync(int id, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowRecommendationsAsync(id, DefaultLanguage, page).ConfigureAwait(false); + return await GetTvShowRecommendationsAsync(id, DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowRecommendationsAsync(int id, string language, int page = 0) + public async Task> GetTvShowRecommendationsAsync(int id, string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.Recommendations, language: language, page: page).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.Recommendations, language: language, page: page, cancellationToken: cancellationToken).ConfigureAwait(false); } [Obsolete("Use GetTvShowPopularAsync")] - public async Task> GetTvShowsPopularAsync(int page = -1, string language = null) + public async Task> GetTvShowsPopularAsync(int page = -1, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowPopularAsync(page, language).ConfigureAwait(false); + return await GetTvShowPopularAsync(page, language, cancellationToken).ConfigureAwait(false); } [Obsolete("Use GetTvShowTopRatedAsync")] - public async Task> GetTvShowsTopRatedAsync(int page = -1, string language = null) + public async Task> GetTvShowsTopRatedAsync(int page = -1, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowTopRatedAsync(page, language).ConfigureAwait(false); + return await GetTvShowTopRatedAsync(page, language, cancellationToken).ConfigureAwait(false); } /// @@ -275,22 +276,22 @@ public async Task> GetTvShowsTopRatedAsync(int page = /// Returns the basic information about a tv show. /// For additional data use the main GetTvShowAsync method using the tv show id as parameter /// - public async Task> GetTvShowTopRatedAsync(int page = -1, string language = null) + public async Task> GetTvShowTopRatedAsync(int page = -1, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowListAsync(page, language, "top_rated").ConfigureAwait(false); + return await GetTvShowListAsync(page, language, "top_rated", cancellationToken).ConfigureAwait(false); } - public async Task GetTvShowTranslationsAsync(int id) + public async Task GetTvShowTranslationsAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod(id, TvShowMethods.Translations).ConfigureAwait(false); + return await GetTvShowMethod(id, TvShowMethods.Translations, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> GetTvShowVideosAsync(int id) + public async Task> GetTvShowVideosAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { - return await GetTvShowMethod>(id, TvShowMethods.Videos).ConfigureAwait(false); + return await GetTvShowMethod>(id, TvShowMethods.Videos, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TvShowRemoveRatingAsync(int tvShowId) + public async Task TvShowRemoveRatingAsync(int tvShowId, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -298,7 +299,7 @@ public async Task TvShowRemoveRatingAsync(int tvShowId) req.AddUrlSegment("tvShowId", tvShowId.ToString(CultureInfo.InvariantCulture)); AddSessionId(req); - RestResponse response = await req.ExecuteDelete().ConfigureAwait(false); + RestResponse response = await req.ExecuteDelete(cancellationToken).ConfigureAwait(false); // status code 13 = "The item/record was deleted successfully." PostReply item = await response.GetDataObject().ConfigureAwait(false); @@ -315,7 +316,7 @@ public async Task TvShowRemoveRatingAsync(int tvShowId) /// True if the the tv show's rating was successfully updated, false if not /// Requires a valid guest or user session /// Thrown when the current client object doens't have a guest or user session assigned. - public async Task TvShowSetRatingAsync(int tvShowId, double rating) + public async Task TvShowSetRatingAsync(int tvShowId, double rating, CancellationToken cancellationToken = default(CancellationToken)) { RequireSessionId(SessionType.GuestSession); @@ -325,7 +326,7 @@ public async Task TvShowSetRatingAsync(int tvShowId, double rating) req.SetBody(new { value = rating }); - RestResponse response = await req.ExecutePost().ConfigureAwait(false); + RestResponse response = await req.ExecutePost(cancellationToken).ConfigureAwait(false); // status code 1 = "Success" // status code 12 = "The item/record was updated successfully" - Used when an item was previously rated by the user diff --git a/TMDbLib/Objects/Discover/DiscoverBase.cs b/TMDbLib/Objects/Discover/DiscoverBase.cs index 64f6ebcf..535a80f0 100644 --- a/TMDbLib/Objects/Discover/DiscoverBase.cs +++ b/TMDbLib/Objects/Discover/DiscoverBase.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using TMDbLib.Client; using TMDbLib.Objects.General; using TMDbLib.Utilities; @@ -18,14 +19,14 @@ public DiscoverBase(string endpoint, TMDbClient client) Parameters = new SimpleNamedValueCollection(); } - public async Task> Query(int page = 0) + public async Task> Query(int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await Query(_client.DefaultLanguage, page).ConfigureAwait(false); + return await Query(_client.DefaultLanguage, page, cancellationToken).ConfigureAwait(false); } - public async Task> Query(string language, int page = 0) + public async Task> Query(string language, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) { - return await _client.DiscoverPerformAsync(_endpoint, language, page, Parameters).ConfigureAwait(false); + return await _client.DiscoverPerformAsync(_endpoint, language, page, Parameters, cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/TMDbLib/Rest/RestRequest.cs b/TMDbLib/Rest/RestRequest.cs index fbb10f02..a53946a3 100644 --- a/TMDbLib/Rest/RestRequest.cs +++ b/TMDbLib/Rest/RestRequest.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using TMDbLib.Objects.Exceptions; @@ -89,54 +90,54 @@ private void CheckResponse(HttpResponseMessage response) throw new UnauthorizedAccessException("Call to TMDb returned unauthorized. Most likely the provided API key is invalid."); } - public async Task ExecuteDelete() + public async Task ExecuteDelete(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Delete).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Delete, cancellationToken).ConfigureAwait(false); CheckResponse(resp); return new RestResponse(resp); } - public async Task> ExecuteDelete() + public async Task> ExecuteDelete(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Delete).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Delete, cancellationToken).ConfigureAwait(false); CheckResponse(resp); return new RestResponse(resp, _client); } - public async Task ExecuteGet() + public async Task ExecuteGet(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Get).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Get, cancellationToken).ConfigureAwait(false); CheckResponse(resp); return new RestResponse(resp); } - public async Task> ExecuteGet() + public async Task> ExecuteGet(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Get).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Get, cancellationToken).ConfigureAwait(false); CheckResponse(resp); return new RestResponse(resp, _client); } - public async Task ExecutePost() + public async Task ExecutePost(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Post).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Post, cancellationToken).ConfigureAwait(false); CheckResponse(resp); return new RestResponse(resp); } - public async Task> ExecutePost() + public async Task> ExecutePost(CancellationToken cancellationToken) { - HttpResponseMessage resp = await SendInternal(HttpMethod.Post).ConfigureAwait(false); + HttpResponseMessage resp = await SendInternal(HttpMethod.Post, cancellationToken).ConfigureAwait(false); CheckResponse(resp); @@ -190,7 +191,7 @@ private HttpRequestMessage PrepRequest(HttpMethod method) return req; } - private async Task SendInternal(HttpMethod method) + private async Task SendInternal(HttpMethod method, CancellationToken cancellationToken) { // Account for the following settings: // - MaxRetryCount Max times to retry @@ -211,7 +212,7 @@ private async Task SendInternal(HttpMethod method) if (_client.Proxy != null) handler.Proxy = _client.Proxy; - HttpResponseMessage resp = await new HttpClient(handler).SendAsync(req).ConfigureAwait(false); + HttpResponseMessage resp = await new HttpClient(handler).SendAsync(req, cancellationToken).ConfigureAwait(false); if (resp.StatusCode == (HttpStatusCode)429) { @@ -219,10 +220,10 @@ private async Task SendInternal(HttpMethod method) TimeSpan? retryAfter = resp.Headers.RetryAfter?.Delta.Value; if (retryAfter.HasValue && retryAfter.Value.TotalSeconds > 0) - await Task.Delay(retryAfter.Value).ConfigureAwait(false); + await Task.Delay(retryAfter.Value, cancellationToken).ConfigureAwait(false); else // TMDb sometimes gives us 0-second waits, which can lead to rapid succession of requests - await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); continue; } From 5c0f1759641d466c2c41761fdb8806de83400993 Mon Sep 17 00:00:00 2001 From: Michael Bisbjerg Date: Fri, 24 Nov 2017 21:28:08 +0100 Subject: [PATCH 2/2] Add xml-docs --- TMDbLib/Client/TMDbClient.cs | 3 ++- TMDbLib/Client/TMDbClientAccount.cs | 1 + TMDbLib/Client/TMDbClientAuthentication.cs | 1 + TMDbLib/Client/TMDbClientFind.cs | 1 + TMDbLib/Client/TMDbClientLists.cs | 7 +++++++ TMDbLib/Client/TMDbClientMovies.cs | 3 +++ TMDbLib/Client/TMDbClientNetworks.cs | 1 + TMDbLib/Client/TMDbClientTimezones.cs | 1 + TMDbLib/Client/TMDbClientTvEpisodes.cs | 4 ++++ TMDbLib/Client/TMDbClientTvSeasons.cs | 4 ++++ TMDbLib/Client/TMDbClientTvShows.cs | 8 ++++++++ 11 files changed, 33 insertions(+), 1 deletion(-) diff --git a/TMDbLib/Client/TMDbClient.cs b/TMDbLib/Client/TMDbClient.cs index c5d838e7..038ec6cb 100644 --- a/TMDbLib/Client/TMDbClient.cs +++ b/TMDbLib/Client/TMDbClient.cs @@ -132,12 +132,13 @@ public bool ThrowErrorOnExeedingMaxCalls /// Check for more information. /// public IWebProxy WebProxy { get; private set; } - + /// /// Used internally to assign a session id to a request. If no valid session is found, an exception is thrown. /// /// Request /// The target session type to set. If set to Unassigned, the method will take the currently set session. + /// The location of the paramter in the resulting query private void AddSessionId(RestRequest req, SessionType targetType = SessionType.Unassigned, ParameterType parameterType = ParameterType.QueryString) { if ((targetType == SessionType.Unassigned && SessionType == SessionType.GuestSession) || diff --git a/TMDbLib/Client/TMDbClientAccount.cs b/TMDbLib/Client/TMDbClientAccount.cs index b991d00e..a574d4a5 100644 --- a/TMDbLib/Client/TMDbClientAccount.cs +++ b/TMDbLib/Client/TMDbClientAccount.cs @@ -46,6 +46,7 @@ public partial class TMDbClient /// The type of media to influence /// The id of the movie/tv show to influence /// True if you want the specified movie to be part of the watchlist, false if not + /// A cancellation token /// True if the the movie's status on the watchlist was successfully updated, false if not /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. diff --git a/TMDbLib/Client/TMDbClientAuthentication.cs b/TMDbLib/Client/TMDbClientAuthentication.cs index f9001142..26fbfae6 100644 --- a/TMDbLib/Client/TMDbClientAuthentication.cs +++ b/TMDbLib/Client/TMDbClientAuthentication.cs @@ -39,6 +39,7 @@ public partial class TMDbClient /// /// A valid TMDb username /// The passoword for the provided login + /// A cancellation token public async Task AuthenticationGetUserSessionAsync(string username, string password, CancellationToken cancellationToken = default(CancellationToken)) { Token token = await AuthenticationRequestAutenticationTokenAsync(cancellationToken).ConfigureAwait(false); diff --git a/TMDbLib/Client/TMDbClientFind.cs b/TMDbLib/Client/TMDbClientFind.cs index 69c59a9a..26410957 100644 --- a/TMDbLib/Client/TMDbClientFind.cs +++ b/TMDbLib/Client/TMDbClientFind.cs @@ -19,6 +19,7 @@ public partial class TMDbClient /// The source the specified id belongs to /// The id of the object you wish to located /// A list of all objects in TMDb that matched your id + /// A cancellation token public async Task FindAsync(FindExternalSource source, string id, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("find/{id}"); diff --git a/TMDbLib/Client/TMDbClientLists.cs b/TMDbLib/Client/TMDbClientLists.cs index c9b0c00e..df11198a 100644 --- a/TMDbLib/Client/TMDbClientLists.cs +++ b/TMDbLib/Client/TMDbClientLists.cs @@ -14,6 +14,7 @@ public partial class TMDbClient /// Retrieve a list by it's id /// /// The id of the list you want to retrieve + /// A cancellation token public async Task GetListAsync(string listId, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(listId)) @@ -32,6 +33,7 @@ public partial class TMDbClient /// /// Id of the list to check in /// Id of the movie to check for in the list + /// A cancellation token public async Task GetListIsMoviePresentAsync(string listId, int movieId, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(listId)) @@ -54,6 +56,7 @@ public partial class TMDbClient /// /// The id of the list to add the movie to /// The id of the movie to add + /// A cancellation token /// True if the method was able to add the movie to the list, will retrun false in case of an issue or when the movie was already added to the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. @@ -66,6 +69,7 @@ public partial class TMDbClient /// Clears a list, without confirmation. /// /// The id of the list to clear + /// A cancellation token /// True if the method was able to remove the movie from the list, will retrun false in case of an issue or when the movie was not present in the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. @@ -96,6 +100,7 @@ public partial class TMDbClient /// The name of the new list /// Optional description for the list /// Optional language that might indicate the language of the content in the list + /// A cancellation token /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. public async Task ListCreateAsync(string name, string description = "", string language = null, CancellationToken cancellationToken = default(CancellationToken)) @@ -132,6 +137,7 @@ public partial class TMDbClient /// Deletes the specified list that is owned by the user /// /// A list id that is owned by the user associated with the current session id + /// A cancellation token /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. public async Task ListDeleteAsync(string listId, CancellationToken cancellationToken = default(CancellationToken)) @@ -159,6 +165,7 @@ public partial class TMDbClient /// /// The id of the list to add the movie to /// The id of the movie to add + /// A cancellation token /// True if the method was able to remove the movie from the list, will retrun false in case of an issue or when the movie was not present in the list /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. diff --git a/TMDbLib/Client/TMDbClientMovies.cs b/TMDbLib/Client/TMDbClientMovies.cs index bd42d15d..5988de5e 100644 --- a/TMDbLib/Client/TMDbClientMovies.cs +++ b/TMDbLib/Client/TMDbClientMovies.cs @@ -23,6 +23,7 @@ public partial class TMDbClient /// Retrieves all information for a specific movie in relation to the current user account /// /// The id of the movie to get the account states for + /// A cancellation token /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. public async Task GetMovieAccountStateAsync(int movieId, CancellationToken cancellationToken = default(CancellationToken)) @@ -70,6 +71,7 @@ public partial class TMDbClient /// The Imdb id of the movie OR the TMDb id as string /// Language to localize the results in. /// A list of additional methods to execute for this req as enum flags + /// A cancellation token /// The reqed movie or null if it could not be found /// Requires a valid user session when specifying the extra method 'AccountStates' flag /// Thrown when the current client object doens't have a user session assigned, see remarks. @@ -343,6 +345,7 @@ private async Task GetMovieMethod(int movieId, MovieMethods movieMethod, s /// /// The id of the movie to rate /// The rating you wish to assign to the specified movie. Value needs to be between 0.5 and 10 and must use increments of 0.5. Ex. using 7.1 will not work and return false. + /// A cancellation token /// True if the the movie's rating was successfully updated, false if not /// Requires a valid guest or user session /// Thrown when the current client object doens't have a guest or user session assigned. diff --git a/TMDbLib/Client/TMDbClientNetworks.cs b/TMDbLib/Client/TMDbClientNetworks.cs index dda219f7..0a804d18 100644 --- a/TMDbLib/Client/TMDbClientNetworks.cs +++ b/TMDbLib/Client/TMDbClientNetworks.cs @@ -12,6 +12,7 @@ public partial class TMDbClient /// Retrieves a network by it's TMDb id. A network is a distributer of media content ex. HBO, AMC /// /// The id of the network object to retrieve + /// A cancellation token public async Task GetNetworkAsync(int networkId, CancellationToken cancellationToken = default(CancellationToken)) { RestRequest req = _client.Create("network/{networkId}"); diff --git a/TMDbLib/Client/TMDbClientTimezones.cs b/TMDbLib/Client/TMDbClientTimezones.cs index bf24d812..9e9e4177 100644 --- a/TMDbLib/Client/TMDbClientTimezones.cs +++ b/TMDbLib/Client/TMDbClientTimezones.cs @@ -18,6 +18,7 @@ public partial class TMDbClient /// /// The source the specified id belongs to /// The id of the object you wish to located + /// A cancellation token /// A list of all objects in TMDb that matched your id public async Task GetTimezonesAsync(CancellationToken cancellationToken = default(CancellationToken)) { diff --git a/TMDbLib/Client/TMDbClientTvEpisodes.cs b/TMDbLib/Client/TMDbClientTvEpisodes.cs index 29702556..1fb91b28 100644 --- a/TMDbLib/Client/TMDbClientTvEpisodes.cs +++ b/TMDbLib/Client/TMDbClientTvEpisodes.cs @@ -38,6 +38,7 @@ public partial class TMDbClient /// The episode number of the episode you want to retrieve. /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token public async Task GetTvEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods extraMethods = TvEpisodeMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { if (extraMethods.HasFlag(TvEpisodeMethods.AccountStates)) @@ -106,6 +107,7 @@ public partial class TMDbClient /// The season number of the season the episode belongs to. Note use 0 for specials. /// The episode number of the episode you want to retrieve information for. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token public async Task GetTvEpisodeCreditsAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Credits, dateFormat: "yyyy-MM-dd", language: language, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -117,6 +119,7 @@ public partial class TMDbClient /// The TMDb id of the target tv show. /// The season number of the season the episode belongs to. Note use 0 for specials. /// The episode number of the episode you want to retrieve information for. + /// A cancellation token public async Task GetTvEpisodeExternalIdsAsync(int tvShowId, int seasonNumber, int episodeNumber, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -132,6 +135,7 @@ public partial class TMDbClient /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// + /// A cancellation token public async Task GetTvEpisodeImagesAsync(int tvShowId, int seasonNumber, int episodeNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvEpisodeMethod(tvShowId, seasonNumber, episodeNumber, TvEpisodeMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); diff --git a/TMDbLib/Client/TMDbClientTvSeasons.cs b/TMDbLib/Client/TMDbClientTvSeasons.cs index cbf21501..021d9b1a 100644 --- a/TMDbLib/Client/TMDbClientTvSeasons.cs +++ b/TMDbLib/Client/TMDbClientTvSeasons.cs @@ -37,6 +37,7 @@ public partial class TMDbClient /// The season number of the season you want to retrieve. Note use 0 for specials. /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token /// The requested season for the specified tv show public async Task GetTvSeasonAsync(int tvShowId, int seasonNumber, TvSeasonMethods extraMethods = TvSeasonMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { @@ -106,6 +107,7 @@ public partial class TMDbClient /// The TMDb id of the target tv show. /// The season number of the season you want to retrieve information for. Note use 0 for specials. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token public async Task GetTvSeasonCreditsAsync(int tvShowId, int seasonNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Credits, dateFormat: "yyyy-MM-dd", language: language, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -116,6 +118,7 @@ public partial class TMDbClient /// /// The TMDb id of the target tv show. /// The season number of the season you want to retrieve information for. Note use 0 for specials. + /// A cancellation token public async Task GetTvSeasonExternalIdsAsync(int tvShowId, int seasonNumber, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -130,6 +133,7 @@ public partial class TMDbClient /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// + /// A cancellation token public async Task GetTvSeasonImagesAsync(int tvShowId, int seasonNumber, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvSeasonMethod(tvShowId, seasonNumber, TvSeasonMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); diff --git a/TMDbLib/Client/TMDbClientTvShows.cs b/TMDbLib/Client/TMDbClientTvShows.cs index a116db98..d735b503 100644 --- a/TMDbLib/Client/TMDbClientTvShows.cs +++ b/TMDbLib/Client/TMDbClientTvShows.cs @@ -29,6 +29,7 @@ public partial class TMDbClient /// Retrieves all information for a specific tv show in relation to the current user account /// /// The id of the tv show to get the account states for + /// A cancellation token /// Requires a valid user session /// Thrown when the current client object doens't have a user session assigned. public async Task GetTvShowAccountStateAsync(int tvShowId, CancellationToken cancellationToken = default(CancellationToken)) @@ -56,6 +57,7 @@ public partial class TMDbClient /// TMDb id of the tv show to retrieve. /// Enum flags indicating any additional data that should be fetched in the same request. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token /// The requested Tv Show public async Task GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { @@ -115,6 +117,7 @@ public partial class TMDbClient /// /// The TMDb id of the target tv show. /// If specified the api will attempt to return a localized result. ex: en,it,es + /// A cancellation token public async Task GetTvShowCreditsAsync(int id, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvShowMethod(id, TvShowMethods.Credits, "yyyy-MM-dd", language, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -124,6 +127,7 @@ public partial class TMDbClient /// Returns an object that contains all known exteral id's for the tv show related to the specified TMDB id. /// /// The TMDb id of the target tv show. + /// A cancellation token public async Task GetTvShowExternalIdsAsync(int id, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvShowMethod(id, TvShowMethods.ExternalIds, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -137,6 +141,7 @@ public partial class TMDbClient /// If specified the api will attempt to return a localized result. ex: en,it,es. /// For images this means that the image might contain language specifc text /// + /// A cancellation token public async Task GetTvShowImagesAsync(int id, string language = null, CancellationToken cancellationToken = default(CancellationToken)) { return await GetTvShowMethod(id, TvShowMethods.Images, language: language, cancellationToken: cancellationToken).ConfigureAwait(false); @@ -169,6 +174,7 @@ public partial class TMDbClient /// Type of list to fetch /// Page /// Only relevant for list type AiringToday + /// A cancellation token /// public async Task> GetTvShowListAsync(TvShowListType list, int page = 0, string timezone = null, CancellationToken cancellationToken = default(CancellationToken)) { @@ -182,6 +188,7 @@ public partial class TMDbClient /// Language /// Page /// Only relevant for list type AiringToday + /// A cancellation token /// public async Task> GetTvShowListAsync(TvShowListType list, string language, int page = 0, string timezone = null, CancellationToken cancellationToken = default(CancellationToken)) { @@ -313,6 +320,7 @@ public partial class TMDbClient /// /// The id of the tv show to rate /// The rating you wish to assign to the specified tv show. Value needs to be between 0.5 and 10 and must use increments of 0.5. Ex. using 7.1 will not work and return false. + /// A cancellation token /// True if the the tv show's rating was successfully updated, false if not /// Requires a valid guest or user session /// Thrown when the current client object doens't have a guest or user session assigned.