Beispiel #1
0
 public static List <TaskWithInfo> GetTasksInExercise(ExerciseWithInfo exercise)
 {
     return((
                from m in exercise.Exercise.GetMethods()
                where m.IsDefined(typeof(TaskAttribute), false)
                let twi = new TaskWithInfo(
                    m,
                    m.GetCustomAttribute(typeof(TaskAttribute)) as TaskAttribute
                    )
                          orderby twi.Number
                          select twi
                ).ToList());
 }
Beispiel #2
0
        private static void RunTask(ExerciseWithInfo exercise, TaskWithInfo task)
        {
            PrintHeading(exercise.Name + " - "
                         + (task.Name.IsWhitespace()
                                           ? task.Task.Name
                                           : task.Name),
                         HeadingLevel.H4
                         );
            PrintLn(task.Description.IsWhitespace() ? "(No description given)" : task.Description);

            var exerciseInstance = exercise.Exercise
                                   .GetConstructor(new Type[] { })
                                   .Invoke(new object[] { });

            task.Task.Invoke(exerciseInstance, new object[] { });
        }
Beispiel #3
0
        /// <returns>false if the user signaled that he wants to exit</returns>
        private static bool ExerciseMenu(ExerciseWithInfo exercise)
        {
            PrintHeading(
                string.IsNullOrWhiteSpace(exercise.Name)
                    ? exercise.Exercise.Name
                    : exercise.Name,
                HeadingLevel.H3
                );
            PrintLn(exercise.Description.IsWhitespace()
                ? "(No description given)"
                : exercise.Description
                    );

            var tasks = Finder.GetTasksInExercise(exercise);

            PrintLn();
            PrintLn("The following tasks are availiable:");
            PrintList(tasks.Select(t => $"{t.Number}: {t.Name}").ToArray());

            FlushIn();
            string input = ReadLn("Type in the number or 'exit'");

            if (input.Trim().ToLower() == "exit")
            {
                return(false);
            }

            var task = Finder.FindTaskByNumber(tasks, input);

            if (task == null)
            {
                PrintLn("Could not find task with specified number!");
                return(true);
            }

            RunTask(exercise, task.Value);
            return(true);
        }