示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classes.clsTask"/> class.
        /// < /summary>
        /// <param name="filepath">Path to a valid json task.</param>
        public clsTask(string filepath)
        {
            clsTask newTask = null;

            using (FileStream f = new FileStream(filepath, FileMode.Open)) {
                DataContractJsonSerializer ser =
                    new DataContractJsonSerializer(typeof(clsTask));

                newTask = (clsTask)ser.ReadObject(f);

                f.Close();
            }

            // Set readonly variables
            this.ExpectedResult    = newTask.ExpectedResult;
            this.LongDescription   = newTask.LongDescription;
            this.Name              = newTask.Name;
            this.ShortDescription  = newTask.ShortDescription;
            this.lazyMatching      = newTask.lazyMatching;
            this.regexMatching     = newTask.regexMatching;
            this.commandToTask     = newTask.commandToTask;
            this.errorToTask       = newTask.errorToTask;
            this.allowedCommands   = newTask.allowedCommands;
            this.disallowedStrings = newTask.disallowedStrings;

            if (this.allowedCommands == null)
            {
                this.allowedCommands = new List <string> ();
            }
            if (this.disallowedStrings == null)
            {
                this.disallowedStrings = new List <string> ();
            }
        }
示例#2
0
        public void TestExistingTaskRead()
        {
            ConSim.Lib.Classes.clsTask newTask =
            new ConSim.Lib.Classes.clsTask (taskJSON);

              // Assert that the values on read-back are the same
              Assert.AreEqual (newTask.ExpectedResult, "true");
              Assert.AreEqual (newTask.LongDescription, "This is a long description");
              Assert.AreEqual (newTask.ShortDescription, "This is short");
              Assert.AreEqual (newTask.Name, "taskness");
        }
示例#3
0
        public void TestExistingTaskRead()
        {
            ConSim.Lib.Classes.clsTask newTask =
                new ConSim.Lib.Classes.clsTask(taskJSON);

            // Assert that the values on read-back are the same
            Assert.AreEqual(newTask.ExpectedResult, "true");
            Assert.AreEqual(newTask.LongDescription, "This is a long description");
            Assert.AreEqual(newTask.ShortDescription, "This is short");
            Assert.AreEqual(newTask.Name, "taskness");
        }
示例#4
0
        public void TestTaskWrite()
        {
            task.save(taskJSON);
            ConSim.Lib.Classes.clsTask newTask =
                new ConSim.Lib.Classes.clsTask(taskJSON);

            // Assert that the values on read-back are the same
            Assert.AreEqual(newTask.ExpectedResult, ExpectedResult);
            Assert.AreEqual(newTask.LongDescription, LongDescription);
            Assert.AreEqual(newTask.ShortDescription, ShortDescription);
            Assert.AreEqual(newTask.Name, Name);
        }
示例#5
0
        public void TestLazyMatching()
        {
            ConSim.Lib.Classes.clsTask newTask =
            new clsTask (Name, ShortDescription, LongDescription, "needle", true,
              false, false, false, new System.Collections.Generic.List<string>(),
              new System.Collections.Generic.List<string>());

              string result = "hayneedlestack";
              string result2 = "haynedlestack";

              // Assert that lazy matching does what it is supposed to.
              Assert.True(newTask.hasPassed(result));
              Assert.False (newTask.hasPassed (result2));
        }
示例#6
0
        public void TestTaskWrite()
        {
            task.save (taskJSON);
              ConSim.Lib.Classes.clsTask newTask =
            new ConSim.Lib.Classes.clsTask (taskJSON);

              // Assert that the values on read-back are the same
              Assert.AreEqual (newTask.ExpectedResult, ExpectedResult);
              Assert.AreEqual (newTask.LongDescription, LongDescription);
              Assert.AreEqual (newTask.ShortDescription, ShortDescription);
              Assert.AreEqual (newTask.Name, Name);
        }
示例#7
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;
                }
            }
        }