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

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

Report support class for Fixed Telecommunications Network (FTN) data model.

    1: using Dart.PowerTCP.Telnet;
    2: using Microsoft.EntityFrameworkCore;
    3: using System;
    4: using System.Collections.Generic;
    5: using System.Data;
    6: using System.IO;
    7: using System.Linq;
    8: using System.Reflection;
    9: using System.Text.RegularExpressions;
   10: using System.Xml.Linq;
   11: using System.Xml.XPath;
   12:  
   13: namespace Ia.Ftn.Cl.Model.Data
   14: {
   15:     ////////////////////////////////////////////////////////////////////////////
   16:  
   17:     /// <summary publish="true">
   18:     /// Report support class for Fixed Telecommunications Network (FTN) data model.
   19:     /// </summary>
   20:     /// 
   21:     /// <remarks> 
   22:     /// Copyright © 2006-2022 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 Report
   35:     {
   36:         private static XDocument xDocument;
   37:         private static List<Ia.Ftn.Cl.Model.Business.Report.Category> categoryList;
   38:         private static List<Ia.Ftn.Cl.Model.Business.Report.Area> areaList;
   39:         private static List<Ia.Ftn.Cl.Model.Business.Report.Indication> indicationList;
   40:         private static List<Ia.Ftn.Cl.Model.Business.Report.Action> actionList;
   41:         private static List<Ia.Ftn.Cl.Model.Business.Report.Resolution> resolutionList;
   42:         /*
   43:         private static List<Ia.Ftn.Cl.Model.Business.Report.Severity> severityList;
   44:         private static List<Ia.Ftn.Cl.Model.Business.Report.Priority> priorityList;
   45:         private static List<Ia.Ftn.Cl.Model.Business.Report.Status> statusList;
   46:         private static List<Ia.Ftn.Cl.Model.Business.Report.Estimate> estimateList;
   47:         private static List<Ia.Ftn.Cl.Model.Business.Report.ServiceType> serviceTypeList;
   48:         private static List<Ia.Ftn.Cl.Model.Business.Report.CustomerCare> customerCare;
   49:          */
   50:  
   51:         private static List<Ia.Ftn.Cl.Model.Report> openStatusOrClosedStatusWithinLast24HourReportList;
   52:         private static Dictionary<string, List<int>> reportResponsibilityByStaffIdDictionary, reportReadabilityByFrameworkIdDictionary;
   53:  
   54:         private static readonly object objectLock = new object();
   55:  
   56:         ////////////////////////////////////////////////////////////////////////////
   57:  
   58:         /// <summary>
   59:         ///
   60:         /// </summary>
   61:         public Report() { }
   62:  
   63:         ////////////////////////////////////////////////////////////////////////////
   64:         ////////////////////////////////////////////////////////////////////////////
   65:  
   66:         /// <summary>
   67:         ///
   68:         /// </summary>
   69:         public static int Create(Ia.Ftn.Cl.Model.Report report, out string result)
   70:         {
   71:             var id = -1;
   72:             result = string.Empty;
   73:  
   74:             using (var db = new Ia.Ftn.Cl.Model.Db())
   75:             {
   76:                 report.Created = report.Updated = DateTime.UtcNow.AddHours(3);
   77:  
   78:                 db.Reports.Add(report);
   79:                 db.SaveChanges();
   80:  
   81:                 id = report.Id;
   82:             }
   83:  
   84:             OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
   85:  
   86:             return id;
   87:         }
   88:  
   89:         ////////////////////////////////////////////////////////////////////////////
   90:  
   91:         /// <summary>
   92:         ///
   93:         /// </summary>
   94:         public static Ia.Ftn.Cl.Model.Report Read(int reportId)
   95:         {
   96:             Ia.Ftn.Cl.Model.Report report;
   97:  
   98:             using (var db = new Ia.Ftn.Cl.Model.Db())
   99:             {
  100:                 report = (from r in db.Reports where r.Id == reportId select r).Include(r => r.ReportHistories).SingleOrDefault();
  101:             }
  102:  
  103:             return report;
  104:         }
  105:  
  106:         ////////////////////////////////////////////////////////////////////////////
  107:  
  108:         /// <summary>
  109:         ///
  110:         /// </summary>
  111:         public static List<Ia.Ftn.Cl.Model.Report> List(string service)
  112:         {
  113:             List<Ia.Ftn.Cl.Model.Report> reportList;
  114:  
  115:             using (var db = new Ia.Ftn.Cl.Model.Db())
  116:             {
  117:                 reportList = (from r in db.Reports where r.Service == service select r).Include(r => r.ReportHistories).ToList();
  118:             }
  119:  
  120:             return reportList;
  121:         }
  122:  
  123:         ////////////////////////////////////////////////////////////////////////////
  124:  
  125:         /// <summary>
  126:         ///
  127:         /// </summary>
  128:         public static List<Ia.Ftn.Cl.Model.Report> ListWhereStatusIsOpenAndNoReportHistoriesAndUpdatedBeforeDateTime(DateTime dateTime)
  129:         {
  130:             List<Ia.Ftn.Cl.Model.Report> reportList;
  131:  
  132:             using (var db = new Ia.Ftn.Cl.Model.Db())
  133:             {
  134:                 var list = (from r in db.Reports
  135:                             where r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open
  136:                             select r).Include(r => r.ReportHistories).AsNoTracking().ToList();
  137:  
  138:                 var list1 = (from r in list
  139:                              where (r.ReportHistories == null || r.ReportHistories.Count == 0) && r.Updated < dateTime
  140:                              select r).ToList();
  141:  
  142:                 var list2 = (from r in list
  143:                              where (r.ReportHistories != null && r.ReportHistories.Count > 0) && r.Updated < dateTime && r.LastReportHistory.Updated < dateTime
  144:                              select r).ToList();
  145:  
  146:                 reportList = list1.Union(list2).ToList();
  147:             }
  148:  
  149:             return reportList;
  150:         }
  151:  
  152:         ////////////////////////////////////////////////////////////////////////////
  153:  
  154:         /// <summary>
  155:         ///
  156:         /// </summary>
  157:         public static List<Ia.Ftn.Cl.Model.Report> ListByReportId(int reportId)
  158:         {
  159:             List<Ia.Ftn.Cl.Model.Report> reportList;
  160:  
  161:             using (var db = new Ia.Ftn.Cl.Model.Db())
  162:             {
  163:                 var serviceList = (from r in db.Reports
  164:                                    where r.Id == reportId
  165:                                    select r.Service).ToList();
  166:  
  167:                 if (serviceList.Count > 0)
  168:                 {
  169:                     reportList = (from r in db.Reports
  170:                                   where serviceList.Contains(r.Service)
  171:                                   select r).Include(r => r.ReportHistories).ToList();
  172:                 }
  173:                 else reportList = new List<Ia.Ftn.Cl.Model.Report>();
  174:             }
  175:  
  176:             return reportList;
  177:         }
  178:  
  179:         /*
  180:         ////////////////////////////////////////////////////////////////////////////
  181: 
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         public static bool UpdateMigratedList(List<Ia.Ftn.Cl.Model.Report> reportList, out string result)
  186:         {
  187:             bool b;
  188:             Ia.Ftn.Cl.Model.Report report;
  189: 
  190:             b = false;
  191:             result = string.Empty;
  192: 
  193:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  194:             {
  195:                 foreach (Ia.Ftn.Cl.Model.Report updatedReport in reportList)
  196:                 {
  197:                     report = (from r in db.Reports where r.Id == updatedReport.Id select r).SingleOrDefault();
  198: 
  199:                     if (report == null)
  200:                     {
  201:                         //updatedReport.Created = updatedReport.Updated = DateTime.UtcNow.AddHours(3);
  202: 
  203:                         db.Reports.Add(updatedReport);
  204:                     }
  205:                     else
  206:                     {
  207:                         // below: copy values from updatedReport to report
  208: 
  209:                         report.UpdateMigrated(updatedReport);
  210: 
  211:                         db.Reports.Attach(report);
  212: 
  213:                         db.Entry(report).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  214:                     }
  215: 
  216:                     b = true;
  217: 
  218:                 }
  219: 
  220:                 db.SaveChanges();
  221: 
  222:                 DbContextProbablyUpdated();
  223: 
  224:                 b = true;
  225:             }
  226: 
  227:             return b;
  228:         }
  229:         */
  230:  
  231:         ////////////////////////////////////////////////////////////////////////////
  232:  
  233:         /// <summary>
  234:         ///
  235:         /// </summary>
  236:         public static bool CloseStatus(Ia.Ftn.Cl.Model.Report report)//, Ia.Ftn.Cl.Model.Staff staff)
  237:         {
  238:             var b = false;
  239:  
  240:             using (var db = new Ia.Ftn.Cl.Model.Db())
  241:             {
  242:                 report.Status = (int)Ia.Ftn.Cl.Model.Business.Report.Status.Closed;
  243:  
  244:                 report.Updated = DateTime.UtcNow.AddHours(3);
  245:                 //this.UserId = staff.Id;
  246:                 // above: can't do that because it will remove the name of the record inserter
  247:  
  248:                 db.Reports.Attach(report);
  249:                 db.Entry(report).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  250:                 db.SaveChanges();
  251:  
  252:                 OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  253:  
  254:                 b = true;
  255:             }
  256:  
  257:             return b;
  258:         }
  259:  
  260:         ////////////////////////////////////////////////////////////////////////////
  261:  
  262:         /// <summary>
  263:         ///
  264:         /// </summary>
  265:         public static bool OpenStatus(Ia.Ftn.Cl.Model.Report report)//, Ia.Ftn.Cl.Model.Staff staff)
  266:         {
  267:             var b = false;
  268:  
  269:             using (var db = new Ia.Ftn.Cl.Model.Db())
  270:             {
  271:                 report.Status = (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open;
  272:  
  273:                 report.Updated = DateTime.UtcNow.AddHours(3);
  274:                 //this.UserId = staff.Id;
  275:                 // above: can't do that because it will remove the name of the record inserter
  276:  
  277:                 db.Reports.Attach(report);
  278:                 db.Entry(report).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  279:                 db.SaveChanges();
  280:  
  281:                 OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  282:  
  283:                 b = true;
  284:             }
  285:  
  286:             return b;
  287:         }
  288:  
  289:         ////////////////////////////////////////////////////////////////////////////
  290:  
  291:         /// <summary>
  292:         ///
  293:         /// </summary>
  294:         public static bool NullifyUserId(string userId, out int numberOfRecordsUpdated)
  295:         {
  296:             return MoveUserId(userId, string.Empty, out numberOfRecordsUpdated);
  297:         }
  298:  
  299:         ////////////////////////////////////////////////////////////////////////////
  300:  
  301:         /// <summary>
  302:         ///
  303:         /// </summary>
  304:         public static bool MoveUserId(string fromUserId, string toUserId, out int numberOfRecordsUpdated)
  305:         {
  306:             var b = false;
  307:             numberOfRecordsUpdated = 0;
  308:  
  309:             using (var db = new Ia.Ftn.Cl.Model.Db())
  310:             {
  311:                 var query = (from r in db.Reports where r.UserId == fromUserId select r).ToList();
  312:  
  313:                 foreach (var v in query)
  314:                 {
  315:                     v.UserId = toUserId;
  316:                     numberOfRecordsUpdated++;
  317:                 }
  318:  
  319:                 db.SaveChanges();
  320:  
  321:                 OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  322:  
  323:                 b = true;
  324:             }
  325:  
  326:             return b;
  327:         }
  328:  
  329:         ////////////////////////////////////////////////////////////////////////////
  330:  
  331:         /// <summary>
  332:         ///
  333:         /// </summary>
  334:         public static bool Delete(int id/*, out string result*/)
  335:         {
  336:             var b = false;
  337:  
  338:             using (var db = new Ia.Ftn.Cl.Model.Db())
  339:             {
  340:                 var v = (from r in db.Reports where r.Id == id select r).FirstOrDefault();
  341:  
  342:                 db.Reports.Remove(v);
  343:                 db.SaveChanges();
  344:  
  345:                 OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
  346:  
  347:                 b = true;
  348:             }
  349:  
  350:             return b;
  351:         }
  352:  
  353:         ////////////////////////////////////////////////////////////////////////////
  354:         ////////////////////////////////////////////////////////////////////////////
  355:  
  356:         /// <summary>
  357:         ///
  358:         /// </summary>
  359:         public static List<Ia.Ftn.Cl.Model.Ui.ReportAccessServiceRequest> ReportWithReportOpenStatusByUserIdListAndFrameworkIdList(List<string> userIdList, List<int> frameworkIdList)
  360:         {
  361:             var list = _ReportWithReportOpenStatusByUserIdListList(userIdList);
  362:  
  363:             /*
  364:             if (frameworkIdList.Count > 0)
  365:             {
  366:                 var siteList = (from s in Ia.Ftn.Cl.Model.Data.Administration.FrameworkList
  367:                                 where frameworkIdList.Contains(s.Id)
  368:                                 select s.Sites).SelectMany(u => u).Distinct().ToList();
  369: 
  370:                 list = (from rasr in list
  371:                         where rasr.Access != null && siteList.Any(u => u.KuwaitFtnAreas.Any(w => w.Id == rasr.Access.AreaId))
  372:                         select rasr).ToList();
  373:             }
  374:             */
  375:  
  376:             return list;
  377:         }
  378:  
  379:         ////////////////////////////////////////////////////////////////////////////
  380:  
  381:         /// <summary>
  382:         ///
  383:         /// </summary>
  384:         private static List<Ia.Ftn.Cl.Model.Ui.ReportAccessServiceRequest> _ReportWithReportOpenStatusByUserIdListList(List<string> userIdList)
  385:         {
  386:             List<Ia.Ftn.Cl.Model.Ui.ReportAccessServiceRequest> reportAccessServiceRequestList;
  387:  
  388:             using (var db = new Ia.Ftn.Cl.Model.Db())
  389:             {
  390:                 if (userIdList != null && userIdList.Count > 0)
  391:                 {
  392:                     reportAccessServiceRequestList = (from r in db.Reports.Include(u => u.ReportHistories)
  393:                                                       join srs in db.ServiceRequestServices on r.Service equals srs.Service
  394:                                                       where r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open
  395:                                                       orderby r.Created
  396:                                                       select new Ia.Ftn.Cl.Model.Ui.ReportAccessServiceRequest
  397:                                                       {
  398:                                                           Report = r,
  399:                                                           Access = r.ServiceType == 1 ? srs.Access
  400:                                                           : null/*(from a in db.Accesses
  401:                                                              where a.Id == (Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessNameToOntAccessIdDictionary.ContainsKey(r.Service) ? Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessNameToOntAccessIdDictionary[r.Service] : string.Empty)
  402:                                                              select a).AsNoTracking().SingleOrDefault()*/
  403:                                                       }
  404:                                                           ).AsNoTracking().ToList();
  405:  
  406:                     reportAccessServiceRequestList = (from r in reportAccessServiceRequestList
  407:                                                       where r.Report.ReportHistories.Any(y => userIdList.Any(z => z == y.UserId))
  408:                                                       select r).ToList();
  409:                 }
  410:                 else
  411:                 {
  412:                     reportAccessServiceRequestList = new List<Ia.Ftn.Cl.Model.Ui.ReportAccessServiceRequest>();
  413:                 }
  414:             }
  415:  
  416:             return reportAccessServiceRequestList;
  417:         }
  418:  
  419:         ////////////////////////////////////////////////////////////////////////////
  420:         ////////////////////////////////////////////////////////////////////////////
  421:  
  422:         /// <summary>
  423:         ///
  424:         /// </summary>
  425:         public static List<Ia.Ftn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourReportList
  426:         {
  427:             get
  428:             {
  429:                 if (openStatusOrClosedStatusWithinLast24HourReportList == null || openStatusOrClosedStatusWithinLast24HourReportList.Count == 0)
  430:                 {
  431:                     lock (objectLock)
  432:                     {
  433:                         openStatusOrClosedStatusWithinLast24HourReportList = Ia.Ftn.Cl.Model.Data.Report._OpenStatusOrClosedStatusWithinLast24HourReportList();
  434:                     }
  435:                 }
  436:  
  437:                 return openStatusOrClosedStatusWithinLast24HourReportList;
  438:             }
  439:         }
  440:  
  441:         ////////////////////////////////////////////////////////////////////////////
  442:  
  443:         /// <summary>
  444:         ///
  445:         /// </summary>
  446:         public static void OpenStatusOrClosedStatusWithinLast24HourReportListClear()
  447:         {
  448:             openStatusOrClosedStatusWithinLast24HourReportList = null;
  449:         }
  450:  
  451:         ////////////////////////////////////////////////////////////////////////////
  452:  
  453:         /// <summary>
  454:         ///
  455:         /// </summary>
  456:         private static List<Ia.Ftn.Cl.Model.Report> _OpenStatusOrClosedStatusWithinLast24HourReportList()
  457:         {
  458:             DateTime before24Hour;
  459:             List<Ia.Ftn.Cl.Model.Report> list;
  460:  
  461:             using (var db = new Ia.Ftn.Cl.Model.Db())
  462:             {
  463:                 before24Hour = DateTime.UtcNow.AddHours(3).AddDays(-1);
  464:  
  465:                 list = (from r in db.Reports
  466:                         where r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open || (r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Closed && r.Updated >= before24Hour)
  467:                         orderby r.Created
  468:                         select r).Include(u => u.ReportHistories).ToList();
  469:             }
  470:  
  471:             return list;
  472:         }
  473:  
  474:         ////////////////////////////////////////////////////////////////////////////
  475:  
  476:         /// <summary>
  477:         ///
  478:         /// </summary>
  479:         public static List<Ia.Ftn.Cl.Model.Report> OpenStatusOrClosedStatusWithinLast24HourByReportIdReportList(List<int> reportIdList)
  480:         {
  481:             List<Ia.Ftn.Cl.Model.Report> list;
  482:  
  483:             if (reportIdList.Count > 0)
  484:             {
  485:                 list = (from r in OpenStatusOrClosedStatusWithinLast24HourReportList
  486:                         join rid in reportIdList on r.Id equals rid
  487:                         select r).ToList();
  488:             }
  489:             else list = new List<Ia.Ftn.Cl.Model.Report>();
  490:  
  491:             return list;
  492:         }
  493:  
  494:         ////////////////////////////////////////////////////////////////////////////
  495:         ////////////////////////////////////////////////////////////////////////////
  496:  
  497:         /// <summary>
  498:         ///
  499:         /// </summary>
  500:         public static Dictionary<string, List<int>> ReportResponsibilityByStaffIdDictionary
  501:         {
  502:             get
  503:             {
  504:                 if (reportResponsibilityByStaffIdDictionary == null || reportResponsibilityByStaffIdDictionary.Count == 0)
  505:                 {
  506:                     lock (objectLock)
  507:                     {
  508:                         reportResponsibilityByStaffIdDictionary = Ia.Ftn.Cl.Model.Data.Report._ReportResponsibilityByStaffIdDictionary();
  509:                     }
  510:                 }
  511:  
  512:                 return reportResponsibilityByStaffIdDictionary;
  513:             }
  514:         }
  515:  
  516:         ////////////////////////////////////////////////////////////////////////////
  517:  
  518:         /// <summary>
  519:         ///
  520:         /// </summary>
  521:         public static void ReportResponsibilityByStaffIdDictionaryClear()
  522:         {
  523:             reportResponsibilityByStaffIdDictionary = null;
  524:         }
  525:  
  526:         ////////////////////////////////////////////////////////////////////////////
  527:  
  528:         /// <summary>
  529:         ///
  530:         /// </summary>
  531:         private static Dictionary<string, List<int>> _ReportResponsibilityByStaffIdDictionary()
  532:         {
  533:             Dictionary<string, List<int>> dictionary;
  534:  
  535:             dictionary = new Dictionary<string, List<int>>();
  536:  
  537:             var staffList = Ia.Ftn.Cl.Model.Data.Staff.List;
  538:  
  539:             var list = Ia.Ftn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
  540:  
  541:             // I will exclude closed reports
  542:             list = (from r in list where r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open select r).ToList();
  543:  
  544:             foreach (var staff in staffList)
  545:             {
  546:                 if (!string.IsNullOrEmpty(staff.Id))
  547:                 {
  548:                     StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(staff, out List<string> staffFrameworkAncestorAndDescendantUserIdList, out List<string> staffSubordinatesUserIdList);
  549:  
  550:                     var re = (from r in list
  551:                               where r.LastReportHistory == null && Ia.Ftn.Cl.Model.Business.Authority.StaffIsResponsibleForAllOpenReportWithNoReportHistory(staff)
  552:                               || r.LastReportHistory == null && r.UserId == staff.Id
  553:                               || r.LastReportHistory == null && staffSubordinatesUserIdList.Contains(r.UserId)
  554:                               || r.LastReportHistory == null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
  555:                               || r.LastReportHistory != null && r.LastReportHistory.UserId == staff.Id
  556:                               || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
  557:                               || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
  558:                               select r).ToList();
  559:  
  560:                     if (re.Count > 0) dictionary[staff.Id] = re.Select(r => r.Id).ToList();
  561:                 }
  562:             }
  563:  
  564:             return dictionary;
  565:         }
  566:  
  567:         ////////////////////////////////////////////////////////////////////////////
  568:  
  569:         /// <summary>
  570:         ///
  571:         /// </summary>
  572:         public static List<string> LicResponsibilityByStaff(Ia.Ftn.Cl.Model.Staff staff)
  573:         {
  574:             List<string> list;
  575:  
  576:             var msanList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.MsanList;
  577:  
  578:             var staffFrameworkMsanList = (from m in msanList
  579:                                           where staff.Framework.Sites.Contains(m.Site) || Ia.Ftn.Cl.Model.Business.Authority.FrameworkIsResponsibleForMissingLic(staff.Framework)
  580:                                           select m).ToList();
  581:  
  582:             if (staffFrameworkMsanList.Count > 0)
  583:             {
  584:                 var msanDomainList = staffFrameworkMsanList.SelectMany(u => u.DomainList).ToList();
  585:  
  586:                 if (msanDomainList.Count > 0)
  587:                 {
  588:                     var list0 = Ia.Ftn.Cl.Model.Data.Provision.ProvisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList(false);
  589:  
  590:                     list = (from l in list0 where msanDomainList.Any(u => l.StartsWith(u.ToString())) select l).ToList();
  591:                 }
  592:                 else list = new List<string>();
  593:             }
  594:             else list = new List<string>();
  595:  
  596:             return list;
  597:         }
  598:  
  599:         ////////////////////////////////////////////////////////////////////////////
  600:  
  601:         /// <summary>
  602:         ///
  603:         /// </summary>
  604:         private static void StaffFrameworkAncestorAndDescendantUserIdListAndStaffSubordinatesUserIdList(Ia.Ftn.Cl.Model.Staff staff, out List<string> staffFrameworkAncestorAndDescendantUserIdList, out List<string> staffSubordinatesUserIdList)
  605:         {
  606:             staffFrameworkAncestorAndDescendantUserIdList = new List<string>();
  607:             staffSubordinatesUserIdList = new List<string>();
  608:  
  609:             // below: add self framework
  610:             staffFrameworkAncestorAndDescendantUserIdList.Add(staff.Framework.Id);
  611:  
  612:             // below: add ancestor frameworks
  613:             foreach (var ancestor in staff.Framework.Ancestors.ToList())
  614:                 staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Id);
  615:  
  616:             // below: add decendant frameworks
  617:             foreach (var descendant in staff.Framework.Descendants.ToList())
  618:                 staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Id);
  619:  
  620:             // below: add children staff
  621:             foreach (var subordinate in staff.Subordinates.ToList()) staffSubordinatesUserIdList.Add(subordinate.Id);
  622:         }
  623:  
  624:         ////////////////////////////////////////////////////////////////////////////
  625:  
  626:         /// <summary>
  627:         ///
  628:         /// </summary>
  629:         private static void FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(Ia.Ftn.Cl.Model.Business.Administration.Framework framework, out List<string> staffFrameworkAncestorAndDescendantUserIdList, out List<string> staffSubordinatesUserIdList)
  630:         {
  631:             staffFrameworkAncestorAndDescendantUserIdList = new List<string>();
  632:             staffSubordinatesUserIdList = new List<string>();
  633:  
  634:             // below: add self framework
  635:             staffFrameworkAncestorAndDescendantUserIdList.Add(framework.Id);
  636:  
  637:             // below: add ancestor frameworks
  638:             foreach (var ancestor in framework.Ancestors) staffFrameworkAncestorAndDescendantUserIdList.Add(ancestor.Id);
  639:  
  640:             // below: add decendants
  641:             foreach (var descendant in framework.Descendants) staffFrameworkAncestorAndDescendantUserIdList.Add(descendant.Id);
  642:  
  643:             // below: add children staff of any of the list of frameworks collected
  644:             staffSubordinatesUserIdList = (from s in Ia.Ftn.Cl.Model.Data.Staff.List
  645:                                            join sfadu in staffFrameworkAncestorAndDescendantUserIdList on s.Framework.Id equals sfadu
  646:                                            select s.Id).ToList();
  647:         }
  648:  
  649:         ////////////////////////////////////////////////////////////////////////////
  650:         ////////////////////////////////////////////////////////////////////////////
  651:  
  652:         /// <summary>
  653:         ///
  654:         /// </summary>
  655:         public static Dictionary<string, List<int>> ReportReadabilityByFrameworkDictionary
  656:         {
  657:             get
  658:             {
  659:                 if (reportReadabilityByFrameworkIdDictionary == null || reportReadabilityByFrameworkIdDictionary.Count == 0)
  660:                 {
  661:                     lock (objectLock)
  662:                     {
  663:                         reportReadabilityByFrameworkIdDictionary = Ia.Ftn.Cl.Model.Data.Report._ReportReadabilityByFrameworkIdDictionary();
  664:                     }
  665:                 }
  666:  
  667:                 return reportReadabilityByFrameworkIdDictionary;
  668:             }
  669:         }
  670:  
  671:         ////////////////////////////////////////////////////////////////////////////
  672:  
  673:         /// <summary>
  674:         ///
  675:         /// </summary>
  676:         public static void ReportReadabilityByFrameworkIdDictionaryClear()
  677:         {
  678:             reportReadabilityByFrameworkIdDictionary = null;
  679:         }
  680:  
  681:         ////////////////////////////////////////////////////////////////////////////
  682:  
  683:         /// <summary>
  684:         ///
  685:         /// </summary>
  686:         private static Dictionary<string, List<int>> _ReportReadabilityByFrameworkIdDictionary()
  687:         {
  688:             Dictionary<string, List<int>> dic;
  689:  
  690:             dic = new Dictionary<string, List<int>>();
  691:  
  692:             var frameworkList = Ia.Ftn.Cl.Model.Data.Administration.FrameworkList;
  693:  
  694:             var reportList = Ia.Ftn.Cl.Model.Data.Report.OpenStatusOrClosedStatusWithinLast24HourReportList;
  695:  
  696:             dic[string.Empty] = reportList.Select(r => r.Id).ToList();
  697:  
  698:             foreach (var framework in frameworkList)
  699:             {
  700:                 if (!string.IsNullOrEmpty(framework.Id))
  701:                 {
  702:                     FrameworkAncestorAndDescendantUserIdListAndFrameworkStaffSubordinatesUserIdList(framework, out List<string> staffFrameworkAncestorAndDescendantUserIdList, out List<string> staffSubordinatesUserIdList);
  703:  
  704:                     var re = (from r in reportList
  705:                               where r.LastReportHistory == null && Ia.Ftn.Cl.Model.Business.Authority.FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(framework)
  706:                               || r.LastReportHistory == null && r.UserId == framework.Id
  707:                               || staffSubordinatesUserIdList.Contains(r.UserId)
  708:                               || staffFrameworkAncestorAndDescendantUserIdList.Contains(r.UserId)
  709:                               || r.LastReportHistory != null && r.LastReportHistory.UserId == framework.Id
  710:                               || r.LastReportHistory != null && staffFrameworkAncestorAndDescendantUserIdList.Contains(r.LastReportHistory.UserId)
  711:                               || r.ReportHistories != null && r.ReportHistories.Any(u => staffSubordinatesUserIdList.Contains(u.UserId))
  712:                               || r.ReportHistories != null && r.ReportHistories.Any(u => staffFrameworkAncestorAndDescendantUserIdList.Contains(u.UserId))
  713:                               || r.LastReportHistory != null && staffSubordinatesUserIdList.Contains(r.LastReportHistory.UserId)
  714:                               select r).ToList();
  715:  
  716:                     if (re.Count > 0) dic[framework.Id] = re.Select(r => r.Id).ToList();
  717:                 }
  718:             }
  719:  
  720:             return dic;
  721:         }
  722:  
  723:         ////////////////////////////////////////////////////////////////////////////    
  724:  
  725:         /// <summary>
  726:         ///
  727:         /// </summary>
  728:         public static List<Ia.Ftn.Cl.Model.Business.Administration.Framework> ReportReadabilityByFrameworkList
  729:         {
  730:             get
  731:             {
  732:                 return (from f in Ia.Ftn.Cl.Model.Data.Administration.FrameworkList
  733:                         join r in ReportReadabilityByFrameworkDictionary on f.Id equals r.Key
  734:                         select f).ToList();
  735:             }
  736:         }
  737:  
  738:         ////////////////////////////////////////////////////////////////////////////
  739:         ////////////////////////////////////////////////////////////////////////////
  740:  
  741:         /// <summary>
  742:         /// When a report list is updated I will reset local lists to null to generate new list
  743:         /// </summary>
  744:         public static void OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear()
  745:         {
  746:             OpenStatusOrClosedStatusWithinLast24HourReportListClear();
  747:             ReportResponsibilityByStaffIdDictionaryClear();
  748:             ReportReadabilityByFrameworkIdDictionaryClear();
  749:         }
  750:  
  751:         ////////////////////////////////////////////////////////////////////////////
  752:         ////////////////////////////////////////////////////////////////////////////
  753:  
  754:         /*
  755:         ////////////////////////////////////////////////////////////////////////////
  756: 
  757:         /// <summary>
  758:         ///
  759:         /// </summary>
  760:         public static List<Ia.Ftn.Cl.Model.Report> OpenStatusAndClosedStatusWithinLast24HourWithNonEmptyReportHistoryReportList()
  761:         {
  762:             var reportList = OpenStatusOrClosedStatusWithinLast24HourReportList;
  763: 
  764:             var lastReportHistoryNotNullReportList = (from r in reportList where r.LastReportHistory != null select r).ToList();
  765: 
  766:             return lastReportHistoryNotNullReportList;
  767:         }
  768:         */
  769:  
  770:         ////////////////////////////////////////////////////////////////////////////
  771:  
  772:         /// <summary>
  773:         ///
  774:         /// </summary>
  775:         public static List<Ia.Ftn.Cl.Model.Report> ReadOpenStatusReportList
  776:         {
  777:             get
  778:             {
  779:                 List<Ia.Ftn.Cl.Model.Report> reportList;
  780:  
  781:                 reportList = (from r in OpenStatusOrClosedStatusWithinLast24HourReportList
  782:                               where r.Status == (int)Ia.Ftn.Cl.Model.Business.Report.Status.Open
  783:                               orderby r.Created
  784:                               select r).ToList();
  785:  
  786:                 return reportList;
  787:             }
  788:         }
  789:  
  790:         ////////////////////////////////////////////////////////////////////////////
  791:  
  792:         /// <summary>
  793:         ///
  794:         /// </summary>
  795:         public static List<Ia.Ftn.Cl.Model.Report> ReadSingleAsList(int reportId)
  796:         {
  797:             List<Ia.Ftn.Cl.Model.Report> reportList;
  798:  
  799:             using (var db = new Ia.Ftn.Cl.Model.Db())
  800:             {
  801:                 reportList = (from r in db.Reports where r.Id == reportId select r).Include(u => u.ReportHistories).ToList();
  802:             }
  803:  
  804:             return reportList;
  805:         }
  806:  
  807:         /*
  808:         ////////////////////////////////////////////////////////////////////////////
  809: 
  810:         /// <summary>
  811:         ///
  812:         /// </summary>
  813:         public static DateTime LastUpdatedDateTime()
  814:         {
  815:             DateTime lastUpdatedDateTime;
  816: 
  817:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  818:             {
  819:                 try
  820:                 {
  821:                     lastUpdatedDateTime = (from r in db.Reports orderby r.Updated descending select r.Updated).Take(1).Single();
  822:                 }
  823:                 catch
  824:                 {
  825:                     lastUpdatedDateTime = Ia.Ftn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
  826:                 }
  827:             }
  828: 
  829:             return lastUpdatedDateTime;
  830:         }
  831: 
  832:         ////////////////////////////////////////////////////////////////////////////
  833: 
  834:         /// <summary>
  835:         ///
  836:         /// </summary>
  837:         public static DateTime LastUpdatedDateTimeOfHistory()
  838:         {
  839:             DateTime lastUpdatedDateTime;
  840: 
  841:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  842:             {
  843:                 try
  844:                 {
  845:                     lastUpdatedDateTime = (from rh in db.ReportHistories orderby rh.Updated descending select rh.Updated).Take(1).Single();
  846:                 }
  847:                 catch
  848:                 {
  849:                     lastUpdatedDateTime = Ia.Ftn.Cl.Model.Business.Administration.SqlFriendlyJanuary1st1753NullDateTime;
  850:                 }
  851:             }
  852: 
  853:             return lastUpdatedDateTime;
  854:         }
  855:         */
  856:  
  857:         ////////////////////////////////////////////////////////////////////////////
  858:         ////////////////////////////////////////////////////////////////////////////
  859:  
  860:  
  861:  
  862:  
  863:         ////////////////////////////////////////////////////////////////////////////
  864:  
  865:         /// <summary>
  866:         ///
  867:         /// </summary>
  868:         public static Dictionary<int, string> CategoryDictionary
  869:         {
  870:             get
  871:             {
  872:                 return DictionaryByXPath("./report/category", false, false);
  873:             }
  874:         }
  875:  
  876:         ////////////////////////////////////////////////////////////////////////////
  877:  
  878:         /// <summary>
  879:         ///
  880:         /// </summary>
  881:         public static Dictionary<int, string> IndicationColoredDictionary
  882:         {
  883:             get
  884:             {
  885:                 return DictionaryByXPath("./report/category/area/descendant::indication", false, true);
  886:             }
  887:         }
  888:  
  889:         ////////////////////////////////////////////////////////////////////////////
  890:  
  891:         /// <summary>
  892:         ///
  893:         /// </summary>
  894:         public static Dictionary<int, string> ActionDictionary
  895:         {
  896:             get
  897:             {
  898:                 return DictionaryByXPath("./report/category/area/descendant::action", false, false);
  899:             }
  900:         }
  901:  
  902:         ////////////////////////////////////////////////////////////////////////////
  903:  
  904:         /// <summary>
  905:         ///
  906:         /// </summary>
  907:         public static Dictionary<int, string> ActionColoredDictionary
  908:         {
  909:             get
  910:             {
  911:                 return DictionaryByXPath("./report/category/area/descendant::action", false, true);
  912:             }
  913:         }
  914:  
  915:         ////////////////////////////////////////////////////////////////////////////
  916:  
  917:         /// <summary>
  918:         ///
  919:         /// </summary>
  920:         public static Dictionary<int, string> ActionIdToColoredNameDictionary
  921:         {
  922:             get
  923:             {
  924:                 var list = (from r in Ia.Ftn.Cl.Model.Data.Report.ActionList
  925:                             where r.Obsolete == false && r.Area.Name == "Service" // <area id="11" name="Service" ...
  926:                             select new { Id = r.XmlId, r.ColoredName }).ToDictionary(r => r.Id, r => r.ColoredName);
  927:  
  928:                 return list;
  929:             }
  930:         }
  931:  
  932:         /*
  933:         ////////////////////////////////////////////////////////////////////////////
  934: 
  935:         /// <summary>
  936:         ///
  937:         /// </summary>
  938:         public static Dictionary<int, string> ResolutionIdToColoredNameDictionaryOld
  939:         {
  940:             get
  941:             {
  942:                 return Dictionary(false, true, "resolution");
  943:             }
  944:         }
  945:         */
  946:  
  947:         ////////////////////////////////////////////////////////////////////////////
  948:  
  949:         /// <summary>
  950:         ///
  951:         /// </summary>
  952:         public static Dictionary<int, string> ResolutionIdToColoredNameDictionary
  953:         {
  954:             get
  955:             {
  956:                 var list = (from r in Ia.Ftn.Cl.Model.Data.Report.ResolutionList
  957:                             where r.Obsolete == false && r.Area.Name == "Service" // <area id="11" name="Service" ...
  958:                             select new { Id = r.XmlId, r.ColoredName }).ToDictionary(r => r.Id, r => r.ColoredName);
  959:  
  960:                 return list;
  961:             }
  962:         }
  963:  
  964:         /*
  965:         ////////////////////////////////////////////////////////////////////////////
  966: 
  967:         /// <summary>
  968:         ///
  969:         /// </summary>
  970:         public static Dictionary<int, string> ResolutionIdToEnglishArabicColoredNameDictionaryOld
  971:         {
  972:             get
  973:             {
  974:                 return Dictionary(true, true, "resolution");
  975:             }
  976:         }
  977:         */
  978:  
  979:         ////////////////////////////////////////////////////////////////////////////
  980:  
  981:         /// <summary>
  982:         ///
  983:         /// </summary>
  984:         public static Dictionary<int, string> ResolutionIdToEnglishArabicColoredNameDictionary
  985:         {
  986:             get
  987:             {
  988:                 var list = (from r in Ia.Ftn.Cl.Model.Data.Report.ResolutionList
  989:                             where r.Obsolete == false && r.Area.Name == "Service" // <area id="11" name="Service" ...
  990:                             select new { Id = r.XmlId, r.ColoredEnglishAndArabicName }).ToDictionary(r => r.Id, r => r.ColoredEnglishAndArabicName);
  991:  
  992:                 return list;
  993:             }
  994:         }
  995:  
  996:         ////////////////////////////////////////////////////////////////////////////
  997:  
  998:         /// <summary>
  999:         ///
 1000:         /// </summary>
 1001:         public static Dictionary<int, string> EstimateDictionary
 1002:         {
 1003:             get
 1004:             {
 1005:                 return DictionaryByXPath("./report/category[@name='General']/area/estimate", false, false);
 1006:             }
 1007:         }
 1008:  
 1009:         ////////////////////////////////////////////////////////////////////////////
 1010:  
 1011:         /// <summary>
 1012:         ///
 1013:         /// </summary>
 1014:         public static Dictionary<int, string> EstimateColoredDictionary
 1015:         {
 1016:             get
 1017:             {
 1018:                 return DictionaryByXPath("./report/category[@name='General']/area/estimate", false, true);
 1019:             }
 1020:         }
 1021:  
 1022:         ////////////////////////////////////////////////////////////////////////////
 1023:  
 1024:         /// <summary>
 1025:         ///
 1026:         /// </summary>
 1027:         public static Dictionary<int, string> EstimateEnglishAndArabicDictionary
 1028:         {
 1029:             get
 1030:             {
 1031:                 return DictionaryByXPath("./report/category[@name='General']/area/estimate", true, false);
 1032:             }
 1033:         }
 1034:  
 1035:         ////////////////////////////////////////////////////////////////////////////
 1036:  
 1037:         /// <summary>
 1038:         ///
 1039:         /// </summary>
 1040:         public static Dictionary<int, string> EstimateEnglishAndArabicColoredDictionary
 1041:         {
 1042:             get
 1043:             {
 1044:                 return DictionaryByXPath("./report/category[@name='General']/area/estimate", true, true);
 1045:             }
 1046:         }
 1047:  
 1048:         ////////////////////////////////////////////////////////////////////////////
 1049:  
 1050:         /// <summary>
 1051:         ///
 1052:         /// </summary>
 1053:         public static Dictionary<int, string> StatusDictionary
 1054:         {
 1055:             get
 1056:             {
 1057:                 return DictionaryByXPath("./report/category[@name='General']/area/status", false, false);
 1058:             }
 1059:         }
 1060:  
 1061:         ////////////////////////////////////////////////////////////////////////////
 1062:  
 1063:         /// <summary>
 1064:         ///
 1065:         /// </summary>
 1066:         public static Dictionary<int, string> StatusColoredDictionary
 1067:         {
 1068:             get
 1069:             {
 1070:                 return DictionaryByXPath("./report/category[@name='General']/area/status", false, true);
 1071:             }
 1072:         }
 1073:  
 1074:         ////////////////////////////////////////////////////////////////////////////
 1075:  
 1076:         /// <summary>
 1077:         ///
 1078:         /// </summary>
 1079:         public static Dictionary<int, string> PriorityDictionary
 1080:         {
 1081:             get
 1082:             {
 1083:                 return DictionaryByXPath("./report/category[@name='General']/area/priority", false, false);
 1084:             }
 1085:         }
 1086:  
 1087:         ////////////////////////////////////////////////////////////////////////////
 1088:  
 1089:         /// <summary>
 1090:         ///
 1091:         /// </summary>
 1092:         public static Dictionary<int, string> PriorityColoredDictionary
 1093:         {
 1094:             get
 1095:             {
 1096:                 return DictionaryByXPath("./report/category[@name='General']/area/priority", false, true);
 1097:             }
 1098:         }
 1099:  
 1100:         ////////////////////////////////////////////////////////////////////////////
 1101:  
 1102:         /// <summary>
 1103:         ///
 1104:         /// </summary>
 1105:         public static Dictionary<int, string> SeverityDictionary
 1106:         {
 1107:             get
 1108:             {
 1109:                 return DictionaryByXPath("./report/category[@name='General']/area/severity", false, false);
 1110:             }
 1111:         }
 1112:  
 1113:         ////////////////////////////////////////////////////////////////////////////
 1114:  
 1115:         /// <summary>
 1116:         ///
 1117:         /// </summary>
 1118:         public static Dictionary<int, string> SeverityColoredDictionary
 1119:         {
 1120:             get
 1121:             {
 1122:                 return DictionaryByXPath("./report/category[@name='General']/area/severity", false, true);
 1123:             }
 1124:         }
 1125:  
 1126:         ////////////////////////////////////////////////////////////////////////////
 1127:  
 1128:         /// <summary>
 1129:         ///
 1130:         /// </summary>
 1131:         public static Dictionary<int, string> CategoryAreaColoredDictionary
 1132:         {
 1133:             get
 1134:             {
 1135:                 return DictionaryByXPath("./report/category/area", false, true);
 1136:             }
 1137:         }
 1138:  
 1139:         ////////////////////////////////////////////////////////////////////////////
 1140:  
 1141:         /// <summary>
 1142:         /// Returns a Dictionary<int, string> dictionary of elements accoring to XPath. If parameter isColored is true the dictionary will contain HTML formatted colored list
 1143:         /// </summary>
 1144:         private static Dictionary<int, string> DictionaryByXPath(string xPath, bool englishAndArabicName, bool isColored)
 1145:         {
 1146:             bool isObsolete;
 1147:             int id;
 1148:             string name, color;
 1149:             IEnumerable<XElement> xElementIenumerable;
 1150:  
 1151:             xElementIenumerable = XDocument.XPathSelectElements(xPath);
 1152:  
 1153:             var specifiedColorList = new List<string>();
 1154:  
 1155:             foreach (XElement x in xElementIenumerable)
 1156:             {
 1157:                 color = x.Attribute("color")?.Value;
 1158:  
 1159:                 if (!string.IsNullOrEmpty(color)) specifiedColorList.Add(color);
 1160:             }
 1161:  
 1162:  
 1163:             var dictionary = new Dictionary<int, string>(xElementIenumerable.Count());
 1164:  
 1165:             foreach (XElement x in xElementIenumerable)
 1166:             {
 1167:                 id = int.Parse(x.Attribute("id").Value);
 1168:  
 1169:                 if (englishAndArabicName)
 1170:                 {
 1171:                     if (x.Attribute("arabicName") != null)
 1172:                     {
 1173:                         name = x.Attribute("name").Value + " (" + x.Attribute("arabicName").Value + ")";
 1174:                     }
 1175:                     else name = x.Attribute("name").Value;
 1176:                 }
 1177:                 else name = x.Attribute("name").Value;
 1178:  
 1179:                 color = x.Attribute("color")?.Value;
 1180:  
 1181:                 if (x.Attribute("obsolete") != null) isObsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
 1182:                 else isObsolete = false;
 1183:  
 1184:                 ColoredDictionaryItem(ref dictionary, isColored, isObsolete, id, name, color, specifiedColorList);
 1185:             }
 1186:  
 1187:             return dictionary;
 1188:         }
 1189:  
 1190:         ////////////////////////////////////////////////////////////////////////////
 1191:  
 1192:         /// <summary>
 1193:         ///
 1194:         /// </summary>
 1195:         private static void ColoredDictionaryItem(ref Dictionary<int, string> dictionary, bool isColored, bool isObsolete, int id, string name, string color, List<string> specifiedColorList)
 1196:         {
 1197:             List<string> lightBackgroundColorList;
 1198:  
 1199:             if (isColored)
 1200:             {
 1201:                 // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1202:                 name = name.Replace(" ", "&nbsp;");
 1203:  
 1204:                 if (isObsolete)
 1205:                 {
 1206:                     color = "Black";
 1207:  
 1208:                     dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
 1209:                 }
 1210:                 else
 1211:                 {
 1212:                     if (!string.IsNullOrEmpty(color))
 1213:                     {
 1214:                         dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
 1215:                     }
 1216:                     else
 1217:                     {
 1218:                         lightBackgroundColorList = Ia.Ftn.Cl.Model.Ui.Default.LightBackgroundColorList.Except(specifiedColorList).ToList();
 1219:  
 1220:                         dictionary.Add(id, @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>");
 1221:                     }
 1222:                 }
 1223:             }
 1224:             else
 1225:             {
 1226:                 dictionary.Add(id, name);
 1227:             }
 1228:         }
 1229:  
 1230:         ////////////////////////////////////////////////////////////////////////////
 1231:  
 1232:         /// <summary>
 1233:         ///
 1234:         /// </summary>
 1235:         private static string ColoredName(int id, string name, string color)
 1236:         {
 1237:             string coloredName;
 1238:             List<string> lightBackgroundColorList;
 1239:  
 1240:             lightBackgroundColorList = Ia.Ftn.Cl.Model.Ui.Default.LightBackgroundColorList.Except(ReservedResolutionColorList).ToList(); ;
 1241:  
 1242:             if (!string.IsNullOrEmpty(color)) coloredName = @"<span style=""color:" + color + @""">" + name + "</span>";
 1243:             else coloredName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>";
 1244:  
 1245:             return coloredName;
 1246:         }
 1247:  
 1248:         ////////////////////////////////////////////////////////////////////////////
 1249:         ////////////////////////////////////////////////////////////////////////////
 1250:  
 1251:         /// <summary>
 1252:         ///
 1253:         /// </summary>
 1254:         public static List<Ia.Ftn.Cl.Model.Business.Report.Category> CategoryList
 1255:         {
 1256:             get
 1257:             {
 1258:                 if (categoryList == null || categoryList.Count == 0)
 1259:                 {
 1260:                     int id;
 1261:                     Ia.Ftn.Cl.Model.Business.Report.Category category;
 1262:  
 1263:                     categoryList = new List<Ia.Ftn.Cl.Model.Business.Report.Category>();
 1264:  
 1265:                     foreach (XElement x in XDocument.Element("report").Elements("category"))
 1266:                     {
 1267:                         category = new Ia.Ftn.Cl.Model.Business.Report.Category();
 1268:  
 1269:                         id = int.Parse(x.Attribute("id").Value);
 1270:  
 1271:                         category.Id = id;
 1272:                         category.Name = x.Attribute("name").Value;
 1273:                         category.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
 1274:  
 1275:                         categoryList.Add(category);
 1276:                     }
 1277:                 }
 1278:  
 1279:                 return categoryList;
 1280:             }
 1281:         }
 1282:  
 1283:         ////////////////////////////////////////////////////////////////////////////
 1284:  
 1285:         /// <summary>
 1286:         ///
 1287:         /// </summary>
 1288:         public static List<Ia.Ftn.Cl.Model.Business.Report.Area> AreaList
 1289:         {
 1290:             get
 1291:             {
 1292:                 if (areaList == null || areaList.Count == 0)
 1293:                 {
 1294:                     int categoryId, id;
 1295:                     Ia.Ftn.Cl.Model.Business.Report.Area area;
 1296:  
 1297:                     areaList = new List<Ia.Ftn.Cl.Model.Business.Report.Area>();
 1298:  
 1299:                     foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
 1300:                     {
 1301:                         area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1302:                         area.Category = new Ia.Ftn.Cl.Model.Business.Report.Category();
 1303:  
 1304:                         categoryId = int.Parse(x.Parent.Attribute("id").Value);
 1305:                         id = int.Parse(x.Attribute("id").Value);
 1306:  
 1307:                         area.Id = area.AreaId(categoryId, id);
 1308:                         area.XmlId = id;
 1309:                         area.Category = (from c in CategoryList where c.Id == categoryId select c).SingleOrDefault();
 1310:                         area.Name = x.Attribute("name").Value;
 1311:                         area.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
 1312:  
 1313:                         if (x.Attribute("framework") != null)
 1314:                         {
 1315:                             area.Frameworks = new List<string>(100);
 1316:  
 1317:                             foreach (string s in x.Attribute("framework").Value.Split(',')) area.Frameworks.Add(s);
 1318:                         }
 1319:  
 1320:                         areaList.Add(area);
 1321:                     }
 1322:                 }
 1323:  
 1324:                 return areaList;
 1325:             }
 1326:         }
 1327:  
 1328:         ////////////////////////////////////////////////////////////////////////////
 1329:  
 1330:         /// <summary>
 1331:         ///
 1332:         /// </summary>
 1333:         public static List<Ia.Ftn.Cl.Model.Business.Report.Indication> IndicationList
 1334:         {
 1335:             get
 1336:             {
 1337:                 if (indicationList == null || indicationList.Count == 0)
 1338:                 {
 1339:                     lock (objectLock)
 1340:                     {
 1341:                         indicationList = Ia.Ftn.Cl.Model.Data.Report._IndicationList;
 1342:                     }
 1343:                 }
 1344:  
 1345:                 return indicationList;
 1346:             }
 1347:         }
 1348:  
 1349:         ////////////////////////////////////////////////////////////////////////////
 1350:  
 1351:         /// <summary>
 1352:         ///
 1353:         /// </summary>
 1354:         private static List<Ia.Ftn.Cl.Model.Business.Report.Indication> _IndicationList
 1355:         {
 1356:             get
 1357:             {
 1358:                 int categoryId, areaId, id;
 1359:                 Ia.Ftn.Cl.Model.Business.Report.Indication indication;
 1360:  
 1361:                 indicationList = new List<Ia.Ftn.Cl.Model.Business.Report.Indication>();
 1362:  
 1363:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("indicationList").Elements("indication"))
 1364:                 {
 1365:                     indication = new Ia.Ftn.Cl.Model.Business.Report.Indication();
 1366:                     indication.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1367:  
 1368:                     categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 1369:                     areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 1370:                     id = int.Parse(x.Attribute("id").Value);
 1371:  
 1372:                     areaId = indication.Area.AreaId(categoryId, areaId);
 1373:  
 1374:                     indication.Id = indication.IndicationId(areaId, id);
 1375:                     indication.XmlId = id;
 1376:                     indication.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
 1377:  
 1378:                     // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1379:                     if (x.Attribute("obsolete") != null) indication.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
 1380:                     else indication.Obsolete = false;
 1381:  
 1382:                     // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1383:                     if (x.Attribute("canInsert") != null) indication.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
 1384:                     else indication.CanInsert = true;
 1385:  
 1386:                     indication.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
 1387:  
 1388:                     // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1389:                     indication.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
 1390:                     indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
 1391:  
 1392:                     if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
 1393:                     {
 1394:                         indication.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1395:                         indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
 1396:                     }
 1397:                     else
 1398:                     {
 1399:                         indication.ArabicName = string.Empty;
 1400:                         indication.ColoredArabicName = string.Empty;
 1401:                     }
 1402:  
 1403:                     if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
 1404:                     else indication.EnglishAndArabicName = indication.Name;
 1405:  
 1406:                     if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
 1407:                     else indication.ColoredEnglishAndArabicName = indication.ColoredName;
 1408:  
 1409:                     if (x.Parent.Attribute("framework") != null)
 1410:                     {
 1411:                         indication.Frameworks = new List<string>(100);
 1412:  
 1413:                         foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) indication.Frameworks.Add(s);
 1414:                     }
 1415:  
 1416:                     indicationList.Add(indication);
 1417:                 }
 1418:  
 1419:                 // below: add the general indications to all areas
 1420:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
 1421:                 {
 1422:                     if (x.Attribute("name").Value != "General")
 1423:                     {
 1424:                         foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/indication"))
 1425:                         {
 1426:                             indication = new Ia.Ftn.Cl.Model.Business.Report.Indication();
 1427:                             indication.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1428:  
 1429:                             categoryId = int.Parse(x.Parent.Attribute("id").Value);
 1430:                             areaId = int.Parse(x.Attribute("id").Value);
 1431:                             id = int.Parse(y.Attribute("id").Value); // y
 1432:  
 1433:                             areaId = indication.Area.AreaId(categoryId, areaId);
 1434:  
 1435:                             indication.Id = indication.IndicationId(areaId, id);
 1436:                             indication.XmlId = id;
 1437:                             indication.Area = null;// (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
 1438:  
 1439:                             // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1440:                             if (y.Attribute("obsolete") != null) indication.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
 1441:                             else indication.Obsolete = false;
 1442:  
 1443:                             // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1444:                             if (y.Attribute("canInsert") != null) indication.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
 1445:                             else indication.CanInsert = true;
 1446:  
 1447:                             indication.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
 1448:  
 1449:                             // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1450:                             indication.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
 1451:                             indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
 1452:  
 1453:                             if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
 1454:                             {
 1455:                                 indication.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1456:                                 indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
 1457:                             }
 1458:                             else
 1459:                             {
 1460:                                 indication.ArabicName = string.Empty;
 1461:                                 indication.ColoredArabicName = string.Empty;
 1462:                             }
 1463:  
 1464:                             if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + "&nbsp;(" + indication.ArabicName + ")";
 1465:                             else indication.EnglishAndArabicName = indication.Name;
 1466:  
 1467:                             if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + "&nbsp;(" + indication.ColoredArabicName + ")";
 1468:                             else indication.ColoredEnglishAndArabicName = indication.ColoredName;
 1469:  
 1470:                             indicationList.Add(indication);
 1471:                         }
 1472:                     }
 1473:                 }
 1474:  
 1475:                 return indicationList;
 1476:             }
 1477:         }
 1478:  
 1479:         ////////////////////////////////////////////////////////////////////////////
 1480:  
 1481:         /// <summary>
 1482:         ///
 1483:         /// </summary>
 1484:         public static List<Ia.Ftn.Cl.Model.Business.Report.Action> ActionList
 1485:         {
 1486:             get
 1487:             {
 1488:                 if (actionList == null || actionList.Count == 0)
 1489:                 {
 1490:                     lock (objectLock)
 1491:                     {
 1492:                         actionList = Ia.Ftn.Cl.Model.Data.Report._ActionList;
 1493:                     }
 1494:                 }
 1495:  
 1496:                 return actionList;
 1497:             }
 1498:         }
 1499:  
 1500:         ////////////////////////////////////////////////////////////////////////////
 1501:  
 1502:         /// <summary>
 1503:         ///
 1504:         /// </summary>
 1505:         private static List<Ia.Ftn.Cl.Model.Business.Report.Action> _ActionList
 1506:         {
 1507:             get
 1508:             {
 1509:                 int categoryId, areaId, id;
 1510:                 Ia.Ftn.Cl.Model.Business.Report.Action action;
 1511:  
 1512:                 actionList = new List<Ia.Ftn.Cl.Model.Business.Report.Action>();
 1513:  
 1514:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("actionList").Elements("action"))
 1515:                 {
 1516:                     action = new Ia.Ftn.Cl.Model.Business.Report.Action();
 1517:                     action.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1518:  
 1519:                     categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 1520:                     areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 1521:                     id = int.Parse(x.Attribute("id").Value);
 1522:  
 1523:                     areaId = action.Area.AreaId(categoryId, areaId);
 1524:  
 1525:                     action.Id = action.ActionId(areaId, id);
 1526:                     action.XmlId = id;
 1527:                     action.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
 1528:  
 1529:                     // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1530:                     if (x.Attribute("obsolete") != null) action.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
 1531:                     else action.Obsolete = false;
 1532:  
 1533:                     // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1534:                     if (x.Attribute("canInsert") != null) action.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
 1535:                     else action.CanInsert = true;
 1536:  
 1537:                     action.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
 1538:  
 1539:                     // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1540:                     action.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
 1541:                     action.ColoredName = ColoredName(id, action.Name, action.Color);
 1542:  
 1543:                     if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
 1544:                     {
 1545:                         action.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1546:                         action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
 1547:                     }
 1548:                     else
 1549:                     {
 1550:                         action.ArabicName = string.Empty;
 1551:                         action.ColoredArabicName = string.Empty;
 1552:                     }
 1553:  
 1554:                     if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
 1555:                     else action.EnglishAndArabicName = action.Name;
 1556:  
 1557:                     if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
 1558:                     else action.ColoredEnglishAndArabicName = action.ColoredName;
 1559:  
 1560:                     if (x.Parent.Attribute("framework") != null)
 1561:                     {
 1562:                         action.Frameworks = new List<string>(100);
 1563:  
 1564:                         foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) action.Frameworks.Add(s);
 1565:                     }
 1566:  
 1567:                     actionList.Add(action);
 1568:                 }
 1569:  
 1570:                 // below: add the general actions to all areas
 1571:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
 1572:                 {
 1573:                     if (x.Attribute("name").Value != "General")
 1574:                     {
 1575:                         foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/action"))
 1576:                         {
 1577:                             action = new Ia.Ftn.Cl.Model.Business.Report.Action();
 1578:                             action.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1579:  
 1580:                             categoryId = int.Parse(x.Parent.Attribute("id").Value);
 1581:                             areaId = int.Parse(x.Attribute("id").Value);
 1582:                             id = int.Parse(y.Attribute("id").Value); // y
 1583:  
 1584:                             areaId = action.Area.AreaId(categoryId, areaId);
 1585:  
 1586:                             action.Id = action.ActionId(areaId, id);
 1587:                             action.XmlId = id;
 1588:                             action.Area = null; // (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
 1589:  
 1590:                             // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1591:                             if (y.Attribute("obsolete") != null) action.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
 1592:                             else action.Obsolete = false;
 1593:  
 1594:                             // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1595:                             if (y.Attribute("canInsert") != null) action.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
 1596:                             else action.CanInsert = true;
 1597:  
 1598:                             action.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
 1599:  
 1600:                             // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1601:                             action.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
 1602:                             action.ColoredName = ColoredName(id, action.Name, action.Color);
 1603:  
 1604:                             if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
 1605:                             {
 1606:                                 action.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1607:                                 action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
 1608:                             }
 1609:                             else
 1610:                             {
 1611:                                 action.ArabicName = string.Empty;
 1612:                                 action.ColoredArabicName = string.Empty;
 1613:                             }
 1614:  
 1615:                             if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + "&nbsp;(" + action.ArabicName + ")";
 1616:                             else action.EnglishAndArabicName = action.Name;
 1617:  
 1618:                             if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + "&nbsp;(" + action.ColoredArabicName + ")";
 1619:                             else action.ColoredEnglishAndArabicName = action.ColoredName;
 1620:  
 1621:                             actionList.Add(action);
 1622:                         }
 1623:                     }
 1624:                 }
 1625:  
 1626:                 return actionList;
 1627:             }
 1628:         }
 1629:  
 1630:         ////////////////////////////////////////////////////////////////////////////
 1631:  
 1632:         /// <summary>
 1633:         ///
 1634:         /// </summary>
 1635:         public static List<Ia.Ftn.Cl.Model.Business.Report.Resolution> ResolutionList
 1636:         {
 1637:             get
 1638:             {
 1639:                 if (resolutionList == null || resolutionList.Count == 0)
 1640:                 {
 1641:                     lock (objectLock)
 1642:                     {
 1643:                         resolutionList = Ia.Ftn.Cl.Model.Data.Report._ResolutionList;
 1644:                     }
 1645:                 }
 1646:  
 1647:                 return resolutionList;
 1648:             }
 1649:         }
 1650:  
 1651:         ////////////////////////////////////////////////////////////////////////////
 1652:  
 1653:         /// <summary>
 1654:         ///
 1655:         /// </summary>
 1656:         private static List<Ia.Ftn.Cl.Model.Business.Report.Resolution> _ResolutionList
 1657:         {
 1658:             get
 1659:             {
 1660:                 int categoryId, areaId, id;
 1661:                 Ia.Ftn.Cl.Model.Business.Report.Resolution resolution;
 1662:  
 1663:                 resolutionList = new List<Ia.Ftn.Cl.Model.Business.Report.Resolution>();
 1664:  
 1665:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("resolutionList").Elements("resolution"))
 1666:                 {
 1667:                     resolution = new Ia.Ftn.Cl.Model.Business.Report.Resolution();
 1668:                     resolution.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1669:  
 1670:                     categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 1671:                     areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 1672:                     id = int.Parse(x.Attribute("id").Value);
 1673:  
 1674:                     areaId = resolution.Area.AreaId(categoryId, areaId);
 1675:  
 1676:                     resolution.Id = resolution.ResolutionId(areaId, id);
 1677:                     resolution.XmlId = id;
 1678:                     resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
 1679:  
 1680:                     // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1681:                     if (x.Attribute("obsolete") != null) resolution.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
 1682:                     else resolution.Obsolete = false;
 1683:  
 1684:                     // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1685:                     if (x.Attribute("canInsert") != null) resolution.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
 1686:                     else resolution.CanInsert = true;
 1687:  
 1688:                     resolution.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
 1689:  
 1690:                     // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1691:                     resolution.Name = x.Attribute("name").Value.Replace(" ", "&nbsp;");
 1692:                     resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
 1693:  
 1694:                     if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
 1695:                     {
 1696:                         resolution.ArabicName = x.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1697:                         resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
 1698:                     }
 1699:                     else
 1700:                     {
 1701:                         resolution.ArabicName = string.Empty;
 1702:                         resolution.ColoredArabicName = string.Empty;
 1703:                     }
 1704:  
 1705:                     if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
 1706:                     else resolution.EnglishAndArabicName = resolution.Name;
 1707:  
 1708:                     if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
 1709:                     else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
 1710:  
 1711:                     resolutionList.Add(resolution);
 1712:                 }
 1713:  
 1714:                 // below: add the general resolutions to all areas
 1715:                 foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
 1716:                 {
 1717:                     if (x.Attribute("name").Value != "General")
 1718:                     {
 1719:                         foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/resolution"))
 1720:                         {
 1721:                             resolution = new Ia.Ftn.Cl.Model.Business.Report.Resolution();
 1722:                             resolution.Area = new Ia.Ftn.Cl.Model.Business.Report.Area();
 1723:  
 1724:                             categoryId = int.Parse(x.Parent.Attribute("id").Value);
 1725:                             areaId = int.Parse(x.Attribute("id").Value);
 1726:  
 1727:                             id = int.Parse(y.Attribute("id").Value); // y
 1728:  
 1729:                             areaId = resolution.Area.AreaId(categoryId, areaId);
 1730:  
 1731:                             resolution.Id = resolution.ResolutionId(areaId, id);
 1732:                             resolution.XmlId = id;
 1733:                             resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
 1734:  
 1735:                             // below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
 1736:                             if (y.Attribute("obsolete") != null) resolution.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
 1737:                             else resolution.Obsolete = false;
 1738:  
 1739:                             // below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
 1740:                             if (y.Attribute("canInsert") != null) resolution.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
 1741:                             else resolution.CanInsert = true;
 1742:  
 1743:                             resolution.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
 1744:  
 1745:                             // below: replace spaces ' ' with HTML fixed space "&nbsp;"
 1746:                             resolution.Name = y.Attribute("name").Value.Replace(" ", "&nbsp;");
 1747:                             resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
 1748:  
 1749:                             if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
 1750:                             {
 1751:                                 resolution.ArabicName = y.Attribute("arabicName").Value.Replace(" ", "&nbsp;");
 1752:                                 resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
 1753:                             }
 1754:                             else
 1755:                             {
 1756:                                 resolution.ArabicName = string.Empty;
 1757:                                 resolution.ColoredArabicName = string.Empty;
 1758:                             }
 1759:  
 1760:                             if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + "&nbsp;(" + resolution.ArabicName + ")";
 1761:                             else resolution.EnglishAndArabicName = resolution.Name;
 1762:  
 1763:                             if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + "&nbsp;(" + resolution.ColoredArabicName + ")";
 1764:                             else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
 1765:  
 1766:                             resolutionList.Add(resolution);
 1767:                         }
 1768:                     }
 1769:                 }
 1770:  
 1771:                 return resolutionList;
 1772:             }
 1773:         }
 1774:  
 1775:         ////////////////////////////////////////////////////////////////////////////
 1776:  
 1777:         /// <summary>
 1778:         ///
 1779:         /// </summary>
 1780:         private static List<string> ReservedResolutionColorList
 1781:         {
 1782:             get
 1783:             {
 1784:                 var list = new List<string>();
 1785:  
 1786:                 foreach (XElement y in XDocument.Element("report").Elements("resolution"))
 1787:                 {
 1788:                     if (y.Attribute("color") != null) list.Add(y.Attribute("color").Value);
 1789:                 }
 1790:  
 1791:                 return list;
 1792:             }
 1793:         }
 1794:  
 1795:         ////////////////////////////////////////////////////////////////////////////
 1796:  
 1797:         /// <summary>
 1798:         ///
 1799:         /// </summary>
 1800:         public static Dictionary<string, int> ReportServiceToCountTopNDictionary(int numberOfTopServicesToTake)
 1801:         {
 1802:             Dictionary<string, int> dictionary;
 1803:  
 1804:             using (var db = new Ia.Ftn.Cl.Model.Db())
 1805:             {
 1806:                 /*
 1807: select top 100 Service, count(0) 
 1808: from Reports 
 1809: where Service like '________'
 1810: group by Service
 1811: order by count(0) desc
 1812:                  */
 1813:  
 1814:                 var dictionary0 = (from r in db.Reports
 1815:                                    group r.Service by r.Service into g
 1816:                                    select new { Service = g.Key, Count = g.Count() }
 1817:                         ).ToDictionary(r => r.Service, r => r.Count);
 1818:  
 1819:  
 1820:                 var i = 1;
 1821:                 dictionary = new Dictionary<string, int>();
 1822:  
 1823:                 foreach (var kvp in dictionary0.OrderByDescending(u => u.Value))
 1824:                 {
 1825:                     if (Regex.IsMatch(kvp.Key, @"(\d{8})"))
 1826:                     {
 1827:                         dictionary[kvp.Key] = kvp.Value;
 1828:  
 1829:                         if (i++ >= numberOfTopServicesToTake) break;
 1830:                     }
 1831:                 }
 1832:             }
 1833:  
 1834:             return dictionary;
 1835:         }
 1836:  
 1837:         ////////////////////////////////////////////////////////////////////////////
 1838:         ////////////////////////////////////////////////////////////////////////////
 1839:  
 1840:         /// <summary>
 1841:         /// 
 1842:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 1843:         /// 
 1844:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 1845:         /// 2. Add "using System.Reflection".
 1846:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
 1847:         /// 
 1848:         /// </summary>
 1849:  
 1850:         public static XDocument XDocument
 1851:         {
 1852:             get
 1853:             {
 1854:                 if (xDocument == null)
 1855:                 {
 1856:                     lock (objectLock)
 1857:                     {
 1858:                         Assembly _assembly;
 1859:                         StreamReader streamReader;
 1860:  
 1861:                         _assembly = Assembly.GetExecutingAssembly();
 1862:                         streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ftn.Cl.model.data.report.xml"));
 1863:  
 1864:                         try
 1865:                         {
 1866:                             if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
 1867:                         }
 1868:                         catch (Exception)
 1869:                         {
 1870:                         }
 1871:                         finally
 1872:                         {
 1873:                         }
 1874:                     }
 1875:                 }
 1876:  
 1877:                 return xDocument;
 1878:             }
 1879:         }
 1880:  
 1881:         ////////////////////////////////////////////////////////////////////////////
 1882:         ////////////////////////////////////////////////////////////////////////////    
 1883:     }
 1884:  
 1885:     ////////////////////////////////////////////////////////////////////////////
 1886:     ////////////////////////////////////////////////////////////////////////////   
 1887: }