Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Onu

Public general use code classes and xml files that we've compiled and used over the years:

Huawei ONU support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Data.Entity;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Huawei ONU support class for Next Generation Network (NGN) data model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2016-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class Onu
  28:      {
  29:          /// <summary/>
  30:          public Onu() { }
  31:   
  32:          ////////////////////////////////////////////////////////////////////////////
  33:   
  34:          /// <summary>
  35:          ///
  36:          /// </summary>
  37:          public static bool Create(Ia.Ngn.Cl.Model.Huawei.Onu onu, out string result)
  38:          {
  39:              bool b;
  40:   
  41:              b = false;
  42:              result = "";
  43:   
  44:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  45:              {
  46:                  onu.Created = onu.Updated = DateTime.UtcNow.AddHours(3);
  47:   
  48:                  onu.Access = (from a in db.Accesses where a.Id == onu.Access.Id select a).SingleOrDefault();
  49:   
  50:                  db.Onus.Add(onu);
  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.Huawei.Onu Read(string id)
  65:          {
  66:              Ia.Ngn.Cl.Model.Huawei.Onu onu;
  67:   
  68:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  69:              {
  70:                  onu = (from o in db.Onus where o.Id == id select o)/*.Include(o => o.OnuServiceVoips)*/.SingleOrDefault();
  71:              }
  72:   
  73:              return onu;
  74:          }
  75:   
  76:          ////////////////////////////////////////////////////////////////////////////
  77:   
  78:          /// <summary>
  79:          ///
  80:          /// </summary>
  81:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> List()
  82:          {
  83:              List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
  84:   
  85:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  86:              {
  87:                  onuList = (from o in db.Onus select o).ToList();
  88:              }
  89:   
  90:              return onuList;
  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 s in db.Onus
 107:                                    where s.Access != null
 108:                                    select new
 109:                                    {
 110:                                        s.Id,
 111:                                        s.Access
 112:                                    }).ToDictionary(u => u.Id, u => u.Access.Id);
 113:   
 114:                      nullDictionary = (from s in db.Onus where s.Access == null select s.Id).ToDictionary(u => u, null);
 115:                  }
 116:   
 117:                  return dictionary.Union(nullDictionary).ToDictionary(u => u.Key, u => u.Value);
 118:              }
 119:          }
 120:   
 121:          ////////////////////////////////////////////////////////////////////////////
 122:   
 123:          /// <summary>
 124:          ///
 125:          /// </summary>
 126:          public static Dictionary<string, List<string>> SerialToIdListDictionary
 127:          {
 128:              get
 129:              {
 130:                  Dictionary<string, List<string>> dictionary;
 131:   
 132:                  dictionary = IdToSerialDictionary.GroupBy(p => p.Value).ToDictionary(g => g.Key, g => g.Select(pp => pp.Key).ToList());
 133:   
 134:                  return dictionary;
 135:              }
 136:          }
 137:   
 138:          ////////////////////////////////////////////////////////////////////////////
 139:   
 140:          /// <summary>
 141:          ///
 142:          /// </summary>
 143:          public static Dictionary<string, string> IdToSerialDictionary
 144:          {
 145:              get
 146:              {
 147:                  Dictionary<string, string> dictionary;
 148:   
 149:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 150:                  {
 151:                      dictionary = (from s in db.Onus
 152:                                    select new
 153:                                    {
 154:                                        s.Id,
 155:                                        s.Serial
 156:                                    }).ToDictionary(u => u.Id, u => u.Serial);
 157:                  }
 158:   
 159:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 160:              }
 161:          }
 162:   
 163:          ////////////////////////////////////////////////////////////////////////////
 164:   
 165:          /// <summary>
 166:          ///
 167:          /// </summary>
 168:          public static List<string> IdList()
 169:          {
 170:              List<string> list;
 171:   
 172:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 173:              {
 174:                  list = (from o in db.Onus select o.Id).ToList();
 175:              }
 176:   
 177:              return list;
 178:          }
 179:   
 180:          ////////////////////////////////////////////////////////////////////////////
 181:   
 182:          /// <summary>
 183:          ///
 184:          /// </summary>
 185:          public static List<string> IdList(int oltId)
 186:          {
 187:              List<string> list;
 188:   
 189:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 190:              {
 191:                  list = (from o in db.Onus where o.Access.Olt == oltId select o.Id).ToList();
 192:              }
 193:   
 194:              return list;
 195:          }
 196:   
 197:          ////////////////////////////////////////////////////////////////////////////
 198:          ////////////////////////////////////////////////////////////////////////////
 199:   
 200:          /// <summary>
 201:          ///
 202:          /// </summary>
 203:          public static string FamilyTypeFromId(int familyTypeId)
 204:          {
 205:              string s;
 206:              Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType familyType;
 207:   
 208:              familyType = (Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType)familyTypeId;
 209:   
 210:              s = familyType.ToString().ToUpper();
 211:   
 212:              return s;
 213:          }
 214:   
 215:          ////////////////////////////////////////////////////////////////////////////
 216:   
 217:          /// <summary>
 218:          ///
 219:          /// </summary>
 220:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> List(string serial)
 221:          {
 222:              List<Ia.Ngn.Cl.Model.Huawei.Onu> list;
 223:   
 224:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 225:              {
 226:                  list = (from o in db.Onus where o.Serial == serial select o).ToList();
 227:              }
 228:   
 229:              return list;
 230:          }
 231:   
 232:          ////////////////////////////////////////////////////////////////////////////
 233:   
 234:          /// <summary>
 235:          ///
 236:          /// </summary>
 237:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> List(int oltId)
 238:          {
 239:              List<Ia.Ngn.Cl.Model.Huawei.Onu> list;
 240:   
 241:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 242:              {
 243:                  list = (from o in db.Onus where o.Access.Olt == oltId select o).ToList();
 244:              }
 245:   
 246:              return list;
 247:          }
 248:   
 249:          /*
 250:          ////////////////////////////////////////////////////////////////////////////
 251:  
 252:          /// <summary>
 253:          ///
 254:          /// </summary>
 255:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> ReadListIncludeOnuServiceVoipsAndAccess(int oltId)
 256:          {
 257:              List<Ia.Ngn.Cl.Model.Huawei.Onu> list;
 258:  
 259:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 260:              {
 261:                  list = (from o in db.Onus where o.Access.Olt == oltId select o).Include(x => x.Access).Include(x => x.OnuServiceVoips).ToList();
 262:              }
 263:  
 264:              return list;
 265:          }
 266:          */
 267:   
 268:          ////////////////////////////////////////////////////////////////////////////
 269:   
 270:          /// <summary>
 271:          ///
 272:          /// </summary>
 273:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> ListIncludeAccess()
 274:          {
 275:              List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
 276:   
 277:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 278:              {
 279:                  onuList = (from o in db.Onus select o).Include(u => u.Access).ToList();
 280:              }
 281:   
 282:              return onuList;
 283:          }
 284:   
 285:          /*
 286:          ////////////////////////////////////////////////////////////////////////////
 287:  
 288:          /// <summary>
 289:          ///
 290:          /// </summary>
 291:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> ListIncludeAccessAndOnuOnuPots()
 292:          {
 293:              List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
 294:  
 295:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 296:              {
 297:                  onuList = (from o in db.Onus select o).Include(u => u.Access).Include(v => v.OnuOnuPotses).ToList();
 298:              }
 299:  
 300:              return onuList;
 301:          }
 302:          */
 303:   
 304:          /*
 305:          ////////////////////////////////////////////////////////////////////////////
 306:  
 307:          /// <summary>
 308:          ///
 309:          /// </summary>
 310:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> ListIncludeAccessAndOnuOnuPots(int oltId)
 311:          {
 312:              List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
 313:  
 314:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 315:              {
 316:                  onuList = (from o in db.Onus where o.Access.Olt == oltId select o).Include(u => u.Access).Include(v => v.OnuOnuPotses).ToList();
 317:              }
 318:  
 319:              return onuList;
 320:          }
 321:          */
 322:   
 323:          ////////////////////////////////////////////////////////////////////////////
 324:   
 325:          /// <summary>
 326:          ///
 327:          /// </summary>
 328:          public static List<Ia.Ngn.Cl.Model.Huawei.Onu> ListIncludeAccess(int oltId)
 329:          {
 330:              List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
 331:   
 332:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 333:              {
 334:                  onuList = (from o in db.Onus where o.Access.Olt == oltId select o).Include(u => u.Access).ToList();
 335:              }
 336:   
 337:              return onuList;
 338:          }
 339:   
 340:          /*
 341:          ////////////////////////////////////////////////////////////////////////////
 342:  
 343:          /// <summary>
 344:          ///
 345:          /// </summary>
 346:          public static List<string> ReadNetworkDesignDocumentAccessNameListWithOnuEquipmentIdNotNullAndAccessIsNullIncludeOnuServiceVoips
 347:          {
 348:              get
 349:              {
 350:                  Hashtable ht;
 351:                  List<string> onuNameList;
 352:                  List<Ia.Ngn.Cl.Model.Huawei.Onu> onuList;
 353:  
 354:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 355:                  {
 356:                      onuList = (from o in db.Onus where o.EquipmentId != null && o.Access == null select o).ToList();
 357:  
 358:                      onuNameList = new List<string>(onuList.Count);
 359:  
 360:                      ht = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OnuListIdToAccessNameHashtable;
 361:  
 362:                      foreach (var onu in onuList)
 363:                      {
 364:                          if (ht.ConuainsKey(onu.Id)) onuNameList.Add(ht[onu.Id].ToString());
 365:                      }
 366:                  }
 367:  
 368:                  return onuNameList;
 369:              }
 370:          }
 371:          */
 372:   
 373:          ////////////////////////////////////////////////////////////////////////////
 374:   
 375:          /// <summary>
 376:          ///
 377:          /// </summary>
 378:          public static bool Update(Ia.Ngn.Cl.Model.Huawei.Onu onu, out string result)
 379:          {
 380:              bool b;
 381:   
 382:              b = false;
 383:              result = "";
 384:   
 385:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 386:              {
 387:                  onu = (from o in db.Onus where o.Id == onu.Id select o).SingleOrDefault();
 388:   
 389:                  onu.Updated = DateTime.UtcNow.AddHours(3);
 390:   
 391:                  db.Onus.Attach(onu);
 392:   
 393:                  db.Entry(onu).State = System.Data.Entity.EntityState.Modified;
 394:                  db.SaveChanges();
 395:   
 396:                  b = true;
 397:              }
 398:   
 399:              return b;
 400:          }
 401:   
 402:          ////////////////////////////////////////////////////////////////////////////
 403:   
 404:          /// <summary>
 405:          ///
 406:          /// </summary>
 407:          public static bool Delete(string id, out string result)
 408:          {
 409:              bool b;
 410:   
 411:              b = false;
 412:              result = "";
 413:   
 414:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 415:              {
 416:                  var v = (from o in db.Onus where o.Id == id select o).FirstOrDefault();
 417:   
 418:                  db.Onus.Remove(v);
 419:                  db.SaveChanges();
 420:   
 421:                  b = true;
 422:              }
 423:   
 424:              return b;
 425:          }
 426:   
 427:          ////////////////////////////////////////////////////////////////////////////
 428:   
 429:          /// <summary>
 430:          ///
 431:          /// </summary>
 432:          public static bool DeleteByAccessId(string accessId, out string result)
 433:          {
 434:              bool b;
 435:   
 436:              b = false;
 437:              result = "";
 438:   
 439:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 440:              {
 441:                  var v = (from o in db.Onus where o.Access.Id == accessId select o).Include(u => u.Access).FirstOrDefault();
 442:   
 443:                  db.Onus.Remove(v);
 444:                  db.SaveChanges();
 445:   
 446:                  b = true;
 447:              }
 448:   
 449:              return b;
 450:          }
 451:   
 452:          ////////////////////////////////////////////////////////////////////////////
 453:          ////////////////////////////////////////////////////////////////////////////
 454:      }
 455:   
 456:      ////////////////////////////////////////////////////////////////////////////
 457:      ////////////////////////////////////////////////////////////////////////////
 458:  }