Exemple #1
0
 public static ExamFileService GetInstance()
 {
     if (instance == null)
     {
         instance = new ExamFileService();
     }
     return(instance);
 }
 public bool Save(Exam exam)
 {
     try
     {
         password  = exam.Password;
         SaverName = exam.Name;
         ExamFileService fileService = ExamFileService.GetInstance();
         fileService.SaveExam(exam, filePath);
         openedExam = exam;
         return(true);
     }
     catch (Exception ex)
     {
         LastExceptionMessage = ex.Message;
         return(false);
     }
 }
        public bool SaveResult(ExecutionResult executionResults)
        {
            Exam exam = GetExam();

            if (exam is null)
            {
                return(false);
            }
            exam.ExecutionResults.Add(executionResults);
            try
            {
                password  = exam.Password;
                SaverName = exam.Name;
                ExamFileService fileService = ExamFileService.GetInstance();
                fileService.SaveExam(exam, filePath);
                return(true);
            }
            catch (Exception ex)
            {
                LastExceptionMessage = ex.Message;
                return(false);
            }
        }
        public Exam GetExam()
        {
            if (openedExam != null)
            {
                return(openedExam);
            }
            Exam exam;

            try
            {
                ExamFileService fileService = ExamFileService.GetInstance();
                exam      = fileService.OpenExam(filePath, password);
                password  = exam.Password;
                SaverName = exam.Name;
            }
            catch (Exception ex)
            {
                LastExceptionMessage = ex.Message;
                exam = null;
            }
            openedExam = exam;
            return(exam);
        }
        public IList <Question> GetQuestions()
        {
            List <Question> result;

            if (openedExam != null)
            {
                result = new List <Question>();
                for (int i = 0; i < openedExam.Tickets.Count; i++)
                {
                    result.AddRange(openedExam.Tickets[i].GetQuestions());
                }
                return(result);
            }
            Exam exam;

            try
            {
                result = new List <Question>();
                ExamFileService fileService = ExamFileService.GetInstance();
                exam       = fileService.OpenExam(filePath, password);
                password   = exam.Password;
                SaverName  = exam.Name;
                openedExam = exam;
                for (int i = 0; i < openedExam.Tickets.Count; i++)
                {
                    result.AddRange(openedExam.Tickets[i].GetQuestions());
                }
            }
            catch (Exception ex)
            {
                LastExceptionMessage = ex.Message;
                result = null;
                exam   = null;
            }
            openedExam = exam;
            return(result);
        }