شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Russian

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