public void Visit(TextQuestion q) { var qmb = _questionPlaceholder.GetComponent <QuestionMenuButtons>(); var length = 0; if (q.RowLabels != null) { length = MenuUtils.GetMaxTextLength(q.RowLabels.Select(l => l.Text).ToList()); } var answernumber = 0; for (var index = 0; index < q.NRows; index++) { var iLocal = index; var text = q.RowLabels != null ? q.RowLabels[index].Text : ""; var labelAndField = MenuUtils.AddLabelText("Questionnaire/Rows/LabelledTextField", text, _dynamicField, "Label", length); var inpt = labelAndField.transform.Find("InputField").GetComponent <InputField>(); inpt.onEndEdit.AddListener(answer => { qmb.SetAnswerString(iLocal, answer); }); if (_oldAnswers != null && _oldAnswers.ContainsKey(answernumber)) { inpt.text = _oldAnswers[answernumber]; } answernumber++; } }
public Question Convert(QuestionResource questionResource) { var existingQuestion = CreatedQuestions.Where(obj => obj.Id == questionResource.Id).FirstOrDefault(); if (existingQuestion != null) { if (existingQuestion is ChoiceQuestion) { Assign(existingQuestion as ChoiceQuestion, questionResource); } else if (existingQuestion is TextQuestion) { Assign(existingQuestion as TextQuestion, questionResource); } return(existingQuestion); } else { if (questionResource.DefaultChoice == null) { var newChoiceQuestion = new ChoiceQuestion(); CreatedQuestions.Add(newChoiceQuestion); Assign(newChoiceQuestion, questionResource); return(newChoiceQuestion); } else { var newTextQuestion = new TextQuestion(); CreatedQuestions.Add(newTextQuestion); Assign(newTextQuestion, questionResource); return(newTextQuestion); } } }
public static TextQuestionDTO MapFrom(this TextQuestion entity) { if (entity == null) { throw new Exception(ExceptionMessages.EntityNotFound); } var answer = string.Empty; if (entity.Answers.Count > 0) { foreach (var item in entity.Answers) { answer = item.Answer; break; } } return(new TextQuestionDTO { Id = entity.Id, Description = entity.Description, IsLongAnswer = entity.IsLongAnswer, IsRequired = entity.IsRequired, QuestionNumber = entity.QuestionNumber, Answer = answer }); }
}//end of changeTeamColor /* * This method is called once. It is used to display the questions character by character to * make it look dynamic. It also displays the answers' text */ private IEnumerator DisplayText() { visibleCharacterCount = 0; while (!goingToNextQuestion) { if (DataModel.CurQuestion() is TextQuestion) { TextQuestion texteQ = (TextQuestion)DataModel.CurQuestion(); questionText.text = texteQ.Question; //formule de merde a changer question_length_to_time = questionText.text.Length * 0.07f; Debug.Log("nb chars " + questionText.text.Length); } else { questionText.text = DataModel.TextToUse["music_display"] + actualQuestion; } questionText.maxVisibleCharacters = visibleCharacterCount; numberOfCharacters = questionText.textInfo.characterCount; while (visibleCharacterCount <= numberOfCharacters) { visibleCharacterCount++; questionText.maxVisibleCharacters = visibleCharacterCount; yield return(new WaitForSeconds(0.07f)); } yield return(null); } }
public TextQuestionViewModel(AppShell appShell, TextQuestion textQuestion) { this.Question = textQuestion.QuestionText; this.BaseObject = textQuestion; this.Title = "Otázka " + NumberOfQuestion; NumberOfQuestion++; this.AppShell = appShell; this.ConfirmQuestion = new Command(OnAnswerConfirmed); FlyOutItem = new FlyoutItem() { Title = this.Title, Icon = "icon_question.png", }; TextQuestionPage = new TextQuestionPage(this) { Title = this.Title }; ShellContent = new ShellContent { Content = TextQuestionPage }; FlyOutItem.Items.Add(ShellContent); }
}//end of changeTeamColor /* * This method is called once. It is used to display the questions character by character to * make it look dynamic. It also displays the answers' text */ private IEnumerator DisplayText() { visibleCharacterCount = 0; while (!goingToNextQuestion) { gfini = false; if (DataModel.CurQuestion() is TextQuestion) { TextQuestion texteQ = (TextQuestion)DataModel.CurQuestion(); questionText.text = texteQ.Question; } else { questionText.text = DataModel.TextToUse["music_display"] + actualQuestion; } questionText.maxVisibleCharacters = visibleCharacterCount; numberOfCharacters = questionText.textInfo.characterCount; while (visibleCharacterCount <= numberOfCharacters) { visibleCharacterCount++; questionText.maxVisibleCharacters = visibleCharacterCount; yield return(new WaitForSeconds(0.05f)); } gfini = true; answers = questions.First().Answers; GameObject.Find("Answer 1").GetComponent <TextMeshProUGUI>().text = answers[0].AnswerText; GameObject.Find("Answer 2").GetComponent <TextMeshProUGUI>().text = answers[1].AnswerText; GameObject.Find("Answer 3").GetComponent <TextMeshProUGUI>().text = answers[2].AnswerText; GameObject.Find("Answer 4").GetComponent <TextMeshProUGUI>().text = answers[3].AnswerText; yield return(null); } }
public async Task <ActionResult <TextQuestion> > PostTextQuestion(TextQuestion textQuestion) { _context.TextQuestion.Add(textQuestion); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTextQuestion", new { id = textQuestion.TextId }, textQuestion)); }
public async Task <IActionResult> PutTextQuestion(int id, TextQuestion textQuestion) { if (id != textQuestion.TextId) { return(BadRequest()); } _context.Entry(textQuestion).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TextQuestionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// Use this for initialization void Start() { _MYInstance = this; textComponete = GetComponent <Text>(); separarQuestString(); // InvokeRepeating("FPS", 1, 1); }
public ActionResult CreateText(int id) { var question = new TextQuestion() { TestID = id }; ViewBag.Create = true; return(View("TextEditor", question)); }
public TextQuestion GetRandomTextQuestion() { int randomIndex = Random.Range(0, listTextQuestions.Count); Debug.Log(listTextQuestions.Count); TextQuestion textQuestion = listTextQuestions[randomIndex]; listTextQuestions.RemoveAt(randomIndex); return(textQuestion); }
public object MapItem(List <IDomainInfoViewModels> list, object Tmodel) { try { Type myType = Tmodel.GetType(); IList <PropertyInfo> props = new List <PropertyInfo>(myType.GetProperties()); foreach (var domainItem in list) { foreach (PropertyInfo property in props) { if (domainItem.DomainInformation.PropertyMapping == property.Name) { switch (domainItem.DomainType.TypeName) { case "StringType": TextQuestion txtQuestion = (TextQuestion)domainItem.Question; property.SetValue(Tmodel, txtQuestion.Value); break; case "BoolType": BoolQuestion boolQuestion = (BoolQuestion)domainItem.Question; property.SetValue(Tmodel, boolQuestion.Value); break; case "IntType": IntQuestion intQuestion = (IntQuestion)domainItem.Question; property.SetValue(Tmodel, intQuestion.Value); break; case "DateTimeType": DateTimeQuestion dateTimeQuestion = (DateTimeQuestion)domainItem.Question; property.SetValue(Tmodel, dateTimeQuestion.Value); break; case "DropdownType": DropdownQuestion dropDownQuestion = (DropdownQuestion)domainItem.Question; property.SetValue(Tmodel, dropDownQuestion.Value); break; } } } } } catch (Exception ex) { var x = ex.Message; } return(Tmodel); }
public TextQuestionService(AppShell appShell, TextQuestion textQuestion, MapService mapService) { Model = textQuestion; Model.Service = this; MapService = mapService; ViewModel = new TextQuestionViewModel(appShell, textQuestion); ViewModel.ConfirmedQuestionEvent += OnConfirm; }
private void GetNewQuestion() { TextQuestion textQuestion = randomTextQuestion.GetRandomTextQuestion(); answer = textQuestion.GetAnswer(); PlayerPrefs.SetString("Correct Answer", textQuestion.GetNormAnswer()); AnswerGenerator answerGenerator = new AnswerGenerator(answer); questionLabel.text = textQuestion.GetQuestion(); blankAnswer = answerGenerator.GetUncompleteAnswer(); answerLabel.text = blankAnswer; indexBlankChar = answerGenerator.GetIndexBlankChar(); listCharacterForAnswerButton = choice.GetChoice(answer[indexBlankChar[0]]); Debug.Log(answer); }
public void TestSurveySerialization() { string expected = "{\"survey\":{\"id\":\"12344134\",\"len\":\"4\",\"questions\":[{\"type\":\"single\"," + "\"question\":\"How well do the professors teach at this university?\",\"options\":[{\"1\":\"Extremely well\"}," + "{\"2\":\"Very well\"}]},{\"type\":\"multiple\",\"question\":\"How effective is the teaching outside yur major at the univesrity?\"," + "\"options\":[{\"1\":\"Extremetly effective\"},{\"2\":\"Very effective\"},{\"3\":\"Somewhat effective\"},{\"4\":\"Not so effective\"}," + "{\"5\":\"Not at all effective\"}]},{\"type\":\"text\",\"question\":\"Some question\"},{\"type\":\"starRate\",\"question\":\"Star rating question\"}]}}"; IQuestion[] questions = new IQuestion[4]; questions[0] = new SingleQuestion() { Question = "How well do the professors teach at this university?", Options = new[] { "Extremely well", "Very well" } }; questions[1] = new MultipleQuestion() { Question = "How effective is the teaching outside yur major at the univesrity?", Options = new[] { "Extremetly effective", "Very effective", "Somewhat effective", "Not so effective", "Not at all effective" } }; questions[2] = new TextQuestion() { Question = "Some question" }; questions[3] = new StarRateQuestion() { Question = "Star rating question" }; Survey survey = new Survey() { Id = "12344134", Questions = questions }; Assert.Equal(expected, survey.GetJson()); }
void Assign(TextQuestion textQuestion, QuestionResource questionResource) { textQuestion.Id = questionResource.Id; if (questionResource.QuestionText != null) { textQuestion.QuestionText = questionResource.QuestionText; } if ((questionResource.ChoicesThatOpensThis != null) && textQuestion.ChoicesThatOpensThis == null) { textQuestion.ChoicesThatOpensThis = new List <Choice>(); foreach (ChoiceResource choiceResource in questionResource.ChoicesThatOpensThis) { Choice newChoice = Convert(choiceResource); textQuestion.ChoicesThatOpensThis.Add(newChoice); if (newChoice.OpensQuestions == null) { newChoice.OpensQuestions = new List <Question>(); } newChoice.OpensQuestions.Add(textQuestion); } } if ((questionResource.Choices != null) && textQuestion.Choices == null) { textQuestion.Choices = new List <ChoiceForTextQuestion>(); foreach (ChoiceResource choiceResource in questionResource.Choices) { ChoiceForTextQuestion newChoice = Convert(choiceResource) as ChoiceForTextQuestion; textQuestion.Choices.Add(newChoice); newChoice.Question = textQuestion; } } if ((questionResource.DefaultChoice != null) && textQuestion.DefaultChoice == null) { DefaultChoice newChoice = Convert(questionResource.DefaultChoice) as DefaultChoice; textQuestion.DefaultChoice = newChoice; newChoice.Question = textQuestion; } }
public void SaveQuestion() { int QuestionNumber = EventSystem.current.currentSelectedGameObject.GetComponentInParent <PanelModel>().PanelNumber; TMP_InputField questionInput = EventSystem.current.currentSelectedGameObject.GetComponentInChildren <TMP_InputField>(); //get the question TMP_InputField[] answersInput = questionInput.GetComponentsInChildren <TMP_InputField>(); //get the answers Toggle[] answersIsCorrect = new Toggle[answersInput.Length]; List <AnswerData> answers = new List <AnswerData>(); for (int i = 1; i < answersInput.Length; i++) { answersIsCorrect[i] = answersInput[i].GetComponentInChildren <Toggle>(); //get the correct statement of the answer answers.Add(new AnswerData(answersInput[i].text, answersIsCorrect[i].isOn)); } TextQuestion question = new TextQuestion(questionInput.text, answers.ToArray()); //create a new TextQuestion DataModel.Rounds[DataModel.IroundCur].Topics[DataModel.ItopicCur].Questions[QuestionNumber - 1] = question; //add the question to the current topic in the DataModel }
public static void Main() { var qone = new TextQuestion(); qone.Label = "How old are you?"; var qtwo = new TextQuestion(); qtwo.Label = "Whats your name?"; Survey one = new Survey("title1"); one.AddQuestion(qone); one.AddQuestion(qtwo); int score = one.GetScore(); Console.WriteLine("Your score: {0} ", score); }
public void LoadFromDatabase(LoggingManager log) { var qDataList = log.GetQuestionSetContent(Name); foreach (var questionData in qDataList) { Question q; switch ((Enums.Question)questionData.QuestionType) { case Enums.Question.Info: q = new InfoScreen(questionData); break; case Enums.Question.Text: q = new TextQuestion(questionData); break; case Enums.Question.Choice: q = new ChoiceQuestion(questionData); break; case Enums.Question.Scale: q = new ScaleQuestion(questionData); break; case Enums.Question.Ladder: q = new LadderQuestion(questionData); break; case Enums.Question.Stimuli: q = new VisualStimuli(questionData); break; default: throw new ArgumentOutOfRangeException(); } q.Jumps = log.GetJumps(questionData); Questions.Add(q); } }
/** * Create a new question in the DataModel and fill it with default value **/ public void NewQuestionPanelData() { nbQ++; questionPrefab = Instantiate(Resources.Load <RectTransform>("Prefabs/QSample"), GameObject.Find("QGrid").transform); questionPrefab.name = "QSample" + nbQ; questionPrefab.GetComponent <PanelModel>().PanelNumber = nbQ; questionPrefab.Find("Delete").GetComponent <Button>().onClick.AddListener(() => RemoveQuestion()); questionPrefab.Find("Delete").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["menu_remove"]; questionPrefab.Find("ValidateQuestion").GetComponent <Button>().onClick.AddListener(() => SaveQuestion()); questionPrefab.Find("ValidateQuestion").Find("Validate").GetComponent <TextMeshProUGUI>().text = DataModel.TextToUse["menu_validate"]; questionPrefab.Find("ValidateQuestion").Find("QField").Find("Text Area").Find("Placeholder").GetComponent <TextMeshProUGUI>().text = DataModel.TextToUse["enter_questiontext"]; for (int i = 1; i < 5; i++) { questionPrefab.Find("ValidateQuestion").Find("QField").Find("AnswerField").Find("A" + i + "Field").Find("Text Area").GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["enter_answertext"]; questionPrefab.Find("ValidateQuestion").Find("QField").Find("AnswerField").Find("A" + i + "Field").Find("TrueA" + i).GetComponentInChildren <TextMeshProUGUI>().text = DataModel.TextToUse["correct_answer"]; } //add a neutral question when user press the AddQuestion button and add it to the DataModel AnswerData[] ans = { new AnswerData("a", false), new AnswerData("b", false), new AnswerData("c", false), new AnswerData("d", false) }; TextQuestion question = new TextQuestion("question", ans); DataModel.Rounds[DataModel.IroundCur].Topics[DataModel.ItopicCur].Questions.Add(question); }
private static List <TextQuestion> CreateObjectFromListTextQuestion(List <Dictionary <string, string> > textQuestion) { List <TextQuestion> newList = new List <TextQuestion>(); foreach (var item in textQuestion) { if (item.Count > 0) { var newTextQuestion = new TextQuestion(); newTextQuestion.Id = Guid.Parse(item["Id"]); newTextQuestion.Description = item["Description"]; newTextQuestion.IsLongAnswer = bool.Parse(item["IsLongAnswer"]); newTextQuestion.IsRequired = bool.Parse(item["IsRequired"]); newTextQuestion.IsDeleted = false; newTextQuestion.FormId = Guid.Parse(item["FormId"]); newTextQuestion.QuestionNumber = int.Parse(item["QuestionNumber"]); newList.Add(newTextQuestion); } } return(newList); }
public TextControl(TextQuestion question) { tb = new TextBox(); tb.CssClass = "alternative"; tb.ID = "q" + question.ID; if (question.Rows > 1) { tb.TextMode = TextBoxMode.MultiLine; tb.Rows = question.Rows; } if (question.Columns.HasValue) { tb.Columns = question.Columns.Value; } l = new Label(); l.CssClass = "label"; l.Text = question.Title; l.AssociatedControlID = tb.ID; Controls.Add(l); Controls.Add(tb); }
public TextControl(TextQuestion question) { tb = new TextBox(); tb.CssClass = "alternative"; tb.ID = "q" + question.ID; if (question.Rows > 1) { tb.TextMode = TextBoxMode.MultiLine; tb.Rows = question.Rows; } if (question.Columns.HasValue) { tb.Columns = question.Columns.Value; } l = new Label(); l.CssClass = "label"; l.Text = question.Title; l.AssociatedControlID = tb.ID; Controls.Add(l); Controls.Add(tb); }
public void AddTextQuestion(TextQuestion textQuestion) { listTextQuestions.Add(textQuestion); }
private static bool IsTextQuestionPresent(TextQuestion textQuestion) { return(textQuestion != null); }
public TextAnswerViewModel(TextQuestion question, TextAnswer answer): base(question) { _answerModel = answer; }
public TextQuestionViewModel(TextQuestion model): base(model) { _model = model; }
public void AddTextQuestion(string questionText) { var textQuestion = new TextQuestion(questionText); _surveyQuestions.Add(textQuestion); }
private void RunningQuestions() { goingToNextQuestion = false; if (isBuzzActivate) { buzz_event = false; EnableTeam(); EnableAllBuzzers(); ReappearAllTeams(); ResetTeamsAnswered(); } else { buzz_event = false; EnableTeam(); ReappearAllTeams(); ResetTeamsAnswered(); DisableAllBuzzers(); } // Make required objects to disappear at the start of question GameObject.Find("ArrowButton").GetComponent <Button>().interactable = false; arrow.GetComponent <CanvasGroup>().alpha = 0; foreach (GameObject e in timerPanelList) { e.GetComponent <CanvasGroup>().alpha = 0; } foreach (GameObject p in answerList) { p.GetComponent <CanvasGroup>().alpha = 0; } isNextAvailable = false; GameObject.Find("QuestionCounter").GetComponent <TextMeshProUGUI>().text = "Question " + actualQuestion + " / " + numberOfQuestions; // Either this is a MusicQuestion and we musicQuestionIsPlaying its music or we musicQuestionIsPlaying the basic question music if (DataModel.CurQuestion() is MusicQuestion) { MusicQuestion musicQ = (MusicQuestion)DataModel.CurQuestion(); var x = new WWW("file:///" + localpath + '/' + musicQ.MusicPath); while (!x.isDone) { } musicSource.clip = x.GetAudioClip(); musicSource.time = musicQ.StartTrack; if (!musicQ.Fade) { musicSource.volume = musicQ.Volume; } question_length_to_time = 2.5f; } else { int music_index = Random.Range(1, 4); music = Resources.Load <AudioClip>("Sounds/" + DataModel.QuestionMusicName + music_index); musicSource.clip = music; musicSource.volume = 0.75f; } foreach (PlayerModel e in teamsCtrl) { ChangeTeamColor(0, e); e.buzzed = false; } if (DataModel.CurQuestion() is MusicQuestion) { musicQuestionIsPlaying = true; } musicSource.Play(); // After 10 seconds, the timer and answers appears, 7 seconds after that a false answer disappears, again 4 seconds after and at 25 sec teams can'musicQ answer // anymore. Finally at 28 seconds, the true answer is revealed and points are given if (DataModel.CurQuestion() is TextQuestion) { TextQuestion texteQ = (TextQuestion)DataModel.CurQuestion(); questionText.text = texteQ.Question; //formule de merde a changer question_length_to_time = questionText.text.Length * 0.07f; } else { questionText.text = DataModel.TextToUse["music_display"] + actualQuestion; } answers = questions.First().Answers; GameObject.Find("Answer 1").GetComponent <TextMeshProUGUI>().text = answers[0].AnswerText; GameObject.Find("Answer 2").GetComponent <TextMeshProUGUI>().text = answers[1].AnswerText; GameObject.Find("Answer 3").GetComponent <TextMeshProUGUI>().text = answers[2].AnswerText; GameObject.Find("Answer 4").GetComponent <TextMeshProUGUI>().text = answers[3].AnswerText; Invoke("RevealAnswers", 3.0f + question_length_to_time); Invoke("EliminateFalseAnswer", 10.0f + question_length_to_time); Invoke("EliminateFalseAnswer", 14.0f + question_length_to_time); Invoke("DisableTeam", 18.0f + question_length_to_time); Invoke("FinalAnswerPhase", 21.0f + question_length_to_time); }
public QuestionTextAnswer(TextQuestion question, string answer) { Question = question; Answer = answer; }
public void Load(string filepath) { string path = filepath; string jsonString = File.ReadAllText(path); JSONObject dataJson = (JSONObject)JSON.Parse(jsonString); // Set values QuizName = dataJson["Quizname"].Value; CurTopicName = dataJson["CurTopicName"].Value; RoundNumber = dataJson["RoundNumber"].AsInt; //indexes IroundCur = dataJson["IroundCur"].AsInt; ItopicCur = dataJson["ItopicCur"].AsInt; IquestionCur = dataJson["IquestionCur"].AsInt; Scores = new int[NumberOfTeams]; Jokers = new bool[NumberOfTeams]; for (int i = 0; i < Scores.Length; i++) { Scores[i] = dataJson[("Score" + i)].AsInt; Jokers[i] = dataJson[("Joker" + i)].AsBool; } // Rounds List <RoundData> rdList = new List <RoundData>(); for (int i = 0; i < dataJson["Rounds"].AsArray.Count; i++) { List <TopicData> tdList = new List <TopicData>(); for (int j = 0; j < dataJson["Rounds"].AsArray[i]["Topics"].AsArray.Count; j++) { List <QuestionData> qdList = new List <QuestionData>(); for (int k = 0; k < dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray.Count; k++) { AnswerData[] adTab = new AnswerData[dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray.Count]; for (int l = 0; l < adTab.Length; l++) { AnswerData ad = new AnswerData(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray[l]["AnswerText"].Value, dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Answers"].AsArray[l]["IsTrue"].AsBool); adTab[l] = ad; } switch (dataJson["Rounds"].AsArray[i]["Type"].Value) { case "Blind test": MusicQuestion mq = new MusicQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["MusicPath"].Value, adTab); mq.StartTrack = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["StartTrack"].AsFloat; mq.Volume = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Volume"].AsFloat; mq.Fade = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Fade"].AsBool; qdList.Add((QuestionData)mq); break; case "Musique": MusicQuestion mq2 = new MusicQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["MusicPath"].Value, adTab); mq2.StartTrack = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["StartTrack"].AsFloat; mq2.Volume = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Volume"].AsFloat; mq2.Fade = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Fade"].AsBool; qdList.Add((QuestionData)mq2); break; case "Image": ImageQuestion iq = new ImageQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["ImagePath"].Value, adTab); qdList.Add((QuestionData)iq); break; case "QCM": TextQuestion tq = new TextQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value, adTab); qdList.Add((QuestionData)tq); break; case "MCQ": TextQuestion tq2 = new TextQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value, adTab); qdList.Add((QuestionData)tq2); break; case "TrueFalse": TrueFalseQuestion tf = new TrueFalseQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value, adTab); qdList.Add((QuestionData)tf); break; case "VraiFaux": TrueFalseQuestion tf2 = new TrueFalseQuestion(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Questions"].AsArray[k]["Question"].Value, adTab); qdList.Add((QuestionData)tf2); break; default: Debug.LogError("Type de question non-reconnu"); break; } } TopicData td = new TopicData(dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["Name"].Value, qdList); td.IsAvailable = dataJson["Rounds"].AsArray[i]["Topics"].AsArray[j]["IsAvailable"].AsBool; tdList.Add(td); } RoundData rd = new RoundData(dataJson["Rounds"].AsArray[i]["Type"].Value, tdList, dataJson["Rounds"].AsArray[i]["IsBuzzActivate"].AsBool); rdList.Add(rd); } Rounds = rdList; }
/** * @author David * * Saving the current state of DataModel in the data.json file **/ public static void Save(string filepath) { JSONObject dataJson = new JSONObject(); dataJson.Add("Quizname", QuizName); dataJson.Add("CurTopicName", CurTopicName); dataJson.Add("RoundNumber", RoundNumber); // indexes dataJson.Add("IroundCur", IroundCur); dataJson.Add("ItopicCur", ItopicCur); dataJson.Add("IquestionCur", IquestionCur); for (int i = 0; i < Scores.Length; i++) { dataJson.Add("Score" + i, Scores[i]); dataJson.Add("Joker" + i, Jokers[i]); } JSONArray roundsJsonArray = new JSONArray(); foreach (RoundData rd in Rounds) { JSONObject roundJson = new JSONObject(); roundJson.Add("Type", rd.Type); roundJson.Add("IsBuzzActivate", rd.IsBuzzRound); JSONArray topicsJsonArray = new JSONArray(); foreach (TopicData td in rd.Topics) { JSONObject topicJson = new JSONObject(); topicJson.Add("Name", td.Name); topicJson.Add("IsAvailable", td.IsAvailable); JSONArray questionsJsonArray = new JSONArray(); foreach (QuestionData qd in td.Questions) { JSONObject questionJson = new JSONObject(); switch (qd.GetType().ToString()) { case "MusicQuestion": MusicQuestion mq = (MusicQuestion)qd; questionJson.Add("MusicPath", mq.MusicPath); questionJson.Add("StartTrack", mq.StartTrack); questionJson.Add("Volume", mq.Volume); questionJson.Add("Fade", mq.Fade); break; case "ImageQuestion": ImageQuestion iq = (ImageQuestion)qd; questionJson.Add("ImagePath", iq.ImagePath); break; case "TextQuestion": TextQuestion tq = (TextQuestion)qd; questionJson.Add("Question", tq.Question); break; case "TrueFalseQuestion": TrueFalseQuestion tfq = (TrueFalseQuestion)qd; questionJson.Add("Question", tfq.Question); break; default: Debug.LogError("Type de question non-reconnu"); break; } JSONArray answersJsonArray = new JSONArray(); foreach (AnswerData ad in qd.Answers) { JSONObject answerJson = new JSONObject(); answerJson.Add("AnswerText", ad.AnswerText); answerJson.Add("IsTrue", ad.IsTrue); answersJsonArray.Add(answerJson); } questionJson.Add("Answers", answersJsonArray); questionsJsonArray.Add(questionJson); } topicJson.Add("Questions", questionsJsonArray); topicsJsonArray.Add(topicJson); } roundJson.Add("Topics", topicsJsonArray); roundsJsonArray.Add(roundJson); } dataJson.Add("Rounds", roundsJsonArray); File.WriteAllText(filepath, dataJson.ToString()); }
public async Task ImportsTextQuestions_WhenOneFileIsNotFound() { // Arrange const string name = "text question"; var fileNames = new[] { "file1", "invalidFile" }; var questionnaire = new Questionnaire { Revision = 1, Name = name }; var question1 = new TextQuestion { Revision = 1, Text = "TextQuestion1", Answer = new TextAnswer { Text = "TextAnswer1" } }; var fileText1 = "2\n" + "Text;Antwort\n" + $"{question1.Text};{question1.Answer.Text}\n"; var questionsUow = A.Fake <IQuestionsUnitOfWork>(); var questionnairesUow = A.Fake <IQuestionnairesUnitOfWork>(); var file = A.Fake <IFile>(); var expectedImportedQuestions = new Dictionary <string, List <string> > { [fileNames[0]] = new List <string> { question1.Text } }; A.CallTo(() => file.ReadAllText(A <string> .That.Matches(_ => _ == fileNames[0]))) .Returns(fileText1); A.CallTo(() => file.ReadAllText(A <string> .That.Matches(_ => _ == fileNames[1]))) .Throws(() => new FileNotFoundException()); var testee = new ImportExportService(questionnairesUow, questionsUow, file); // Act (Dictionary <string, List <string> > importedQuestions, List <string> erroredFiles) = await testee.Import(name, "", fileNames); // Assert importedQuestions.Should().BeEquivalentTo(expectedImportedQuestions); erroredFiles.Should().BeEquivalentTo(fileNames[1]); A.CallTo(() => questionnairesUow.QuestionnairesRepo.Add(A <Questionnaire> .That.Matches(_ => this.matchEntity(_, questionnaire)))) .MustHaveHappened(); A.CallTo(() => questionsUow.TextQuestionsRepo.Add(A <TextQuestion> .That.Matches(_ => this.matchEntity(_, question1)))) .MustHaveHappened(); A.CallTo(() => questionnairesUow.Complete()) .MustHaveHappened(); A.CallTo(() => questionsUow.Complete()) .MustHaveHappened(Repeated.Exactly.Twice); }