Exemple #1
0
        /// <summary>
        /// Loads properties from the given kanji entity.
        /// </summary>
        /// <param name="se">Target SRS entry.</param>
        /// <param name="k">Kanji to load.</param>
        public static void LoadFromKanji(this SrsEntry se, KanjiEntity k)
        {
            // Compute the meaning string.
            string meaningString = string.Empty;

            foreach (KanjiMeaning km in k.Meanings)
            {
                meaningString += MultiValueFieldHelper.ReplaceSeparator(km.Meaning) + MultiValueFieldHelper.ValueSeparator;
            }
            meaningString = meaningString.Trim(
                new char[] { MultiValueFieldHelper.ValueSeparator });
            meaningString = MultiValueFieldHelper.Expand(meaningString);

            // Compute the reading string.
            string readingString = (k.OnYomi
                                    + MultiValueFieldHelper.ValueSeparator)
                                   + k.KunYomi;

            readingString = MultiValueFieldHelper.Expand(readingString
                                                         .Trim(new char[] { MultiValueFieldHelper.ValueSeparator }));

            // Set values.
            se.Meanings        = meaningString;
            se.Readings        = readingString;
            se.AssociatedKanji = k.Character;
        }
Exemple #2
0
        /// <summary>
        /// Loads properties from the given vocab entity.
        /// </summary>
        /// <param name="se">Target SRS entry.</param>
        /// <param name="v">Vocab to load.</param>
        public static void LoadFromVocab(this SrsEntry se, VocabEntity v)
        {
            // Compute the meaning string.
            string meaningString = string.Empty;

            foreach (VocabMeaning vm in v.Meanings)
            {
                meaningString += MultiValueFieldHelper.ReplaceSeparator(vm.Meaning)
                                 .Replace(" ;", MultiValueFieldHelper.ValueSeparator.ToString())
                                 + MultiValueFieldHelper.ValueSeparator;
            }
            meaningString = meaningString.Trim(
                new char[] { MultiValueFieldHelper.ValueSeparator });
            meaningString = MultiValueFieldHelper.Trim(meaningString);
            meaningString = MultiValueFieldHelper.Expand(meaningString);

            // Set values.
            se.Meanings        = meaningString;
            se.Readings        = v.KanaWriting;
            se.AssociatedVocab = v.KanjiWriting;

            if (string.IsNullOrEmpty(se.AssociatedVocab))
            {
                se.AssociatedVocab = v.KanaWriting;
            }
        }
        /// <summary>
        /// Background task work method.
        /// Retrieves the first matching vocab.
        /// </summary>
        private void DoGetAssociatedVocab(object sender, DoWorkEventArgs e)
        {
            IEnumerable <VocabEntity> results = _vocabDao.GetMatchingVocab(AssociatedVocabString);

            if (results.Any())
            {
                VocabEntity   entity   = new VocabEntity();
                StringBuilder meanings = new StringBuilder();
                StringBuilder readings = new StringBuilder();
                foreach (VocabEntity result in results)
                {
                    foreach (VocabMeaning meaning in result.Meanings)
                    {
                        meanings.Append(MultiValueFieldHelper.ReplaceSeparator(meaning.Meaning)
                                        .Replace(';', MultiValueFieldHelper.ValueSeparator)
                                        + MultiValueFieldHelper.ValueSeparator);
                    }
                    readings.Append(result.KanaWriting + MultiValueFieldHelper.ValueSeparator);
                }
                entity.Meanings.Add(new VocabMeaning()
                {
                    Meaning = MultiValueFieldHelper.Expand(MultiValueFieldHelper.Distinct(meanings.ToString()))
                });
                entity.KanaWriting = MultiValueFieldHelper.Expand(MultiValueFieldHelper.Distinct(readings.ToString()));
                AssociatedVocab    = entity;
            }
            else
            {
                AssociatedVocab = null;
            }
        }