Ejemplo n.º 1
0
        /* INTERNALS */
        #region Internals

        /// <summary>
        /// Loads the allowed modules when given
        /// a list of clsModule.
        /// </summary>
        /// <returns>The allowed modules.</returns>
        /// <param name="Modules">Modules.</param>
        private Dictionary <string, Interfaces.iModule> loadAllowedModules()
        {
            Dictionary <string, Interfaces.iModule> mm =
                new Dictionary <string, iModule> ();

            string tempPath = Path.GetTempPath();


            foreach (clsModule m in AllowedModules)
            {
                string src = lessonpath + Path.DirectorySeparatorChar + "Modules" +
                             Path.DirectorySeparatorChar + m.filename;

                string dest = tempPath + m.filename;

                if (File.Exists(dest))
                {
                    try {
                        File.Copy(src, dest, true);
                    } catch (IOException) {
                        // Couldn't copy the file probably
                        // Because it is already in use.
                    }
                }
                else
                {
                    File.Copy(src, dest);
                }

                Assembly DLL        = Assembly.LoadFile(dest);
                Type     moduleType = DLL.GetType(m.gettype);

                ConSim.Lib.Interfaces.iModule mod =
                    (ConSim.Lib.Interfaces.iModule)Activator.CreateInstance(moduleType);

                mm.Add(m.filename, mod);
            }

            return(mm);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loop during a lesson until finished.
        /// </summary>
        private static void lessonLoop()
        {
            while (true == true)
            {
                ConSim.Lib.Classes.clsTask task = null;

                if (currentLesson.isSandbox == false)
                {
                    task = currentLesson.activeTask;
                }

                Console.Write(lessonHeader() + nl + nl);
                Console.Write(">");

                string[] line        = Console.ReadLine().Split(' ');
                string   command     = line [0];
                string[] args        = filterLine(line);
                bool     attemptTask = false;
                bool     boolBreak   = false;

                try {
                    ConSim.Lib.Interfaces.iModule mod = currentLesson.cmdToiMod(command);

                    mod.errorOutputChanged +=
                        new EventHandler <iModuleOutputEventArgs>(onErrorOutputChange);
                    mod.standardOutputChanged +=
                        new EventHandler <iModuleOutputEventArgs>(onStandardOutputChange);
                    mod.resultCodeChanged +=
                        new EventHandler <iModuleOutputEventArgs>(onResultChange);

                    attemptTask = currentLesson.attemptTask(command, args, mod);

                    mod.errorOutputChanged    -= onErrorOutputChange;
                    mod.standardOutputChanged -= onStandardOutputChange;
                    mod.resultCodeChanged     -= onResultChange;
                } catch (Exception ex) {
                    currentLesson.lastErrorOutput = ex.Message;
                    Console.WriteLine(nl + ex.Message);
                }

                // Lesson has been completed
                if (attemptTask && currentLesson.isSandbox == false)
                {
                    Console.Write(nl + "Congratulations! You passed the lesson!");
                    boolBreak = true;
                }

                // Task was completed but still more tasks to go
                if (attemptTask == false &&
                    currentLesson.isSandbox == false &&
                    task.Equals(currentLesson.activeTask) == false)
                {
                    Console.Write(nl + "Congratulations! You passed this task!");
                }

                // Attempt was unsuccessful
                if (attemptTask == false &&
                    currentLesson.isSandbox == false &&
                    task.Equals(currentLesson.activeTask))
                {
                    Console.Write(nl + "Unfortunately this was not the expected " +
                                  "output :(. Try Again!");
                }

                if (currentLesson.isSandbox == false)
                {
                    Console.ReadKey();
                    Console.Clear();
                }

                if (boolBreak)
                {
                    break;
                }
            }
        }