Ejemplo n.º 1
0
        public KanjiSearchResult GetKanjiInfo(char inKanji, Language inLanguage)
        {
            KanjiSearchResult kanjiSearchResult = new KanjiSearchResult();

            string kanjiURL;

            if (inLanguage == Language.Japanese)
            {
                kanjiURL = String.Format("http://kanji.nihongo.cz/image.php?text={0}&font=sod.ttf&fontsize=300", inKanji);
            }
            else
            {
                kanjiURL = String.Format("http://cdn.yabla.com/chinese_static/strokes/{0}-bw.png", inKanji);
            }

            Uri  uriResult;
            bool isValidURL = Uri.TryCreate(kanjiURL, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;

            if (isValidURL)
            {
                try
                {
                    byte[]       imageData = (new WebClient()).DownloadData(uriResult);
                    MemoryStream stream    = new MemoryStream(imageData);
                    kanjiSearchResult.mStrokeOrderImage = Image.FromStream(stream);
                }
                catch (System.Net.WebException ex)
                {
                    return(null);
                }
            }

            if (inLanguage == Language.Japanese)
            {
                if (mKanjiInfos.ContainsKey(inKanji.ToString()))
                {
                    KanjiInfo kanjiInfo = mKanjiInfos[inKanji.ToString()];
                    kanjiSearchResult.mDescription = "On yomi: " + kanjiInfo.mOnYomi + "\nKun yomi: " + kanjiInfo.mKunYomi;
                }
            }

            return(kanjiSearchResult);
        }
Ejemplo n.º 2
0
        private async void FillKanjiPage()
        {
            dataViewKanji.Rows.Clear();

            if (mSelectedLanguage == Language.Chinese)
            {
                dataViewKanji.Columns[0].Width = 250;
            }
            else
            {
                dataViewKanji.Columns[0].Width = 180;
            }

            List <KanjiSearchResult> kanjiInfo = new List <KanjiSearchResult>();

            await Task.Run(() =>
            {
                foreach (char c in mSearchText)
                {
                    KanjiSearchResult kanjiSearchResult = mKanjiHelper.GetKanjiInfo(c, mSelectedLanguage);
                    if (kanjiSearchResult != null && kanjiSearchResult.mStrokeOrderImage != null)
                    {
                        kanjiInfo.Add(kanjiSearchResult);
                    }
                }
            });

            for (int i = 0; i < kanjiInfo.Count; i++)
            {
                dataViewKanji.Rows.Add();
            }

            for (int i = 0; i < kanjiInfo.Count; i++)
            {
                dataViewKanji.Rows[i].Cells[0].Value = kanjiInfo[i].mStrokeOrderImage;
                dataViewKanji.Rows[i].Cells[1].Value = kanjiInfo[i].mDescription;
            }
        }