public async Task GetPreviousPageAsync(bool ascendingSort = true, NiblOrderBy orderby = NiblOrderBy.FileName) { if (string.IsNullOrEmpty(PreviousPage)) { throw new Exception("The previous page is not available."); } await SearchBotsDeepAsync(SearchTerms, page : PreviousPage, size : ResultsPerPage, botId : BotId, ascendingSort : ascendingSort, orderby : orderby); }
public async Task GoToPageAsync(int page, bool ascendingSort = true, NiblOrderBy orderby = NiblOrderBy.FileName) { --page; if (page <= TotalPages && page >= 0) { string newpage = CurrentPage; var parse = HttpUtility.ParseQueryString(newpage); parse.Set("page", page.ToString()); newpage = parse.ToString(); await SearchBotsDeepAsync(SearchTerms, page : newpage, size : ResultsPerPage, botId : BotId, ascendingSort : ascendingSort, orderby : orderby); } }
public async Task <NiblPackList> SearchPackListFullAsync(string search, string page = null, int?botId = null, int size = 10, int epNumber = -1, string specificPage = null, bool ascendingSort = true, NiblOrderBy order = NiblOrderBy.FileName) { using (var client = new HttpClient()) { var botadd = (botId == null) ? string.Empty : $"{((int)botId).ToString()}/"; string sortOrder = (ascendingSort) ? "ASC" : "DESC"; string orderby; switch (order) { case NiblOrderBy.BotId: orderby = "botId"; break; case NiblOrderBy.FileName: orderby = "name"; break; case NiblOrderBy.FileSize: orderby = "sizekbits"; break; case NiblOrderBy.PackName: orderby = "number"; break; default: orderby = "name"; break; } var baseurl = $"https://api.nibl.co.uk/nibl/search/{botadd}page?query={search}&episodeNumber={epNumber}&page=0&size={size}&sort={orderby}&direction={sortOrder}"; if (page != null) { baseurl = $"https://api.nibl.co.uk/nibl/search/{botadd}page?{page}"; } if (specificPage != null) { baseurl = $"https://api.nibl.co.uk/nibl/search/{botadd}page?query={search}&episodeNumber={epNumber}&page=0&size={size}&sort={orderby}&direction={sortOrder}"; } var data = await client.GetStringAsync(baseurl).ConfigureAwait(false); var nibl = NiblPackList.FromJson(data); if (nibl.Status != "OK") { throw new Exception("Bot search not available"); } return(nibl); } }
public async Task SearchBotsDeepAsync(string search, string page = null, int?botId = null, int size = 10, int epNumber = -1, string specificPage = null, bool ascendingSort = true, NiblOrderBy orderby = NiblOrderBy.FileName) { NextPage = ""; PreviousPage = ""; CurrentPage = ""; SearchTerms = ""; TotalResults = 0; TotalPages = 0; NiblPackList list; //await GetBotsAsync(); try { if (botList.Count() == 0) { await GetBotsAsync(); } list = await niblSearchClient.SearchPackListFullAsync(search, page, botId, size, epNumber, specificPage, ascendingSort, orderby).ConfigureAwait(false); } catch (Exception exception) { throw new Exception($"{exception.Message}"); } SearchTerms = search; NextPage = list.Next; PreviousPage = list.Previous; CurrentPage = list.Current; TotalResults = (int)list.Total; TotalPages = ((int)list.Total / size); if ((list.Total % size) > 0) { TotalPages++; } string value = HttpUtility.ParseQueryString(list.Current).Get("page"); ActivePage = Convert.ToInt32(value) + 1; ResultsPerPage = ((int)list.Max); BotId = botId; var withName = list.PackList.Select(x => new SimplePack((long)x.BotId, botList[(long)x.BotId], x.Name, x.Size, (long)x.Number)); Model.SimpleCollection = new ObservableCollection <SimplePack>(withName); return; }