Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classes.clsLesson"/> class.
        /// < /summary>
        /// <param name="filepath">Path to a valid json lesson.</param>
        public clsLesson(string filepath)
        {
            clsLesson newLesson = null;

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

                newLesson = (clsLesson)ser.ReadObject(f);
            }

            //Set readonly variables
            this.Name           = newLesson.Name;
            this.Tasks          = (List <clsTask>)newLesson.Tasks;
            this.Version        = newLesson.Version;
            this.AllowedModules = newLesson.AllowedModules;
            this.lessonpath     = Path.GetDirectoryName(filepath);
            this.ModuleMap      = loadAllowedModules();

            try {
                this.activeTask = this.Tasks[0];
            } catch (Exception) {
                //WARNING: No tasks in this lesson, sandbox mode is active!
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classes.clsLesson"/> class.
        /// </summary>
        /// <param name="Name">Name.</param>
        /// <param name="Version">Version.</param>
        /// <param name="AllowedModules">Allowed modules.</param>
        /// <param name="Tasks">Tasks.</param>
        /// <param name="LessonDirectory">Root directory of the lesson
        /// (used to load modules)</param>
        public clsLesson(string Name, string Version, List <clsTask> Tasks,
                         List <clsModule> Modules, string LessonDirectory,
                         bool commandToTask = false)
        {
            this.Name           = Name;
            this.Version        = Version;
            this.Tasks          = Tasks;
            this.AllowedModules = Modules;
            this.lessonpath     = LessonDirectory;
            this.ModuleMap      = loadAllowedModules();

            try {
                this.activeTask = this.Tasks [0];
            } catch (Exception) {
                //WARNING: No tasks in this lesson, sandbox mode is active!
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Attempts the task. Returns true if the lesson is finished
        /// a false return means you should refresh the task.
        /// </summary>
        /// <returns><c>true</c>, if task was attempted,
        /// <c>false</c> otherwise.</returns>
        /// <param name="command">Command.</param>
        /// <param name="args">Arguments.</param>
        public bool attemptTask(string command, string[] args,
                                Interfaces.iModule mod)
        {
            cleanOnRun();

            string disallowedArg = disallowedCheck(args);

            if (disallowedArg != null)
            {
                throw new ArgumentException
                          ("ERROR: Your command contains a disallowed argument: "
                          + disallowedArg);
            }

            if (mod.unsupportedCommand(command, args))
            {
                throw new ArgumentException
                          ("This command is unsupported by the module");
            }

            mod.run(command, args);

            string comparison = mod.standardOutput();

            lastStandardOutput = mod.standardOutput();
            lastErrorOutput    = mod.errorOutput();
            lastResultCode     = mod.resultCode();

            if (isSandbox)
            {
                return(false);
            }

            if (activeTask.errorToTask)
            {
                comparison = mod.errorOutput();
            }
            if (activeTask.commandToTask)
            {
                comparison = command + " ";

                foreach (string s in args)
                {
                    comparison += s + " ";
                }

                comparison = comparison.TrimEnd();
            }
            if (activeTask.errorToTask && activeTask.commandToTask)
            {
                comparison = mod.errorOutput()
                             + Environment.NewLine
                             + Environment.NewLine
                             + command;
            }

            if (activeTask.hasPassed(comparison) && isLastTask)
            {
                return(true);
            }

            if (activeTask.hasPassed(comparison) && isLastTask == false)
            {
                activeTask = Tasks [currentTaskNo + 1];
                return(false);
            }

            if (activeTask.hasPassed(comparison) == false)
            {
                return(false);
            }

            throw new Exception("An unknown exception ocurred in the lesson flow");
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts the task. Returns true if the lesson is finished
        /// a false return means you should refresh the task.
        /// </summary>
        /// <returns><c>true</c>, if task was attempted, 
        /// <c>false</c> otherwise.</returns>
        /// <param name="command">Command.</param>
        /// <param name="args">Arguments.</param>
        public bool attemptTask(string command, string[] args, 
      Interfaces.iModule mod)
        {
            cleanOnRun ();

              string disallowedArg = disallowedCheck (args);

              if (disallowedArg != null) {
            throw new ArgumentException
              ("ERROR: Your command contains a disallowed argument: "
              + disallowedArg);
              }

              if (mod.unsupportedCommand(command, args))
              {
            throw new ArgumentException
              ("This command is unsupported by the module");
              }

              mod.run (command, args);

              string comparison = mod.standardOutput ();

              lastStandardOutput = mod.standardOutput ();
              lastErrorOutput = mod.errorOutput ();
              lastResultCode = mod.resultCode ();

              if (isSandbox)
            return false;

              if (activeTask.errorToTask)
            comparison = mod.errorOutput ();
              if (activeTask.commandToTask) {
            comparison = command + " ";

            foreach (string s in args) {
              comparison += s + " ";
            }

            comparison = comparison.TrimEnd ();
              }
              if (activeTask.errorToTask && activeTask.commandToTask)
            comparison = mod.errorOutput ()
            + Environment.NewLine
            + Environment.NewLine
            + command;

              if (activeTask.hasPassed (comparison) && isLastTask)
            return true;

              if (activeTask.hasPassed (comparison) && isLastTask == false)
              {
            activeTask = Tasks [currentTaskNo + 1];
            return false;
              }

              if (activeTask.hasPassed (comparison) == false)
            return false;

              throw new Exception ("An unknown exception ocurred in the lesson flow");
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classes.clsLesson"/> class.
        /// </summary>
        /// <param name="Name">Name.</param>
        /// <param name="Version">Version.</param>
        /// <param name="AllowedModules">Allowed modules.</param>
        /// <param name="Tasks">Tasks.</param>
        /// <param name="LessonDirectory">Root directory of the lesson 
        /// (used to load modules)</param>
        public clsLesson(string Name, string Version, List<clsTask> Tasks, 
      List<clsModule> Modules, string LessonDirectory,
      bool commandToTask = false)
        {
            this.Name = Name;
              this.Version = Version;
              this.Tasks = Tasks;
              this.AllowedModules = Modules;
              this.lessonpath = LessonDirectory;
              this.ModuleMap = loadAllowedModules ();

              try {
            this.activeTask = this.Tasks [0];
              } catch (Exception) {
            //WARNING: No tasks in this lesson, sandbox mode is active!
              }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classes.clsLesson"/> class.
        /// < /summary>
        /// <param name="filepath">Path to a valid json lesson.</param>
        public clsLesson(string filepath)
        {
            clsLesson newLesson = null;

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

            newLesson = (clsLesson)ser.ReadObject(f);

               }

              //Set readonly variables
              this.Name = newLesson.Name;
              this.Tasks = (List<clsTask>)newLesson.Tasks;
              this.Version = newLesson.Version;
              this.AllowedModules = newLesson.AllowedModules;
              this.lessonpath = Path.GetDirectoryName (filepath);
              this.ModuleMap = loadAllowedModules();

              try {
            this.activeTask = this.Tasks[0];
              } catch (Exception) {
            //WARNING: No tasks in this lesson, sandbox mode is active!
              }
        }