private FlashCard DoGenerateCardWordTranslations(Guid meaningId, Guid typeId) { FlashCard card = new FlashCard(); if (!DoAddQuestion(card, meaningId, PracticeStrings.SQL_QUESTION_WORD, GetWordText, FlashCardItemType.Word)) return null; if (!DoAddAnswer(card, meaningId, PracticeStrings.SQL_ANSWER_TRANSLATIONS, GetTranslationText, FlashCardItemType.Translations)) return null; if (!DoAddAnswers(card, meaningId, typeId, PracticeStrings.SQL_ANSWERS_TRANSLATIONS, GetTranslationText, FlashCardItemType.Translations)) return null; return card; }
private FlashCard DoGenerateCardWordSynonyms(Guid meaningId, Guid typeId) { FlashCard card = new FlashCard(); if (!DoAddQuestion(card, meaningId, PracticeStrings.SQL_QUESTION_WORD, GetWordText, FlashCardItemType.Word)) return null; if (!DoAddAnswer(card, meaningId, PracticeStrings.SQL_ANSWER_SYNONYMS, GetWordText, FlashCardItemType.Synonyms)) return null; if (!DoAddAnswers(card, meaningId, typeId, PracticeStrings.SQL_ANSWERS_RELATIONS, GetWordText, FlashCardItemType.Synonyms)) return null; return card; }
private FlashCard DoGenerateCardWordDefinitions(Guid meaningId, Guid typeId) { FlashCard card = new FlashCard(); if (!DoAddQuestion(card, meaningId, PracticeStrings.SQL_QUESTION_WORD, GetWordText, FlashCardItemType.Word)) return null; if (!DoAddAnswer(card, meaningId, PracticeStrings.SQL_ANSWER_DEFINITION, GetDefinitionText, FlashCardItemType.Definition)) return null; if (!DoAddAnswers(card, meaningId, typeId, PracticeStrings.SQL_ANSWERS_DEFINITION, GetDefinitionText, FlashCardItemType.Definition)) return null; return card; }
private bool DoAddQuestion(FlashCard card, Guid meaningId, String query, DGetText GetText, FlashCardItemType itemType) { Debug.Assert(card != null); FlashCardItem item = DoCreateCardItem(meaningId, query, GetText, itemType, true); if (item == null) return false; card.Question = item; return true; }
private bool DoAddAnswers(FlashCard card, Guid meaningId, Guid typeId, String query, DGetText GetText, FlashCardItemType itemType) { Debug.Assert(card != null); SqlCeCommand cmd = null; lock (_commands) { if (!_commands.TryGetValue(query, out cmd)) { cmd = new SqlCeCommand(query, _connVocabulary); cmd.Parameters.Add(new SqlCeParameter("TypeId", SqlDbType.UniqueIdentifier)); cmd.Parameters.Add(new SqlCeParameter("SeedId", SqlDbType.UniqueIdentifier)); AddCommand(cmd); _commands[query] = cmd; } } lock (_connVocabulary) { cmd.Parameters["TypeId"].Value = typeId; for (int i = 0; i < 10 && card.InnerAnswers.Count < ANSWERS_NUMBER; ++i) { cmd.Parameters["SeedId"].Value = Guid.NewGuid(); using (SqlCeDataReader reader = cmd.ExecuteReader()) { StringBuilder sb = new StringBuilder(); Guid previousMeaningId = Guid.Empty; while (card.InnerAnswers.Count < ANSWERS_NUMBER && reader.Read()) { Guid currentMeaningId = reader.GetGuid(0); if (currentMeaningId != meaningId && card.InnerAnswers.Count<FlashCardItem>(x => x.Id == currentMeaningId) == 0) { if (currentMeaningId != previousMeaningId && previousMeaningId != Guid.Empty) { Debug.Assert(sb.Length > 0); FlashCardItem item = new FlashCardItem(previousMeaningId, itemType, sb.ToString()); card.InnerAnswers.Add(item); sb.Length = 0; } if (sb.Length > 0) sb.Append(", "); sb.Append(GetText(reader)); previousMeaningId = currentMeaningId; } } if (card.InnerAnswers.Count < ANSWERS_NUMBER && previousMeaningId != Guid.Empty && sb.Length > 0) { FlashCardItem item = new FlashCardItem(previousMeaningId, itemType, sb.ToString()); card.InnerAnswers.Add(item); } } } } return card.InnerAnswers.Count > 2; }
private bool DoAddAnswer(FlashCard card, Guid meaningId, String query, DGetText GetText, FlashCardItemType itemType) { Debug.Assert(card != null); Debug.Assert(card.InnerAnswers.Count == 0); FlashCardItem item = DoCreateCardItem(meaningId, query, GetText, itemType, false); if (item == null) return false; card.InnerAnswers.Add(item); return true; }