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

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

Kana class

    1: using System.Reflection;
    2: using System.Data;
    3: using System.Xml.Linq;
    4: using System;
    5: using System.Linq;
    6: using System.Collections.Generic;
    7: using System.IO;
    8:  
    9: namespace Ia.TentPlay.Cl.Model.Memorise
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Kana class
   15:     /// </summary>
   16:     /// <value>
   17:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   18:     /// </value>
   19:     /// <remarks> 
   20:     /// Copyright © 2008-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   21:     ///
   22:     /// 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
   23:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   24:     ///
   25:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   26:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   27:     /// 
   28:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   29:     /// 
   30:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   31:     /// </remarks> 
   32:     public class Kana : Test
   33:     {
   34:         private static XDocument xDocument;
   35:  
   36:         protected override TestTopic testTopic
   37:         {
   38:             get
   39:             {
   40:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kana;
   41:             }
   42:         }
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         public enum CharType { Hiragana, Katakana };
   50:  
   51:         ////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         public struct Char
   57:         {
   58:             public string Hiragana;
   59:             public string Katakana;
   60:             public string Pronunciation;
   61:  
   62:             public Char(string hiragana, string katakana, string pronunciation)
   63:             {
   64:                 this.Hiragana = hiragana;
   65:                 this.Katakana = katakana;
   66:                 this.Pronunciation = pronunciation;
   67:             }
   68:         }
   69:  
   70:         ////////////////////////////////////////////////////////////////////////////
   71:  
   72:         /// <summary>
   73:         ///
   74:         /// </summary>
   75:         public Kana() { }
   76:  
   77:         ////////////////////////////////////////////////////////////////////////////
   78:  
   79:         /// <summary>
   80:         ///
   81:         /// </summary>
   82:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
   83:         {
   84:             int count;
   85:             string question, answer;
   86:             CharType charType;
   87:             Ia.TentPlay.Cl.Model.Memorise.Score score;
   88:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
   89:  
   90:             // below: synch database words with XML list
   91:             using (var db = new Ia.TentPlay.Db())
   92:             {
   93:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kana select s).Count();
   94:  
   95:                 if (count == 0)
   96:                 {
   97:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.KanaScoreList(userId);
   98:  
   99:                     foreach (bool b in new bool[] { true, false })
  100:                     {
  101:                         foreach (var @char in List)
  102:                         {
  103:                             if (b)
  104:                             {
  105:                                 question = @char.Hiragana;
  106:                                 charType = CharType.Hiragana;
  107:                             }
  108:                             else
  109:                             {
  110:                                 question = @char.Katakana;
  111:                                 charType = CharType.Katakana;
  112:                             }
  113:  
  114:                             answer = @char.Pronunciation;
  115:  
  116:                             score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer && s.TypeId == (int)charType select s).FirstOrDefault();
  117:  
  118:                             if (score == null)
  119:                             {
  120:                                 score = new Ia.TentPlay.Cl.Model.Memorise.Score
  121:                                 {
  122:                                     Question = question,
  123:                                     Answer = answer,
  124:                                     TestId = (int)testTopic,
  125:                                     TypeId = (int)charType,
  126:                                     Created = DateTime.UtcNow.AddHours(3),
  127:                                     Updated = DateTime.UtcNow.AddHours(3),
  128:                                     Viewed = DateTime.UtcNow.AddHours(3),
  129:                                     UserId = userId
  130:                                 };
  131:  
  132:                                 db.Scores.Add(score);
  133:                             }
  134:                         }
  135:                     }
  136:  
  137:                     db.SaveChanges();
  138:                 }
  139:             }
  140:         }
  141:  
  142:         ////////////////////////////////////////////////////////////////////////////
  143:  
  144:         /// <summary>
  145:         ///
  146:         /// </summary>
  147:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  148:         {
  149:             CharType charType;
  150:  
  151:             if (Ia.Cl.Models.Default.RandomBool) charType = CharType.Hiragana;
  152:             else charType = CharType.Katakana;
  153:  
  154:             return (int)charType;
  155:         }
  156:  
  157:         ////////////////////////////////////////////////////////////////////////////
  158:  
  159:         /// <summary>
  160:         /// Read all Kana symbol characters
  161:         /// </summary>
  162:         public static List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char> List
  163:         {
  164:             get
  165:             {
  166:                 Ia.TentPlay.Cl.Model.Memorise.Kana.Char @char;
  167:                 List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char> charList;
  168:  
  169:                 charList = new List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char>(2000);
  170:  
  171:                 foreach (XElement xe in XDocument.Element("kana").Elements("char"))
  172:                 {
  173:                     // <kana hiragana="あ" katakana="ア" pronunciation="a [a]" />
  174:  
  175:                     @char = new Ia.TentPlay.Cl.Model.Memorise.Kana.Char(
  176:                     xe.Attribute("hiragana").Value,
  177:                     xe.Attribute("katakana").Value,
  178:                     xe.Attribute("pronunciation").Value);
  179:  
  180:                     charList.Add(@char);
  181:                 }
  182:  
  183:                 return charList;
  184:             }
  185:         }
  186:  
  187:         ////////////////////////////////////////////////////////////////////////////
  188:         ////////////////////////////////////////////////////////////////////////////
  189:  
  190:         /// <summary>
  191:         /// 
  192:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  193:         /// 
  194:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  195:         /// 2. Add "using System.Reflection".
  196:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  197:         /// 
  198:         /// </summary>
  199:         public static XDocument XDocument
  200:         {
  201:             get
  202:             {
  203:                 if (xDocument == null)
  204:                 {
  205:                     Assembly _assembly;
  206:                     StreamReader streamReader;
  207:  
  208:                     _assembly = Assembly.GetExecutingAssembly();
  209:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.kana.xml"));
  210:  
  211:                     try
  212:                     {
  213:                         if (streamReader.Peek() != -1)
  214:                         {
  215:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  216:                         }
  217:                     }
  218:                     catch (Exception)
  219:                     {
  220:                     }
  221:                     finally
  222:                     {
  223:                     }
  224:                 }
  225:  
  226:                 return xDocument;
  227:             }
  228:         }
  229:  
  230:         ////////////////////////////////////////////////////////////////////////////
  231:         ////////////////////////////////////////////////////////////////////////////    
  232:     }
  233: }