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