1: using System.Xml.Linq;
2: using System.Reflection;
3: using System.Text.RegularExpressions;
4:
5: namespace Ia.TentPlay.Cl.Model.Memorise
6: {
7: ////////////////////////////////////////////////////////////////////////////
8:
9: /// <summary publish="true">
10: /// ApplicationInformation Support class for TentPlay Memorise model
11: /// </summary>
12: ///
13: /// <remarks>
14: /// Copyright © 2006-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
15: ///
16: /// 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
17: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
18: ///
19: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21: ///
22: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
23: ///
24: /// Copyright notice: This notice may not be removed or altered from any source distribution.
25: /// </remarks>
26: public class ApplicationInformation
27: {
28: private static XDocument xDocument;
29: private static List<Application> applicationList;
30: private static List<Translation> translationList;
31:
32: ////////////////////////////////////////////////////////////////////////////
33:
34: /// <summary>
35: ///
36: /// </summary>
37: public ApplicationInformation() { }
38:
39: ////////////////////////////////////////////////////////////////////////////
40: ////////////////////////////////////////////////////////////////////////////
41:
42: /// <summary>
43: ///
44: /// </summary>
45: public class Application
46: {
47: /// <summary/>
48: public Application() { }
49:
50: /// <summary/>
51: public string Id { get; set; }
52: /// <summary/>
53: public Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic TestTopic { get; set; }
54: /// <summary/>
55: public string Name { get; set; }
56: /// <summary/>
57: public Dictionary<string, string> NameDictionary { get; set; }
58: /// <summary/>
59: public string ManifestPackagePrefix { get; set; }
60:
61: /// <summary/>
62: public string WhatsNew { get; set; }
63: /// <summary/>
64: public string VersionName { get; set; }
65: /// <summary/>
66: public string CopyrightYear { get; set; }
67: /// <summary/>
68: public string ManifestPackage { get; set; }
69:
70: /// <summary/>
71: public string ApplicationDownloadLink { get; set; }
72:
73: /// <summary/>
74: public string GoogleAdMobAdUnitDebugId { get; set; }
75: /// <summary/>
76: public string GoogleAdMobAppId { get; set; }
77: /// <summary/>
78: public string GoogleAdMobAdUnitProductionId { get; set; }
79:
80: /// <summary/>
81: public DateTime Published { get; set; }
82:
83: /// <summary/>
84: public int Count { get; set; }
85: /// <summary/>
86: /// <summary/>
87: public string ColorPrimary { get; set; }
88: /// <summary/>
89: public string ColorPrimaryDark { get; set; }
90: /// <summary/>
91: public string ColorAccent { get; set; }
92:
93: /// <summary/>
94: public bool LanguageListMatchesTranslationList
95: {
96: get
97: {
98: bool b;
99:
100: if (Languages != null && Translations != null)
101: {
102: b = Languages.All(u => Translations.Any(y => y.Iso6391 == u.Iso6391)) && Translations.All(u => Languages.Any(y => y.Iso6391 == u.Iso6391)) && Languages.Count == Translations.Count;
103: }
104: else b = false;
105:
106: return b;
107: }
108: }
109: /// <summary/>
110: public virtual List<Image> NavigationHeaderImages { get; set; }
111: /// <summary/>
112: public virtual List<Ia.Cl.Model.Language> Languages { get; set; }
113: /// <summary/>
114: public virtual ICollection<Translation> Translations
115: {
116: get
117: {
118: if (translationList == null || translationList.Count == 0)
119: {
120: translationList = TranslationList; // (this);
121: }
122:
123: return translationList;
124: }
125: }
126: }
127:
128: ////////////////////////////////////////////////////////////////////////////
129:
130: public class Image
131: {
132: /// <summary/>
133: //public string Caption { get; set; }
134: /// <summary/>
135: //public string Photographer { get; set; }
136: /// <summary/>
137: //public string Source { get; set; }
138: /// <summary/>
139: public string AndroidFileName { get; set; }
140: /// <summary/>
141: public string FileName { get; set; }
142: }
143:
144: ////////////////////////////////////////////////////////////////////////////
145:
146: public class Translation
147: {
148: /// <summary/>
149: public Translation() { }
150:
151: /// <summary/>
152: public string Iso6391 { get; set; }
153: /// <summary/>
154: public string SiteName { get; set; }
155: /// <summary/>
156: public string CompanyName { get; set; }
157: /// <summary/>
158: public string ShortDescription { get; set; }
159: /// <summary/>
160: public string LongDescription { get; set; }
161:
162: /// <summary/>
163: public string About { get; set; }
164: /// <summary/>
165: public string AboutTitle { get; set; }
166: /// <summary/>
167: public string SearchSearchHint { get; set; }
168: /// <summary/>
169: public string Statistic { get; set; }
170: /// <summary/>
171: public string StatisticTitle { get; set; }
172: /// <summary/>
173: public string Setting { get; set; }
174: /// <summary/>
175: public string SettingTitle { get; set; }
176:
177: /// <summary/>
178: public string ShareTitle { get; set; }
179: /// <summary/>
180: public string ShareApplication { get; set; }
181: /// <summary/>
182: public string ShareTrek { get; set; }
183: /// <summary/>
184: public string ShareNoEmailClientInstalled { get; set; }
185: /// <summary/>
186: public string ShareContactUs { get; set; }
187:
188: /// <summary/>
189: public string HelpFeedbackTitle { get; set; }
190: /// <summary/>
191: public string Help { get; set; }
192: /// <summary/>
193: public string HelpTitle { get; set; }
194: /// <summary/>
195: public string HelpMagnifiyingGlass { get; set; }
196: /// <summary/>
197: public string HelpMainListOrder { get; set; }
198: /// <summary/>
199: public string Feedback { get; set; }
200: /// <summary/>
201: public string FeedbackTitle { get; set; }
202: /// <summary/>
203: public string FeedbackEmailSubject { get; set; }
204:
205: /// <summary/>
206: public string Legal { get; set; }
207: /// <summary/>
208: public string LegalTitle { get; set; }
209: }
210:
211: ////////////////////////////////////////////////////////////////////////////
212:
213: /// <summary>
214: ///
215: /// </summary>
216: public static List<Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application> ApplicationList
217: {
218: get
219: {
220: /*
221: if (applicationList == null || applicationList.Count == 0)
222: {
223: if (HttpContext.Current != null && HttpContext.Current.Application["applicationList"] != null)
224: {
225: applicationList = (List<Application>)HttpContext.Current.Application["applicationList"];
226: }
227: else
228: {
229: applicationList = Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation._ApplicationList;
230:
231: if (HttpContext.Current != null) HttpContext.Current.Application["applicationList"] = applicationList;
232: }
233: }
234: */
235:
236: return applicationList;
237: }
238: }
239:
240: ////////////////////////////////////////////////////////////////////////////
241:
242: /// <summary>
243: ///
244: /// </summary>
245: private static List<Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application> _ApplicationList
246: {
247: get
248: {
249: if (applicationList == null || applicationList.Count == 0)
250: {
251: Application application;
252:
253: applicationList = new List<Application>(100);
254:
255: foreach (XElement x in XDocument.Element("applicationInformation").Element("applicationList").Elements("application"))
256: {
257: application = new Application();
258: application.Id = x.Attribute("id").Value;
259:
260: // public enum TestTopic { MorseCode = 0, German = 1, Math = 2, Kanji = 3, Russian = 4, Kana = 5, PhoneticAlphabet = 6 };
261: switch(application.Id)
262: {
263: case "morsecode": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.MorseCode; break;
264: case "german": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.German; break;
265: case "math": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Math; break;
266: case "kanji": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kanji; break;
267: case "russian": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Russian; break;
268: case "kana": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.Kana; break;
269: case "phoneticAlphabet": application.TestTopic = Ia.TentPlay.Cl.Model.Memorise.Test.TestTopic.PhoneticAlphabet; break;
270: default: application.TestTopic = 0; break;
271: }
272:
273: application.Name = x.Element("name").Attribute("en").Value;
274: application.NameDictionary = ApplicationNameDictionary(x);
275:
276: application.ManifestPackagePrefix = x.Parent.Parent.Element("manifestPackagePrefix").Value;
277:
278: application.GoogleAdMobAdUnitDebugId = x.Parent.Parent.Element("googleAdMobAdUnitDebugId").Value;
279:
280: application.WhatsNew = Regex.Replace(x.Parent.Parent.Element("googleStoreWhatsNew").Value.Trim(), @"\n[ ]+", "\n");
281:
282: application.VersionName = x.Element("version").Attribute("name").Value;
283: application.CopyrightYear = x.Element("version").Attribute("copyrightYear").Value;
284: application.Published = (x.Attribute("published") != null) ? DateTime.Parse(x.Attribute("published").Value) : DateTime.MinValue;
285:
286: application.ManifestPackage = x.Element("manifestPackage").Value;
287:
288: application.ApplicationDownloadLink = ReplaceNameVariableWithName(Ia.TentPlay.Cl.Model.Data.CompanyInformation.ApplicationDownloadLink, application);
289:
290: application.GoogleAdMobAppId = x.Element("googleAdMobAppId").Value;
291: application.GoogleAdMobAdUnitProductionId = x.Element("googleAdMobAdUnitId").Value;
292:
293: application.ColorPrimary = (from e in x.Element("colorTheme").Elements("color") where e.Attribute("name").Value == "colorPrimary" select e.Attribute("value").Value).SingleOrDefault();
294: application.ColorPrimaryDark = (from e in x.Element("colorTheme").Elements("color") where e.Attribute("name").Value == "colorPrimaryDark" select e.Attribute("value").Value).SingleOrDefault();
295: application.ColorAccent = (from e in x.Element("colorTheme").Elements("color") where e.Attribute("name").Value == "colorAccent" select e.Attribute("value").Value).SingleOrDefault();
296:
297: application.NavigationHeaderImages = ApplicationImageList(x.Element("navigationHeader").Element("imageList"));
298:
299: application.Languages = ApplicationLanguageList(application.Id);
300:
301: applicationList.Add(application);
302: }
303: }
304:
305: return applicationList.ToList();
306: }
307: }
308:
309: ////////////////////////////////////////////////////////////////////////////
310:
311: /// <summary>
312: ///
313: /// </summary>
314: private static List<Ia.Cl.Model.Language> ApplicationLanguageList(string fileCountry)
315: {
316: List<Ia.Cl.Model.Language> list, countrySpokenLanguageList, featureDesignationLanguageList;
317:
318: list = new List<Ia.Cl.Model.Language>();
319:
320: countrySpokenLanguageList = (from c in Ia.Cl.Model.Country.List where c.Iso3 == fileCountry select c.SpokenLanguageList).SingleOrDefault();
321:
322: featureDesignationLanguageList = Ia.TentPlay.Cl.Model.Data.Trek.FeatureDesignation.LanguageList;
323:
324: // I will only support English
325: //list = (from c in countrySpokenLanguageList join n in featureDesignationLanguageList on c.Symbol equals n.Symbol select c).ToList();
326:
327: // below: add English to all language lists for all countries
328: if (list.Find(u => u.Symbol == "en") == null) list.Add(Ia.Cl.Model.Language.List.Single(u => u.Symbol == "en"));
329:
330: return list;
331: }
332:
333: ////////////////////////////////////////////////////////////////////////////
334:
335: /// <summary>
336: ///
337: /// </summary>
338: private static List<Image> ApplicationImageList(XElement imageList)
339: {
340: Image image;
341: List<Image> list;
342:
343: list = new List<Image>();
344:
345: foreach (XElement x in imageList.Elements("image"))
346: {
347: image = new Image();
348:
349: // Attribute
350: //image.Caption = x.Attribute("caption").Value;
351: //image.Photographer = x.Attribute("photographer").Value.Replace(" ", "").ToLower();
352: //image.Source = x.Attribute("source").Value.ToLower();
353: image.FileName = x.Attribute("fileName").Value;
354: image.AndroidFileName = x.Attribute("fileName").Value.Replace("-", "_");
355:
356: list.Add(image);
357: }
358:
359: return list;
360: }
361:
362: ////////////////////////////////////////////////////////////////////////////
363:
364: /// <summary>
365: ///
366: /// </summary>
367: public static void Statistic(ref Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application application)
368: {
369: int featureCount, administrative, populated, vegetation, locality, undersea, street, hypsographic, hydrographic, spot;
370: Ia.Cl.Model.Result result;
371:
372: //Ia.TentPlay.Cl.Model.Data.Trek.Feature.Statistic(application.Iso3, out featureCount, out administrative, out populated, out vegetation, out locality, out undersea, out street, out hypsographic, out hydrographic, out spot, out result);
373:
374: application.Count = 0; // featureCount;
375: }
376:
377: ////////////////////////////////////////////////////////////////////////////
378:
379: /// <summary>
380: ///
381: /// </summary>
382: private static Dictionary<string, string> ApplicationNameDictionary(XElement xElement)
383: {
384: XElement xe;
385: IEnumerable<XAttribute> list;
386: Dictionary<string, string> dictionary;
387:
388: dictionary = new Dictionary<string, string>();
389:
390: xe = xElement.Element("name");
391:
392: if (xe.HasAttributes)
393: {
394: list = xe.Attributes();
395:
396: foreach (XAttribute xa in list)
397: {
398: dictionary.Add(xa.Name.LocalName, xa.Value);
399: }
400: }
401:
402: return dictionary;
403: }
404:
405: ////////////////////////////////////////////////////////////////////////////
406: ////////////////////////////////////////////////////////////////////////////
407:
408: /// <summary>
409: ///
410: /// </summary>
411: public static List<Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Translation> TranslationList
412: {
413: get
414: {
415: /*
416: if (translationList == null || translationList.Count == 0)
417: {
418: if (HttpContext.Current != null && HttpContext.Current.Application["translationList"] != null)
419: {
420: translationList = (List<Translation>)HttpContext.Current.Application["translationList"];
421: }
422: else
423: {
424: translationList = Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation._TranslationList;
425:
426: if (HttpContext.Current != null) HttpContext.Current.Application["translationList"] = translationList;
427: }
428: }
429: */
430:
431: return translationList;
432: }
433: }
434:
435: ////////////////////////////////////////////////////////////////////////////
436:
437: /// <summary>
438: ///
439: /// </summary>
440: private static List<Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Translation> _TranslationList
441: {
442: get
443: {
444: if (translationList == null || translationList.Count == 0)
445: {
446: Translation translation;
447:
448: translationList = new List<Translation>(100);
449:
450: foreach (XElement x in XDocument.Element("applicationInformation").Element("translationList").Elements("translation"))
451: {
452: translation = new Translation();
453: translation.Iso6391 = x.Attribute("id").Value;
454: translation.SiteName = x.Element("siteName").Value;
455: translation.CompanyName = x.Element("companyName").Value;
456: translation.About = x.Element("about").Value.Trim();
457: translation.AboutTitle = x.Element("about").Attribute("title").Value;
458: translation.Statistic = x.Element("statistic").Value.Trim();
459: translation.StatisticTitle = x.Element("statistic").Attribute("title").Value;
460: translation.Setting = x.Element("setting").Value.Trim();
461: translation.SettingTitle = x.Element("setting").Attribute("title").Value;
462:
463: translation.ShareTitle = x.Element("share").Attribute("title").Value;
464: translation.ShareApplication = x.Element("share").Element("application").Value.Trim();
465: translation.ShareTrek = x.Element("share").Element("trek").Value.Trim();
466: translation.ShareNoEmailClientInstalled = x.Element("share").Attribute("noEmailClientInstalled").Value;
467: translation.ShareContactUs = x.Element("share").Attribute("contactUs").Value;
468:
469: translation.HelpFeedbackTitle = x.Element("help_feedback").Attribute("title").Value;
470: translation.Help = x.Element("help_feedback").Element("help").Value.Trim();
471: translation.HelpTitle = x.Element("help_feedback").Element("help").Attribute("title").Value;
472: translation.HelpMainListOrder = x.Element("help_feedback").Element("help").Attribute("mainListOrder").Value;
473: translation.HelpMagnifiyingGlass = x.Element("help_feedback").Element("help").Attribute("magnifiyingGlass").Value;
474: translation.Feedback = x.Element("help_feedback").Element("feedback").Value.Trim();
475: translation.FeedbackTitle = x.Element("help_feedback").Element("feedback").Attribute("title").Value;
476: translation.FeedbackEmailSubject = x.Element("help_feedback").Element("feedback").Attribute("feedbackEmailSubject").Value;
477:
478: translation.Legal = x.Element("legal").Value.Trim();
479: translation.LegalTitle = x.Element("legal").Attribute("title").Value;
480:
481:
482: translationList.Add(translation);
483: }
484: }
485:
486: return translationList.ToList();
487: }
488: }
489:
490: ////////////////////////////////////////////////////////////////////////////
491:
492: /// <summary>
493: ///
494: /// </summary>
495: private static string ReplaceNameVariableWithName(string line, Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application application)
496: {
497: return ReplaceNameVariableWithName(line, application, null);
498: }
499:
500: ////////////////////////////////////////////////////////////////////////////
501:
502: /// <summary>
503: ///
504: /// </summary>
505: private static string ReplaceNameVariableWithName(string line, Ia.TentPlay.Cl.Model.Memorise.ApplicationInformation.Application application, string iso6391)
506: {
507: string s;
508:
509: s = line;
510:
511: // this must be before $manifestPackage
512: s = Replace(s, "$applicationDownloadLink", application.ApplicationDownloadLink);
513:
514: if (!string.IsNullOrEmpty(iso6391))
515: {
516: s = Replace(s, "$applicationName", application.NameDictionary[iso6391]);
517: // s = Replace(s, "$countryName", application.NameDictionary[iso6391]);
518: }
519:
520: //s = Replace(s, "$countryIso3", application.Iso3);
521: s = Replace(s, "$version", application.VersionName);
522: s = Replace(s, "$manifestPackagePrefix", application.ManifestPackagePrefix);
523: s = Replace(s, "$manifestPackage", application.ManifestPackage);
524: s = Replace(s, "$copyrightYear", application.CopyrightYear);
525: s = Replace(s, "$featureCount", application.Count.ToString());
526:
527: s = Replace(s, "$companyName", Ia.TentPlay.Cl.Model.Data.CompanyInformation.CompanyName);
528: s = Replace(s, "$companyEmail", Ia.TentPlay.Cl.Model.Data.CompanyInformation.CompanyEmail);
529: s = Replace(s, "$companyUrl", Ia.TentPlay.Cl.Model.Data.CompanyInformation.CompanyUrl);
530:
531: s = Replace(s, "$applicationCompanyName", Ia.TentPlay.Cl.Model.Data.CompanyInformation.ApplicationCompanyName);
532: s = Replace(s, "$applicationCompanyEmail", Ia.TentPlay.Cl.Model.Data.CompanyInformation.ApplicationCompanyEmail);
533: s = Replace(s, "$applicationCompanyUrl", Ia.TentPlay.Cl.Model.Data.CompanyInformation.ApplicationCompanyUrl);
534:
535: return s;
536: }
537:
538: ////////////////////////////////////////////////////////////////////////////
539:
540: /// <summary>
541: ///
542: /// </summary>
543: private static string Replace(string content, string term, string replacementTerm)
544: {
545: return content.Replace(term, replacementTerm);
546: }
547:
548: ////////////////////////////////////////////////////////////////////////////
549: ////////////////////////////////////////////////////////////////////////////
550:
551: /// <summary>
552: ///
553: /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
554: ///
555: /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
556: /// 2. Add "using System.Reflection".
557: /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
558: ///
559: /// </summary>
560:
561: private static XDocument XDocument
562: {
563: get
564: {
565: Assembly _assembly;
566: StreamReader streamReader;
567:
568: if (xDocument == null)
569: {
570: _assembly = Assembly.GetExecutingAssembly();
571: streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.TentPlay.Cl.model.data.memorise.application-information.xml"));
572:
573: try
574: {
575: if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
576: }
577: catch (Exception)
578: {
579: }
580: finally
581: {
582: }
583: }
584:
585: return xDocument;
586: }
587: }
588:
589: ////////////////////////////////////////////////////////////////////////////
590: ////////////////////////////////////////////////////////////////////////////
591: }
592: }