Exemple #1
0
        protected void SaveActivityStateAndTransition <ToViewModel>()
        {
            DebugLog.Info("Save state");
            navigator.Reveal <ProgressIndicatorViewModel>().Then((vm, onRevealed, onRevealError) =>
            {
                ProgressIndicatorViewModel progressIndicatorViewModel = vm.ResultAs <ProgressIndicatorViewModel>();
                ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Saving...");
                activityService.SaveActivityState(ActivityState)
                .Then((prevResult, onCompleted, onError) =>
                {
                    navigator.Transition(this, typeof(ToViewModel));
                    onCompleted(true);
                })
                .Catch((Exception e) =>
                {
                    navigator.Reveal <AlertViewModel>(alert =>
                    {
                        alert.Title           = "Unable to save";
                        alert.Message         = e.Message;
                        alert.Error           = e;
                        alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                    }).Start();
                }).Finally(() =>
                {
                    busyIndicator.Dispose();
                }).Start();

                onRevealed(true);
            }).Start();
        }
        private void RefreshActivityList()
        {
            try
            {
                Contract.PropertyNotNull("sessionState.CourseSettings", sessionState.CourseSettings);

                DebugLog.Info("RefreshActivityList");
                navigator.Reveal <ProgressIndicatorViewModel>().Then((vm, onRevealed, onRevealError) =>
                {
                    ProgressIndicatorViewModel progressIndicatorViewModel = vm.ResultAs <ProgressIndicatorViewModel>();
                    ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Loading...");
                    activityService.LoadActivities(sessionState.CourseSettings.CourseId)
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Activities loaded");
                        Activities = prevResult.ResultAs <List <Activity> >();
                        IEnumerable <string> activityIds = Activities.Select(a => a.Id);
                        activityService.LoadActivityStates(sessionState.Student.Id, activityIds).Start(onCompleted, onError);
                    })
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Activity States loaded");
                        ActivityStates = prevResult.ResultAs <List <ActivityState> >();
                        onCompleted(true);
                    })
                    .Catch((Exception e) =>
                    {
                        DebugLog.Error("Can't load activitues: {0}", e.Message);
                        navigator.Reveal <AlertViewModel>(alert =>
                        {
                            alert.Title           = "Unable to load activity information.";
                            alert.Message         = e.Message;
                            alert.Error           = e;
                            alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                        }).Start();
                    }).Finally(() =>
                    {
                        busyIndicator.Dispose();
                    }).Start();

                    onRevealed(true);
                }).Start();
            }
            catch (Exception e)
            {
                navigator.Reveal <AlertViewModel>(alert =>
                {
                    alert.Title   = "Unable load activity information";
                    alert.Message = e.Message;
                    alert.Error   = e;
                }).Start();
            }
        }
        public void StartActivity(Activity activity)
        {
            try
            {
                Contract.ArgumentNotNull("activity", activity);

                DebugLog.Info("Started Activity {0}", activity.Name);

                navigator.Reveal <ProgressIndicatorViewModel>().Then((vm, onRevealed, onRevealError) =>
                {
                    ProgressIndicatorViewModel progressIndicatorViewModel = vm.ResultAs <ProgressIndicatorViewModel>();
                    ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Starting...");
                    activityLauncher.Start(sessionState.Student, activity, false)
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        navigator.Transition(this, prevResult.ResultAs <ActivityViewModel>());
                        onCompleted(true);
                    })
                    .Catch((Exception e) =>
                    {
                        navigator.Reveal <AlertViewModel>(alert =>
                        {
                            alert.Title           = "Unable to start activity";
                            alert.Message         = e.Message;
                            alert.Error           = e;
                            alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                        }).Start();
                    }).Finally(() =>
                    {
                        busyIndicator.Dispose();
                    }).Start();
                }).Start();
            }
            catch (Exception e)
            {
                navigator.Reveal <AlertViewModel>(alert =>
                {
                    alert.Title   = "Unable to start activity";
                    alert.Message = e.Message;
                    alert.Error   = e;
                }).Start();
            }
        }
Exemple #4
0
        public void SignIn(string group, string username, string password)
        {
            try
            {
                if (string.IsNullOrEmpty(username))
                {
                    throw new Exception("Username is blank");
                }

                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("Password is blank");
                }

                sessionState.Student = null;
                sessionState.Session = null;

                DebugLog.Info("SignIn {0}...", username);
                navigator.Reveal <ProgressIndicatorViewModel>().Then((vm, onRevealed, onRevealError) =>
                {
                    ProgressIndicatorViewModel progressIndicatorViewModel = vm.ResultAs <ProgressIndicatorViewModel>();
                    ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Signing in...");
                    // TODO rgtaylor 2015-12-10 Replace hardcoded 'domain'
                    authenticator.SignIn(group, username, password)
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Signed in {0}", username);
                        sessionState.Student = prevResult.ResultAs <Student>();
                        sessionService.Start(sessionState.Student.SessionGuid).Start(onCompleted, onError);
                    })
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Session started");
                        sessionState.Session = prevResult.ResultAs <Session>();
                        courseSettingsService.LoadSettings(sessionState.Student.Id).Start(onCompleted, onError);
                    })
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Settings loaded");
                        sessionState.CourseSettings = prevResult.ResultAs <CourseSettings>();
                        navigator.Transition(this, typeof(MainMenuViewModel));
                        onCompleted(true);
                    }).Catch((Exception e) =>
                    {
                        navigator.Reveal <AlertViewModel>(alert =>
                        {
                            alert.Title           = "Unable to sign in";
                            alert.Message         = e.Message;
                            alert.Error           = e;
                            alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                        });
                    }).Finally(() =>
                    {
                        busyIndicator.Dispose();
                    }).Start();

                    onRevealed(true);
                }).Start();
            }
            catch (Exception e)
            {
                navigator.Reveal <AlertViewModel>(alert =>
                {
                    alert.Title   = "Unable to sign in";
                    alert.Message = e.Message;
                    alert.Error   = e;
                }).Start();
            }
        }