1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4:
5: namespace Ia.Ngn.Cl.Model.Business
6: {
7: ////////////////////////////////////////////////////////////////////////////
8:
9: /// <summary publish="true">
10: /// Administration support class of Next Generation Network'a (NGN's) business model.
11: /// </summary>
12: ///
13: /// <remarks>
14: /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
15: ///
16: /// 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
17: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
18: ///
19: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21: ///
22: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
23: ///
24: /// Copyright notice: This notice may not be removed or altered from any source distribution.
25: /// </remarks>
26: public class Administration
27: {
28: private const int initialFrameworkListLength = 100;
29:
30: /// <summary/>
31: public static DateTime OfficialMorningStartOfWorkTime = DateTime.Parse("07:00");
32: /// <summary/>
33: public static DateTime OfficialMorningEndOfWorkTime = DateTime.Parse("14:00");
34: /// <summary/>
35: public static DateTime OfficialEveningStartOfWorkTime = DateTime.Parse("16:00");
36: /// <summary/>
37: public static DateTime OfficialEveningEndOfWorkTime = DateTime.Parse("20:00");
38:
39: /// <summary/>
40: public static DateTime EarliestServiceRequestDate = DateTime.Parse("2000-01-01");
41:
42: /// <summary/>
43: public static DateTime SqlFriendlyJanuary1st1753NullDateTime = new DateTime(1753, 1, 1);
44:
45: /// <summary/>
46: public static DateTime EarliestRequestDateTime = new DateTime(1970, 1, 1);
47:
48: /// <summary/>
49: public static int InitialFrameworkListLength { get { return initialFrameworkListLength; } }
50:
51:
52: ////////////////////////////////////////////////////////////////////////////
53:
54: /// <summary>
55: ///
56: /// </summary>
57: public class Framework
58: {
59: public Framework() { }
60:
61: /// <summary/>
62: public int Id { get; set; }
63: /// <summary/>
64: public int Level { get; set; }
65: /// <summary/>
66: public Guid Guid { get; set; }
67: /// <summary/>
68: public string Type { get; set; }
69: /// <summary/>
70: public string Name { get; set; }
71: /// <summary/>
72: public string ArabicName { get; set; }
73: /// <summary/>
74: public string ColoredArabicName { get; set; }
75: /// <summary/>
76: public Framework Parent { get; set; }
77: /// <summary/>
78: public List<Framework> Ancestors { get; set; }
79: /// <summary/>
80: public List<Framework> Siblings { get; set; }
81: /// <summary/>
82: public List<Framework> Children { get; set; }
83: /// <summary/>
84: public List<Framework> Descendants { get; set; }
85: /// <summary/>
86: public List<Authority> Authorities { get; set; }
87:
88: /// <summary/>
89: public Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site Site { get; set; }
90:
91: /// <summary/>
92: //public Ia.Cl.Model.Identity.User Role { get; set; }
93:
94: /// <summary/>
95: public static bool operator ==(Framework fa, Framework fb)
96: {
97: bool b;
98:
99: // if both are null, or both are same instance, return true.
100: if (System.Object.ReferenceEquals(fa, fb)) b = true;
101: // if one is null, but not both, return false.
102: else if (((object)fa == null) || ((object)fb == null)) b = false;
103: // true if the fields match:
104: else b = fa.Id == fb.Id;
105:
106: return b;
107: }
108:
109: /// <summary/>
110: public static bool operator !=(Framework fa, Framework fb)
111: {
112: return !(fa == fb);
113: }
114:
115: /// <summary/>
116: public string FullyQualifiedArabicName
117: {
118: get
119: {
120: string s;
121:
122: s = string.Empty;
123:
124: foreach (var f in this.Ancestors) s += f.ArabicName + " | ";
125:
126: s = s + this.ArabicName;
127:
128: return s;
129: }
130: }
131:
132: ////////////////////////////////////////////////////////////////////////////
133:
134: /// <summary>
135: ///
136: /// </summary>
137: public override bool Equals(object value)
138: {
139: return value != null && Equals(value as Framework);
140: }
141:
142: /// <summary/>
143: public int FrameworkId(int parentId, int frameworkId)
144: {
145: return parentId * 10 + frameworkId;
146: }
147:
148: /// <summary/>
149: public static int ParentId(long frameworkId)
150: {
151: int i;
152: string s;
153:
154: s = frameworkId.ToString();
155:
156: if (s.Length > 2)
157: {
158: s = s.Substring(0, s.Length - 2);
159:
160: i = (int.TryParse(s, out i)) ? i : 0;
161: }
162: else i = 0;
163:
164: return i;
165: }
166: }
167:
168: ////////////////////////////////////////////////////////////////////////////
169:
170: /// <summary>
171: ///
172: /// </summary>
173: public class Category
174: {
175: /// <summary/>
176: public Category() { }
177: /// <summary/>
178: public string Name { get; set; }
179: /// <summary/>
180: public string Description { get; set; }
181: /// <summary/>
182: public string Regex { get; set; }
183: /// <summary/>
184: public string Color { get; set; }
185: }
186:
187: ////////////////////////////////////////////////////////////////////////////
188:
189: /// <summary>
190: ///
191: /// </summary>
192: public class StaffFramework
193: {
194: private bool isStaff;
195:
196: /// <summary/>
197: public StaffFramework() { }
198: /// <summary/>
199: public Guid Guid { get; set; }
200: /// <summary/>
201: public long FrameworkId { get; set; }
202: /// <summary/>
203: public string Name { get; set; }
204: /// <summary/>
205: public bool IsStaff
206: {
207: get { return isStaff; }
208: set { isStaff = true; }
209: }
210: /// <summary/>
211: public bool IsFramework
212: {
213: get { return !isStaff; }
214: set { isStaff = false; }
215: }
216: }
217:
218:
219: ////////////////////////////////////////////////////////////////////////////
220: ////////////////////////////////////////////////////////////////////////////
221:
222: /// <summary>
223: ///
224: /// </summary>
225: public class Statistic
226: {
227: /// <summary/>
228: public Statistic() { }
229:
230: public class Site
231: {
232: /// <summary/>
233: public string Id { get; set; }
234: /// <summary/>
235: public string Name { get; set; }
236: /// <summary/>
237: public string Symbol { get; set; }
238: /// <summary/>
239: public string KuwaitAreaNameListString { get; set; }
240: /// <summary/>
241: public string DomainListString { get; set; }
242: /// <summary/>
243: public string SymbolListString { get; set; }
244:
245: /// <summary/>
246: public int SiteAccessCapacity { get; set; }
247:
248: /// <summary/>
249: public int NddOntNokiaAccessCount { get; set; }
250: /// <summary/>
251: public int NddOntHuaweiAccessCount { get; set; }
252: /// <summary/>
253: public int NddOntAccessCount { get; set; }
254:
255:
256:
257: /// <summary/>
258: public int AccessCapacity { get; set; }
259: /// <summary/>
260: public int AccessInstalledContractor { get; set; }
261: /// <summary/>
262: public int AccessInstalledContractorWithSerial { get; set; }
263: /// <summary/>
264: public int AccessProvisioned { get; set; }
265: /// <summary/>
266: public int AccessReadyForService { get; set; }
267: /// <summary/>
268: public int AccessDefinedInCustomerDepartment { get; set; }
269: /// <summary/>
270: public int AccessUtilized { get; set; }
271: /// <summary/>
272: public int AccessUtilizedNoService { get; set; }
273: /// <summary/>
274: public int AccessUtilizedOneService { get; set; }
275: /// <summary/>
276: public int AccessUtilizedTwoServices { get; set; }
277: /// <summary/>
278: public int AccessUtilizedThreeServices { get; set; }
279: /// <summary/>
280: public int AccessUtilizedFourServices { get; set; }
281: /// <summary/>
282: public int AccessUtilizedFiveOrMoreServices { get; set; }
283:
284: /// <summary/>
285: public int ServiceCapacity { get; set; }
286: public int ServiceCount { get; set; }
287:
288: ////////////////////////////////////////////////////////////////////////////
289:
290: /// <summary>
291: ///
292: /// </summary>
293: public string ToSimpleTextString()
294: {
295: string per;
296:
297: StringBuilder sb;
298:
299: sb = new StringBuilder();
300:
301: per = (this.ServiceCount != 0) ? "%" + (int)(100 * ((float)(this.ServiceCount) / (float)(this.ServiceCapacity))) : per = "%";
302:
303: sb.AppendLine("Site: " + this.Name);
304: sb.AppendLine("Areas: " + this.KuwaitAreaNameListString);
305: sb.AppendLine("Symbols: " + this.SymbolListString);
306: sb.AppendLine("Access Capacity: " + this.AccessCapacity);
307: sb.AppendLine("Service Capacity: " + this.ServiceCapacity);
308: sb.AppendLine("Service Count: " + this.ServiceCount + " (" + per + ")");
309:
310: return sb.ToString();
311: }
312:
313: ////////////////////////////////////////////////////////////////////////////
314: ////////////////////////////////////////////////////////////////////////////
315: }
316:
317: public class KuwaitArea
318: {
319: /// <summary/>
320: public KuwaitArea() { }
321:
322: /// <summary/>
323: public KuwaitArea(string name, string arabicName)
324: {
325: this.Name = name + " (" + arabicName + ")";
326: }
327:
328: /// <summary/>
329: public string Id { get; set; }
330: /// <summary/>
331: public string Name { get; set; }
332: /// <summary/>
333: public string Symbol { get; set; }
334:
335: /// <summary/>
336: public int AccessCapacity { get; set; }
337:
338: /// <summary/>
339: public int NokiaOnt { get; set; }
340: /// <summary/>
341: public int HuaweiOnt { get; set; }
342: /// <summary/>
343: public string OntTotalNokiaHuawei { get; set; }
344:
345: /// <summary/>
346: public int NokiaAccess { get; set; }
347: /// <summary/>
348: public int HuaweiAccess { get; set; }
349: /// <summary/>
350: public string AccessTotalNokiaHuawei { get; set; }
351:
352: /// <summary/>
353: public int ServiceRequestService { get; set; }
354: /// <summary/>
355: public int Service { get; set; }
356: /// <summary/>
357: public string ServiceRequestServiceService { get; set; }
358:
359: /// <summary/>
360: public int AccessReadyForService { get; set; }
361:
362: ////////////////////////////////////////////////////////////////////////////
363:
364: /// <summary>
365: ///
366: /// </summary>
367: public string ToSimpleTextString()
368: {
369: StringBuilder sb;
370:
371: sb = new StringBuilder();
372:
373: sb.AppendLine("Name: " + this.Name);
374: sb.AppendLine("Symbol: " + this.Symbol);
375: sb.AppendLine("Access Capacity: " + this.AccessCapacity);
376: sb.AppendLine("Access (Nokia/Huawei): " + this.AccessTotalNokiaHuawei);
377: sb.AppendLine("ONT/ONU (Nokia/Huawei): " + this.OntTotalNokiaHuawei);
378: sb.AppendLine("Access ready for service: " + this.AccessReadyForService);
379: sb.AppendLine("Services (installed): " + this.ServiceRequestServiceService);
380:
381: return sb.ToString();
382: }
383:
384: ////////////////////////////////////////////////////////////////////////////
385: ////////////////////////////////////////////////////////////////////////////
386: }
387:
388: }
389:
390: ////////////////////////////////////////////////////////////////////////////
391:
392: /// <summary>
393: ///
394: /// </summary>
395: public Administration() { }
396:
397: /// <summary/>
398: public static bool NowIsOfficialWorkingTime
399: {
400: get
401: {
402: bool b;
403: DateTime now;
404:
405: now = DateTime.UtcNow.AddHours(3);
406:
407: b = now.DayOfWeek != DayOfWeek.Friday && now.DayOfWeek != DayOfWeek.Saturday &&
408: (
409: now.TimeOfDay >= OfficialMorningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialMorningEndOfWorkTime.TimeOfDay
410: ||
411: now.TimeOfDay >= OfficialEveningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialEveningEndOfWorkTime.TimeOfDay
412: );
413:
414: return b;
415: }
416: }
417:
418: ////////////////////////////////////////////////////////////////////////////
419:
420: /// <summary>
421: /// Tests a given Guid value to see if it has a special format used in framework items. Framework ites will have 00000000- prefixed to them
422: /// </summary>
423: public static bool IsFrameworkGuid(Guid guid)
424: {
425: bool isFrameworkGuid;
426:
427: isFrameworkGuid = (guid.ToString().Substring(0, 9) == "00000000-") ? true : false;
428:
429: return isFrameworkGuid;
430: }
431:
432: ////////////////////////////////////////////////////////////////////////////
433:
434: /// <summary>
435: ///
436: /// </summary>
437: public static List<Ia.Ngn.Cl.Model.Business.Administration.Framework> FrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Staff staff)
438: {
439: List<Ia.Ngn.Cl.Model.Business.Administration.Framework> frameworkList;
440:
441: frameworkList = new List<Ia.Ngn.Cl.Model.Business.Administration.Framework>();
442:
443: frameworkList.AddRange(staff.Framework.Children);
444: frameworkList.AddRange(staff.Framework.Siblings);
445:
446: return frameworkList;
447: }
448:
449: ////////////////////////////////////////////////////////////////////////////
450:
451: /// <summary>
452: ///
453: /// </summary>
454: public class StaffContact
455: {
456: private Ia.Ngn.Cl.Model.Staff staff;
457: private Ia.Ngn.Cl.Model.Contact contact;
458: private string email;
459: private string apiKey;
460: private Guid userId;
461:
462: /// <summary/>
463: public StaffContact() { }
464:
465: /// <summary/>
466: public Ia.Ngn.Cl.Model.Staff Staff
467: {
468: get
469: {
470: return staff;
471: }
472:
473: set
474: {
475: staff = value;
476:
477: var v = this.FullName;
478: var w = this.Email;
479: var x = this.UserId;
480: var y = this.ApiKey;
481: }
482: }
483:
484: /// <summary/>
485: public Ia.Ngn.Cl.Model.Contact Contact
486: {
487: get
488: {
489: return contact;
490: }
491:
492: set
493: {
494: contact = value;
495:
496: var v = this.FullName;
497: var w = this.Email;
498: var x = this.UserId;
499: var y = this.ApiKey;
500: }
501: }
502:
503: /// <summary/>
504: public string FullName
505: {
506: get
507: {
508: string name;
509:
510: if (staff != null) name = staff.FullName;
511: else if (contact != null) name = contact.FullName;
512: else name = string.Empty;
513:
514: return name;
515: }
516: }
517:
518: /// <summary/>
519: public string Email
520: {
521: get
522: {
523: if (staff != null && staff.User != null) email = staff.User.Email;
524: else if (contact != null) email = contact.Email;
525: else email = string.Empty;
526:
527: return email;
528: }
529: }
530:
531: /// <summary/>
532: public Guid UserId
533: {
534: get
535: {
536: if (staff != null) userId = staff.UserId;
537: else if (contact != null) userId = contact.UserId;
538: else userId = Guid.Empty;
539:
540: return userId;
541: }
542: }
543:
544: /// <summary/>
545: public string ApiKey
546: {
547: get
548: {
549: if (staff != null && staff.User != null) apiKey = UserId.ToString().Substring(0, 8);
550: else if (contact != null) apiKey = UserId.ToString().Substring(0, 8);
551: else apiKey = string.Empty;
552:
553: return apiKey;
554: }
555: }
556:
557: /// <summary/>
558: public bool IsApproved
559: {
560: get
561: {
562: return !string.IsNullOrEmpty(email); // && contact.IsApproved;
563: }
564: }
565:
566: ////////////////////////////////////////////////////////////////////////////
567: ////////////////////////////////////////////////////////////////////////////
568: }
569: }
570:
571: ////////////////////////////////////////////////////////////////////////////
572: ////////////////////////////////////////////////////////////////////////////
573: }