Exemple #1
0
 private void LoadExamsList(IImportView view)
 {
     view.IsListLoading = true;
     currentExamSaver   = null;
     view.ExamSavers    = ExamsListService.GetInstance().ExamSavers;
     view.IsListLoading = false;
 }
Exemple #2
0
        private async void ViewSelectedExamChanged(IImportView sender)
        {
            if (!ReferenceEquals(sender.CurrentExamSaver, currentExamSaver))
            {
                sender.IsExamLoading = true;
                sender.IsExamLoading = true;
                ExamsListService examsList = ExamsListService.GetInstance();
                IExamSaver       saver     = sender.CurrentExamSaver;
                IList <Question> questions = await Task.Run(() => saver.GetQuestions());

                if (questions == null)
                {
                    sender.ShowError($"Не удалось загрузить экзамен.\nОн был удален из списка.{ Environment.NewLine }Ошибка: { saver.LastExceptionMessage }");
                    examsList.Remove(sender.CurrentExamSaver);
                    currentExamSaver     = null;
                    sender.IsExamLoading = false;
                    return;
                }
                else
                {
                    currentExamSaver     = sender.CurrentExamSaver;
                    sender.Questions     = questions;
                    sender.IsExamLoading = false;
                }
            }
        }
Exemple #3
0
        private async void ViewExamChanged(IStartView sender)
        {
            if (!ReferenceEquals(sender.CurrentExamSaver, currentExamSaver))
            {
                sender.IsExamLoading = true;
                ExamsListService examsList = ExamsListService.GetInstance();
                IExamSaver       saver     = sender.CurrentExamSaver;
                Exam             exam      = await ApplicationController.Run <LoadingContextPresenter <Exam>, Task <Exam> >(Task.Run(() => saver.GetExam())).GetTask();

                if (exam == null)
                {
                    sender.ShowError($"Не удалось загрузить экзамен.\nОн был удален из списка.{saver.LastExceptionMessage}");
                    try
                    {
                        examsList.Remove(sender.CurrentExamSaver);
                    }
                    catch { }
                    currentExamSaver     = null;
                    sender.IsExamLoading = false;
                    return;
                }
                else
                {
                    currentExamSaver     = sender.CurrentExamSaver;
                    sender.CurrentExam   = exam;
                    sender.IsExamLoading = false;
                }
            }
        }
Exemple #4
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}");
            }
        }
Exemple #5
0
        private async void ViewDeleted(IStartView sender)
        {
            ExamsListService examsList = ExamsListService.GetInstance();

            if (!await Task.Run(() => currentExamSaver.Delete()))
            {
                sender.ShowError("Не удалось удалить экзамен из его расположения.\nОн удален из списка.");
            }
            examsList.Remove(currentExamSaver);
            currentExamSaver = null;
        }
Exemple #6
0
        private void ViewViewShown(IStartView sender)
        {
            sender.IsListLoading = true;
            currentExamSaver     = null;
            sender.ExamSavers    = ExamsListService.GetInstance().ExamSavers;
            sender.IsListLoading = false;
            SessionService sessionService = SessionService.GetInstance();

            if (sessionService.Session != null)
            {
                sessionService.Session.Abort();
                sessionService.Session = null;
            }
        }
Exemple #7
0
        public ImportPresenter(IImportView view, IApplicationController applicationController) : base(view, applicationController)
        {
            view.ViewShown           += ViewViewShown;
            view.ConnectionAsked     += ViewConnectionAsked;
            view.FileOpened          += ViewFileOpened;
            view.Searched            += ViewSearched;
            view.SelectedExamChanged += ViewSelectedExamChanged;
            view.Imported            += ViewImported;
            ExamsListService examsList = ExamsListService.GetInstance();

            examsList.ListRefreshed += ExamsListListRefreshed;
            DatabaseService databaseService = DatabaseService.GetInstance();

            databaseService.ConnctionEstablished += DatabaseServiceConnctionEstablished;
            databaseService.ConnctionLosted      += DatabaseServiceConnctionLosted;
        }
Exemple #8
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}");
            }
        }
Exemple #9
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 }");
            }
        }
Exemple #10
0
        public StartPresenter(IStartView view, IApplicationController applicationController) : base(view, applicationController)
        {
            view.SessionStarted       += ViewSessionStarted;
            view.ViewShown            += ViewViewShown;
            view.ConnectionAsked      += ViewConnected;
            view.ExamSelectionChanged += ViewExamChanged;
            view.ExamDeleted          += ViewDeleted;
            view.FileOpened           += ViewOpened;
            view.DeleteResult         += ViewDeleteResult;
            view.ExamEdited           += ViewExamEdited;
            view.ExamCreated          += ViewExamCreated;
            view.WatchTask            += ViewWatchTask;
            view.WatchResult          += ViewWatchResult;
            view.WatchBlank           += ViewWatchBlank;
            ExamsListService examsList = ExamsListService.GetInstance();

            examsList.ListRefreshed += ExamsListListRefreshed;
            DatabaseService databaseService = DatabaseService.GetInstance();

            databaseService.ConnctionEstablished += DatabaseServiceConnctionEstablished;
            databaseService.ConnctionLosted      += DatabaseServiceConnctionLosted;
        }
Exemple #11
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}");
            }
        }