private async Task RunScraper( IActionTypeAssistant actionTypeAssistant, ITvMazeDataManipulator dataManipulator, int lastShowId, CancellationToken cancellationToken) { var pageId = actionTypeAssistant.GetFirstPageToCall(lastShowId); IEnumerable <TvMazeShow> tvMazeShows; do { tvMazeShows = await GetTvMazeShowsPagedAsync(pageId ++); foreach (var show in tvMazeShows) { if (cancellationToken.IsCancellationRequested) { break; } if (actionTypeAssistant.ShouldOmitShow(lastShowId, show.Id)) { continue; } var actors = await GetTvMazeCastAsync(show); await dataManipulator.RunAsync(show, actors.Select(actor => actor.Person)); } } while (actionTypeAssistant.ShouldContinue(lastShowId, pageId) && tvMazeShows.Any() && !cancellationToken.IsCancellationRequested); }
private void InitializeActionTypeAssistants(IEnumerable <IActionTypeAssistant> actionTypeAssistants) { foreach (var actionTypeAssistant in actionTypeAssistants) { if (actionTypeAssistant.GetType() == typeof(NewDataAssistant)) { _newDataAssistant = actionTypeAssistant; } else if (actionTypeAssistant.GetType() == typeof(ExistingDataAssistant)) { _existingDataAssistant = actionTypeAssistant; } } }