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

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

Koran Reference Network Class Library support functions: Data model

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Data;
    5: using System.Collections;
    6: using System.Xml.Linq;
    7: using System.IO;
    8: using System.Reflection;
    9: using Microsoft.EntityFrameworkCore;
   10:  
   11: namespace Ia.Islamic.Cl.Model.Data
   12: {
   13:     ////////////////////////////////////////////////////////////////////////////
   14:  
   15:     /// <summary publish="true">
   16:     /// Koran Reference Network Class Library support functions: Data model
   17:     /// </summary>
   18:     /// <value>
   19:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   20:     /// </value>
   21:     /// <remarks> 
   22:     /// Copyright © 2001-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   23:     ///
   24:     /// 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
   25:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   26:     ///
   27:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   28:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   29:     /// 
   30:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   31:     /// 
   32:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   33:     /// </remarks> 
   34:     public class Default
   35:     {
   36:         private static XDocument faithXDocument;
   37:         private static XDocument kashAlShubuhatFiAlTawheed;
   38:  
   39:         ////////////////////////////////////////////////////////////////////////////
   40:  
   41:         /// <summary>
   42:         ///
   43:         /// </summary>
   44:         public Default() { }
   45:  
   46:         ////////////////////////////////////////////////////////////////////////////
   47:  
   48:         /// <summary>
   49:         ///
   50:         /// </summary>
   51:         public static XDocument KashAlShubuhatFiAlTawheed
   52:         {
   53:             get
   54:             {
   55:                 kashAlShubuhatFiAlTawheed = Ia.Cl.Models.Xml.Load(@"app_data\\tawheed.xml");
   56:  
   57:                 return kashAlShubuhatFiAlTawheed;
   58:             }
   59:         }
   60:  
   61:         ////////////////////////////////////////////////////////////////////////////
   62:  
   63:         /// <summary>
   64:         ///
   65:         /// </summary>
   66:         public static string[] UsedKoranLanguageSymbolList
   67:         {
   68:             get
   69:             {
   70:                 string[] p = { "en", "es", "fr", "de", "nl", "ja", "ko", "ar", "zh", "ru" };
   71:  
   72:                 return p;
   73:             }
   74:         }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         /// 
   80:         /// </summary>
   81:         public static Hashtable FaithHashtable()
   82:         {
   83:             var hashtable = new Hashtable();
   84:  
   85:             foreach (XElement xe in FaithXDocument.Elements("faithTopic").Elements("topic"))
   86:             {
   87:                 var id = int.Parse(xe.Attribute("id").Value);
   88:                 var name = xe.Attribute("name").Value;
   89:  
   90:                 hashtable[id] = name;
   91:             }
   92:  
   93:             return hashtable;
   94:         }
   95:  
   96:         ////////////////////////////////////////////////////////////////////////////
   97:  
   98:         /// <summary>
   99:         /// 
  100:         /// </summary>
  101:         public static void CreateVerseTopic(Ia.Islamic.Cl.Model.VerseTopic verseTopic, string verseId, out int op, out string result)
  102:         {
  103:             op = 0;
  104:             result = "";
  105:  
  106:             using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
  107:             {
  108:                 if (db.VerseTopics.Find(verseTopic.Id) == null)
  109:                 {
  110:                     db.VerseTopics.Add(verseTopic);
  111:  
  112:                     op = 1;
  113:                     result = "Success: record added. ";
  114:  
  115:                     db.SaveChanges();
  116:                 }
  117:                 else
  118:                 {
  119:                     op = -1;
  120:                     result = "Error: record aready exists. ";
  121:                 }
  122:             }
  123:         }
  124:  
  125:         ////////////////////////////////////////////////////////////////////////////
  126:  
  127:         /// <summary>
  128:         /// 
  129:         /// </summary>
  130:         public static List<Ia.Islamic.Cl.Model.Chapter> ChapterListByLanguageSymbol(string languageSymbol, out int op, out string result)
  131:         {
  132:             List<Ia.Islamic.Cl.Model.Chapter> list;
  133:  
  134:             op = 0;
  135:             result = "";
  136:             list = null;
  137:  
  138:             using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
  139:             {
  140:                 list = (from c in db.Chapters where c.Koran.LanguageIso == languageSymbol select c).OrderBy(p => p.Id).ToList();
  141:  
  142:                 if (list.Count() > 0)
  143:                 {
  144:                     op = 1;
  145:                 }
  146:                 else
  147:                 {
  148:                     op = -1;
  149:                     result = "Error: ReturnChapterListUsingLanguage()";
  150:                 }
  151:             }
  152:  
  153:             return list;
  154:         }
  155:  
  156:         ////////////////////////////////////////////////////////////////////////////
  157:  
  158:         /// <summary>
  159:         /// 
  160:         /// </summary>
  161:         public static List<Ia.Islamic.Cl.Model.Ui.VerseUi> VerseListByLanguageSymbolAndChapter(string languageSymbol, int chapterNumber, out int op, out string result)
  162:         {
  163:             List<Ia.Islamic.Cl.Model.Ui.VerseUi> list;
  164:  
  165:             op = 0;
  166:             result = "";
  167:             list = null;
  168:  
  169:             using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
  170:             {
  171:                 list = (from v in db.Verses
  172:                         where v.Chapter.Koran.LanguageIso == languageSymbol && v.Chapter.Number == chapterNumber
  173:                         select new Ia.Islamic.Cl.Model.Ui.VerseUi
  174:                         {
  175:                             Id = v.Id,
  176:                             Number = v.Number,
  177:                             ChapterNumber = v.Chapter.Number,
  178:                             Content = v.Content
  179:                         }).OrderBy(p => p.Id).ToList();
  180:  
  181:                 if (list.Count() > 0)
  182:                 {
  183:                     op = 1;
  184:                 }
  185:                 else
  186:                 {
  187:                     op = -1;
  188:                     result = "Error: ReturnVerseListUsingLanguageSymbolAndChapter()";
  189:                 }
  190:             }
  191:  
  192:             return list;
  193:         }
  194:  
  195:         ////////////////////////////////////////////////////////////////////////////
  196:         ////////////////////////////////////////////////////////////////////////////
  197:  
  198:         /// <summary>
  199:         /// 
  200:         /// </summary>
  201:         public static List<Ia.Islamic.Cl.Model.Ui.VerseUi> VerseList(Ia.Cl.Models.Language language, List<List<string>> variantListList, int maximumLengthOfVerseList, out Ia.Cl.Models.Result result)
  202:         {
  203:             bool skippedFirst;
  204:  
  205:             List<Ia.Islamic.Cl.Model.Ui.VerseUi> verseUiList;
  206:             List<Ia.Islamic.Cl.Model.Verse> verseList;
  207:             result = new Ia.Cl.Models.Result();
  208:  
  209:             using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
  210:             {
  211:                 // I can't use this. The compiler can not translate: where variantList.All(y => y.Any(x => v.Content.Contains(x))) && v.Chapter.Koran.LanguageIso == language.Id
  212:  
  213:                 verseList = new List<Ia.Islamic.Cl.Model.Verse>();
  214:  
  215:                 skippedFirst = false;
  216:  
  217:                 foreach (var variantList in variantListList)
  218:                 {
  219:                     var list = (from v in db.Verses
  220:                                 join wv in db.WordVerses on v.Id equals wv.VerseId
  221:                                 join w in db.Words on wv.WordId equals w.Id
  222:                                 where variantList.Any(x => w.Content == x) && v.Chapter.Koran.LanguageIso == language.Id
  223:                                 select v).Include(u => u.Chapter).ToList();
  224:  
  225:                     if (skippedFirst)
  226:                     {
  227:                         verseList = verseList.Intersect(list).ToList();
  228:  
  229:                         if (verseList.Count == 0) break;
  230:                     }
  231:                     else
  232:                     {
  233:                         verseList = verseList.Union(list).ToList();
  234:  
  235:                         skippedFirst = true;
  236:                     }
  237:                 }
  238:  
  239:                 if (verseList.Count > 0)
  240:                 {
  241:                     verseUiList = (from v in verseList
  242:                                    select new Ia.Islamic.Cl.Model.Ui.VerseUi
  243:                                    {
  244:                                        Id = v.Id,
  245:                                        Number = v.Number,
  246:                                        ChapterNumber = v.Chapter.Number,
  247:                                        Content = v.Content
  248:                                    }).OrderBy(p => p.Id).Take(maximumLengthOfVerseList).ToList();
  249:                 }
  250:                 else verseUiList = new List<Ia.Islamic.Cl.Model.Ui.VerseUi>();
  251:             }
  252:  
  253:             return verseUiList.ToList();
  254:         }
  255:  
  256:         ////////////////////////////////////////////////////////////////////////////
  257:  
  258:         /// <summary>
  259:         /// 
  260:         /// </summary>
  261:         public static Ia.Islamic.Cl.Model.Ui.VerseUi Verse(Ia.Cl.Models.Language language, int chapterNumber, int verseNumber, out int op, out string result)
  262:         {
  263:             op = 0;
  264:             result = "";
  265:             Ia.Islamic.Cl.Model.Ui.VerseUi verse;
  266:  
  267:             using (var db = new Ia.Islamic.Cl.Model.Context.Koran())
  268:             {
  269:                 verse = (from v in db.Verses
  270:                          where v.Chapter.Koran.LanguageIso == language.Id
  271:                          && v.Chapter.Number == chapterNumber
  272:                          && v.Number == verseNumber
  273:                          select new Ia.Islamic.Cl.Model.Ui.VerseUi
  274:                          {
  275:                              Id = v.Id,
  276:                              Number = v.Number,
  277:                              ChapterNumber = v.Chapter.Number,
  278:                              Content = v.Content
  279:                          }).FirstOrDefault();
  280:  
  281:                 if (verse != null)
  282:                 {
  283:                 }
  284:                 else
  285:                 {
  286:                     op = -1;
  287:                     result = "Error: ReturnSingleVerseUsingLanguageAndChapterNumberAndVerseNumber()";
  288:                 }
  289:             }
  290:  
  291:             return verse;
  292:         }
  293:  
  294:         ////////////////////////////////////////////////////////////////////////////
  295:  
  296:         /// <summary>
  297:         /// 
  298:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
  299:         /// 
  300:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
  301:         /// 2. Add "using System.Reflection".
  302:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
  303:         /// 
  304:         /// </summary>
  305:  
  306:         public static XDocument FaithXDocument
  307:         {
  308:             get
  309:             {
  310:                 Assembly _assembly;
  311:                 StreamReader streamReader;
  312:  
  313:                 faithXDocument = null;
  314:                 _assembly = Assembly.GetExecutingAssembly();
  315:                 streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Islamic.Cl.model.faith-topic.xml"));
  316:  
  317:                 try
  318:                 {
  319:                     if (streamReader.Peek() != -1)
  320:                     {
  321:                         faithXDocument = System.Xml.Linq.XDocument.Load(streamReader);
  322:                     }
  323:                 }
  324:                 catch (Exception)
  325:                 {
  326:                 }
  327:                 finally
  328:                 {
  329:                 }
  330:  
  331:                 return faithXDocument;
  332:             }
  333:         }
  334:  
  335:         ////////////////////////////////////////////////////////////////////////////
  336:         ////////////////////////////////////////////////////////////////////////////
  337:     }
  338: }