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

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