public FlashCardItem(Guid id, FlashCardItemType type, String text, String example)
		{
			Debug.Assert(text != null);
			_id = id;
			_type = type;
			_text = text;
			_example = example;
		}
Example #2
0
 private Font GetFont(FlashCardItemType type)
 {
     Font font = this.Font;
     switch (type)
     {
         case FlashCardItemType.Word:
             font = this._fontTextWord;
             break;
         case FlashCardItemType.Translations:
         case FlashCardItemType.Synonyms:
         case FlashCardItemType.Antonyms:
             font = this._fontTextTranslations;
             break;
         case FlashCardItemType.Definition:
             font = this._fontTextDefinition;
             break;
     }
     return font;
 }
        private FlashCardItem DoCreateCardItem(Guid meaningId, String query, DGetText GetText, FlashCardItemType itemType, bool useExample)
        {
            FlashCardItem item = null;

            SqlCeCommand cmd;
            lock (_commands)
            {
                if (!_commands.TryGetValue(query, out cmd))
                {
                    cmd = new SqlCeCommand(query, _connVocabulary);
                    cmd.Parameters.Add(new SqlCeParameter("MeaningId", SqlDbType.UniqueIdentifier));
                    AddCommand(cmd);
                }
            }

            lock (_connVocabulary)
            {
                cmd.Parameters["MeaningId"].Value = meaningId;
                using (SqlCeDataReader reader = cmd.ExecuteReader())
                {
                    StringBuilder sb = new StringBuilder();
                    String example = String.Empty;
                    while (reader.Read())
                    {
                        if (sb.Length > 0)
                            sb.Append(", ");
                        sb.Append(GetText(reader));

                        if (useExample)
                            example = GetExampleText(reader);
                    }

                    if (sb.Length > 0)
                        item = new FlashCardItem(meaningId, itemType, sb.ToString(), example);
                }
            }

            return item;
        }
        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;
 }
		public FlashCardItem(Guid id, FlashCardItemType type, String text)
			: this(id, type, text, String.Empty)
		{
		}