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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » PhoneticAlphabet

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

Phonetic Alphabet

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