Esempio n. 1
0
        /// <summary>
        /// Puts the answers to survey instance.
        /// </summary>
        /// <returns>The answers to survey instance.</returns>
        /// <param name="currentViews">Current views.</param>
        /// <param name="surveyScheme">Survey scheme.</param>
        private static SurveyAnswer PutAnswersToSurveyInstance(ICollection <QuestionView> currentViews, Survey surveyScheme)
        {
            UserData user = new UserData();

            user.Username = "******";
            user.ID       = "test_ID";

            SurveyAnswer sa = new SurveyAnswer(surveyScheme, user);

            sa.Answers = new List <Answer> ();

            foreach (QuestionView qv in currentViews)
            {
                Answer a = new Answer();
                a.QuestionRef = new QuestionReference();
                Question temporaryQuestion = qv.question.Question;

                a.QuestionRef.Question = new Question {
                    QuestionId = temporaryQuestion.QuestionId
                };

                foreach (AnswerOption ao in qv.answers)
                {
                    a.AnsweredOption = new AnswerOption {
                        Content = ao.Content
                    };
                }
                sa.Answers.Add(a);
            }
            return(sa);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the instances of SurveyAnswers for a specific user.
        /// </summary>
        /// <returns>The instances.</returns>
        /// <param name="schemas">Schemas.</param>
        /// <param name="userData">User data.</param>
        public static List <SurveyAnswer> generateInstances(List <Survey> schemas, UserData userData)
        {
            List <SurveyAnswer> instances = new List <SurveyAnswer> ();

            foreach (Survey schema in schemas)
            {
                SurveyAnswer instance = new SurveyAnswer(schema, userData);
                instances.Add(instance);
            }
            return(instances);
        }
Esempio n. 3
0
 /// <summary>
 /// Reschedule the specified survey.
 /// </summary>
 /// <param name="survey">Survey.</param>
 public static SurveyAnswer reschedule(SurveyAnswer survey)
 {
     survey.Survey.Scheduler = generateNewDate(survey.Survey.Scheduler);
     survey.Survey.isActive  = false;
     foreach (SurveyPart sp in survey.Survey.SurveyParts)
     {
         sp.Scheduler = generateNewDate(sp.Scheduler);
         sp.isActive  = false;
     }
     setActive(survey);
     survey.Answers = new System.Collections.Generic.List <Answer> ();
     return(survey);
 }
Esempio n. 4
0
        /// <summary>
        /// Writes the survey result.
        /// </summary>
        /// <param name="surveyScheme">Survey scheme.</param>
        /// <param name="currentViews">Current views.</param>
        public static async void WriteSurveyResult(Survey surveyScheme, ICollection <QuestionView> currentViews)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder     = await rootFolder.CreateFolderAsync(Constants.filledFolder,
                                                                    CreationCollisionOption.OpenIfExists);

            string fileName = surveyScheme.SurveyId.ToString().Substring(0, 5) + "_" + surveyScheme.SurveyName + "_" + DateTime.Now.DayOfYear.ToString() + ".json";

            IFile file = await folder.CreateFileAsync(fileName,
                                                      CreationCollisionOption.ReplaceExisting);

            SurveyAnswer SurveyfilledScheme = PutAnswersToSurveyInstance(currentViews, surveyScheme);
            string       serialized         = JSonTranslator.Serialize(SurveyfilledScheme);

            await file.WriteAllTextAsync(serialized);
        }
Esempio n. 5
0
 /// <summary>
 /// Sets the active parameter in the survey.
 /// </summary>
 /// <returns><c>true</c>, if active was set in any of the parts, <c>false</c> otherwise.</returns>
 /// <param name="survey">Survey.</param>
 public static bool setActive(SurveyAnswer survey)
 {
     foreach (SurveyPart sp in survey.Survey.SurveyParts)
     {
         if (sp.Scheduler.Available.CompareTo(DateTime.Today) <= 0)
         {
             sp.isActive            = true;
             survey.Survey.isActive = true;
         }
     }
     if (survey.Survey.isActive)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
        /// <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
            };
        }