Ejemplo n.º 1
0
        public ActionResult CreateStage(AssessmentStageCreateModel model)
        {
            var assessment = Db.Assessments.SingleOrDefault(x => x.Id == model.AssessmentId);

            var stage = new AssessmentStage();

            stage.Assessment        = assessment;
            stage.Name              = model.Name;
            stage.Description       = model.Description;
            stage.OpeningDateTime   = DateTime.Parse(model.Start);
            stage.ClosingDateTime   = DateTime.Parse(model.End);
            stage.ReportingDateTime = DateTime.Parse(model.Publish);
            stage.IsAvailable       = model.IsAvailable;

            Db.AssessmentStages.Add(stage);
            Db.SaveChanges();


            return(RedirectToAction("Details", new { id = model.AssessmentId }));
        }
Ejemplo n.º 2
0
        private async void LoadData(Bundle bundle)
        {
            ProgressDialog dialog = null;

            currentStage = AssessmentStage.Preparing;

            RunOnUiThread(() =>
            {
                dialog = new ProgressDialog(this);
                dialog.SetTitle("Downloading...");
                dialog.SetMessage("Please wait while we prepare your assessment.");
                dialog.SetCancelable(false);
                dialog.Show();
            });

            int id = Intent.GetIntExtra("ActivityId", -1);

            if (id >= 0)
            {
                assessment = (Assessment)await AppData.Session.FetchActivityWithId(id);
            }
            else
            {
                assessment = await ServerData.FetchAssessment();
            }

            if (assessment == null)
            {
                RunOnUiThread(() =>
                {
                    dialog.Hide();
                    SelfDestruct("It looks like you're offline...",
                        "Oops! We couldn't download your assessment - check your internet connection and try again later!");
                });
                return;
            }

            helpers = await assessment.PrepareTasks();

            FindViewById<TextView>(Resource.Id.assessment_preamble).Text = assessment.Description;

            tasks = assessment.AssessmentTasks;
            zipPath = Path.Combine(AppData.Exports.Path, assessment.Id + "_assessmentRes.zip");
            results = new ScenarioResult(assessment.Id, zipPath) { IsAssessment = true };

            if (bundle != null)
            {
                var previous = bundle.GetInt("ASSESSMENT_PROGRESS", -1);

                if (previous >= 0 && previous < tasks.Length)
                {
                    taskIndex = previous;
                    StartAssessment(bundle.GetInt("TASK_PROGRESS", -1));
                }
                else
                {
                    currentStage = AssessmentStage.Preamble;
                    preambleContainer.Visibility = ViewStates.Visible;
                    recButton.Visibility = ViewStates.Visible;
                    helpButton.Visibility = ViewStates.Visible;
                }
            }
            else
            {
                currentStage = AssessmentStage.Preamble;
                preambleContainer.Visibility = ViewStates.Visible;
                recButton.Visibility = ViewStates.Visible;
                helpButton.Visibility = ViewStates.Gone;
            }

            RunOnUiThread(() => { dialog.Hide(); });
        }
Ejemplo n.º 3
0
        private async void FinishAssessment()
        {
            currentStage = AssessmentStage.Finished;
            ProgressDialog progress;
            AppCompatDialog ratingsDialog = null;
            bool rated = false;

            RunOnUiThread(() =>
            {
                progress = new ProgressDialog(this);
                progress.SetTitle("Assessment Complete!");
                progress.SetMessage("Getting your recordings ready to upload...");

                ratingsDialog = new Android.Support.V7.App.AlertDialog.Builder(this)
                    .SetTitle("Assessment Complete!")
                    .SetMessage("How do you feel you did?")
                    .SetView(Resource.Layout.RatingDialog)
                    .SetCancelable(false)
                    .SetPositiveButton("Done", (par1, par2) =>
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        // ReSharper disable once AccessToModifiedClosure
                        RatingBar rating = ratingsDialog.FindViewById<RatingBar>(Resource.Id.dialogRatingBar);
                        results.UserRating = rating.Rating;
                        progress.Show();
                        rated = true;
                    })
                    .Create();

                ratingsDialog.Show();
            });

            FastZip fastZip = new FastZip();
            fastZip.CreateZip(zipPath, localTempDirectory, true, null);
            Directory.Delete(localTempDirectory, true);

            while (!rated)
            {
                await Task.Delay(200);
            }

            results.CompletionDate = DateTime.Now;
            AppData.Session.ResultsToUpload.Add(results);
            AppData.SaveCurrentData();
            StartActivity(typeof (UploadsActivity));
            Finish();
        }
Ejemplo n.º 4
0
        private void StartAssessment(int startPosition = -1)
        {
            preambleContainer.Visibility =
                (Resources.Configuration.Orientation == Android.Content.Res.Orientation.Landscape)
                    ? ViewStates.Invisible
                    : ViewStates.Gone;
            recButton.Visibility = ViewStates.Visible;
            helpButton.Visibility = ViewStates.Visible;

            currentStage = AssessmentStage.Running;

            if (startPosition >= 0)
            {
                currentFragment = FragmentManager.FindFragmentByTag<AssessmentFragment>("ASSESSMENT_TASK");
                currentFragment.GoToStage(startPosition);
            }
            else
            {
                SetNewFragment();
                FragmentManager.BeginTransaction()
                    .Add(Resource.Id.fragment_container, currentFragment, "ASSESSMENT_TASK")
                    .Commit();
            }

            fragmentContainer.Visibility = ViewStates.Visible;

            // If the device was rotated, the fragment might already exist and the data will be ready
            if (currentFragment.finishedCreating)
            {
                assessmentType.Text = currentFragment.GetTitle();
            }
            // Otherwise, the fragment's data is currently waiting to be unbundled and so actions should be queued
            else
            {
                currentFragment.runOnceCreated.Push(
                    delegate { RunOnUiThread(() => { assessmentType.Text = currentFragment.GetTitle(); }); });
            }

            recButton.Text = "Record";
        }