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

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