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

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

Phonetic Alphabet

    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:     /// Phonetic Alphabet
   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 PhoneticAlphabet : 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.PhoneticAlphabet;
   41:             }
   42:         }
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         //public enum CharacterType { };
   50:  
   51:         ////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         public struct Character
   57:         {
   58:             public string Name;
   59:             public string Telephony;
   60:  
   61:             public Character(string name, string telephony)
   62:             {
   63:                 this.Name = name;
   64:                 this.Telephony = telephony;
   65:             }
   66:         }
   67:  
   68:         ////////////////////////////////////////////////////////////////////////////
   69:  
   70:         /// <summary>
   71:         ///
   72:         /// </summary>
   73:         public PhoneticAlphabet() { }
   74:  
   75:         ////////////////////////////////////////////////////////////////////////////
   76:  
   77:         /// <summary>
   78:         ///
   79:         /// </summary>
   80:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
   81:         {
   82:             int count;
   83:             string question, answer;
   84:             //CharType charType;
   85:             Ia.TentPlay.Cl.Model.Memorise.Score score;
   86:             List<Ia.TentPlay.Cl.Model.Memorise.Score> scoreList;
   87:  
   88:             // below: synch database words with XML list
   89:             using (var db = new Ia.TentPlay.Db())
   90:             {
   91:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.PhoneticAlphabet select s).Count();
   92:  
   93:                 if (count == 0)
   94:                 {
   95:                     scoreList = Ia.TentPlay.Cl.Model.Memorise.Score.PhoneticAlphabetScoreList(userId);
   96:  
   97:                     foreach (var character in List)
   98:                     {
   99:                         question = character.Name;
  100:                         answer = character.Telephony;
  101:  
  102:                         score = (from s in scoreList where s.TestId == (int)testTopic && s.Question == question && s.Answer == answer /*&& s.TypeId == (int)charType*/ select s).FirstOrDefault();
  103:  
  104:                         if (score == null)
  105:                         {
  106:                             score = new Ia.TentPlay.Cl.Model.Memorise.Score
  107:                             {
  108:                                 Question = question,
  109:                                 Answer = answer,
  110:                                 TestId = (int)testTopic,
  111:                                 TypeId = 0,//(int)charType,
  112:                                 Created = DateTime.UtcNow.AddHours(3),
  113:                                 Updated = DateTime.UtcNow.AddHours(3),
  114:                                 Viewed = DateTime.UtcNow.AddHours(3),
  115:                                 UserId = userId
  116:                             };
  117:  
  118:                             db.Scores.Add(score);
  119:                         }
  120:                     }
  121:  
  122:                     db.SaveChanges();
  123:                 }
  124:             }
  125:         }
  126:  
  127:         ////////////////////////////////////////////////////////////////////////////
  128:  
  129:         /// <summary>
  130:         ///
  131:         /// </summary>
  132:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  133:         {
  134:             return 0; // (int)charType;
  135:         }
  136:  
  137:         ////////////////////////////////////////////////////////////////////////////
  138:  
  139:         /// <summary>
  140:         ///
  141:         /// </summary>
  142:         public static List<Ia.TentPlay.Cl.Model.Memorise.PhoneticAlphabet.Character> List
  143:         {
  144:             get
  145:             {
  146:                 Ia.TentPlay.Cl.Model.Memorise.PhoneticAlphabet.Character character;
  147:                 List<Ia.TentPlay.Cl.Model.Memorise.PhoneticAlphabet.Character> characterList;
  148:  
  149:                 characterList = new List<Ia.TentPlay.Cl.Model.Memorise.PhoneticAlphabet.Character>(40);
  150:  
  151:                 foreach (XElement xe in XDocument.Element("phoneticAlphabet").Elements("character"))
  152:                 {
  153:                     // <character name="A" telephony="Alfa" />
  154:  
  155:                     character = new Ia.TentPlay.Cl.Model.Memorise.PhoneticAlphabet.Character(
  156:                     xe.Attribute("name").Value,
  157:                     xe.Attribute("telephony").Value);
  158:  
  159:                     characterList.Add(character);
  160:                 }
  161:  
  162:                 return characterList;
  163:             }
  164:         }
  165:  
  166:         ////////////////////////////////////////////////////////////////////////////
  167:         ////////////////////////////////////////////////////////////////////////////
  168:  
  169:         /// <summary>
  170:         /// 
  171:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  172:         /// 
  173:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  174:         /// 2. Add "using System.Reflection".
  175:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  176:         /// 
  177:         /// </summary>
  178:         public static XDocument XDocument
  179:         {
  180:             get
  181:             {
  182:                 if (xDocument == null)
  183:                 {
  184:                     Assembly _assembly;
  185:                     StreamReader streamReader;
  186:  
  187:                     _assembly = Assembly.GetExecutingAssembly();
  188:                     streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.phonetic-alphabet.xml"));
  189:  
  190:                     try
  191:                     {
  192:                         if (streamReader.Peek() != -1)
  193:                         {
  194:                             xDocument = System.Xml.Linq.XDocument.Load(streamReader);
  195:                         }
  196:                     }
  197:                     catch (Exception)
  198:                     {
  199:                     }
  200:                     finally
  201:                     {
  202:                     }
  203:                 }
  204:  
  205:                 return xDocument;
  206:             }
  207:         }
  208:  
  209:         ////////////////////////////////////////////////////////////////////////////
  210:         ////////////////////////////////////////////////////////////////////////////    
  211:     }
  212: }