)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation LinksHome » Code Library » Report

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

Report support class for Optical Fiber Network (OFN) data model.

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