Esempio n. 1
0
        /// <summary>
        /// Returns stroke order animation, it it exists for requested character.
        /// </summary>
        public IActionResult CharStrokes([FromQuery] string hanzi)
        {
            IActionResult res;

            if (hanzi != null)
            {
                hanzi = WebUtility.UrlDecode(hanzi);
            }
            if (hanzi == null || hanzi.Length != 1)
            {
                // TO-DO: log warning
                return(StatusCode(400, "A single Hanzi expected."));
            }
            HanziStrokes strokes = langRepo.GetStrokes(hanzi[0]);

            if (strokes == null)
            {
                res = new ObjectResult(null);
            }
            else
            {
                CharStrokes cstrokes = new CharStrokes();
                cstrokes.Strokes = new string[strokes.Strokes.Count];
                cstrokes.Medians = new short[strokes.Strokes.Count][][];
                for (int i = 0; i != strokes.Strokes.Count; ++i)
                {
                    var stroke = strokes.Strokes[i];
                    cstrokes.Strokes[i] = stroke.SVG;
                    cstrokes.Medians[i] = new short[stroke.Median.Count][];
                    for (int j = 0; j != stroke.Median.Count; ++j)
                    {
                        cstrokes.Medians[i][j]    = new short[2];
                        cstrokes.Medians[i][j][0] = stroke.Median[j].Item1;
                        cstrokes.Medians[i][j][1] = stroke.Median[j].Item2;
                    }
                }
                res = new ObjectResult(cstrokes);
            }
            // Log this request (after resolving country code).
            string country;
            string xfwd = HttpContext.Request.Headers["X-Real-IP"];

            if (xfwd != null)
            {
                country = cres.GetContryCode(IPAddress.Parse(xfwd));
            }
            else
            {
                country = cres.GetContryCode(HttpContext.Connection.RemoteIpAddress);
            }
            qlog.LogHanzi(country, hanzi[0], strokes != null);
            // Return result
            return(res);
        }
Esempio n. 2
0
        private void mmahLine(string line)
        {
            if (!line.StartsWith("{"))
            {
                return;
            }
            MMAHParser   parser = new MMAHParser(line);
            HanziStrokes hi     = null;
            char         c;

            parser.Parse();
            c  = parser.Hanzi;
            hi = parser.GetHanziInfo();
            CharInfo ci = getOrMake(c);

            ci.HanziInfo = hi;
        }