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:
/*
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> ResolutionIdToEnglishArabicColoredNameDictionaryOld
{
get
{
return Dictionary(true, true, "resolution");
}
}
*/
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> ResolutionIdToEnglishArabicColoredNameDictionary
{
get
{
var list = (from r in Ia.Ngn.Cl.Model.Data.Report.ResolutionList
where r.Obsolete == false && r.Area.Name == "Service" // <area id="11" name="Service" ...
select new { Id = r.XmlId, r.ColoredEnglishAndArabicName }).ToDictionary(r => r.Id, r => r.ColoredEnglishAndArabicName);
return list;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> EstimateDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/estimate", false, false);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> EstimateColoredDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/estimate", false, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> EstimateEnglishAndArabicDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/estimate", true, false);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> EstimateEnglishAndArabicColoredDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/estimate", true, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> StatusDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/status", false, false);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> StatusColoredDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/status", false, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> PriorityDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/priority", false, false);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> PriorityColoredDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/priority", false, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> SeverityDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/severity", false, false);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> SeverityColoredDictionary
{
get
{
return DictionaryByXPath("./report/category[@name='General']/area/severity", false, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<int, string> CategoryAreaColoredDictionary
{
get
{
return DictionaryByXPath("./report/category/area", false, true);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Returns a Dictionary<int, string> dictionary of elements accoring to XPath. If parameter isColored is true the dictionary will contain HTML formatted colored list
/// </summary>
private static Dictionary<int, string> DictionaryByXPath(string xPath, bool englishAndArabicName, bool isColored)
{
bool isObsolete;
int id;
string name, color;
IEnumerable<XElement> xElementIenumerable;
xElementIenumerable = XDocument.XPathSelectElements(xPath);
var specifiedColorList = new List<string>();
foreach (XElement x in xElementIenumerable)
{
color = x.Attribute("color")?.Value;
if (!string.IsNullOrEmpty(color)) specifiedColorList.Add(color);
}
var dictionary = new Dictionary<int, string>(xElementIenumerable.Count());
foreach (XElement x in xElementIenumerable)
{
id = int.Parse(x.Attribute("id").Value);
if (englishAndArabicName)
{
if (x.Attribute("arabicName") != null)
{
name = x.Attribute("name").Value + " (" + x.Attribute("arabicName").Value + ")";
}
else name = x.Attribute("name").Value;
}
else name = x.Attribute("name").Value;
color = x.Attribute("color")?.Value;
if (x.Attribute("obsolete") != null) isObsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
else isObsolete = false;
ColoredDictionaryItem(ref dictionary, isColored, isObsolete, id, name, color, specifiedColorList);
}
return dictionary;
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static void ColoredDictionaryItem(ref Dictionary<int, string> dictionary, bool isColored, bool isObsolete, int id, string name, string color, List<string> specifiedColorList)
{
List<string> lightBackgroundColorList;
if (isColored)
{
// below: replace spaces ' ' with HTML fixed space " "
name = name.Replace(" ", " ");
if (isObsolete)
{
color = "Black";
dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
}
else
{
if (!string.IsNullOrEmpty(color))
{
dictionary.Add(id, @"<span style=""color:" + color + @""">" + name + "</span>");
}
else
{
lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList.Except(specifiedColorList).ToList();
dictionary.Add(id, @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>");
}
}
}
else
{
dictionary.Add(id, name);
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static string ColoredName(int id, string name, string color)
{
string coloredName;
List<string> lightBackgroundColorList;
lightBackgroundColorList = Ia.Ngn.Cl.Model.Ui.Default.LightBackgroundColorList.Except(ReservedResolutionColorList).ToList(); ;
if (!string.IsNullOrEmpty(color)) coloredName = @"<span style=""color:" + color + @""">" + name + "</span>";
else coloredName = @"<span style=""color:" + lightBackgroundColorList[id % lightBackgroundColorList.Count] + @""">" + name + "</span>";
return coloredName;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static List<Ia.Ngn.Cl.Model.Business.Report.Category> CategoryList
{
get
{
if (categoryList == null || categoryList.Count == 0)
{
int id;
Ia.Ngn.Cl.Model.Business.Report.Category category;
categoryList = new List<Ia.Ngn.Cl.Model.Business.Report.Category>();
foreach (XElement x in XDocument.Element("report").Elements("category"))
{
category = new Ia.Ngn.Cl.Model.Business.Report.Category();
id = int.Parse(x.Attribute("id").Value);
category.Id = id;
category.Name = x.Attribute("name").Value;
category.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
categoryList.Add(category);
}
}
return categoryList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static List<Ia.Ngn.Cl.Model.Business.Report.Area> AreaList
{
get
{
if (areaList == null || areaList.Count == 0)
{
int categoryId, id;
Ia.Ngn.Cl.Model.Business.Report.Area area;
areaList = new List<Ia.Ngn.Cl.Model.Business.Report.Area>();
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
{
area = new Ia.Ngn.Cl.Model.Business.Report.Area();
area.Category = new Ia.Ngn.Cl.Model.Business.Report.Category();
categoryId = int.Parse(x.Parent.Attribute("id").Value);
id = int.Parse(x.Attribute("id").Value);
area.Id = area.AreaId(categoryId, id);
area.XmlId = id;
area.Category = (from c in CategoryList where c.Id == categoryId select c).SingleOrDefault();
area.Name = x.Attribute("name").Value;
area.ArabicName = (x.Attribute("arabicName") != null) ? x.Attribute("arabicName").Value : string.Empty;
if (x.Attribute("framework") != null)
{
area.Frameworks = new List<string>(100);
foreach (string s in x.Attribute("framework").Value.Split(',')) area.Frameworks.Add(s);
}
areaList.Add(area);
}
}
return areaList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static List<Ia.Ngn.Cl.Model.Business.Report.Indication> IndicationList
{
get
{
if (indicationList == null || indicationList.Count == 0)
{
lock (objectLock)
{
indicationList = Ia.Ngn.Cl.Model.Data.Report._IndicationList;
}
}
return indicationList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static List<Ia.Ngn.Cl.Model.Business.Report.Indication> _IndicationList
{
get
{
int categoryId, areaId, id;
Ia.Ngn.Cl.Model.Business.Report.Indication indication;
indicationList = new List<Ia.Ngn.Cl.Model.Business.Report.Indication>();
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("indicationList").Elements("indication"))
{
indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
id = int.Parse(x.Attribute("id").Value);
areaId = indication.Area.AreaId(categoryId, areaId);
indication.Id = indication.IndicationId(areaId, id);
indication.XmlId = id;
indication.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("obsolete") != null) indication.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
else indication.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("canInsert") != null) indication.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
else indication.CanInsert = true;
indication.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
indication.Name = x.Attribute("name").Value.Replace(" ", " ");
indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
{
indication.ArabicName = x.Attribute("arabicName").Value.Replace(" ", " ");
indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
}
else
{
indication.ArabicName = string.Empty;
indication.ColoredArabicName = string.Empty;
}
if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + " (" + indication.ArabicName + ")";
else indication.EnglishAndArabicName = indication.Name;
if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + " (" + indication.ColoredArabicName + ")";
else indication.ColoredEnglishAndArabicName = indication.ColoredName;
if (x.Parent.Attribute("framework") != null)
{
indication.Frameworks = new List<string>(100);
foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) indication.Frameworks.Add(s);
}
indicationList.Add(indication);
}
// below: add the general indications to all areas
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
{
if (x.Attribute("name").Value != "General")
{
foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/indication"))
{
indication = new Ia.Ngn.Cl.Model.Business.Report.Indication();
indication.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Attribute("id").Value);
areaId = int.Parse(x.Attribute("id").Value);
id = int.Parse(y.Attribute("id").Value); // y
areaId = indication.Area.AreaId(categoryId, areaId);
indication.Id = indication.IndicationId(areaId, id);
indication.XmlId = id;
indication.Area = null;// (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("obsolete") != null) indication.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
else indication.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("canInsert") != null) indication.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
else indication.CanInsert = true;
indication.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
indication.Name = y.Attribute("name").Value.Replace(" ", " ");
indication.ColoredName = ColoredName(id, indication.Name, indication.Color);
if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
{
indication.ArabicName = y.Attribute("arabicName").Value.Replace(" ", " ");
indication.ColoredArabicName = ColoredName(id, indication.ArabicName, indication.Color);
}
else
{
indication.ArabicName = string.Empty;
indication.ColoredArabicName = string.Empty;
}
if (indication.ArabicName != string.Empty) indication.EnglishAndArabicName = indication.Name + " (" + indication.ArabicName + ")";
else indication.EnglishAndArabicName = indication.Name;
if (indication.ColoredArabicName != string.Empty) indication.ColoredEnglishAndArabicName = indication.ColoredName + " (" + indication.ColoredArabicName + ")";
else indication.ColoredEnglishAndArabicName = indication.ColoredName;
indicationList.Add(indication);
}
}
}
return indicationList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static List<Ia.Ngn.Cl.Model.Business.Report.Action> ActionList
{
get
{
if (actionList == null || actionList.Count == 0)
{
lock (objectLock)
{
actionList = Ia.Ngn.Cl.Model.Data.Report._ActionList;
}
}
return actionList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static List<Ia.Ngn.Cl.Model.Business.Report.Action> _ActionList
{
get
{
int categoryId, areaId, id;
Ia.Ngn.Cl.Model.Business.Report.Action action;
actionList = new List<Ia.Ngn.Cl.Model.Business.Report.Action>();
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("actionList").Elements("action"))
{
action = new Ia.Ngn.Cl.Model.Business.Report.Action();
action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
id = int.Parse(x.Attribute("id").Value);
areaId = action.Area.AreaId(categoryId, areaId);
action.Id = action.ActionId(areaId, id);
action.XmlId = id;
action.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("obsolete") != null) action.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
else action.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("canInsert") != null) action.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
else action.CanInsert = true;
action.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
action.Name = x.Attribute("name").Value.Replace(" ", " ");
action.ColoredName = ColoredName(id, action.Name, action.Color);
if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
{
action.ArabicName = x.Attribute("arabicName").Value.Replace(" ", " ");
action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
}
else
{
action.ArabicName = string.Empty;
action.ColoredArabicName = string.Empty;
}
if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + " (" + action.ArabicName + ")";
else action.EnglishAndArabicName = action.Name;
if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + " (" + action.ColoredArabicName + ")";
else action.ColoredEnglishAndArabicName = action.ColoredName;
if (x.Parent.Attribute("framework") != null)
{
action.Frameworks = new List<string>(100);
foreach (string s in x.Parent.Attribute("framework").Value.Split(',')) action.Frameworks.Add(s);
}
actionList.Add(action);
}
// below: add the general actions to all areas
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
{
if (x.Attribute("name").Value != "General")
{
foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/action"))
{
action = new Ia.Ngn.Cl.Model.Business.Report.Action();
action.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Attribute("id").Value);
areaId = int.Parse(x.Attribute("id").Value);
id = int.Parse(y.Attribute("id").Value); // y
areaId = action.Area.AreaId(categoryId, areaId);
action.Id = action.ActionId(areaId, id);
action.XmlId = id;
action.Area = null; // (from q in AreaList where q.Id == areaId select q).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("obsolete") != null) action.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
else action.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("canInsert") != null) action.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
else action.CanInsert = true;
action.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
action.Name = y.Attribute("name").Value.Replace(" ", " ");
action.ColoredName = ColoredName(id, action.Name, action.Color);
if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
{
action.ArabicName = y.Attribute("arabicName").Value.Replace(" ", " ");
action.ColoredArabicName = ColoredName(id, action.ArabicName, action.Color);
}
else
{
action.ArabicName = string.Empty;
action.ColoredArabicName = string.Empty;
}
if (action.ArabicName != string.Empty) action.EnglishAndArabicName = action.Name + " (" + action.ArabicName + ")";
else action.EnglishAndArabicName = action.Name;
if (action.ColoredArabicName != string.Empty) action.ColoredEnglishAndArabicName = action.ColoredName + " (" + action.ColoredArabicName + ")";
else action.ColoredEnglishAndArabicName = action.ColoredName;
actionList.Add(action);
}
}
}
return actionList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> ResolutionList
{
get
{
if (resolutionList == null || resolutionList.Count == 0)
{
lock (objectLock)
{
resolutionList = Ia.Ngn.Cl.Model.Data.Report._ResolutionList;
}
}
return resolutionList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static List<Ia.Ngn.Cl.Model.Business.Report.Resolution> _ResolutionList
{
get
{
int categoryId, areaId, id;
Ia.Ngn.Cl.Model.Business.Report.Resolution resolution;
resolutionList = new List<Ia.Ngn.Cl.Model.Business.Report.Resolution>();
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area").Elements("resolutionList").Elements("resolution"))
{
resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
areaId = int.Parse(x.Parent.Parent.Attribute("id").Value);
id = int.Parse(x.Attribute("id").Value);
areaId = resolution.Area.AreaId(categoryId, areaId);
resolution.Id = resolution.ResolutionId(areaId, id);
resolution.XmlId = id;
resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("obsolete") != null) resolution.Obsolete = (x.Attribute("obsolete").Value == "true") ? true : false;
else resolution.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (x.Attribute("canInsert") != null) resolution.CanInsert = (x.Attribute("canInsert").Value == "true") ? true : false;
else resolution.CanInsert = true;
resolution.Color = (x.Attribute("color") != null) ? x.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
resolution.Name = x.Attribute("name").Value.Replace(" ", " ");
resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
if (x.Attribute("arabicName") != null && x.Attribute("arabicName").Value != string.Empty)
{
resolution.ArabicName = x.Attribute("arabicName").Value.Replace(" ", " ");
resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
}
else
{
resolution.ArabicName = string.Empty;
resolution.ColoredArabicName = string.Empty;
}
if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + " (" + resolution.ArabicName + ")";
else resolution.EnglishAndArabicName = resolution.Name;
if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + " (" + resolution.ColoredArabicName + ")";
else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
resolutionList.Add(resolution);
}
// below: add the general resolutions to all areas
foreach (XElement x in XDocument.Element("report").Elements("category").Elements("area"))
{
if (x.Attribute("name").Value != "General")
{
foreach (XElement y in XDocument.XPathSelectElements("./report/category[@name='General']/area/resolution"))
{
resolution = new Ia.Ngn.Cl.Model.Business.Report.Resolution();
resolution.Area = new Ia.Ngn.Cl.Model.Business.Report.Area();
categoryId = int.Parse(x.Parent.Attribute("id").Value);
areaId = int.Parse(x.Attribute("id").Value);
id = int.Parse(y.Attribute("id").Value); // y
areaId = resolution.Area.AreaId(categoryId, areaId);
resolution.Id = resolution.ResolutionId(areaId, id);
resolution.XmlId = id;
resolution.Area = (from a in AreaList where a.Id == areaId select a).SingleOrDefault();
// below: obsolete indicates weather the attribute is still used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("obsolete") != null) resolution.Obsolete = (y.Attribute("obsolete").Value == "true") ? true : false;
else resolution.Obsolete = false;
// below: canInsert indicates weather the attribute is used as a selection, but it must remain as a value of int in the storage
if (y.Attribute("canInsert") != null) resolution.CanInsert = (y.Attribute("canInsert").Value == "true") ? true : false;
else resolution.CanInsert = true;
resolution.Color = (y.Attribute("color") != null) ? y.Attribute("color").Value : string.Empty;
// below: replace spaces ' ' with HTML fixed space " "
resolution.Name = y.Attribute("name").Value.Replace(" ", " ");
resolution.ColoredName = ColoredName(id, resolution.Name, resolution.Color);
if (y.Attribute("arabicName") != null && y.Attribute("arabicName").Value != string.Empty)
{
resolution.ArabicName = y.Attribute("arabicName").Value.Replace(" ", " ");
resolution.ColoredArabicName = ColoredName(id, resolution.ArabicName, resolution.Color);
}
else
{
resolution.ArabicName = string.Empty;
resolution.ColoredArabicName = string.Empty;
}
if (resolution.ArabicName != string.Empty) resolution.EnglishAndArabicName = resolution.Name + " (" + resolution.ArabicName + ")";
else resolution.EnglishAndArabicName = resolution.Name;
if (resolution.ColoredArabicName != string.Empty) resolution.ColoredEnglishAndArabicName = resolution.ColoredName + " (" + resolution.ColoredArabicName + ")";
else resolution.ColoredEnglishAndArabicName = resolution.ColoredName;
resolutionList.Add(resolution);
}
}
}
return resolutionList;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
private static List<string> ReservedResolutionColorList
{
get
{
var list = new List<string>();
foreach (XElement y in XDocument.Element("report").Elements("resolution"))
{
if (y.Attribute("color") != null) list.Add(y.Attribute("color").Value);
}
return list;
}
}
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// </summary>
public static Dictionary<string, int> ReportServiceToCountTopNDictionary(int numberOfTopServicesToTake)
{
Dictionary<string, int> dictionary;
using (var db = new Ia.Ngn.Cl.Model.Ngn())
{
/*
select top 100 Service, count(0)
from Reports
where Service like '________'
group by Service
order by count(0) desc
*/
var dictionary0 = (from r in db.Reports
group r.Service by r.Service into g
select new { Service = g.Key, Count = g.Count() }
).ToDictionary(r => r.Service, r => r.Count);
var i = 1;
dictionary = new Dictionary<string, int>();
foreach (var kvp in dictionary0.OrderByDescending(u => u.Value))
{
if (Regex.IsMatch(kvp.Key, @"(\d{8})"))
{
dictionary[kvp.Key] = kvp.Value;
if (i++ >= numberOfTopServicesToTake) break;
}
}
}
return dictionary;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/// <summary>
///
/// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
///
/// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
/// 2. Add "using System.Reflection".
/// 3. Manifest resource stream will start with the project namespace, the location of XML file.
///
/// </summary>
public static XDocument XDocument
{
get
{
if (xDocument == null)
{
lock (objectLock)
{
Assembly _assembly;
StreamReader streamReader;
_assembly = Assembly.GetExecutingAssembly();
streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.report.xml"));
try
{
if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
}
catch (Exception)
{
}
finally
{
}
}
}
return xDocument;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
}