)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Kanji (Ia.Learning.Cl.Models.Data)

Public general use code classes and xml files that we've compiled and used over the years:

Kanji support class

    1: using System;
    2: using System.Reflection;
    3: using System.Xml.Linq;
    4: using System.IO;
    5: using System.Collections.Generic;
    6:  
    7: namespace Ia.Learning.Cl.Models.Data
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Kanji support class
   13:     /// </summary>
   14:     /// <value>
   15:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   16:     /// </value>
   17:     /// <remarks> 
   18:     /// Copyright © 2008-2016 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     ///
   20:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   21:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   22:     ///
   23:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   24:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   25:     /// 
   26:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   27:     /// 
   28:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   29:     /// </remarks> 
   30:     public partial class Kanji
   31:     {
   32:         private static XDocument xDocument;
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public Kanji() { }
   40:  
   41:         ////////////////////////////////////////////////////////////////////////////
   42:  
   43:         /// <summary>
   44:         /// Read all Kanji characters
   45:         /// </summary>
   46:         public static List<Ia.Learning.Cl.Models.Business.Kanji> List
   47:         {
   48:             get
   49:             {
   50:                 Ia.Learning.Cl.Models.Business.Kanji kanji;
   51:                 List<Ia.Learning.Cl.Models.Business.Kanji> kanjiList;
   52:  
   53:                 kanjiList = new List<Ia.Learning.Cl.Models.Business.Kanji>(2000);
   54:  
   55:                 foreach (XElement xe in XDocument.Element("kanji").Elements("char"))
   56:                 {
   57:                     //  <char id="1" wikiId="1" name="一" grade="1" wikiEnglish="one" english="one" stroke="1" onyomiJapanese="イチ、イツ" onyomiEnglish="ichi, itsu" kunyomiJapanese="ひと、ひと-つ" kunyomiEnglish="hito, hito-tsu" />
   58:  
   59:                     kanji = new Ia.Learning.Cl.Models.Business.Kanji();
   60:  
   61:                     kanji.Id = int.Parse(xe.Attribute("id").Value);
   62:                     kanji.WikiId = int.Parse(xe.Attribute("wikiId").Value);
   63:                     kanji.Name = xe.Attribute("name").Value;
   64:                     kanji.Grade = int.Parse(xe.Attribute("grade").Value);
   65:                     kanji.WikiEnglish = xe.Attribute("wikiEnglish").Value;
   66:                     kanji.English = xe.Attribute("english").Value;
   67:                     kanji.Stroke = int.Parse(xe.Attribute("stroke").Value);
   68:                     kanji.JapaneseOnyomi = xe.Attribute("japaneseOnyomi").Value;
   69:                     kanji.EnglishOnyomi = xe.Attribute("englishOnyomi").Value;
   70:                     kanji.JapaneseKunyomi = xe.Attribute("japaneseKunyomi").Value;
   71:                     kanji.EnglishKunyomi = xe.Attribute("englishKunyomi").Value;
   72:  
   73:                     kanjiList.Add(kanji);
   74:                 }
   75:  
   76:                 return kanjiList;
   77:             }
   78:         }
   79:  
   80:         ////////////////////////////////////////////////////////////////////////////
   81:         ////////////////////////////////////////////////////////////////////////////
   82:  
   83:         /// <summary>
   84:         /// 
   85:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
   86:         /// 
   87:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
   88:         /// 2. Add "using System.Reflection".
   89:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
   90:         /// 
   91:         /// </summary>
   92:         public static XDocument XDocument
   93:         {
   94:             get
   95:             {
   96:                 if (xDocument == null)
   97:                 {
   98:                     Assembly assembly;
   99:                     StreamReader streamReader;
  100:  
  101:                     assembly = Assembly.GetExecutingAssembly();
  102:                     streamReader = new StreamReader(assembly.GetManifestResourceStream("Ia.Learning.Cl.Models.Data.kanji.xml"));
  103:  
  104:                     try
  105:                     {
  106:                         if (streamReader.Peek() != -1)
  107:                         {
  108:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  109:                         }
  110:                     }
  111:                     catch (Exception)
  112:                     {
  113:                     }
  114:                     finally
  115:                     {
  116:                     }
  117:                 }
  118:  
  119:                 return xDocument;
  120:             }
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:         ////////////////////////////////////////////////////////////////////////////    
  125:     }
  126:  
  127:     ////////////////////////////////////////////////////////////////////////////
  128:     ////////////////////////////////////////////////////////////////////////////    
  129: }