Exemplo n.º 1
0
        private async void ViewOpened(IStartView sender, OpenExamEventArgs e)
        {
            Exam             exam      = null;
            IExamSaver       loaded    = null;
            ExamsListService examsList = ExamsListService.GetInstance();

            try
            {
                loaded = new FileExamSaver(e.FilePath, e.Password, sender.CurrentExamSaver.SaverName);
                int index = examsList.ExamSavers.IndexOf(loaded);
                if (index >= 0)
                {
                    sender.CurrentExamSaver = examsList.ExamSavers[index];
                    currentExamSaver        = examsList.ExamSavers[index];
                    return;
                }
            }
            catch
            { }
            loaded = new FileExamSaver(e.FilePath, e.Password, "");
            exam   = await Task.Run(() => loaded.GetExam());

            if (exam != null)
            {
                loaded = new FileExamSaver(e.FilePath, e.Password, exam.Name);
                examsList.Add(loaded);
                sender.CurrentExam = exam;
                currentExamSaver   = loaded;
            }
            else
            {
                sender.ShowError($"Не удалось открыть экзамен. {loaded.LastExceptionMessage}");
            }
        }
Exemplo n.º 2
0
        private async void ViewSavedAs(IEditSavingView sender, SaveExamEventArgs e)
        {
            Exam exam = GetCheckedExam();

            if (exam == null)
            {
                return;
            }
            IExamSaver       loaded    = null;
            ExamsListService examsList = ExamsListService.GetInstance();

            try
            {
                loaded = new FileExamSaver(e.FilePath, exam.Password, exam.Name);
                int index = examsList.ExamSavers.IndexOf(loaded);
                if (index >= 0)
                {
                    loaded = examsList.ExamSavers[index];
                }
            }
            catch
            { }
            if (loaded == null)
            {
                loaded = new FileExamSaver(e.FilePath, exam.Password, exam.Name);
            }
            Argument.ExamSaver = loaded;
            if (await ApplicationController.Run <LoadingContextPresenter <bool>, Task <bool> >(Task.Run(() => Argument.ExamSaver.Save(exam))).GetTask())
            {
                examsList.Add(loaded);
                IList <string> temp = View.Warnings;
                temp.Add("Сохранено!");
                sender.Warnings  = temp;
                sender.AllowSave = true;
                savingFailed     = false;
            }
            else
            {
                sender.ShowError($"Непредвиденная ошибка сохранения.{ Environment.NewLine }Ошибка: {Argument.ExamSaver.LastExceptionMessage}");
            }
        }
Exemplo n.º 3
0
        private async void ViewFileOpened(IImportView sender, OpenExamEventArgs e)
        {
            Exam             exam      = null;
            IExamSaver       loaded    = null;
            ExamsListService examsList = ExamsListService.GetInstance();

            try
            {
                loaded = new FileExamSaver(e.FilePath, e.Password, sender.CurrentExamSaver.SaverName);
                int index = examsList.ExamSavers.IndexOf(loaded);
                if (index >= 0)
                {
                    sender.CurrentExamSaver = examsList.ExamSavers[index];
                    currentExamSaver        = examsList.ExamSavers[index];
                    return;
                }
            }
            catch
            { }
            loaded = new FileExamSaver(e.FilePath, e.Password, "");
            exam   = await Task.Run(() => loaded.GetExam());

            if (exam != null)
            {
                loaded = new FileExamSaver(e.FilePath, e.Password, exam.Name);
                examsList.Add(loaded);
                List <Question> questions = new List <Question>();
                for (int i = 0; i < exam.Tickets.Count; i++)
                {
                    questions.AddRange(exam.Tickets[i].GetQuestions());
                }
                sender.Questions = questions;
                currentExamSaver = loaded;
            }
            else
            {
                sender.ShowError($"Не удалось открыть экзамен.{ Environment.NewLine }Ошибка: { loaded.LastExceptionMessage }");
            }
        }