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