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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Ont

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

ONT support class for Next Generation Network (NGN) Nokia data model.

   1:  using Microsoft.EntityFrameworkCore;
   2:  using System;
   3:  using System.Collections;
   4:  using System.Collections.Generic;
   5:  using System.Linq;
   6:  using System.Text;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data.Nokia
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// ONT support class for Next Generation Network (NGN) Nokia data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class Ont
  30:      {
  31:          /// <summary/>
  32:          public Ont() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static bool Create(Ia.Ngn.Cl.Model.Ont ont, out string result)
  40:          {
  41:              bool b;
  42:   
  43:              b = false;
  44:              result = string.Empty;
  45:   
  46:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  47:              {
  48:                  ont.Created = ont.Updated = DateTime.UtcNow.AddHours(3);
  49:   
  50:                  db.Onts.Add(ont);
  51:                  db.SaveChanges();
  52:   
  53:                  b = true;
  54:              }
  55:   
  56:              return b;
  57:          }
  58:   
  59:          ////////////////////////////////////////////////////////////////////////////
  60:   
  61:          /// <summary>
  62:          ///
  63:          /// </summary>
  64:          public static Ia.Ngn.Cl.Model.Ont Read(string id)
  65:          {
  66:              Ia.Ngn.Cl.Model.Ont ont;
  67:   
  68:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  69:              {
  70:                  ont = (from o in db.Onts where o.Id == id select o).Include(o => o.OntServiceVoips).SingleOrDefault();
  71:              }
  72:   
  73:              return ont;
  74:          }
  75:   
  76:          ////////////////////////////////////////////////////////////////////////////
  77:   
  78:          /// <summary>
  79:          ///
  80:          /// </summary>
  81:          public static List<Ia.Ngn.Cl.Model.Ont> List()
  82:          {
  83:              List<Ia.Ngn.Cl.Model.Ont> ontList;
  84:   
  85:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  86:              {
  87:                  ontList = (from o in db.Onts select o).ToList();
  88:              }
  89:   
  90:              return ontList;
  91:          }
  92:   
  93:          ////////////////////////////////////////////////////////////////////////////
  94:   
  95:          /// <summary>
  96:          ///
  97:          /// </summary>
  98:          public static Dictionary<string, string> IdToAccessIdDictionary
  99:          {
 100:              get
 101:              {
 102:                  Dictionary<string, string> dictionary, nullDictionary;
 103:   
 104:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 105:                  {
 106:                      dictionary = (from o in db.Onts where o.Access != null select new { o.Id, o.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 107:   
 108:                      nullDictionary = (from o in db.Onts where o.Access == null select o.Id).ToDictionary(u => u, null);
 109:                  }
 110:   
 111:                  return dictionary.Union(nullDictionary).ToDictionary(u => u.Key, u => u.Value);
 112:              }
 113:          }
 114:   
 115:   
 116:          ////////////////////////////////////////////////////////////////////////////
 117:   
 118:          /// <summary>
 119:          ///
 120:          /// </summary>
 121:          public static Dictionary<string, string> AccessIdToIdDictionary
 122:          {
 123:              get
 124:              {
 125:                  Dictionary<string, string> dictionary, idToAccessIdDictionary;
 126:   
 127:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 128:                  {
 129:                      idToAccessIdDictionary = IdToAccessIdDictionary;
 130:   
 131:                      dictionary = new Dictionary<string, string>(idToAccessIdDictionary.Count);
 132:   
 133:                      foreach (KeyValuePair<string, string> kvp in idToAccessIdDictionary)
 134:                      {
 135:                          if (!dictionary.ContainsKey(kvp.Value)) dictionary[kvp.Value] = kvp.Key;
 136:                      }
 137:                  }
 138:   
 139:                  return dictionary;
 140:              }
 141:          }
 142:   
 143:          ////////////////////////////////////////////////////////////////////////////
 144:   
 145:          /// <summary>
 146:          ///
 147:          /// </summary>
 148:          public static Dictionary<string, string> IdToDescription1ForNonNullAccessDictionary
 149:          {
 150:              get
 151:              {
 152:                  Dictionary<string, string> dictionary;
 153:   
 154:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 155:                  {
 156:                      dictionary = (from s in db.Onts
 157:                                    where s.Access != null
 158:                                    select new
 159:                                    {
 160:                                        s.Id,
 161:                                        s.Description1
 162:                                    }).ToDictionary(u => u.Id, u => u.Description1);
 163:                  }
 164:   
 165:                  return dictionary;
 166:              }
 167:          }
 168:   
 169:          ////////////////////////////////////////////////////////////////////////////
 170:   
 171:          /// <summary>
 172:          ///
 173:          /// </summary>
 174:          public static Dictionary<string, string> IdToDescription1ForNullAccessDictionary
 175:          {
 176:              get
 177:              {
 178:                  Dictionary<string, string> dictionary;
 179:   
 180:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 181:                  {
 182:                      dictionary = (from s in db.Onts
 183:                                    where s.Access == null
 184:                                    select new
 185:                                    {
 186:                                        s.Id,
 187:                                        s.Description1
 188:                                    }).ToDictionary(u => u.Id, u => u.Description1);
 189:                  }
 190:   
 191:                  return dictionary;
 192:              }
 193:          }
 194:   
 195:          ////////////////////////////////////////////////////////////////////////////
 196:   
 197:          /// <summary>
 198:          ///
 199:          /// </summary>
 200:          public static Dictionary<int, int> DistributionOfFamilyTypeIdInOntWhereSerialIsAssignedAndAccessIsNotNullDictionary
 201:          {
 202:              get
 203:              {
 204:                  Dictionary<int, int> dictionary;
 205:   
 206:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 207:                  {
 208:                      var v = (from s in db.Onts where s.Serial != null && s.Serial != "ALCL00000000" && s.Access != null group s by s.FamilyTypeId into g select new { FamilyTypeId = g.Key, Count = g.Count() });
 209:                      dictionary = v.ToDictionary(u => u.FamilyTypeId, u => u.Count);
 210:                  }
 211:   
 212:                  return dictionary;
 213:              }
 214:          }
 215:   
 216:          ////////////////////////////////////////////////////////////////////////////
 217:   
 218:          /// <summary>
 219:          ///
 220:          /// </summary>
 221:          public static Hashtable IdWithNullAccessHashtable
 222:          {
 223:              get
 224:              {
 225:                  List<string> list;
 226:                  Hashtable ht;
 227:   
 228:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 229:                  {
 230:                      list = (from o in db.Onts where o.Access == null select o.Id).ToList();
 231:   
 232:                      if (list.Count > 0)
 233:                      {
 234:                          ht = new Hashtable(list.Count);
 235:   
 236:                          foreach (string s in list) ht[s] = null;
 237:                      }
 238:                      else ht = null;
 239:                  }
 240:   
 241:                  return ht;
 242:              }
 243:          }
 244:   
 245:          ////////////////////////////////////////////////////////////////////////////
 246:   
 247:          /// <summary>
 248:          ///
 249:          /// </summary>
 250:          public static Dictionary<string, string> SerialToIdListDictionary
 251:          {
 252:              get
 253:              {
 254:                  Dictionary<string, string> dictionary;
 255:   
 256:                  dictionary = IdToSerialDictionary.Reverse();
 257:   
 258:                  return dictionary;
 259:              }
 260:          }
 261:   
 262:          ////////////////////////////////////////////////////////////////////////////
 263:   
 264:          /// <summary>
 265:          ///
 266:          /// </summary>
 267:          public static Dictionary<string, string> IdToSerialDictionary
 268:          {
 269:              get
 270:              {
 271:                  Dictionary<string, string> dictionary;
 272:   
 273:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 274:                  {
 275:                      dictionary = (from s in db.Onts
 276:                                    select new
 277:                                    {
 278:                                        s.Id,
 279:                                        s.Serial
 280:                                    }).ToDictionary(u => u.Id, u => u.Serial);
 281:                  }
 282:   
 283:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 284:              }
 285:          }
 286:   
 287:          ////////////////////////////////////////////////////////////////////////////
 288:   
 289:          /// <summary>
 290:          ///
 291:          /// </summary>
 292:          public static List<string> IdList()
 293:          {
 294:              List<string> list;
 295:   
 296:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 297:              {
 298:                  list = (from o in db.Onts select o.Id).ToList();
 299:              }
 300:   
 301:              return list;
 302:          }
 303:   
 304:          ////////////////////////////////////////////////////////////////////////////
 305:   
 306:          /// <summary>
 307:          ///
 308:          /// </summary>
 309:          public static List<string> IdList(int oltId)
 310:          {
 311:              List<string> list;
 312:   
 313:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 314:              {
 315:                  list = (from o in db.Onts where o.Access.Olt == oltId select o.Id).ToList();
 316:              }
 317:   
 318:              return list;
 319:          }
 320:   
 321:          ////////////////////////////////////////////////////////////////////////////
 322:   
 323:          /// <summary>
 324:          ///
 325:          /// </summary>
 326:          public static bool Update(Ia.Ngn.Cl.Model.Ont ont, out string result)
 327:          {
 328:              bool b;
 329:   
 330:              b = false;
 331:              result = string.Empty;
 332:   
 333:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 334:              {
 335:                  ont = (from o in db.Onts where o.Id == ont.Id select o).SingleOrDefault();
 336:   
 337:                  ont.Updated = DateTime.UtcNow.AddHours(3);
 338:   
 339:                  db.Onts.Attach(ont);
 340:   
 341:                  db.Entry(ont).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 342:                  db.SaveChanges();
 343:   
 344:                  b = true;
 345:              }
 346:   
 347:              return b;
 348:          }
 349:   
 350:          ////////////////////////////////////////////////////////////////////////////
 351:   
 352:          /// <summary>
 353:          ///
 354:          /// </summary>
 355:          public static bool NullifyAccessIdByAccessId(string accessId, out string result)
 356:          {
 357:              bool b;
 358:              int numberOfRecordsWhereAccessIsNullified;
 359:              Ia.Ngn.Cl.Model.Ont ont;
 360:   
 361:              b = false;
 362:              numberOfRecordsWhereAccessIsNullified = 0;
 363:   
 364:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 365:              {
 366:                  // --update Onts set Access_Id = null where Access_Id = '1040101010040004'
 367:                  //var query = (from o in db.Onts where o.Access.Id == accessId select o).ToList();
 368:   
 369:                  //foreach (var q in query)
 370:                  //{
 371:                  //ont = (from o in db.Onts where o.Id == q.Id select o).SingleOrDefault();
 372:                  ont = (from o in db.Onts where o.Access.Id == accessId select o).FirstOrDefault(); //.SingleOrDefault();
 373:   
 374:                  if (ont != null)
 375:                  {
 376:                      ont.Access = null;
 377:                      //ont.UserId = userId;
 378:                      ont.Updated = DateTime.UtcNow.AddHours(3);
 379:   
 380:                      db.Onts.Attach(ont);
 381:                      db.Entry(ont).Property(u => u.Updated).IsModified = true;
 382:   
 383:                      db.SaveChanges();
 384:   
 385:                      numberOfRecordsWhereAccessIsNullified++;
 386:                  }
 387:                  //}
 388:   
 389:                  b = true;
 390:              }
 391:   
 392:              result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 393:   
 394:              return b;
 395:          }
 396:   
 397:          ////////////////////////////////////////////////////////////////////////////
 398:   
 399:          /// <summary>
 400:          ///
 401:          /// </summary>
 402:          public static bool Delete(string id, out string result)
 403:          {
 404:              bool b;
 405:   
 406:              b = false;
 407:              result = string.Empty;
 408:   
 409:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 410:              {
 411:                  var v = (from o in db.Onts where o.Id == id select o).FirstOrDefault();
 412:   
 413:                  db.Onts.Remove(v);
 414:                  db.SaveChanges();
 415:   
 416:                  b = true;
 417:              }
 418:   
 419:              return b;
 420:          }
 421:   
 422:          ////////////////////////////////////////////////////////////////////////////
 423:          ////////////////////////////////////////////////////////////////////////////
 424:   
 425:          /// <summary>
 426:          ///
 427:          /// </summary>
 428:          public static string FamilyTypeFromId(int familyTypeId)
 429:          {
 430:              string s;
 431:              Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType familyType;
 432:   
 433:              familyType = (Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType)familyTypeId;
 434:   
 435:              s = familyType.ToString().ToUpper();
 436:   
 437:              return s;
 438:          }
 439:   
 440:          ////////////////////////////////////////////////////////////////////////////
 441:   
 442:          /// <summary>
 443:          ///
 444:          /// </summary>
 445:          public static List<Ia.Ngn.Cl.Model.Ont> List(string serial)
 446:          {
 447:              List<Ia.Ngn.Cl.Model.Ont> list;
 448:   
 449:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 450:              {
 451:                  list = (from o in db.Onts where o.Serial == serial select o).ToList();
 452:              }
 453:   
 454:              return list;
 455:          }
 456:   
 457:          ////////////////////////////////////////////////////////////////////////////
 458:   
 459:          /// <summary>
 460:          ///
 461:          /// </summary>
 462:          public static List<Ia.Ngn.Cl.Model.Ont> List(int oltId)
 463:          {
 464:              List<Ia.Ngn.Cl.Model.Ont> list;
 465:   
 466:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 467:              {
 468:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).ToList();
 469:              }
 470:   
 471:              return list;
 472:          }
 473:   
 474:          ////////////////////////////////////////////////////////////////////////////
 475:   
 476:          /// <summary>
 477:          ///
 478:          /// </summary>
 479:          public static List<Ia.Ngn.Cl.Model.Ont> ReadListIncludeOntServiceVoipsAndAccess(int oltId)
 480:          {
 481:              List<Ia.Ngn.Cl.Model.Ont> list;
 482:   
 483:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 484:              {
 485:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).Include(u => u.OntServiceVoips).ToList();
 486:              }
 487:   
 488:              return list;
 489:          }
 490:   
 491:          ////////////////////////////////////////////////////////////////////////////
 492:   
 493:          /// <summary>
 494:          ///
 495:          /// </summary>
 496:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess()
 497:          {
 498:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 499:   
 500:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 501:              {
 502:                  ontList = (from o in db.Onts select o).Include(u => u.Access).ToList();
 503:              }
 504:   
 505:              return ontList;
 506:          }
 507:   
 508:          ////////////////////////////////////////////////////////////////////////////
 509:   
 510:          /// <summary>
 511:          ///
 512:          /// </summary>
 513:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots()
 514:          {
 515:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 516:   
 517:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 518:              {
 519:                  ontList = (from o in db.Onts select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 520:   
 521:                  /*
 522:                  ontList = (from o in db.Onts 
 523:                             join a in db.Accesses on o.Access equals a 
 524:                             join oop in db.OntOntPotses on o equals oop.Ont select o).ToList();
 525:                   */
 526:              }
 527:   
 528:              return ontList;
 529:          }
 530:   
 531:          ////////////////////////////////////////////////////////////////////////////
 532:   
 533:          /// <summary>
 534:          ///
 535:          /// </summary>
 536:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots(int oltId)
 537:          {
 538:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 539:   
 540:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 541:              {
 542:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 543:              }
 544:   
 545:              return ontList;
 546:          }
 547:   
 548:          ////////////////////////////////////////////////////////////////////////////
 549:   
 550:          /// <summary>
 551:          ///
 552:          /// </summary>
 553:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess(int oltId)
 554:          {
 555:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 556:   
 557:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 558:              {
 559:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).ToList();
 560:              }
 561:   
 562:              return ontList;
 563:          }
 564:   
 565:          ////////////////////////////////////////////////////////////////////////////
 566:   
 567:          /// <summary>
 568:          ///
 569:          /// </summary>
 570:          public static List<Ia.Ngn.Cl.Model.Ont> NonNullAccessList(int oltId)
 571:          {
 572:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 573:   
 574:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 575:              {
 576:                  ontList = (from o in db.Onts where o.Access != null && o.Access.Olt == oltId select o).Include(u => u.Access).ToList();
 577:              }
 578:   
 579:              return ontList;
 580:          }
 581:   
 582:          ////////////////////////////////////////////////////////////////////////////
 583:   
 584:          /// <summary>
 585:          ///
 586:          /// </summary>
 587:          public static List<string> ReadNetworkDesignDocumentAccessNameListWithOntEquipmentIdNotNullAndAccessIsNullIncludeOntServiceVoips
 588:          {
 589:              get
 590:              {
 591:                  Dictionary<string, string> di;
 592:                  List<string> ontNameList;
 593:                  List<Ia.Ngn.Cl.Model.Ont> ontList;
 594:   
 595:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 596:                  {
 597:                      ontList = (from o in db.Onts where o.EquipmentId != null && o.Access == null select o).ToList();
 598:   
 599:                      ontNameList = new List<string>(ontList.Count);
 600:   
 601:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 602:   
 603:                      foreach (var ont in ontList)
 604:                      {
 605:                          if (di.ContainsKey(ont.Id)) ontNameList.Add(di[ont.Id]);
 606:                      }
 607:                  }
 608:   
 609:                  return ontNameList;
 610:              }
 611:          }
 612:   
 613:          ////////////////////////////////////////////////////////////////////////////
 614:          ////////////////////////////////////////////////////////////////////////////
 615:   
 616:          /// <summary>
 617:          ///
 618:          /// </summary>
 619:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Ont ont)
 620:          {
 621:              StringBuilder sb;
 622:   
 623:              sb = new StringBuilder();
 624:   
 625:              //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia.Name);
 626:              sb.AppendLine("State: " + ont.State);
 627:              sb.AppendLine("FamilyType: " + Ia.Ngn.Cl.Model.Data.Nokia.Ont.FamilyTypeFromId(ont.FamilyTypeId));
 628:              sb.AppendLine("Serial: " + ont.Serial);
 629:              sb.AppendLine("EquipmentId: " + ont.EquipmentId);
 630:              sb.AppendLine("ActiveSoftware: " + ont.ActiveSoftware);
 631:              //sb.AppendLine("PassiveSoftware: " + ont.PassiveSoftware);
 632:              sb.AppendLine("PlannedSoftware: " + ont.PlannedSoftware);
 633:              //sb.AppendLine("BatteryBackupAvailable: " + ont.BatteryBackupAvailable);
 634:              sb.AppendLine("Description1: " + ont.Description1);
 635:              sb.AppendLine("Description2: " + ont.Description2);
 636:   
 637:              return sb.ToString();
 638:          }
 639:   
 640:          ////////////////////////////////////////////////////////////////////////////
 641:          ////////////////////////////////////////////////////////////////////////////
 642:      }
 643:   
 644:      ////////////////////////////////////////////////////////////////////////////
 645:      ////////////////////////////////////////////////////////////////////////////
 646:  }