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 }");
            }
        }
Exemplo n.º 4
0
        private async void ViewSavedDb(IEditSavingView sender)
        {
            DatabaseService databaseService = DatabaseService.GetInstance();

            if (databaseService.ExamDatabaseWorker == null)
            {
                ApplicationController.Run <LogInDbPresenter, object>(null);
            }
            if (databaseService.ExamDatabaseWorker == null)
            {
                sender.ShowError("Подключение к базе данных не установлено.");
                return;
            }
            ExamsListService examsState = ExamsListService.GetInstance();
            Exam             exam       = GetCheckedExam();

            if (exam == null)
            {
                return;
            }
            IExamSaver examSaver = new DatabaseExamSaver(null, exam.Name);

            if (await ApplicationController.Run <LoadingContextPresenter <bool>, Task <bool> >(Task.Run(() => examSaver.Save(exam))).GetTask())
            {
                Argument.ExamSaver = examSaver;
                examsState.Add(examSaver);
                IList <string> temp = View.Warnings;
                temp.Add("Сохранено!");
                sender.Warnings  = temp;
                sender.AllowSave = true;
                savingFailed     = false;
            }
            else
            {
                sender.ShowError($"Непредвиденная ошибка сохранения.{ Environment.NewLine }Ошибка: {examSaver.LastExceptionMessage}");
            }
        }