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

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:  
    5: namespace Ia.TentPlay.Cl.Model.Memorise
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Kana 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 Kana : Test
   29:     {
   30:         private static XDocument xDocument;
   31:  
   32:         protected override TestTopic testTopic
   33:         {
   34:             get
   35:             {
   36:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kana;
   37:             }
   38:         }
   39:  
   40:         ////////////////////////////////////////////////////////////////////////////
   41:  
   42:         /// <summary>
   43:         ///
   44:         /// </summary>
   45:         public enum CharType { Hiragana, Katakana };
   46:  
   47:         ////////////////////////////////////////////////////////////////////////////
   48:  
   49:         /// <summary>
   50:         ///
   51:         /// </summary>
   52:         public struct Char
   53:         {
   54:             public string Hiragana;
   55:             public string Katakana;
   56:             public string Pronunciation;
   57:  
   58:             public Char(string hiragana, string katakana, string pronunciation)
   59:             {
   60:                 this.Hiragana = hiragana;
   61:                 this.Katakana = katakana;
   62:                 this.Pronunciation = pronunciation;
   63:             }
   64:         }
   65:  
   66:         ////////////////////////////////////////////////////////////////////////////
   67:  
   68:         /// <summary>
   69:         ///
   70:         /// </summary>
   71:         public Kana() { }
   72:  
   73:         ////////////////////////////////////////////////////////////////////////////
   74:  
   75:         /// <summary>
   76:         ///
   77:         /// </summary>
   78:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
   79:         {
   80:             int count;
   81:             string question, answer;
   82:             CharType charType;
   83:             Ia.TentPlay.Cl.Model.Memorise.Score score;
   84:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
   85:  
   86:             // below: synch database words with XML list
   87:             using (var db = new Ia.TentPlay.Db())
   88:             {
   89:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kana select s).Count();
   90:  
   91:                 if (count == 0)
   92:                 {
   93:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.KanaScoreList(userId);
   94:  
   95:                     foreach (bool b in new bool[] { true, false })
   96:                     {
   97:                         foreach (var @char in List)
   98:                         {
   99:                             if (b)
  100:                             {
  101:                                 question = @char.Hiragana;
  102:                                 charType = CharType.Hiragana;
  103:                             }
  104:                             else
  105:                             {
  106:                                 question = @char.Katakana;
  107:                                 charType = CharType.Katakana;
  108:                             }
  109:  
  110:                             answer = @char.Pronunciation;
  111:  
  112:                             score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer && s.TypeId == (int)charType select s).FirstOrDefault();
  113:  
  114:                             if (score == null)
  115:                             {
  116:                                 score = new Ia.TentPlay.Cl.Model.Memorise.Score
  117:                                 {
  118:                                     Question = question,
  119:                                     Answer = answer,
  120:                                     TestId = (int)testTopic,
  121:                                     TypeId = (int)charType,
  122:                                     Created = DateTime.UtcNow.AddHours(3),
  123:                                     Updated = DateTime.UtcNow.AddHours(3),
  124:                                     Viewed = DateTime.UtcNow.AddHours(3),
  125:                                     UserId = userId
  126:                                 };
  127:  
  128:                                 db.Scores.Add(score);
  129:                             }
  130:                         }
  131:                     }
  132:  
  133:                     db.SaveChanges();
  134:                 }
  135:             }
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////
  139:  
  140:         /// <summary>
  141:         ///
  142:         /// </summary>
  143:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  144:         {
  145:             CharType charType;
  146:  
  147:             if (Ia.Cl.Model.Default.RandomBool) charType = CharType.Hiragana;
  148:             else charType = CharType.Katakana;
  149:  
  150:             return (int)charType;
  151:         }
  152:  
  153:         ////////////////////////////////////////////////////////////////////////////
  154:  
  155:         /// <summary>
  156:         /// Read all Kana symbol characters
  157:         /// </summary>
  158:         public static List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char> List
  159:         {
  160:             get
  161:             {
  162:                 Ia.TentPlay.Cl.Model.Memorise.Kana.Char @char;
  163:                 List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char> charList;
  164:  
  165:                 charList = new List<Ia.TentPlay.Cl.Model.Memorise.Kana.Char>(2000);
  166:  
  167:                 foreach (XElement xe in XDocument.Element("kana").Elements("char"))
  168:                 {
  169:                     // <kana hiragana="あ" katakana="ア" pronunciation="a [a]" />
  170:  
  171:                     @char = new Ia.TentPlay.Cl.Model.Memorise.Kana.Char(
  172:                     xe.Attribute("hiragana").Value,
  173:                     xe.Attribute("katakana").Value,
  174:                     xe.Attribute("pronunciation").Value);
  175:  
  176:                     charList.Add(@char);
  177:                 }
  178:  
  179:                 return charList;
  180:             }
  181:         }
  182:  
  183:         ////////////////////////////////////////////////////////////////////////////
  184:         ////////////////////////////////////////////////////////////////////////////
  185:  
  186:         /// <summary>
  187:         /// 
  188:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  189:         /// 
  190:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  191:         /// 2. Add "using System.Reflection".
  192:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  193:         /// 
  194:         /// </summary>
  195:         public static XDocument XDocument
  196:         {
  197:             get
  198:             {
  199:                 if (xDocument == null)
  200:                 {
  201:                     Assembly _assembly;
  202:                     StreamReader streamReader;
  203:  
  204:                     _assembly = Assembly.GetExecutingAssembly();
  205:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.kana.xml"));
  206:  
  207:                     try
  208:                     {
  209:                         if (streamReader.Peek() != -1)
  210:                         {
  211:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  212:                         }
  213:                     }
  214:                     catch (Exception)
  215:                     {
  216:                     }
  217:                     finally
  218:                     {
  219:                     }
  220:                 }
  221:  
  222:                 return xDocument;
  223:             }
  224:         }
  225:  
  226:         ////////////////////////////////////////////////////////////////////////////
  227:         ////////////////////////////////////////////////////////////////////////////    
  228:     }
  229: }