شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Administration

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

Administration support class of Next Generation Network'a (NGN's) business model.

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