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