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

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

Russian class

    1: using System;
    2: using System.Linq;
    3: using System.Collections.Generic;
    4: using System.IO;
    5: using System.Xml.Linq;
    6: using System.Data;
    7: using System.Reflection;
    8:  
    9: namespace Ia.TentPlay.Cl.Model.Memorise
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Russian 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 Russian : Test
   33:     {
   34:         private XDocument xDocument;
   35:         protected override TestTopic testTopic
   36:         {
   37:             get
   38:             {
   39:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Russian;
   40:             }
   41:         }
   42:  
   43:         ////////////////////////////////////////////////////////////////////////////
   44:  
   45:         /// <summary>
   46:         ///
   47:         /// </summary>
   48:         public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
   49:  
   50:         ////////////////////////////////////////////////////////////////////////////
   51:  
   52:         /// <summary>
   53:         ///
   54:         /// </summary>
   55:         public struct Word
   56:         {
   57:             public WordType Type;
   58:             public string English;
   59:             public string Russian;
   60:  
   61:             /// <summary/>
   62:             public Word(string english, string russian, WordType type)
   63:             {
   64:                 this.Type = type;
   65:                 this.English = english;
   66:                 this.Russian = russian;
   67:             }
   68:  
   69:             /// <summary/>
   70:             public override string ToString()
   71:             {
   72:                 return this.Russian + ":" + this.English + ":" + this.Type;
   73:             }
   74:         }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         ///
   80:         /// </summary>
   81:         public Russian() { }
   82:  
   83:         ////////////////////////////////////////////////////////////////////////////
   84:  
   85:         /// <summary>
   86:         /// Read all tests
   87:         /// </summary>
   88:         public List<Word> ReadList()
   89:         {
   90:             WordType wordType;
   91:             Word word;
   92:             List<Word> wordList;
   93:  
   94:             wordList = new List<Word>(10000);
   95:  
   96:             foreach (XElement xe in XDocument.Elements("russian").Elements())
   97:             {
   98:                 switch (xe.Name.LocalName)
   99:                 {
  100:                     case "verb": wordType = WordType.Verb; break;
  101:                     case "noun": wordType = WordType.Noun; break;
  102:                     case "adjective": wordType = WordType.Adjective; break;
  103:                     case "adverb": wordType = WordType.Adverb; break;
  104:                     default: wordType = WordType.Unspecified; break;
  105:                 }
  106:  
  107:                 word = new Word(xe.Attribute("english").Value, xe.Attribute("russian").Value, wordType);
  108:  
  109:                 wordList.Add(word);
  110:             }
  111:  
  112:             return wordList;
  113:         }
  114:  
  115:         ////////////////////////////////////////////////////////////////////////////
  116:  
  117:         /// <summary>
  118:         ///
  119:         /// </summary>
  120:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
  121:         {
  122:             int count;
  123:             string question, answer;
  124:             XDocument xDocument;
  125:             WordType wordType;
  126:             Ia.TentPlay.Cl.Model.Memorise.Score score;
  127:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
  128:  
  129:             xDocument = XDocument;
  130:  
  131:             // below: synch database words with XML list
  132:             using (var db = new Ia.TentPlay.Db())
  133:             {
  134:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Russian select s).Count();
  135:  
  136:                 if (count == 0)
  137:                 {
  138:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.RussianScoreList(userId);
  139:  
  140:                     foreach (XElement xe in xDocument.Elements("russian").Elements())
  141:                     {
  142:                         switch (xe.Name.LocalName)
  143:                         {
  144:                             case "verb": wordType = WordType.Verb; break;
  145:                             case "noun": wordType = WordType.Noun; break;
  146:                             case "adjective": wordType = WordType.Adjective; break;
  147:                             case "adverb": wordType = WordType.Adverb; break;
  148:                             default: wordType = WordType.Unspecified; break;
  149:                         }
  150:  
  151:                         question = xe.Attribute("russian").Value;
  152:                         answer = xe.Attribute("english").Value;
  153:  
  154:                         score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer && s.TypeId == (int)wordType select s).FirstOrDefault();
  155:  
  156:                         if (score == null)
  157:                         {
  158:                             score = new Ia.TentPlay.Cl.Model.Memorise.Score();
  159:  
  160:                             score.Question = question;
  161:                             score.Answer = answer;
  162:                             score.TestId = (int)testTopic;
  163:                             score.TypeId = 0; //(int)wordType;
  164:                             score.Created = score.Updated = score.Viewed = DateTime.UtcNow.AddHours(3);
  165:                             score.UserId = userId;
  166:  
  167:                             db.Scores.Add(score);
  168:                         }
  169:                     }
  170:  
  171:                     db.SaveChanges();
  172:                 }
  173:             }
  174:         }
  175:  
  176:         ////////////////////////////////////////////////////////////////////////////
  177:  
  178:         /// <summary>
  179:         ///
  180:         /// </summary>
  181:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  182:         {
  183:             /*
  184:             int countOfAllTypes, countOfTypeId1, countOfTypeId2, countOfTypeId3, countOfTypeId4, countOfTypeId5, typeId;
  185:             ArrayList countArrayList;
  186: 
  187:             // public enum WordType { Verb = 1, Noun, Adjective, Adverb, Unspecified };
  188: 
  189:             using (var db = new Ia.TentPlay.Db())
  190:             {
  191:                 countOfAllTypes = (from s in db.Scores where s.TestId == (int)testTopic select s).Count();
  192:                 countOfTypeId1 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Verb select s).Count();
  193:                 countOfTypeId2 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Noun select s).Count();
  194:                 countOfTypeId3 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adjective select s).Count();
  195:                 countOfTypeId4 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Adverb select s).Count();
  196:                 countOfTypeId5 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)WordType.Unspecified select s).Count();
  197: 
  198:                 countArrayList = new ArrayList(countOfAllTypes);
  199: 
  200:                 // below: populate ArrayList with TypeId keys a number of times equal to its count
  201:                 for (int i = 0; i < countOfTypeId1; i++) countArrayList.Add((int)WordType.Verb);
  202:                 for (int i = 0; i < countOfTypeId2; i++) countArrayList.Add((int)WordType.Noun);
  203:                 for (int i = 0; i < countOfTypeId3; i++) countArrayList.Add((int)WordType.Adjective);
  204:                 for (int i = 0; i < countOfTypeId4; i++) countArrayList.Add((int)WordType.Adverb);
  205:                 for (int i = 0; i < countOfTypeId5; i++) countArrayList.Add((int)WordType.Unspecified);
  206: 
  207:                 typeId = (int)countArrayList[random.Next(countOfAllTypes)];
  208:             }
  209:             */
  210:  
  211:             return 0; // typeId;
  212:         }
  213:  
  214:         ////////////////////////////////////////////////////////////////////////////
  215:         ////////////////////////////////////////////////////////////////////////////
  216:  
  217:         /// <summary>
  218:         /// 
  219:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  220:         /// 
  221:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  222:         /// 2. Add "using System.Reflection".
  223:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  224:         /// 
  225:         /// </summary>
  226:         public XDocument XDocument
  227:         {
  228:             get
  229:             {
  230:                 if (xDocument == null)
  231:                 {
  232:                     Assembly _assembly;
  233:                     StreamReader streamReader;
  234:  
  235:                     _assembly = Assembly.GetExecutingAssembly();
  236:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.russian.xml"));
  237:  
  238:                     try
  239:                     {
  240:                         if (streamReader.Peek() != -1)
  241:                         {
  242:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  243:                         }
  244:                     }
  245:                     catch (Exception)
  246:                     {
  247:                     }
  248:                     finally
  249:                     {
  250:                     }
  251:                 }
  252:  
  253:                 return xDocument;
  254:             }
  255:         }
  256:  
  257:         ////////////////////////////////////////////////////////////////////////////
  258:         ////////////////////////////////////////////////////////////////////////////    
  259:     }
  260:  
  261:     ////////////////////////////////////////////////////////////////////////////
  262:     ////////////////////////////////////////////////////////////////////////////   
  263: }