)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation LinksHome » Code Library » Kanji

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

Kanji class

    1: using System.Reflection;
    2: using System.Data;
    3: using System.Xml.Linq;
    4:  
    5: namespace Ia.TentPlay.Cl.Model.Memorise
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Kanji class
   11:     /// </summary>
   12:     /// <value>
   13:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   14:     /// </value>
   15:     /// <remarks> 
   16:     /// Copyright © 2008-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class Kanji : Test
   29:     {
   30:         // <char id="1" wiki_id="1" name="一" grade="1" wiki_en="one" en="one" stroke="1" onyomi_ja="イチ、イツ" onyomi_en="ichi, itsu" kunyomi_ja="ひと、ひと-つ" kunyomi_en="hito, hito-tsu" />
   31:  
   32:         private static XDocument xDocument;
   33:  
   34:         protected override TestTopic testTopic
   35:         {
   36:             get
   37:             {
   38:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kanji;
   39:             }
   40:         }
   41:  
   42:         ////////////////////////////////////////////////////////////////////////////
   43:  
   44:         /// <summary>
   45:         ///
   46:         /// </summary>
   47:         //public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
   48:  
   49:         ////////////////////////////////////////////////////////////////////////////
   50:  
   51:         /// <summary>
   52:         ///
   53:         /// </summary>
   54:         public struct Symbol
   55:         {
   56:             public int Id;
   57:             public int WikiId;
   58:             public string Name;
   59:             public int Grade;
   60:             public string WikiEnglish;
   61:             public string English;
   62:             public int Stroke;
   63:             public string JapaneseOnyomi;
   64:             public string EnglishOnyomi;
   65:             public string JapaneseKunyomi;
   66:             public string EnglishKunyomi;
   67:  
   68:             public Symbol(int id, int wikiId, string name, int grade, string wikiEnglish, string english, int stroke, string japaneseOnyomi, string englishOnyomi, string japaneseKunyomi, string englishKunyomi)
   69:             {
   70:                 this.Id = id;
   71:                 this.WikiId = wikiId;
   72:                 this.Name = name;
   73:                 this.Grade = grade;
   74:                 this.WikiEnglish = wikiEnglish;
   75:                 this.English = english;
   76:                 this.Stroke = stroke;
   77:                 this.JapaneseOnyomi = japaneseOnyomi;
   78:                 this.EnglishOnyomi = englishOnyomi;
   79:                 this.JapaneseKunyomi = japaneseKunyomi;
   80:                 this.EnglishKunyomi = englishKunyomi;
   81:             }
   82:         }
   83:  
   84:         ////////////////////////////////////////////////////////////////////////////
   85:  
   86:         /// <summary>
   87:         ///
   88:         /// </summary>
   89:         public Kanji() { }
   90:  
   91:         ////////////////////////////////////////////////////////////////////////////
   92:  
   93:         /// <summary>
   94:         ///
   95:         /// </summary>
   96:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
   97:         {
   98:             int count;
   99:             string question, answer;
  100:             //WordType wordType;
  101:             Ia.TentPlay.Cl.Model.Memorise.Score score;
  102:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
  103:  
  104:             // below: synch database words with XML list
  105:             using (var db = new Ia.TentPlay.Db())
  106:             {
  107:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kanji select s).Count();
  108:  
  109:                 if (count == 0)
  110:                 {
  111:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.KanjiScoreList(userId);
  112:  
  113:                     foreach (var symbol in List)
  114:                     {
  115:                         question = symbol.Name;
  116:                         answer = symbol.English;
  117:  
  118:                         score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer /*&& s.TypeId == (int)wordType*/ select s).FirstOrDefault();
  119:  
  120:                         if (score == null)
  121:                         {
  122:                             score = new Ia.TentPlay.Cl.Model.Memorise.Score
  123:                             {
  124:                                 Question = question,
  125:                                 Answer = answer,
  126:                                 TestId = (int)testTopic,
  127:                                 TypeId = 0, //(int)wordType
  128:                                 Created = DateTime.UtcNow.AddHours(3),
  129:                                 Updated = DateTime.UtcNow.AddHours(3),
  130:                                 Viewed = DateTime.UtcNow.AddHours(3),
  131:                                 UserId = userId
  132:                             };
  133:  
  134:                             db.Scores.Add(score);
  135:                         }
  136:                     }
  137:  
  138:                     db.SaveChanges();
  139:                 }
  140:             }
  141:         }
  142:  
  143:         ////////////////////////////////////////////////////////////////////////////
  144:  
  145:         /// <summary>
  146:         ///
  147:         /// </summary>
  148:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  149:         {
  150:             /*
  151:             int countOfAllTypes, countOfTypeId1, countOfTypeId2, countOfTypeId3, countOfTypeId4, countOfTypeId5, typeId;
  152:             ArrayList countArrayList;
  153: 
  154:             // public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
  155: 
  156:             using (var db = new Ia.TentPlay.Db())
  157:             {
  158:                 countOfAllTypes = (from s in db.Scores where s.TestId == (int)testTopic select s).Count();
  159:                 countOfTypeId1 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Verb select s).Count();
  160:                 countOfTypeId2 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Noun select s).Count();
  161:                 countOfTypeId3 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adjective select s).Count();
  162:                 countOfTypeId4 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adverb select s).Count();
  163:                 countOfTypeId5 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Unspecified select s).Count();
  164: 
  165:                 countArrayList = new ArrayList(countOfAllTypes);
  166: 
  167:                 // below: populate ArrayList with TypeId keys a number of times equal to its count
  168:                 for (int i = 0; i < countOfTypeId1; i++) countArrayList.Add((int)WordType.Verb);
  169:                 for (int i = 0; i < countOfTypeId2; i++) countArrayList.Add((int)Noun.Verb);
  170:                 for (int i = 0; i < countOfTypeId3; i++) countArrayList.Add((int)Adjective.Verb);
  171:                 for (int i = 0; i < countOfTypeId4; i++) countArrayList.Add((int)Adverb.Verb);
  172:                 for (int i = 0; i < countOfTypeId5; i++) countArrayList.Add((int)Unspecified.Verb);
  173: 
  174:                 typeId = (int)countArrayList[random.Next(countOfAllTypes)];
  175:             }
  176:             */
  177:  
  178:             return 0; // typeId;
  179:         }
  180:  
  181:         ////////////////////////////////////////////////////////////////////////////
  182:  
  183:         /// <summary>
  184:         /// Read all Kanji symbol characters
  185:         /// </summary>
  186:         public static List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol> List
  187:         {
  188:             get
  189:             {
  190:                 Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol symbol;
  191:                 List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol> symbolList;
  192:  
  193:                 symbolList = new List<Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol>(2000);
  194:  
  195:                 foreach (XElement xe in XDocument.Element("kanji").Elements("char"))
  196:                 {
  197:                     //  <char id="1" wikiId="1" name="一" grade="1" wikiEnglish="one" english="one" stroke="1" onyomiJapanese="イチ、イツ" onyomiEnglish="ichi, itsu" kunyomiJapanese="ひと、ひと-つ" kunyomiEnglish="hito, hito-tsu" />
  198:  
  199:                     symbol = new Ia.TentPlay.Cl.Model.Memorise.Kanji.Symbol(
  200:                     int.Parse(xe.Attribute("id").Value),
  201:                     int.Parse(xe.Attribute("wikiId").Value),
  202:                     xe.Attribute("name").Value,
  203:                     int.Parse(xe.Attribute("grade").Value),
  204:                     xe.Attribute("wikiEnglish").Value,
  205:                     xe.Attribute("english").Value,
  206:                     int.Parse(xe.Attribute("stroke").Value),
  207:                     xe.Attribute("japaneseOnyomi").Value,
  208:                     xe.Attribute("englishOnyomi").Value,
  209:                     xe.Attribute("japaneseKunyomi").Value,
  210:                     xe.Attribute("englishKunyomi").Value);
  211:  
  212:                     symbolList.Add(symbol);
  213:                 }
  214:  
  215:                 return symbolList;
  216:             }
  217:         }
  218:  
  219:         ////////////////////////////////////////////////////////////////////////////
  220:         ////////////////////////////////////////////////////////////////////////////
  221:  
  222:         /// <summary>
  223:         /// 
  224:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  225:         /// 
  226:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  227:         /// 2. Add "using System.Reflection".
  228:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  229:         /// 
  230:         /// </summary>
  231:         public static XDocument XDocument
  232:         {
  233:             get
  234:             {
  235:                 if (xDocument == null)
  236:                 {
  237:                     Assembly _assembly;
  238:                     StreamReader streamReader;
  239:  
  240:                     _assembly = Assembly.GetExecutingAssembly();
  241:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.kanji.xml"));
  242:  
  243:                     try
  244:                     {
  245:                         if (streamReader.Peek() != -1)
  246:                         {
  247:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  248:                         }
  249:                     }
  250:                     catch (Exception)
  251:                     {
  252:                     }
  253:                     finally
  254:                     {
  255:                     }
  256:                 }
  257:  
  258:                 return xDocument;
  259:             }
  260:         }
  261:  
  262:         ////////////////////////////////////////////////////////////////////////////
  263:         ////////////////////////////////////////////////////////////////////////////    
  264:     }
  265: }