/// <summary> /// Loads the tracks of the given author /// </summary> /// <param name="searchType">The search type</param> /// <param name="author">The author</param> /// <param name="trackName">The name of the track</param> /// <param name="environment">The selected environment</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The list of tracks</returns> public async Task <List <Track> > LoadTracks(SearchType searchType, string author, string trackName, Environment environment, CancellationTokenSource cancellationToken) { var limit = 50; if (string.IsNullOrEmpty(author) && string.IsNullOrEmpty(trackName) && searchType == SearchType.Filter) { searchType = SearchType.LatestTracks; } if (searchType != SearchType.Filter) { limit = 10; } var page = 1; var result = new List <Track>(); if (cancellationToken.IsCancellationRequested) { return(new List <Track>()); } var initData = await LoadTracks(searchType, author, trackName, environment, limit, page); if (initData == null) { return(result); } result.AddRange(initData.Results); if (searchType != SearchType.Filter) { return(result); } var maxEntries = Math.Round(initData.TotalItemCount / (double)limit); for (page = 2; page <= maxEntries; page++) { if (cancellationToken.IsCancellationRequested) { return(result); } var data = await LoadTracks(searchType, author, trackName, environment, limit, page); if (data != null) { result.AddRange(data.Results); } } return(result); }
/// <summary> /// Loads a list of tracks of the author /// </summary> /// <param name="searchType">The search type</param> /// <param name="author">The author name</param> /// <param name="trackName">The name of the track</param> /// <param name="environment">The selected environment</param> /// <param name="limit">The limit of results per page</param> /// <param name="page">The page</param> /// <param name="showLatest">true when only the latest tracks should be shown, otherwise false</param> /// <returns>The list with the tracks</returns> private async Task <TrackList> LoadTracks(SearchType searchType, string author, string trackName, Environment environment, int limit, int page) { // Step 0: Get the endpoint var endpoint = GetEndpoint(EndpointType.TrackSearch); // Step 1: Create the request var request = new RestRequest(Method.GET) { RequestFormat = DataFormat.Json }; request.AddParameter("api", "on"); request.AddParameter("limit", limit); if (searchType != SearchType.Filter) { request.AddParameter("mode", (int)searchType); } else { if (!string.IsNullOrEmpty(author)) { request.AddParameter("author", author); } if (!string.IsNullOrEmpty(trackName)) { request.AddParameter("trackname", trackName); } request.AddParameter("page", page); } if (environment.Id != 0) { request.AddParameter("environments", environment.Id); } return(await ExecuteAsync <TrackList>(request, endpoint.Path)); }