예제 #1
0
        public string RandomAssessmentID(AssessmentSession session, string coursePath)
        {
            if (Directory.Exists(@coursePath))
            {
                string[] dirs = Directory.GetDirectories(@coursePath);
                if (dirs.Count() > 0)
                {
                    string id = "";
                    do
                    {
                        id = Util.RandomString(6);
                    } while (id == "" || dirs.Where(c => c.EndsWith(id)).Any());

                    return(session.AssessmentInfo.AssessmentName + " - " + id);
                }
                else
                {
                    string id = Util.RandomString(6);
                    return(session.AssessmentInfo.AssessmentName + " - " + id);
                }
            }
            else
            {
                throw new ArgumentException("Cannot find specified path: \n\n" + coursePath, "coursePath");
            }
        }
예제 #2
0
 private void LoadAllCourses(string coursesPath)
 {
     string[] courseDirs = Directory.GetDirectories(coursesPath);
     if (courseDirs.Count() > 0)
     {
         for (int i = 0; i < courseDirs.Count(); i++)
         {
             //Get all the files in the course dir
             string[] files = Directory.GetFiles(courseDirs[i]);
             string   path  = null;
             try
             {
                 path = (from t in files
                         where Path.GetExtension(t) == COURSE_EXT
                         select t).First();
             }
             catch { }
             if (!path.NullOrEmpty())
             {
                 Course c = LoadCourse(path);
                 if (c != null)
                 {
                     c.ResetAssessments();
                     courses.Add(c);
                     //Load the assessments for this course
                     string[] assessmentDirs = Directory.GetDirectories(courseDirs[i]);
                     if (assessmentDirs.Count() > 0)
                     {
                         foreach (string a in assessmentDirs)
                         {
                             string assessmentPath = null;
                             try
                             {
                                 assessmentPath = (from t in Directory.GetFiles(a)
                                                   where Path.GetExtension(t) == ASSESSMENT_SESSION_EXT
                                                   select t).First();
                             }
                             catch { }
                             if (!assessmentPath.NullOrEmpty())
                             {
                                 AssessmentSession session = LoadSession(assessmentPath);
                                 if (session != null)
                                 {
                                     c.Assessments.Add(session);
                                     session.FolderPath = a;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #3
0
        public void AddAssessmentSession(AssessmentSession session)
        {
            Course c = (from t in Courses
                        where t.ID == session.CourseID
                        select t).First();

            if (c != null)
            {
                c.Assessments.Add(session);
            }
        }
예제 #4
0
        public EmailHandler(AssessmentSession session, List <StudentMarkingData> smd, bool includeModelAnswers)
        {
            InitializeComponent();
            this.session             = session;
            this.smd                 = smd;
            this.includeModelAnswers = includeModelAnswers;

            if (smd == null || smd.Count == 0)
            {
                throw new ArgumentException("Given StudentMarkingData is null or contains no elements", "smd");
            }
            progress.Maximum = smd.Count;
            SentCount        = 0;
        }
예제 #5
0
 public string CreateAssessmentDir(AssessmentSession session, string coursePath)
 {
     try
     {
         string dirName = Path.Combine(@coursePath, RandomAssessmentID(session, @coursePath));
         if (!Directory.Exists(dirName))
         {
             Directory.CreateDirectory(dirName);
         }
         return(dirName);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #6
0
        public AssessmentSession LoadSession(string path)
        {
            AssessmentSession s = null;

            try
            {
                using (FileStream fs = File.Open(@path, FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    s = (AssessmentSession)bf.Deserialize(fs);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to load assessment session: \n\n" + ex.Message);
            }
            return(s);
        }
예제 #7
0
        public bool SerialiseSession(AssessmentSession session, string filePath)
        {
            try
            {
                using (FileStream s = File.Open(@filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(s, session);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save assessment session: \n\n" + ex.Message);
                return(false);
            }

            return(true);
        }
예제 #8
0
 public HandoutWriter(AssessmentSession session, string outputPath, string rulesPath)
 {
     this.session    = session;
     this.outputPath = outputPath;
     this.rulesPath  = rulesPath;
 }
예제 #9
0
 public EmailHandler(AssessmentSession session, StudentMarkingData smd, bool includeModelAnswers) : this(session, new List <StudentMarkingData> {
     smd
 }, includeModelAnswers)
 {
 }
예제 #10
0
 public AssessmentSessionNode(AssessmentSession session)
 {
     this.session = session;
     Text         = session.AssessmentInfo.AssessmentName;
     Name         = Text;
 }
 public AssessmentSessionResultsWriter(AssessmentSession session, string filePath)
 {
     this.session  = session;
     this.filePath = filePath;
 }
예제 #12
0
        public void DeleteSession(AssessmentSession session)
        {
            try
            {
                //Delete session backup files
                if (Directory.Exists(session.FolderPath))
                {
                    FileSystem.DeleteDirectory(session.FolderPath, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error removing session backup files: \n\n" + e.Message);
            }
            //Delete any deployed files
            if (Directory.Exists(session.DeploymentTarget))
            {
                string[] accountDirs = Directory.GetDirectories(session.DeploymentTarget);
                if (accountDirs.Count() > 0)
                {
                    foreach (var accountDir in accountDirs)
                    {
                        //Delete the files
                        string[] files = Directory.GetFiles(accountDir);
                        if (files.Count() > 0)
                        {
                            foreach (var file in files)
                            {
                                try
                                {
                                    string fileName   = Path.GetFileName(file);
                                    string scriptName = session.AssessmentInfo.AssessmentName + ASSESSMENT_SCRIPT_EXT;
                                    if (fileName == scriptName)
                                    {
                                        FileSystem.DeleteFile(file);
                                        continue;
                                    }
                                    else if (session.AdditionalFiles.Count > 0 && session.AdditionalFiles.Contains(fileName))
                                    {
                                        FileSystem.DeleteFile(file);
                                        continue;
                                    }
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show("Error removing session files: \n\n" + e.Message);
                                }
                            }
                        }
                        string[] subDirs = Directory.GetDirectories(accountDir);
                        if (subDirs.Count() > 0)
                        {
                            //Delete the autosaves folder
                            try
                            {
                                string autosavesDir = (from t in subDirs
                                                       where new DirectoryInfo(t).Name == AUTOSAVE_FOLDER_NAME(session.AssessmentInfo.AssessmentName)
                                                       select t).First();
                                if (!autosavesDir.NullOrEmpty())
                                {
                                    if (Directory.Exists(autosavesDir))
                                    {
                                        FileSystem.DeleteDirectory(autosavesDir, UIOption.OnlyErrorDialogs, RecycleOption.DeletePermanently);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show("Error removing autosaves directory: \n\n " + e.Message);
                            }
                        }
                    }
                }
            }
            Course c = FindCourseByID(session.CourseID);

            if (c != null)
            {
                c.Assessments.Remove(session);
            }
        }