/// <summary> /// Get character data /// </summary> /// <param name="client"></param> /// <param name="vnid"></param> /// <param name="ro"></param> /// <returns></returns> internal async Task <List <Character> > GetCharactersAsync(VndbSharp.Vndb client, uint vnid, RequestOptions ro) { try { stopwatch.Restart(); int pageCount = 1; bool shouldContinue = true; List <Character> characterList = new List <Character>(); while (shouldContinue) { ro.Page = pageCount; VndbResponse <Character> characters = await client.GetCharacterAsync(VndbFilters.VisualNovel.Equals(vnid), VndbFlags.FullCharacter, ro); switch (characters) { case null when client.GetLastError().Type == ErrorType.Throttled: await HandleVndbErrors.ThrottledWaitAsync((ThrottledError)client.GetLastError(), 0); break; case null: HandleVndbErrors.HandleErrors(client.GetLastError()); _didErrorOccur = true; return(null); default: { shouldContinue = characters.HasMore; //When false, it will exit the while loop characterList.AddRange(characters.Items); pageCount++; if (stopwatch.Elapsed > maxTime) { return(null); } break; } } } return(characterList); } catch (Exception e) { App.Logger.Warning(e, "Failed to Get Visual novel characters"); SentryHelper.SendException(e, null, SentryLevel.Warning); return(null); } }
/// <summary> /// Get Visual Novel data /// </summary> /// <param name="client"></param> /// <param name="vnid"></param> /// <returns></returns> internal async Task <VisualNovel> GetVisualNovelAsync(VndbSharp.Vndb client, uint vnid) { try { stopwatch.Restart(); while (true) { if (stopwatch.Elapsed > maxTime) { return(null); } VndbResponse <VisualNovel> visualNovels = await client.GetVisualNovelAsync(VndbFilters.Id.Equals(vnid), VndbFlags.FullVisualNovel); switch (visualNovels) { case null when client.GetLastError().Type == ErrorType.Throttled: await HandleVndbErrors.ThrottledWaitAsync((ThrottledError)client.GetLastError(), 0); break; case null: HandleVndbErrors.HandleErrors(client.GetLastError()); _didErrorOccur = true; return(null); default: return(visualNovels.First()); } } } catch (Exception e) { App.Logger.Warning(e, "Failed to Get Visual novel"); SentryHelper.SendException(e, null, SentryLevel.Warning); return(null); } }