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

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 = "";
  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<int, int> DistributionOfFamilyTypeIdInOntWhereSerialIsAssignedAndAccessIsNotNullDictionary
 178:          {
 179:              get
 180:              {
 181:                  Dictionary<int, int> dictionary;
 182:   
 183:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 184:                  {
 185:                      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() });
 186:                      dictionary = v.ToDictionary(u => u.FamilyTypeId, u => u.Count);
 187:                  }
 188:   
 189:                  return dictionary;
 190:              }
 191:          }
 192:   
 193:          ////////////////////////////////////////////////////////////////////////////
 194:   
 195:          /// <summary>
 196:          ///
 197:          /// </summary>
 198:          public static Hashtable IdWithNullAccessHashtable
 199:          {
 200:              get
 201:              {
 202:                  List<string> list;
 203:                  Hashtable ht;
 204:   
 205:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 206:                  {
 207:                      list = (from o in db.Onts where o.Access == null select o.Id).ToList();
 208:   
 209:                      if (list.Count > 0)
 210:                      {
 211:                          ht = new Hashtable(list.Count);
 212:   
 213:                          foreach (string s in list) ht[s] = null;
 214:                      }
 215:                      else ht = null;
 216:                  }
 217:   
 218:                  return ht;
 219:              }
 220:          }
 221:   
 222:          ////////////////////////////////////////////////////////////////////////////
 223:   
 224:          /// <summary>
 225:          ///
 226:          /// </summary>
 227:          public static Dictionary<string, string> SerialToIdListDictionary
 228:          {
 229:              get
 230:              {
 231:                  Dictionary<string, string> dictionary;
 232:   
 233:                  dictionary = IdToSerialDictionary.Reverse();
 234:   
 235:                  return dictionary;
 236:              }
 237:          }
 238:   
 239:          ////////////////////////////////////////////////////////////////////////////
 240:   
 241:          /// <summary>
 242:          ///
 243:          /// </summary>
 244:          public static Dictionary<string, string> IdToSerialDictionary
 245:          {
 246:              get
 247:              {
 248:                  Dictionary<string, string> dictionary;
 249:   
 250:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 251:                  {
 252:                      dictionary = (from s in db.Onts
 253:                                    select new
 254:                                    {
 255:                                        s.Id,
 256:                                        s.Serial
 257:                                    }).ToDictionary(u => u.Id, u => u.Serial);
 258:                  }
 259:   
 260:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 261:              }
 262:          }
 263:   
 264:          ////////////////////////////////////////////////////////////////////////////
 265:   
 266:          /// <summary>
 267:          ///
 268:          /// </summary>
 269:          public static List<string> IdList()
 270:          {
 271:              List<string> list;
 272:   
 273:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 274:              {
 275:                  list = (from o in db.Onts select o.Id).ToList();
 276:              }
 277:   
 278:              return list;
 279:          }
 280:   
 281:          ////////////////////////////////////////////////////////////////////////////
 282:   
 283:          /// <summary>
 284:          ///
 285:          /// </summary>
 286:          public static List<string> IdList(int oltId)
 287:          {
 288:              List<string> list;
 289:   
 290:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 291:              {
 292:                  list = (from o in db.Onts where o.Access.Olt == oltId select o.Id).ToList();
 293:              }
 294:   
 295:              return list;
 296:          }
 297:   
 298:          ////////////////////////////////////////////////////////////////////////////
 299:   
 300:          /// <summary>
 301:          ///
 302:          /// </summary>
 303:          public static bool Update(Ia.Ngn.Cl.Model.Ont ont, out string result)
 304:          {
 305:              bool b;
 306:   
 307:              b = false;
 308:              result = "";
 309:   
 310:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 311:              {
 312:                  ont = (from o in db.Onts where o.Id == ont.Id select o).SingleOrDefault();
 313:   
 314:                  ont.Updated = DateTime.UtcNow.AddHours(3);
 315:   
 316:                  db.Onts.Attach(ont);
 317:   
 318:                  db.Entry(ont).State = System.Data.Entity.EntityState.Modified;
 319:                  db.SaveChanges();
 320:   
 321:                  b = true;
 322:              }
 323:   
 324:              return b;
 325:          }
 326:   
 327:          ////////////////////////////////////////////////////////////////////////////
 328:   
 329:          /// <summary>
 330:          ///
 331:          /// </summary>
 332:          public static bool Delete(string id, out string result)
 333:          {
 334:              bool b;
 335:   
 336:              b = false;
 337:              result = "";
 338:   
 339:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 340:              {
 341:                  var v = (from o in db.Onts where o.Id == id select o).FirstOrDefault();
 342:   
 343:                  db.Onts.Remove(v);
 344:                  db.SaveChanges();
 345:   
 346:                  b = true;
 347:              }
 348:   
 349:              return b;
 350:          }
 351:   
 352:          ////////////////////////////////////////////////////////////////////////////
 353:          ////////////////////////////////////////////////////////////////////////////
 354:   
 355:          /// <summary>
 356:          ///
 357:          /// </summary>
 358:          public static string FamilyTypeFromId(int familyTypeId)
 359:          {
 360:              string s;
 361:              Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType familyType;
 362:   
 363:              familyType = (Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType)familyTypeId;
 364:   
 365:              s = familyType.ToString().ToUpper();
 366:   
 367:              return s;
 368:          }
 369:   
 370:          ////////////////////////////////////////////////////////////////////////////
 371:   
 372:          /// <summary>
 373:          ///
 374:          /// </summary>
 375:          public static List<Ia.Ngn.Cl.Model.Ont> List(string serial)
 376:          {
 377:              List<Ia.Ngn.Cl.Model.Ont> list;
 378:   
 379:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 380:              {
 381:                  list = (from o in db.Onts where o.Serial == serial select o).ToList();
 382:              }
 383:   
 384:              return list;
 385:          }
 386:   
 387:          ////////////////////////////////////////////////////////////////////////////
 388:   
 389:          /// <summary>
 390:          ///
 391:          /// </summary>
 392:          public static List<Ia.Ngn.Cl.Model.Ont> List(int oltId)
 393:          {
 394:              List<Ia.Ngn.Cl.Model.Ont> list;
 395:   
 396:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 397:              {
 398:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).ToList();
 399:              }
 400:   
 401:              return list;
 402:          }
 403:   
 404:          ////////////////////////////////////////////////////////////////////////////
 405:   
 406:          /// <summary>
 407:          ///
 408:          /// </summary>
 409:          public static List<Ia.Ngn.Cl.Model.Ont> ReadListIncludeOntServiceVoipsAndAccess(int oltId)
 410:          {
 411:              List<Ia.Ngn.Cl.Model.Ont> list;
 412:   
 413:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 414:              {
 415:                  list = (from o in db.Onts where o.Access.Olt == oltId select o).Include(x => x.Access).Include(x => x.OntServiceVoips).ToList();
 416:              }
 417:   
 418:              return list;
 419:          }
 420:   
 421:          ////////////////////////////////////////////////////////////////////////////
 422:   
 423:          /// <summary>
 424:          ///
 425:          /// </summary>
 426:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess()
 427:          {
 428:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 429:   
 430:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 431:              {
 432:                  ontList = (from o in db.Onts select o).Include(u => u.Access).ToList();
 433:              }
 434:   
 435:              return ontList;
 436:          }
 437:   
 438:          ////////////////////////////////////////////////////////////////////////////
 439:   
 440:          /// <summary>
 441:          ///
 442:          /// </summary>
 443:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots()
 444:          {
 445:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 446:   
 447:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 448:              {
 449:                  ontList = (from o in db.Onts select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 450:   
 451:                  /*
 452:                  ontList = (from o in db.Onts 
 453:                             join a in db.Accesses on o.Access equals a 
 454:                             join oop in db.OntOntPotses on o equals oop.Ont select o).ToList();
 455:                   */ 
 456:              }
 457:   
 458:              return ontList;
 459:          }
 460:   
 461:          ////////////////////////////////////////////////////////////////////////////
 462:   
 463:          /// <summary>
 464:          ///
 465:          /// </summary>
 466:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccessAndOntOntPots(int oltId)
 467:          {
 468:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 469:   
 470:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 471:              {
 472:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).Include(v => v.OntOntPotses).ToList();
 473:              }
 474:   
 475:              return ontList;
 476:          }
 477:   
 478:          ////////////////////////////////////////////////////////////////////////////
 479:   
 480:          /// <summary>
 481:          ///
 482:          /// </summary>
 483:          public static List<Ia.Ngn.Cl.Model.Ont> ListIncludeAccess(int oltId)
 484:          {
 485:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 486:   
 487:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 488:              {
 489:                  ontList = (from o in db.Onts where o.Access.Olt == oltId select o).Include(u => u.Access).ToList();
 490:              }
 491:   
 492:              return ontList;
 493:          }
 494:   
 495:          ////////////////////////////////////////////////////////////////////////////
 496:   
 497:          /// <summary>
 498:          ///
 499:          /// </summary>
 500:          public static List<Ia.Ngn.Cl.Model.Ont> NonNullAccessList(int oltId)
 501:          {
 502:              List<Ia.Ngn.Cl.Model.Ont> ontList;
 503:   
 504:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 505:              {
 506:                  ontList = (from o in db.Onts where o.Access != null && o.Access.Olt == oltId select o).ToList();
 507:              }
 508:   
 509:              return ontList;
 510:          }
 511:   
 512:          ////////////////////////////////////////////////////////////////////////////
 513:   
 514:          /// <summary>
 515:          ///
 516:          /// </summary>
 517:          public static List<string> ReadNetworkDesignDocumentAccessNameListWithOntEquipmentIdNotNullAndAccessIsNullIncludeOntServiceVoips
 518:          {
 519:              get
 520:              {
 521:                  Dictionary<string, string> di;
 522:                  List<string> ontNameList;
 523:                  List<Ia.Ngn.Cl.Model.Ont> ontList;
 524:   
 525:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 526:                  {
 527:                      ontList = (from o in db.Onts where o.EquipmentId != null && o.Access == null select o).ToList();
 528:   
 529:                      ontNameList = new List<string>(ontList.Count);
 530:   
 531:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 532:   
 533:                      foreach (var ont in ontList)
 534:                      {
 535:                          if (di.ContainsKey(ont.Id)) ontNameList.Add(di[ont.Id]);
 536:                      }
 537:                  }
 538:   
 539:                  return ontNameList;
 540:              }
 541:          }
 542:   
 543:          ////////////////////////////////////////////////////////////////////////////
 544:          ////////////////////////////////////////////////////////////////////////////
 545:   
 546:          /// <summary>
 547:          ///
 548:          /// </summary>
 549:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Ont ont)
 550:          {
 551:              StringBuilder sb;
 552:   
 553:              sb = new StringBuilder();
 554:   
 555:              //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia.Name);
 556:              sb.AppendLine("State: " + ont.State);
 557:              sb.AppendLine("FamilyType: " + Ia.Ngn.Cl.Model.Data.Nokia.Ont.FamilyTypeFromId(ont.FamilyTypeId));
 558:              sb.AppendLine("Serial: " + ont.Serial);
 559:              sb.AppendLine("EquipmentId: " + ont.EquipmentId);
 560:              sb.AppendLine("ActiveSoftware: " + ont.ActiveSoftware);
 561:              //sb.AppendLine("PassiveSoftware: " + ont.PassiveSoftware);
 562:              sb.AppendLine("PlannedSoftware: " + ont.PlannedSoftware);
 563:              //sb.AppendLine("BatteryBackupAvailable: " + ont.BatteryBackupAvailable);
 564:              sb.AppendLine("Description1: " + ont.Description1);
 565:              sb.AppendLine("Description2: " + ont.Description2);
 566:   
 567:              return sb.ToString();
 568:          }
 569:   
 570:          ////////////////////////////////////////////////////////////////////////////
 571:          ////////////////////////////////////////////////////////////////////////////
 572:      }
 573:   
 574:      ////////////////////////////////////////////////////////////////////////////
 575:      ////////////////////////////////////////////////////////////////////////////
 576:  }