Exemplo n.º 1
0
        public bool DemoStopped()
        {
            for (var i = 0; i < 10; i++)
            {
                if (DemoStateHandler.Instance.Stopped)
                {
                    _nextDemoState = Constants.ApplicationState.ScheduleAdd;
                    Application.Current.Dispatcher.Invoke(
                        () => { _viewModel.RemoveClassroom(DemoStateHandler.Instance.DemoClassroomId); });
                    DemoStateHandler.Instance.StopDemo();

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        DrawerHost.IsLeftDrawerOpen = false;
                        _viewModel.FindLastSchedule();
                        OpenLastSchedule();
                        _viewModel.RemoveClassroom(DemoStateHandler.Instance.DemoClassroomId);
                    });

                    return(true);
                }
                Thread.Sleep(100);
            }
            return(false);
        }
Exemplo n.º 2
0
        public void DoDemo()
        {
            Task.Factory.StartNew(() =>
            {
                if (DemoStopped())
                {
                    return;
                }
                switch (_nextDemoState)
                {
                case Constants.ApplicationState.ScheduleAdd:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        DrawerHost.IsLeftDrawerOpen = false;
                        var dialog = new ScheduleName {
                            Owner = this
                        };
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();

                        if (!string.IsNullOrEmpty(dialog.Name))
                        {
                            if (_viewModel.LastOpenedSchedule != null)
                            {
                                _viewModel.UpdateCurrentSchedule();
                            }

                            _viewModel.LastOpenedSchedule = new Schedule
                            {
                                Id = dialog.Name,
                            };

                            _viewModel.SaveCurrentSchedule();
                            _viewModel.InitRemainigSessions();

                            // in case this is the first time running
                            ScheduleView.Visibility   = Visibility.Visible;
                            ClassromsPanel.Visibility = Visibility.Visible;
                            ScheduleLabel.Visibility  = Visibility.Hidden;
                            GlobalButton.IsEnabled    = true;

                            Schedule.Appointments.Clear();

                            Title = $"{dialog.Name} - {_appTitle}";
                        }

                        _nextDemoState = Constants.ApplicationState.Courses;
                        DrawerHost.IsLeftDrawerOpen = true;
                    });
                    DemoStopped();
                    break;

                case Constants.ApplicationState.Courses:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var dialog = new CourseList(_viewModel);
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();
                        _nextDemoState = Constants.ApplicationState.Softwares;
                    });
                    DemoStopped();
                    break;

                case Constants.ApplicationState.Softwares:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var dialog = new SoftwareList(_viewModel);
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();
                        _nextDemoState = Constants.ApplicationState.Subjects;
                    });
                    DemoStopped();
                    break;

                case Constants.ApplicationState.Subjects:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var dialog = new SubjectList(_viewModel);
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();
                        _nextDemoState = Constants.ApplicationState.Classrooms;
                    });
                    DemoStopped();
                    break;

                case Constants.ApplicationState.Classrooms:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var dialog = new ClassroomList(_viewModel);
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();
                        _nextDemoState = Constants.ApplicationState.SessionDetails;
                        DrawerHost.IsLeftDrawerOpen = false;
                    });
                    DemoStopped();
                    break;

                case Constants.ApplicationState.SessionDetails:
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        _viewModel.Classroom = _viewModel.Classrooms[0];
                        var startTime        = DateTime.Now.StartOfWeek().Date + new TimeSpan(7, 15, 0);
                        var session          = _viewModel.RemainingSessions[0];
                        var avaibleTerms     = _viewModel.GetAvailableTerms(null, startTime, session);
                        var dialog           = new SessionDetails(_viewModel, Schedule.Appointments, avaibleTerms, startTime,
                                                                  session);
                        DemoStateHandler.Instance.DemoState = dialog;
                        dialog.ShowDialog();
                        _nextDemoState = Constants.ApplicationState.ScheduleAdd;
                    });
                    if (DemoStopped())
                    {
                        return;
                    }
                    //if (DemoStopped()) return;
                    Application.Current.Dispatcher.Invoke(
                        () => { _viewModel.RemoveClassroom(DemoStateHandler.Instance.DemoClassroomId); });
                    DemoStateHandler.Instance.RemoveDemoEntities();
                    _viewModel.LastOpenedSchedule = null;
                    break;
                }
            });
        }