private static async Task HandleRefreshAction() { await CoursesExtractor.ExtractCourses(); if (SharedVars.SelectedCourseLink != null) { await SectionExtractor.ExtractSectionsForCourse(SharedVars.SelectedCourseLink); } }
private static void HandleQueueModificationBaseAction(QueueModificationBaseAction action) { List <IDownloadableLink> matchingLinks; switch (action.MatchingItemType) { case ItemTypeToAddRemove.Course: matchingLinks = SharedVars.Courses .Where((course, j) => action.MatchingItems.Contains(j)) .SelectMany(course => SectionExtractor.ExtractSectionsForCourse(course).Result .SelectMany(section => section.Links)) .ToList(); break; case ItemTypeToAddRemove.Section: matchingLinks = SharedVars.Sections .Where((section, j) => action.MatchingItems.Contains(j)) .SelectMany(section => section.Links) .ToList(); break; case ItemTypeToAddRemove.Link: matchingLinks = SharedVars.SelectedSection.Links .Where((link, j) => action.MatchingItems.Contains(j)) .ToList(); break; default: matchingLinks = Enumerable.Empty <IDownloadableLink>().ToList(); break; } if (!matchingLinks.Any()) { ConsoleUtils.WriteLine("Unfortunately downloading files using multiple naming methods at once is not possible", ConsoleIOType.Error); return; } do { string message; if (action is AddAction) { var count = matchingLinks.Except(SharedVars.DownloadQueue).Count(); SharedVars.DownloadQueue.AddUnique(matchingLinks); message = $"Added {count} items (to revert, " + "simply call Remove like you did with Add in the same way and location"; } else { var count = SharedVars.DownloadQueue.Intersect(matchingLinks).Count(); SharedVars.DownloadQueue.RemoveAll(link => matchingLinks.Contains(link)); message = $"Removed {count} items (to revert, " + "simply call Add like you did with Remove in the same way and location"; } ConsoleUtils.WriteLine(message, ConsoleColor.Yellow); if (action is AddAction) { action = new RemoveAction(); } else { action = new AddAction(); } } while (MenuChooseItem.AskYesNoQuestion("Do you want to revert now? [Y/N] ")); }