Exemple #1
0
        private static async Task <NamingMethod> AskForNamingMethod()
        {
            const string secondChoice   = "Use the file name that appears on courses (Recommended)";
            const string examplesChoice = "Show examples and ask again (will show random 5 examples, BUT slower)";

            var choicesPossible = new List <string>
            {
                "Use the file name from the url (default behavior when downloading from browser)",
                secondChoice,
                examplesChoice
            };

            while (true)
            {
                var result = MenuChooseItem.AskInputForSingleItemFromList(choicesPossible, "choice", "choose");

                if (result == choicesPossible[0])
                {
                    SharedVars.NamingMethod = NamingMethod.UrlName;
                    break;
                }

                if (result == choicesPossible[1])
                {
                    SharedVars.NamingMethod = NamingMethod.CoursesName;
                    break;
                }

                if (result == choicesPossible[2])
                {
                    // because we're displaying in place but AskInputForSingleItemFromList still appends to breadcrumbs
                    SharedVars.ChosenItemsTillNow.Remove(SharedVars.ChosenItemsTillNow.Keys.Last());

                    choicesPossible.Remove(examplesChoice);
                    var randomN = SharedVars.DownloadQueue.TakeRandomN(5);

                    var table = new ConsoleTableUtil("From Courses", "From URL (Default)");

                    foreach (var link in randomN)
                    {
                        await link.GetNameFromUrlNow();

                        table.AddRow(
                            link.FileFromCourses.FileNameAndExtensionOnly,
                            link.FileFromUrl.FileNameAndExtensionOnly
                            );
                    }

                    var examples = $"Some examples:\n\n{table}";

                    choicesPossible.Remove(secondChoice);
                    choicesPossible.Add($"{secondChoice}\n{examples}");
                }
            }


            return(SharedVars.NamingMethod);
        }
Exemple #2
0
        private static async Task <ISection> AskForSection()
        {
            await SectionExtractor.ExtractSectionsForCourse(SharedVars.SelectedCourseLink);

            var result = MenuChooseItem.AskInputForSingleItemFromList(SharedVars.Sections, "section");

            SharedVars.SelectedSection = result;
            return(result);
        }
Exemple #3
0
        private static async Task <ICourseLink> AskForCourse()
        {
            await CoursesExtractor.ExtractCourses();

            var result = MenuChooseItem.AskInputForSingleItemFromList(SharedVars.Courses, "course");

            SharedVars.SelectedCourseLink = result;
            return(result);
        }
Exemple #4
0
        private static async Task HandleSwitchSemesterAction()
        {
            var namedSemesters = new List <string>
            {
                "1st Semester",
                "2nd Semester",
                "3rd Semester"
            };

            namedSemesters.AddRange(Enumerable.Range(4, 5).Select(i => $"{i}th Semester"));

            var semestersCount = await CoursesExtractor.ExtractSemestersCount();

            var itemsList = namedSemesters.Take(semestersCount).ToList();

            var chosenItem = MenuChooseItem.AskInputForSingleItemFromList(itemsList, "semester", "switch to", breadcrumbs: false);

            var chosenSemester = namedSemesters.IndexOf(chosenItem) + 1;

            SharedVars.CurrentSemesterNumber = chosenSemester;
        }