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