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

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 System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Data.Entity;
   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), Internet 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 = System.Data.Entity.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:   
 378:                      db.Onts.Attach(ont);
 379:                      db.Entry(ont).State = System.Data.Entity.EntityState.Modified;
 380:   
 381:                      db.SaveChanges();
 382:   
 383:                      numberOfRecordsWhereAccessIsNullified++;
 384:                  }
 385:                  //}
 386:   
 387:                  b = true;
 388:              }
 389:   
 390:              result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 391:   
 392:              return b;
 393:          }
 394:   
 395:          ////////////////////////////////////////////////////////////////////////////
 396:   
 397:          /// <summary>
 398:          ///
 399:          /// </summary>
 400:          public static bool Delete(string id, out string result)
 401:          {
 402:              bool b;
 403:   
 404:              b = false;
 405:              result = string.Empty;
 406:   
 407:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 408:              {
 409:                  var v = (from o in db.Onts where o.Id == id select o).FirstOrDefault();
 410:   
 411:                  db.Onts.Remove(v);
 412:                  db.SaveChanges();
 413:   
 414:                  b = true;
 415:              }
 416:   
 417:              return b;
 418:          }
 419:   
 420:          ////////////////////////////////////////////////////////////////////////////
 421:          ////////////////////////////////////////////////////////////////////////////
 422:   
 423:          /// <summary>
 424:          ///
 425:          /// </summary>
 426:          public static string FamilyTypeFromId(int familyTypeId)
 427:          {
 428:              string s;
 429:              Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType familyType;
 430:   
 431:              familyType = (Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType)familyTypeId;
 432:   
 433:              s = familyType.ToString().ToUpper();
 434:   
 435:              return s;
 436:          }
 437:   
 438:          ////////////////////////////////////////////////////////////////////////////
 439:   
 440:          /// <summary>
 441:          ///
 442:          /// </summary>
 443:          public static List<Ia.Ngn.Cl.Model.Ont> List(string serial)
 444:          {
 445:              List<Ia.Ngn.Cl.Model.Ont> list;
 446:   
 447:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 448:              {
 449:                  list = (from o in db.Onts where o.Serial == serial select o).ToList();
 450:              }
 451:   
 452:              return list;
 453:          }
 454:   
 455:          ////////////////////////////////////////////////////////////////////////////
 456:   
 457:          /// <summary>
 458:          ///
 459:          /// </summary>
 460:          public static List<Ia.Ngn.Cl.Model.Ont> List(int oltId)
 461:          {
 462:              List<Ia.Ngn.Cl.Model.Ont> list;
 463:   
 464:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 465:              {
 466:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).ToList();
 467:              }
 468:   
 469:              return list;
 470:          }
 471:   
 472:          ////////////////////////////////////////////////////////////////////////////
 473:   
 474:          /// <summary>
 475:          ///
 476:          /// </summary>
 477:          public static List<Ia.Ngn.Cl.Model.Ont> ReadListIncludeOntServiceVoipsAndAccess(int oltId)
 478:          {
 479:              List<Ia.Ngn.Cl.Model.Ont> list;
 480:   
 481:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 482:              {
 483:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).Include(x => x.Access).Include(x => x.OntServiceVoips).ToList();
 484:              }
 485:   
 486:              return list;
 487:          }
 488:   
 489:          ////////////////////////////////////////////////////////////////////////////
 490:   
 491:          /// <summary>
 492:          ///
 493:          /// </summary>
 494:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess()
 495:          {
 496:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 497:   
 498:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 499:              {
 500:                  ontList = (from o in db.Onts select o).Include(u => u.Access).ToList();
 501:              }
 502:   
 503:              return ontList;
 504:          }
 505:   
 506:          ////////////////////////////////////////////////////////////////////////////
 507:   
 508:          /// <summary>
 509:          ///
 510:          /// </summary>
 511:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots()
 512:          {
 513:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 514:   
 515:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 516:              {
 517:                  ontList = (from o in db.Onts select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 518:   
 519:                  /*
 520:                  ontList = (from o in db.Onts 
 521:                             join a in db.Accesses on o.Access equals a 
 522:                             join oop in db.OntOntPotses on o equals oop.Ont select o).ToList();
 523:                   */
 524:              }
 525:   
 526:              return ontList;
 527:          }
 528:   
 529:          ////////////////////////////////////////////////////////////////////////////
 530:   
 531:          /// <summary>
 532:          ///
 533:          /// </summary>
 534:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots(int oltId)
 535:          {
 536:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 537:   
 538:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 539:              {
 540:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 541:              }
 542:   
 543:              return ontList;
 544:          }
 545:   
 546:          ////////////////////////////////////////////////////////////////////////////
 547:   
 548:          /// <summary>
 549:          ///
 550:          /// </summary>
 551:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess(int oltId)
 552:          {
 553:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 554:   
 555:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 556:              {
 557:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).ToList();
 558:              }
 559:   
 560:              return ontList;
 561:          }
 562:   
 563:          ////////////////////////////////////////////////////////////////////////////
 564:   
 565:          /// <summary>
 566:          ///
 567:          /// </summary>
 568:          public static List<Ia.Ngn.Cl.Model.Ont> NonNullAccessList(int oltId)
 569:          {
 570:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 571:   
 572:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 573:              {
 574:                  ontList = (from o in db.Onts where o.Access != null && o.Access.Olt == oltId select o).ToList();
 575:              }
 576:   
 577:              return ontList;
 578:          }
 579:   
 580:          ////////////////////////////////////////////////////////////////////////////
 581:   
 582:          /// <summary>
 583:          ///
 584:          /// </summary>
 585:          public static List<string> ReadNetworkDesignDocumentAccessNameListWithOntEquipmentIdNotNullAndAccessIsNullIncludeOntServiceVoips
 586:          {
 587:              get
 588:              {
 589:                  Dictionary<string, string> di;
 590:                  List<string> ontNameList;
 591:                  List<Ia.Ngn.Cl.Model.Ont> ontList;
 592:   
 593:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 594:                  {
 595:                      ontList = (from o in db.Onts where o.EquipmentId != null && o.Access == null select o).ToList();
 596:   
 597:                      ontNameList = new List<string>(ontList.Count);
 598:   
 599:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 600:   
 601:                      foreach (var ont in ontList)
 602:                      {
 603:                          if (di.ContainsKey(ont.Id)) ontNameList.Add(di[ont.Id]);
 604:                      }
 605:                  }
 606:   
 607:                  return ontNameList;
 608:              }
 609:          }
 610:   
 611:          ////////////////////////////////////////////////////////////////////////////
 612:          ////////////////////////////////////////////////////////////////////////////
 613:   
 614:          /// <summary>
 615:          ///
 616:          /// </summary>
 617:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Ont ont)
 618:          {
 619:              StringBuilder sb;
 620:   
 621:              sb = new StringBuilder();
 622:   
 623:              //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia.Name);
 624:              sb.AppendLine("State: " + ont.State);
 625:              sb.AppendLine("FamilyType: " + Ia.Ngn.Cl.Model.Data.Nokia.Ont.FamilyTypeFromId(ont.FamilyTypeId));
 626:              sb.AppendLine("Serial: " + ont.Serial);
 627:              sb.AppendLine("EquipmentId: " + ont.EquipmentId);
 628:              sb.AppendLine("ActiveSoftware: " + ont.ActiveSoftware);
 629:              //sb.AppendLine("PassiveSoftware: " + ont.PassiveSoftware);
 630:              sb.AppendLine("PlannedSoftware: " + ont.PlannedSoftware);
 631:              //sb.AppendLine("BatteryBackupAvailable: " + ont.BatteryBackupAvailable);
 632:              sb.AppendLine("Description1: " + ont.Description1);
 633:              sb.AppendLine("Description2: " + ont.Description2);
 634:   
 635:              return sb.ToString();
 636:          }
 637:   
 638:          ////////////////////////////////////////////////////////////////////////////
 639:          ////////////////////////////////////////////////////////////////////////////
 640:      }
 641:   
 642:      ////////////////////////////////////////////////////////////////////////////
 643:      ////////////////////////////////////////////////////////////////////////////
 644:  }