private void ProcessMissingInformation(List <RequestQueue> requests) { if (!requests.Any()) { return; } var sonarrSettings = SonarrSettings.GetSettings(); var sickrageSettings = SickrageSettings.GetSettings(); var tv = requests.Where(x => x.Type == RequestType.TvShow); // TV var tvApi = new TvMazeApi(); foreach (var t in tv) { var providerId = int.Parse(t.PrimaryIdentifier); var showInfo = tvApi.ShowLookup(providerId); if (showInfo.externals?.thetvdb != null) { // We now have the info var tvModel = ByteConverterHelper.ReturnObject <RequestedModel>(t.Content); tvModel.ProviderId = showInfo.externals.thetvdb.Value; var result = ProcessTvShow(tvModel, sonarrSettings, sickrageSettings); if (!result) { // we now have the info but couldn't add it, so add it back into the queue but with a different fault t.Content = ByteConverterHelper.ReturnBytes(tvModel); t.FaultType = FaultType.RequestFault; t.LastRetry = DateTime.UtcNow; Repo.Update(t); } else { // Make sure it's been requested var existingRequests = RequestService.GetAll(); var thisItem = existingRequests.Any(x => x.Title.Equals(tvModel.Title)); if (!thisItem) { tvModel.Approved = true; RequestService.AddRequest(tvModel); } // Successful, remove from the fault queue Repo.Delete(t); } } } }
private void ProcessTransientErrors(List <RequestQueue> requests) { var sonarrSettings = SonarrSettings.GetSettings(); var sickrageSettings = SickrageSettings.GetSettings(); var cpSettings = CpSettings.GetSettings(); var hpSettings = HeadphoneSettings.GetSettings(); if (!requests.Any()) { return; } foreach (var request in requests) { var model = ByteConverterHelper.ReturnObject <RequestedModel>(request.Content); bool result; switch (request.Type) { case RequestType.Movie: result = ProcessMovies(model); break; case RequestType.TvShow: result = ProcessTvShow(model, sonarrSettings, sickrageSettings); break; case RequestType.Album: result = ProcessAlbums(model, hpSettings); break; default: throw new ArgumentOutOfRangeException(); } if (!result) { // we now have the info but couldn't add it, so do nothing now. request.LastRetry = DateTime.UtcNow; Repo.Update(request); } else { // Successful, remove from the fault queue Repo.Delete(request); } } }