)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation LinksHome » Code Library » MorseCode

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

Morse code class

    1: using System.Data;
    2: using System.Collections;
    3: using System;
    4: using System.Linq;
    5: using System.Collections.Generic;
    6: using System.IO;
    7:  
    8: namespace Ia.TentPlay.Cl.Model.Memorise
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Morse code class
   14:     /// </summary>
   15:     /// <value>
   16:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   17:     /// </value>
   18:     /// <remarks> 
   19:     /// Copyright © 2008-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   20:     ///
   21:     /// 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
   22:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   23:     ///
   24:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   25:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   26:     /// 
   27:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   28:     /// 
   29:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   30:     /// </remarks> 
   31:     public class MorseCode : Test
   32:     {
   33:         private Dictionary<string, string> internationalMorseCodeDicitonary, reverseInternationalMorseCodeDicitonary;
   34:  
   35:         protected override TestTopic testTopic
   36:         {
   37:             get
   38:             {
   39:                 return Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.MorseCode;
   40:             }
   41:         }
   42:  
   43:         ////////////////////////////////////////////////////////////////////////////
   44:  
   45:         /// <summary>
   46:         ///
   47:         /// </summary>
   48:         public enum DirectionType { MorseCodeToAscii = 1, AsciiToMorseCode = 2 };
   49:  
   50:         ////////////////////////////////////////////////////////////////////////////
   51:  
   52:         /// <summary>
   53:         ///
   54:         /// </summary>
   55:         public MorseCode() { }
   56:  
   57:         ////////////////////////////////////////////////////////////////////////////
   58:  
   59:         /// <summary>
   60:         ///
   61:         /// </summary>
   62:         public override void PopulateTestDatabaseTableWithInitialQuestionsIfEmpty(Guid userId)
   63:         {
   64:             int count;
   65:             Ia.TentPlay.Cl.Model.Memorise.Score score;
   66:  
   67:             using (var db = new Ia.TentPlay.Db())
   68:             {
   69:                 count = (from s in db.Scores where s.TestId == (int)Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.MorseCode select s).Count();
   70:  
   71:                 if (count == 0)
   72:                 {
   73:                     // MorseCodeToAscii
   74:                     foreach (KeyValuePair<string, string> kvp in InternationalMorseCodeDicitonary)
   75:                     {
   76:                         score = new Ia.TentPlay.Cl.Model.Memorise.Score();
   77:  
   78:                         score.Question = kvp.Key;
   79:                         score.Answer = kvp.Value;
   80:                         score.TestId = (int)testTopic;
   81:                         score.TypeId = (int)Ia.TentPlay.Cl.Model.Memorise.MorseCode.DirectionType.MorseCodeToAscii;
   82:                         score.Created = score.Updated = score.Viewed = DateTime.UtcNow.AddHours(3);
   83:                         score.UserId = userId;
   84:  
   85:                         db.Scores.Add(score);
   86:                     }
   87:  
   88:                     // AsciiToMorseCode
   89:                     foreach (KeyValuePair<string, string> kvp in ReverseInternationalMorseCodeDicitonary)
   90:                     {
   91:                         score = new Ia.TentPlay.Cl.Model.Memorise.Score();
   92:  
   93:                         score.Question = kvp.Key;
   94:                         score.Answer = kvp.Value;
   95:                         score.TestId = (int)testTopic;
   96:                         score.TypeId = (int)DirectionType.AsciiToMorseCode;
   97:                         score.Created = score.Updated = score.Viewed = DateTime.UtcNow.AddHours(3);
   98:                         score.UserId = userId;
   99:  
  100:                         db.Scores.Add(score);
  101:                     }
  102:  
  103:                     db.SaveChanges();
  104:                 }
  105:             }
  106:         }
  107:  
  108:         ////////////////////////////////////////////////////////////////////////////
  109:  
  110:         /// <summary>
  111:         ///
  112:         /// </summary>
  113:         public override int WeightedRandomTypeIdAccordingTypeDistribution(Guid userId)
  114:         {
  115:             int countOfAllTypes, countOfTypeId1, countOfTypeId2, typeId;
  116:             ArrayList countArrayList;
  117:  
  118:             using (var db = new Ia.TentPlay.Db())
  119:             {
  120:                 countOfAllTypes = (from s in db.Scores where s.TestId == (int)testTopic select s).Count();
  121:                 countOfTypeId1 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)DirectionType.AsciiToMorseCode select s).Count();
  122:                 countOfTypeId2 = (from s in db.Scores where s.TestId == (int)testTopic && s.TypeId == (int)DirectionType.MorseCodeToAscii select s).Count();
  123:  
  124:                 countArrayList = new ArrayList(countOfAllTypes);
  125:  
  126:                 // below: populate ArrayList with TypeId keys a number of times equal to its count
  127:                 for (int i = 0; i < countOfTypeId1; i++) countArrayList.Add((int)DirectionType.AsciiToMorseCode);
  128:                 for (int i = 0; i < countOfTypeId2; i++) countArrayList.Add((int)DirectionType.MorseCodeToAscii);
  129:  
  130:                 if (countArrayList.Count > 0)
  131:                 {
  132:                     typeId = (int)countArrayList[random.Next(countOfAllTypes)];
  133:                 }
  134:                 else
  135:                 {
  136:                     typeId = (Ia.Cl.Model.Default.RandomBool) ? (int)DirectionType.AsciiToMorseCode : (int)DirectionType.MorseCodeToAscii;
  137:                 }
  138:             }
  139:  
  140:             return typeId;
  141:         }
  142:  
  143:         ////////////////////////////////////////////////////////////////////////////
  144:  
  145:         /// <summary>
  146:         /// 
  147:         /// <see cref="https://en.wikipedia.org/wiki/Morse_code"/>
  148:         /// </summary>
  149:         public Dictionary<string, string> InternationalMorseCodeDicitonary
  150:         {
  151:             get
  152:             {
  153:                 /*
  154:                  * https://en.wikipedia.org/wiki/Morse_code
  155:                  * 
  156:                  * International Morse Code
  157:                  * 
  158:                  * 1. The length of a dot is one unit
  159:                  * 2. A dash is three units
  160:                  * 3. The space between parts of the same letter is one unit.
  161:                  * 4. The space between letters is three units.
  162:                  * 5. The space between words is seven units.
  163:                  */
  164:  
  165:                 if (internationalMorseCodeDicitonary == null || internationalMorseCodeDicitonary.Count == 0)
  166:                 {
  167:                     internationalMorseCodeDicitonary = new Dictionary<string, string>(50);
  168:  
  169:                     internationalMorseCodeDicitonary["A"] = ".-";
  170:                     internationalMorseCodeDicitonary["B"] = "-...";
  171:                     internationalMorseCodeDicitonary["C"] = "-.-.";
  172:                     internationalMorseCodeDicitonary["D"] = "-..";
  173:                     internationalMorseCodeDicitonary["E"] = ".";
  174:                     internationalMorseCodeDicitonary["F"] = "..-.";
  175:                     internationalMorseCodeDicitonary["G"] = "--.";
  176:                     internationalMorseCodeDicitonary["H"] = "....";
  177:                     internationalMorseCodeDicitonary["I"] = "..";
  178:                     internationalMorseCodeDicitonary["J"] = ".---";
  179:                     internationalMorseCodeDicitonary["K"] = "-.-";
  180:                     internationalMorseCodeDicitonary["L"] = ".-..";
  181:                     internationalMorseCodeDicitonary["M"] = "--";
  182:                     internationalMorseCodeDicitonary["N"] = "-.";
  183:                     internationalMorseCodeDicitonary["O"] = "---";
  184:                     internationalMorseCodeDicitonary["P"] = ".--.";
  185:                     internationalMorseCodeDicitonary["Q"] = "--.-";
  186:                     internationalMorseCodeDicitonary["R"] = ".-.";
  187:                     internationalMorseCodeDicitonary["S"] = "...";
  188:                     internationalMorseCodeDicitonary["T"] = "-";
  189:                     internationalMorseCodeDicitonary["U"] = "..-";
  190:                     internationalMorseCodeDicitonary["V"] = "...-";
  191:                     internationalMorseCodeDicitonary["W"] = ".--";
  192:                     internationalMorseCodeDicitonary["X"] = "-..-";
  193:                     internationalMorseCodeDicitonary["Y"] = "-.--";
  194:                     internationalMorseCodeDicitonary["Z"] = "--..";
  195:  
  196:                     internationalMorseCodeDicitonary["1"] = ".----";
  197:                     internationalMorseCodeDicitonary["2"] = "..---";
  198:                     internationalMorseCodeDicitonary["3"] = "...--";
  199:                     internationalMorseCodeDicitonary["4"] = "....-";
  200:                     internationalMorseCodeDicitonary["5"] = ".....";
  201:                     internationalMorseCodeDicitonary["6"] = "-....";
  202:                     internationalMorseCodeDicitonary["7"] = "--...";
  203:                     internationalMorseCodeDicitonary["8"] = "---..";
  204:                     internationalMorseCodeDicitonary["9"] = "----.";
  205:                     internationalMorseCodeDicitonary["0"] = "-----";
  206:  
  207:                 }
  208:                 else
  209:                 {
  210:  
  211:                 }
  212:  
  213:                 return internationalMorseCodeDicitonary;
  214:             }
  215:         }
  216:  
  217:         ////////////////////////////////////////////////////////////////////////////
  218:  
  219:         /// <summary>
  220:         /// 
  221:         /// </summary>
  222:         public Dictionary<string, string> ReverseInternationalMorseCodeDicitonary
  223:         {
  224:             get
  225:             {
  226:                 if (reverseInternationalMorseCodeDicitonary == null || reverseInternationalMorseCodeDicitonary.Count == 0)
  227:                 {
  228:                     reverseInternationalMorseCodeDicitonary = new Dictionary<string, string>(50);
  229:  
  230:                     foreach (KeyValuePair<string, string> kvp in InternationalMorseCodeDicitonary) reverseInternationalMorseCodeDicitonary[kvp.Value] = kvp.Key;
  231:                 }
  232:                 else
  233:                 {
  234:  
  235:                 }
  236:  
  237:                 return reverseInternationalMorseCodeDicitonary;
  238:             }
  239:         }
  240:  
  241:         ////////////////////////////////////////////////////////////////////////////
  242:         ////////////////////////////////////////////////////////////////////////////    
  243:     }
  244:  
  245:     ////////////////////////////////////////////////////////////////////////////
  246:     ////////////////////////////////////////////////////////////////////////////   
  247: }