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