Beispiel #1
0
        /// <summary>
        /// Attempts to retrieve the kanji strokes SVG matching the given kanji inside the zip file.
        /// </summary>
        /// <param name="k">Target kanji.</param>
        /// <returns>A kanji strokes entity, never null, that contains either the retrieved data or an
        /// empty byte array when the entry was not found.</returns>
        private KanjiStrokes RetrieveSvg(KanjiEntity k)
        {
            KanjiStrokes strokes = new KanjiStrokes();
            strokes.FramesSvg = new byte[0];

            if (!k.UnicodeValue.HasValue)
            {
                return strokes;
            }

            ZipArchive svgZip = GetSvgZipArchive();
            string entryName = string.Format("{0}_frames.svg", k.UnicodeValue.Value);
            ZipArchiveEntry entry = svgZip.GetEntry(entryName);
            if (entry != null)
            {
                using (Stream stream = entry.Open())
                {
                    strokes.FramesSvg = StringCompressionHelper.Zip(StreamHelper.ReadToEnd(stream));
                    StringCompressionHelper.Unzip(strokes.FramesSvg);
                }
            }

            return strokes;
        }
Beispiel #2
0
        //public KanjiStrokes GetKanjiStrokes(long id)
        //{
        //    KanjiStrokes result = null;

        //    DaoConnection connection = null;
        //    try
        //    {
        //        // Create and open synchronously the primary Kanji connection.
        //        connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

        //        // FILTERS COMPUTED.
        //        // Execute the final request.
        //        IEnumerable<NameValueCollection> results = connection.Query(
        //            "SELECT * "
        //            + "FROM " + SqlHelper.Table_KanjiStrokes + " ks "
        //            + "WHERE ks." + SqlHelper.Field_KanjiStrokes_Id + "=@ks;",
        //        new DaoParameter("@ks", id));

        //        if (results.Any())
        //        {
        //            KanjiStrokesBuilder builder = new KanjiStrokesBuilder();
        //            result = builder.BuildEntity(results.First(), null);
        //        }
        //    }
        //    finally
        //    {
        //        if (connection != null)
        //        {
        //            connection.Dispose();
        //        }
        //    }

        //    return result;
        //}

        public KanjiStrokes GetKanjiStrokes(long id)
        {
            KanjiStrokes result = new KanjiStrokes();
            result.ID = id;
            result.FramesSvg = new byte[0];

            DaoConnection connection = null;
            SQLiteDataReader reader = null;
            try
            {
                // Create and open synchronously the primary Kanji connection.
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

                reader = connection.QueryDataReader(
                    "SELECT " + SqlHelper.Field_KanjiStrokes_FramesSvg
                    + " FROM " + SqlHelper.Table_KanjiStrokes
                    + " WHERE " + SqlHelper.Field_KanjiStrokes_Id + "=@id;",
                    new DaoParameter("@id", id));

                while (reader.Read())
                {
                    result.FramesSvg = GetBytes(reader);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return result;
        }