Exemplo n.º 1
0
            public void btnLearningMode_Click(object sender, EventArgs e)
            {
                BTProgressHUD.Show("Downloading Exam", 0);
                bool _isDownloadSuccessful = false;

                Task.Factory.StartNew(() => {
                    try {
                        WebserviceHelper.GenerateUserExam(true, AppSession.SelectedExam.MainSystemID, AppSession.LoggedInUser.MainSystemID);
                        //Use && statement in if so that code gets evaluated only if the previous statement returns true (e.g. if DownloadExamBaseData, we dont need to execute DownloadExamImageFiles)
                        if (SyncManager.DownloadExamBaseData(AppSession.SelectedExam) &&
                            SyncManager.DownloadExamImageFiles(AppSession.SelectedExam, DownloadExamImageProgressUpdated) &&
                            SyncManager.DownloadUserExamCompleteData(AppSession.LoggedInUser, AppSession.SelectedExam))
                        {
                            AppSession.SelectedUserExam = BusinessModel.UserExam.GetFirstUserExamByUserIDAndExamID(
                                AppSession.LoggedInUser.UserID,
                                AppSession.SelectedExam.ExamID);

                            AppSession.SelectedUserExam.IsDownloaded = true;
                            AppSession.SelectedUserExam.Save();
                            _isDownloadSuccessful = true;
                        }
                        else
                        {
                            _isDownloadSuccessful = false;
                        }
                    } catch (Exception ex) {
                        _isDownloadSuccessful = false;
                        Console.WriteLine(ex.ToString());
                    }
                }).ContinueWith(task1 => {
                    BTProgressHUD.Dismiss();
                    if (_isDownloadSuccessful)
                    {
                        if (!AppSession.SelectedUserExam.HasReadDisclosure)
                        {
                            //Show Disclosure
                            ExamDisclosureView _disclosureView = new ExamDisclosureView(true);
                            m_currentViewController.NavigationController.PushViewController(_disclosureView, true);
                        }
                        else if (!AppSession.SelectedUserExam.HasReadPrivacyPolicy)
                        {
                            //Show Privacy Policy
                            ExamPrivacyPolicyView _privacyPolicyView = new ExamPrivacyPolicyView(true);
                            m_currentViewController.NavigationController.PushViewController(_privacyPolicyView, true);
                        }
                        else
                        {
                            //Navigate straight to the exam
                            if (UserInterfaceIdiomIsPhone)
                            {
                                m_currentViewController.NavigationController.PushViewController(new ExamQuestionList_iPhone(), true);
                            }
                            else
                            {
                                QuestionSplitView _questionSplitView = new QuestionSplitView();
                                _questionSplitView.PresentAsRootViewWithAnimation();
                            }
                        }
                    }
                    else
                    {
                        UIAlertView _alert = new UIAlertView("Download Failed", "We could not download your exam right now. Please try again later", null, "Ok", null);
                        _alert.Show();
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
Exemplo n.º 2
0
            private void downloadExamAlertView_Dismissed(object sender, UIButtonEventArgs e)
            {
                if (e.ButtonIndex == ((UIAlertView)sender).CancelButtonIndex)
                {
                    //If cancel button is clicked then we return as we dont need to do anything
                    return;
                }
                bool _isDownloadSuccessful = false;

                if (AppSession.SelectedUserExam == null)
                {
                    //Direct the user to a specific page to select their exam types
                    m_currentViewController.NavigationController.PushViewController(new GenerateNewExamView(), true);
                    return;
                }

                BTProgressHUD.Show("Downloading Exam", 0);
                UIApplication.SharedApplication.IdleTimerDisabled = true;
                Task.Factory.StartNew(() => {
                    try{
                        if (SyncManager.DownloadExamBaseData(AppSession.SelectedExam) &&
                            SyncManager.DownloadExamImageFiles(AppSession.SelectedExam, DownloadExamImageProgressUpdated) &&
                            SyncManager.DownloadUserExamCompleteData(AppSession.LoggedInUser, AppSession.SelectedExam))
                        {
                            //Update the user exam to session just in case the user exam gets updated in download
                            AppSession.SelectedUserExam = BusinessModel.UserExam.GetFirstUserExamByUserIDAndExamID(
                                AppSession.LoggedInUser.UserID,
                                AppSession.SelectedExam.ExamID);

                            AppSession.SelectedUserExam.IsDownloaded = true;
                            AppSession.SelectedUserExam.Save();
                            _isDownloadSuccessful = true;
                        }
                        else
                        {
                            _isDownloadSuccessful = false;
                        }
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }).ContinueWith(task1 => {
                    BTProgressHUD.Dismiss();
                    UIApplication.SharedApplication.IdleTimerDisabled = false;
                    if (_isDownloadSuccessful)
                    {
                        if (!AppSession.SelectedUserExam.HasReadDisclosure)
                        {
                            ExamDisclosureView _disclosureView = new ExamDisclosureView(true);
                            m_currentViewController.NavigationController.PushViewController(_disclosureView, true);
                        }
                        else if (!AppSession.SelectedUserExam.HasReadPrivacyPolicy)
                        {
                            ExamPrivacyPolicyView _privacyPolicyView = new ExamPrivacyPolicyView(true);
                            m_currentViewController.NavigationController.PushViewController(_privacyPolicyView, true);
                        }
                        else
                        {
                            if (UserInterfaceIdiomIsPhone)
                            {
                                m_currentViewController.NavigationController.PushViewController(new ExamQuestionList_iPhone(), true);
                            }
                            else
                            {
                                QuestionSplitView _questionSplitView = new QuestionSplitView();
                                _questionSplitView.PresentAsRootViewWithAnimation();
                            }
                        }
                    }
                    else
                    {
                        UIAlertView _alert = new UIAlertView("Download Failed", "We could not download your exam right now. Please try again later", null, "Ok", null);
                        _alert.Show();
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }