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

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("07:00");
  33:          /// <summary/>
  34:          public static DateTime OfficialMorningEndOfWorkTime = DateTime.Parse("14:00");
  35:          /// <summary/>
  36:          public static DateTime OfficialEveningStartOfWorkTime = DateTime.Parse("16:00");
  37:          /// <summary/>
  38:          public static DateTime OfficialEveningEndOfWorkTime = 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:              /// <summary/>
  63:              public int Id { get; set; }
  64:   
  65:              /// <summary/>
  66:              public int Level { get; set; }
  67:   
  68:              /// <summary/>
  69:              public Guid Guid { get; set; }
  70:   
  71:              /// <summary/>
  72:              public string Type { get; set; }
  73:   
  74:              /// <summary/>
  75:              public string Name { get; set; }
  76:   
  77:              /// <summary/>
  78:              public string ArabicName { get; set; }
  79:   
  80:              /// <summary/>
  81:              public string ColoredArabicName { get; set; }
  82:   
  83:              /// <summary/>
  84:              public Framework Parent { get; set; }
  85:   
  86:              /// <summary/>
  87:              public List<Framework> Ancestors { get; set; }
  88:   
  89:              /// <summary/>
  90:              public List<Framework> Siblings { get; set; }
  91:   
  92:              /// <summary/>
  93:              public List<Framework> Children { get; set; }
  94:   
  95:              /// <summary/>
  96:              public List<Framework> Descendants { get; set; }
  97:   
  98:              /// <summary/>
  99:              public List<Authority> Authorities { get; set; }
 100:   
 101:              /// <summary/>
 102:              public List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site> Sites { get; set; }
 103:   
 104:              /// <summary/>
 105:              //public Ia.Cl.Model.Identity.User Role { get; set; }
 106:   
 107:              ////////////////////////////////////////////////////////////////////////////    
 108:   
 109:              /// <summary>
 110:              ///
 111:              /// </summary>
 112:              public static bool operator ==(Framework fa, Framework fb)
 113:              {
 114:                  bool b;
 115:   
 116:                  // if both are null, or both are same instance, return true.
 117:                  if (System.Object.ReferenceEquals(fa, fb)) b = true;
 118:                  // if one is null, but not both, return false.
 119:                  else if (((object)fa == null) || ((object)fb == null)) b = false;
 120:                  // true if the fields match:
 121:                  else b = fa.Id == fb.Id;
 122:   
 123:                  return b;
 124:              }
 125:   
 126:              ////////////////////////////////////////////////////////////////////////////    
 127:   
 128:              /// <summary>
 129:              ///
 130:              /// </summary>
 131:              public static bool operator !=(Framework fa, Framework fb)
 132:              {
 133:                  return !(fa == fb);
 134:              }
 135:   
 136:              ////////////////////////////////////////////////////////////////////////////    
 137:   
 138:              /// <summary>
 139:              ///
 140:              /// </summary>
 141:              public string FullyQualifiedArabicName
 142:              {
 143:                  get
 144:                  {
 145:                      string s;
 146:   
 147:                      s = string.Empty;
 148:   
 149:                      foreach (var f in this.Ancestors) s += f.ArabicName + " | ";
 150:   
 151:                      s = s + this.ArabicName;
 152:   
 153:                      return s;
 154:                  }
 155:              }
 156:   
 157:              ////////////////////////////////////////////////////////////////////////////
 158:   
 159:              /// <summary>
 160:              ///
 161:              /// </summary>
 162:              public override bool Equals(object value)
 163:              {
 164:                  return value != null && Equals(value as Framework);
 165:              }
 166:   
 167:              ////////////////////////////////////////////////////////////////////////////    
 168:   
 169:              /// <summary>
 170:              ///
 171:              /// </summary>
 172:              public int FrameworkId(int parentId, int frameworkId)
 173:              {
 174:                  return parentId * 10 + frameworkId;
 175:              }
 176:   
 177:              ////////////////////////////////////////////////////////////////////////////    
 178:   
 179:              /// <summary>
 180:              ///
 181:              /// </summary>
 182:              public static int ParentId(long frameworkId)
 183:              {
 184:                  int i;
 185:                  string s;
 186:   
 187:                  s = frameworkId.ToString();
 188:   
 189:                  if (s.Length > 2)
 190:                  {
 191:                      s = s.Substring(0, s.Length - 2);
 192:   
 193:                      i = (int.TryParse(s, out i)) ? i : 0;
 194:                  }
 195:                  else i = 0;
 196:   
 197:                  return i;
 198:              }
 199:   
 200:              ////////////////////////////////////////////////////////////////////////////    
 201:   
 202:              /// <summary>
 203:              ///
 204:              /// </summary>
 205:              public string ArabicNameBracketParentArabicNameBracket
 206:              {
 207:                  get
 208:                  {
 209:                      string name;
 210:   
 211:                      name = ArabicName + " (" + Parent.ArabicName + ")";
 212:   
 213:                      return name;
 214:                  }
 215:              }
 216:   
 217:              ////////////////////////////////////////////////////////////////////////////    
 218:              ////////////////////////////////////////////////////////////////////////////    
 219:          }
 220:   
 221:          ////////////////////////////////////////////////////////////////////////////
 222:   
 223:          /// <summary>
 224:          ///
 225:          /// </summary>
 226:          public class Category
 227:          {
 228:              /// <summary/>
 229:              public Category() { }
 230:              /// <summary/>
 231:              public string Name { get; set; }
 232:              /// <summary/>
 233:              public string Description { get; set; }
 234:              /// <summary/>
 235:              public string Regex { get; set; }
 236:              /// <summary/>
 237:              public string Color { get; set; }
 238:          }
 239:   
 240:          ////////////////////////////////////////////////////////////////////////////
 241:   
 242:          /// <summary>
 243:          ///
 244:          /// </summary>
 245:          public class StaffFramework
 246:          {
 247:              private bool isStaff;
 248:   
 249:              /// <summary/>
 250:              public StaffFramework() { }
 251:              /// <summary/>
 252:              public Guid Guid { get; set; }
 253:              /// <summary/>
 254:              public long FrameworkId { get; set; }
 255:              /// <summary/>
 256:              public string Name { get; set; }
 257:              /// <summary/>
 258:              public bool IsStaff
 259:              {
 260:                  get { return isStaff; }
 261:                  set { isStaff = true; }
 262:              }
 263:              /// <summary/>
 264:              public bool IsFramework
 265:              {
 266:                  get { return !isStaff; }
 267:                  set { isStaff = false; }
 268:              }
 269:          }
 270:   
 271:   
 272:          ////////////////////////////////////////////////////////////////////////////
 273:          ////////////////////////////////////////////////////////////////////////////
 274:   
 275:          /// <summary>
 276:          ///
 277:          /// </summary>
 278:          public class Statistic
 279:          {
 280:              /// <summary/>
 281:              public Statistic() { }
 282:   
 283:              public class Site
 284:              {
 285:                  /// <summary/>
 286:                  public string Id { get; set; }
 287:                  /// <summary/>
 288:                  public string Name { get; set; }
 289:                  /// <summary/>
 290:                  public string Symbol { get; set; }
 291:                  /// <summary/>
 292:                  public string KuwaitAreaNameListString { get; set; }
 293:                  /// <summary/>
 294:                  public string DomainListString { get; set; }
 295:                  /// <summary/>
 296:                  public string SymbolListString { get; set; }
 297:   
 298:                  /// <summary/>
 299:                  public int SiteAccessCapacity { get; set; }
 300:   
 301:                  /// <summary/>
 302:                  public int NddOntNokiaAccessCount { get; set; }
 303:                  /// <summary/>
 304:                  public int NddOntHuaweiAccessCount { get; set; }
 305:                  /// <summary/>
 306:                  public int NddOntAccessCount { get; set; }
 307:   
 308:                  /// <summary/>
 309:                  public int AccessCapacity { get; set; }
 310:                  /// <summary/>
 311:                  public int AccessInstalledContractor { get; set; }
 312:                  /// <summary/>
 313:                  public int AccessInstalledContractorWithSerial { get; set; }
 314:                  /// <summary/>
 315:                  public int AccessProvisioned { get; set; }
 316:                  /// <summary/>
 317:                  public int AccessReadyForService { get; set; }
 318:                  /// <summary/>
 319:                  public int AccessDefinedInCustomerDepartment { get; set; }
 320:                  /// <summary/>
 321:                  public int AccessUtilized { get; set; }
 322:                  /// <summary/>
 323:                  public int AccessUtilizedNoService { get; set; }
 324:                  /// <summary/>
 325:                  public int AccessUtilizedOneService { get; set; }
 326:                  /// <summary/>
 327:                  public int AccessUtilizedTwoServices { get; set; }
 328:                  /// <summary/>
 329:                  public int AccessUtilizedThreeServices { get; set; }
 330:                  /// <summary/>
 331:                  public int AccessUtilizedFourServices { get; set; }
 332:                  /// <summary/>
 333:                  public int AccessUtilizedFiveOrMoreServices { get; set; }
 334:   
 335:                  /// <summary/>
 336:                  public int ServiceCapacity { get; set; }
 337:   
 338:                  /// <summary/>
 339:                  public int Service { get; set; }
 340:                  /// <summary/>
 341:                  public int NokiaService { get; set; }
 342:                  /// <summary/>
 343:                  public int HuaweiService { get; set; }
 344:                  /// <summary/>
 345:                  public string NokiaHuaweiService { get; set; }
 346:   
 347:                  ////////////////////////////////////////////////////////////////////////////
 348:   
 349:                  /// <summary>
 350:                  ///
 351:                  /// </summary>
 352:                  public string ToSimpleTextString()
 353:                  {
 354:                      string per;
 355:   
 356:                      StringBuilder sb;
 357:   
 358:                      sb = new StringBuilder();
 359:   
 360:                      per = (this.Service != 0) ? "%" + (int)(100 * ((float)(this.Service) / (float)(this.ServiceCapacity))) : per = "%";
 361:   
 362:                      sb.AppendLine("Site: " + this.Name);
 363:                      sb.AppendLine("Areas: " + this.KuwaitAreaNameListString);
 364:                      sb.AppendLine("Symbols: " + this.SymbolListString);
 365:                      sb.AppendLine("Access Capacity: " + this.AccessCapacity);
 366:                      sb.AppendLine("Service Capacity: " + this.ServiceCapacity);
 367:                      sb.AppendLine("Service (Nokia/Huawei): " + this.NokiaHuaweiService + " (" + per + ")");
 368:   
 369:                      return sb.ToString();
 370:                  }
 371:   
 372:                  ////////////////////////////////////////////////////////////////////////////
 373:                  ////////////////////////////////////////////////////////////////////////////
 374:              }
 375:   
 376:              public class KuwaitArea
 377:              {
 378:                  /// <summary/>
 379:                  public KuwaitArea() { }
 380:   
 381:                  /// <summary/>
 382:                  public KuwaitArea(string name, string arabicName)
 383:                  {
 384:                      this.Name = name + " (" + arabicName + ")";
 385:                  }
 386:   
 387:                  /// <summary/>
 388:                  public string Id { get; set; }
 389:   
 390:                  /// <summary/>
 391:                  public string Name { get; set; }
 392:   
 393:                  /// <summary/>
 394:                  public string Symbol { get; set; }
 395:   
 396:                  /// <summary/>
 397:                  public int AccessCapacity { get; set; }
 398:   
 399:                  /// <summary/>
 400:   
 401:                  public int NokiaOnt { get; set; }
 402:                  /// <summary/>
 403:   
 404:                  public int HuaweiOnt { get; set; }
 405:                  /// <summary/>
 406:   
 407:                  public string NokiaHuaweiOnt { get; set; }
 408:   
 409:                  /// <summary/>
 410:                  public int NokiaAccess { get; set; }
 411:   
 412:                  /// <summary/>
 413:                  public int HuaweiAccess { get; set; }
 414:   
 415:                  /// <summary/>
 416:                  public string NokiaHuaweiAccess { get; set; }
 417:   
 418:                  /// <summary/>
 419:                  public int ServiceRequestService { get; set; }
 420:   
 421:                  /// <summary/>
 422:                  public int Service { get; set; }
 423:   
 424:                  /// <summary/>
 425:                  public int NokiaService { get; set; }
 426:   
 427:                  /// <summary/>
 428:                  public int HuaweiService { get; set; }
 429:   
 430:                  /// <summary/>
 431:                  public string NokiaHuaweiService { get; set; }
 432:   
 433:                  /// <summary/>
 434:                  public int AccessReadyForService { get; set; }
 435:   
 436:                  ////////////////////////////////////////////////////////////////////////////
 437:   
 438:                  /// <summary>
 439:                  ///
 440:                  /// </summary>
 441:                  public string ToSimpleTextString()
 442:                  {
 443:                      StringBuilder sb;
 444:   
 445:                      sb = new StringBuilder();
 446:   
 447:                      sb.AppendLine("Name: " + this.Name);
 448:                      sb.AppendLine("Symbol: " + this.Symbol);
 449:                      sb.AppendLine("Access Capacity: " + this.AccessCapacity);
 450:                      sb.AppendLine("Access (Nokia/Huawei): " + this.NokiaHuaweiAccess);
 451:                      sb.AppendLine("ONT/ONU (Nokia/Huawei): " + this.NokiaHuaweiOnt);
 452:                      sb.AppendLine("Access ready for service: " + this.AccessReadyForService);
 453:                      sb.AppendLine("Service Request Services: " + this.ServiceRequestService);
 454:                      sb.AppendLine("Service (Nokia/Huawei): " + this.NokiaHuaweiService);
 455:   
 456:                      return sb.ToString();
 457:                  }
 458:   
 459:                  ////////////////////////////////////////////////////////////////////////////
 460:                  ////////////////////////////////////////////////////////////////////////////
 461:              }
 462:          }
 463:   
 464:          ////////////////////////////////////////////////////////////////////////////
 465:   
 466:          /// <summary>
 467:          ///
 468:          /// </summary>
 469:          public Administration() { }
 470:   
 471:          /// <summary/>
 472:          public static bool NowIsOfficialWorkingTime
 473:          {
 474:              get
 475:              {
 476:                  bool b;
 477:                  DateTime now;
 478:   
 479:                  now = DateTime.UtcNow.AddHours(3);
 480:   
 481:                  b = now.DayOfWeek != DayOfWeek.Friday && now.DayOfWeek != DayOfWeek.Saturday &&
 482:                      (
 483:                      now.TimeOfDay >= OfficialMorningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialMorningEndOfWorkTime.TimeOfDay
 484:                      ||
 485:                      now.TimeOfDay >= OfficialEveningStartOfWorkTime.TimeOfDay && now.TimeOfDay < OfficialEveningEndOfWorkTime.TimeOfDay
 486:                      );
 487:   
 488:                  return b;
 489:              }
 490:          }
 491:   
 492:          ////////////////////////////////////////////////////////////////////////////    
 493:   
 494:          /// <summary>
 495:          /// 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
 496:          /// </summary>
 497:          public static bool IsFrameworkGuid(Guid guid)
 498:          {
 499:              bool isFrameworkGuid;
 500:   
 501:              isFrameworkGuid = (guid.ToString().Substring(0, 9) == "00000000-") ? true : false;
 502:   
 503:              return isFrameworkGuid;
 504:          }
 505:   
 506:          ////////////////////////////////////////////////////////////////////////////    
 507:   
 508:          /// <summary>
 509:          ///
 510:          /// </summary>
 511:          public static List<Ia.Ngn.Cl.Model.Business.Administration.Framework> FrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Staff staff)
 512:          {
 513:              List<Ia.Ngn.Cl.Model.Business.Administration.Framework> frameworkList;
 514:   
 515:              frameworkList = new List<Ia.Ngn.Cl.Model.Business.Administration.Framework>();
 516:   
 517:              frameworkList.AddRange(staff.Framework.Children);
 518:              frameworkList.AddRange(staff.Framework.Siblings);
 519:   
 520:              return frameworkList;
 521:          }
 522:   
 523:          ////////////////////////////////////////////////////////////////////////////    
 524:   
 525:          /// <summary>
 526:          ///
 527:          /// </summary>
 528:          public static bool FrameworkHasAHead(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 529:          {
 530:              bool hasHead;
 531:   
 532:              if (framework != null)
 533:              {
 534:                  hasHead = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.Framework.Id == framework.Id select s).Any(u => u.IsHead);
 535:              }
 536:              else hasHead = false;
 537:   
 538:              return hasHead;
 539:          }
 540:   
 541:          ////////////////////////////////////////////////////////////////////////////
 542:   
 543:          /// <summary>
 544:          ///
 545:          /// </summary>
 546:          public class StaffContact
 547:          {
 548:              private Ia.Ngn.Cl.Model.Staff staff;
 549:              private Ia.Ngn.Cl.Model.Contact contact;
 550:              private string email;
 551:              private string apiKey;
 552:              private Guid userId;
 553:   
 554:              /// <summary/>
 555:              public StaffContact() { }
 556:   
 557:              /// <summary/>
 558:              public Ia.Ngn.Cl.Model.Staff Staff
 559:              {
 560:                  get
 561:                  {
 562:                      return staff;
 563:                  }
 564:   
 565:                  set
 566:                  {
 567:                      staff = value;
 568:   
 569:                      var v = this.FullName;
 570:                      var w = this.Email;
 571:                      var x = this.UserId;
 572:                      var y = this.ApiKey;
 573:                  }
 574:              }
 575:   
 576:              /// <summary/>
 577:              public Ia.Ngn.Cl.Model.Contact Contact
 578:              {
 579:                  get
 580:                  {
 581:                      return contact;
 582:                  }
 583:   
 584:                  set
 585:                  {
 586:                      contact = value;
 587:   
 588:                      var v = this.FullName;
 589:                      var w = this.Email;
 590:                      var x = this.UserId;
 591:                      var y = this.ApiKey;
 592:                  }
 593:              }
 594:   
 595:              /// <summary/>
 596:              public string FullName
 597:              {
 598:                  get
 599:                  {
 600:                      string name;
 601:   
 602:                      if (staff != null) name = staff.FullName;
 603:                      else if (contact != null) name = contact.FullName;
 604:                      else name = string.Empty;
 605:   
 606:                      return name;
 607:                  }
 608:              }
 609:   
 610:              /// <summary/>
 611:              public string Email
 612:              {
 613:                  get
 614:                  {
 615:                      if (staff != null && staff.User != null) email = staff.User.Email;
 616:                      else if (contact != null) email = contact.Email;
 617:                      else email = string.Empty;
 618:   
 619:                      return email;
 620:                  }
 621:              }
 622:   
 623:              /// <summary/>
 624:              public Guid UserId
 625:              {
 626:                  get
 627:                  {
 628:                      if (staff != null) userId = staff.UserId;
 629:                      else if (contact != null) userId = contact.UserId;
 630:                      else userId = Guid.Empty;
 631:   
 632:                      return userId;
 633:                  }
 634:              }
 635:   
 636:              /// <summary/>
 637:              public string ApiKey
 638:              {
 639:                  get
 640:                  {
 641:                      if (staff != null && staff.User != null) apiKey = UserId.ToString().Substring(0, 8);
 642:                      else if (contact != null) apiKey = UserId.ToString().Substring(0, 8);
 643:                      else apiKey = string.Empty;
 644:   
 645:                      return apiKey;
 646:                  }
 647:              }
 648:   
 649:              /// <summary/>
 650:              public bool IsApproved
 651:              {
 652:                  get
 653:                  {
 654:                      return !string.IsNullOrEmpty(email); // && contact.IsApproved;
 655:                  }
 656:              }
 657:   
 658:              ////////////////////////////////////////////////////////////////////////////
 659:              ////////////////////////////////////////////////////////////////////////////    
 660:          }
 661:      }
 662:   
 663:      ////////////////////////////////////////////////////////////////////////////
 664:      ////////////////////////////////////////////////////////////////////////////   
 665:  }