public void OnNextClicked(object sender, EventArgs args) { QuestionView v = vg.NextQuestion(); if (v == null) { DisplayAlert("Done!", "Thank you for filling the survey", "Submit", "Change").ContinueWith(t => { if (t.Result == true) { IOController.WriteSurveyResult(vg.SurveyScheme, vg.CurrentViews); _tflp.Reschedule(); this.navigationContent.Navigation.PopAsync(); this.navigationContent.Navigation.PopAsync(); } }, TaskScheduler.FromCurrentSynchronizationContext()); } else { InitializePropertyCallback(v); surveyContent.Children.RemoveAt(0); surveyContent.Children.Insert(0, v); this.goToNextButton.IsEnabled = v.IsAnswered; this.goToPreviousButton.IsEnabled = true; } }
/// <summary> /// Reschedule the instance of the chosen SurveyAnswer. /// </summary> public void Reschedule() { ScheduleController.reschedule(chosenSurvey); string rescheduled = JSonTranslator.Serialize(chosenSurvey); IOController.SaveFile(rescheduled, chosenSurvey.Survey.SurveyName + "_" + chosenSurvey.Survey.SurveyId.ToString().Substring(0, 4), Constants.toFillFolder); }
/// <summary> /// Mockup class simulating actual connection for the new surveys. /// </summary> public void DownloadNewSurveys() { // this part is actually faking the connection to the Internet Assembly assembly = GetType().GetTypeInfo().Assembly; string resource = "Surveys.SerializedSurveys.MedicalSurvey.json"; string ss; using (Stream stream = assembly.GetManifestResourceStream(resource)) { using (StreamReader reader = new StreamReader(stream)) { var stringTask = reader.ReadToEndAsync(); ss = stringTask.Result; } } // process and save in the desired directory Survey s = JSonTranslator.Deserialize <Survey> (ss); IOController.SaveFile(ss, s.SurveyName, Constants.schemasFolder); }
/// <summary> /// Initializes a new instance of the <see cref="Surveys.SavedListPage"/> class. /// </summary> public SavedListPage() { this.Title = "List of saved survey results"; // Create and initialize ListView. ListView listView = new ListView(); this.FilledSurveys = IOController.ReadFileNames(Constants.filledFolder); listView.ItemsSource = FilledSurveys; listView.ItemSelected += (sender, args) => { if (args.SelectedItem != null) { // Deselect the item. listView.SelectedItem = null; string selectedFileName = (string)args.SelectedItem; string selectedFileContent = IOController.ReadFile(selectedFileName, Constants.filledFolder); this.Navigation.PushAsync(new SavedInstancePage(selectedFileContent, selectedFileName)); } }; this.Content = new ScrollView { Content = listView }; }
/// <summary> /// Initializes a new instance of the <see cref="Surveys.ToFillListPage"/> class. /// </summary> public ToFillListPage() { this.Title = "To be answered"; // Read schemas, instances and check for new List <Survey> allSchemas = IOController.ReadAllSchemas(); List <SurveyAnswer> filledAnswers = new List <SurveyAnswer> (); List <string> filledAnswersSerialized = IOController.ReadFiles(Constants.filledFolder); foreach (string s in filledAnswersSerialized) { filledAnswers.Add(JSonTranslator.Deserialize <SurveyAnswer> (s)); } List <Survey> newSchemas = StartupController.checkForNewSchemas(allSchemas, filledAnswers); // If new, generate unfilled instances List <SurveyAnswer> surveyUnfilledInstances = new List <SurveyAnswer> (); if (newSchemas.Count != 0) { UserData user = new UserData(); user.Username = "******"; user.ID = "test_ID"; surveyUnfilledInstances = StartupController.generateInstances(newSchemas, user); } // Read previously stored unfilled instances List <string> previouslyUnfilledSerialized = IOController.ReadFiles(Constants.toFillFolder); foreach (string s in previouslyUnfilledSerialized) { SurveyAnswer sa = JSonTranslator.Deserialize <SurveyAnswer> (s); surveyUnfilledInstances.Add(sa); } // set active parts and preapre a display dictionary Dictionary <string, SurveyAnswer> toAnswerNamed = new Dictionary <string, SurveyAnswer> (); foreach (SurveyAnswer sa in surveyUnfilledInstances) { if (ScheduleController.setActive(sa)) { toAnswerNamed.Add(sa.Survey.SurveyName + "_" + sa.SurveyId.ToString().Substring(0, 4) + "_" + DateTime.Now.DayOfYear, sa); } } // Create and initialize ListView. ListView listView = new ListView(); listView.ItemsSource = toAnswerNamed.Keys; listView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { if (e.SelectedItem != null) { listView.SelectedItem = null; chosenSurvey = toAnswerNamed [(string)e.SelectedItem]; ViewGenerator vg = new ViewGenerator(chosenSurvey.Survey); ContentPage surveyPage = new SurveyViewPage(vg, this); this.Navigation.PushAsync(surveyPage); } }; this.Content = new ScrollView { Content = listView }; }