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

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:

Huawei's Ont support class of Next Generation Network'a (NGN's) data model.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Data;
   5:  using System.Data.Entity;
   6:  using System.Linq;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Huawei's Ont support class of Next Generation Network'a (NGN's) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2016-2019 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 List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> List()
  40:          {
  41:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> list;
  42:   
  43:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  44:              {
  45:                  list = (from o in db.EmsOnts select o).ToList();
  46:              }
  47:   
  48:              return list;
  49:          }
  50:   
  51:          ////////////////////////////////////////////////////////////////////////////
  52:   
  53:          /// <summary>
  54:          ///
  55:          /// </summary>
  56:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ListIncludeAccess()
  57:          {
  58:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> list;
  59:   
  60:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  61:              {
  62:                  list = (from o in db.EmsOnts select o).Include(u => u.Access).ToList();
  63:              }
  64:   
  65:              return list;
  66:          }
  67:   
  68:          ////////////////////////////////////////////////////////////////////////////
  69:   
  70:          /// <summary>
  71:          ///
  72:          /// </summary>
  73:          public static List<string> IdList()
  74:          {
  75:              List<string> list;
  76:   
  77:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  78:              {
  79:                  list = (from o in db.EmsOnts select o.Id).ToList();
  80:              }
  81:   
  82:              return list;
  83:          }
  84:   
  85:          ////////////////////////////////////////////////////////////////////////////
  86:   
  87:          /// <summary>
  88:          ///
  89:          /// </summary>
  90:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ListByDidFnSnPn(int did, int fn, int sn, int pn)
  91:          {
  92:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> list;
  93:   
  94:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  95:              {
  96:                  list = (from o in db.EmsOnts where o.DID == did && o.FN == fn && o.SN == sn && o.PN == pn select o).ToList();
  97:              }
  98:   
  99:              return list;
 100:          }
 101:   
 102:          ////////////////////////////////////////////////////////////////////////////
 103:   
 104:          /// <summary>
 105:          ///
 106:          /// </summary>
 107:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ListByDid(int did)
 108:          {
 109:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> list;
 110:   
 111:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 112:              {
 113:                  list = (from o in db.EmsOnts where o.DID == did select o).Include(x => x.Access).ToList();
 114:              }
 115:   
 116:              return list;
 117:          }
 118:   
 119:          ////////////////////////////////////////////////////////////////////////////
 120:   
 121:          /// <summary>
 122:          ///
 123:          /// </summary>
 124:          public static Ia.Ngn.Cl.Model.Huawei.EmsOnt ReadByDidFnSnPnOntId(int did, int fn, int sn, int pn, int ontId)
 125:          {
 126:              Ia.Ngn.Cl.Model.Huawei.EmsOnt item;
 127:   
 128:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 129:              {
 130:                  item = (from o in db.EmsOnts where o.DID == did && o.FN == fn && o.SN == sn && o.PN == pn && o.ONTID == ontId select o).SingleOrDefault();
 131:              }
 132:   
 133:              return item;
 134:          }
 135:   
 136:          ////////////////////////////////////////////////////////////////////////////
 137:   
 138:          /// <summary>
 139:          ///
 140:          /// </summary>
 141:          public static Ia.Ngn.Cl.Model.Huawei.EmsOnt Read(string id)
 142:          {
 143:              Ia.Ngn.Cl.Model.Huawei.EmsOnt item;
 144:   
 145:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 146:              {
 147:                  item = (from o in db.EmsOnts where o.Id == id select o).SingleOrDefault(); // use Id to connecto MduDev.NddOntId instead.Include(u => u.Access).SingleOrDefault();
 148:              }
 149:   
 150:              return item;
 151:          }
 152:   
 153:          ////////////////////////////////////////////////////////////////////////////
 154:   
 155:          /// <summary>
 156:          ///
 157:          /// </summary>
 158:          public static Ia.Ngn.Cl.Model.Huawei.EmsOnt ReadWithAccess(string id)
 159:          {
 160:              Ia.Ngn.Cl.Model.Huawei.EmsOnt item;
 161:   
 162:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 163:              {
 164:                  item = (from o in db.EmsOnts where o.Id == id select o).Include(u => u.Access).SingleOrDefault();
 165:              }
 166:   
 167:              return item;
 168:          }
 169:   
 170:          /*
 171:          ////////////////////////////////////////////////////////////////////////////
 172:  
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public static List<Ia.Ngn.Cl.Model.Huawei.Ont> List(string portId)
 177:          {
 178:              List<Ia.Ngn.Cl.Model.Huawei.Ont> list;
 179:  
 180:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 181:              {
 182:                  list = (from o in db.EmsOnts where o.Port.Id == portId select o).ToList();
 183:              }
 184:  
 185:              return list;
 186:          }
 187:          */
 188:   
 189:          /*
 190:          ////////////////////////////////////////////////////////////////////////////
 191:  
 192:          /// <summary>
 193:          ///
 194:          /// </summary>
 195:          public static List<Ia.Ngn.Cl.Model.Huawei.Ont> ListByBoardId(string boardId)
 196:          {
 197:              List<Ia.Ngn.Cl.Model.Huawei.Ont> list;
 198:  
 199:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 200:              {
 201:                  list = (from o in db.EmsOnts where o.Port.Board.Id == boardId select o).ToList();
 202:              }
 203:  
 204:              return list;
 205:          }
 206:          */
 207:   
 208:          /*
 209:          ////////////////////////////////////////////////////////////////////////////
 210:  
 211:          /// <summary>
 212:          ///
 213:          /// </summary>
 214:          public static List<Ia.Ngn.Cl.Model.Huawei.Ont> ListByDevId(int devId)
 215:          {
 216:              List<Ia.Ngn.Cl.Model.Huawei.Ont> list;
 217:  
 218:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 219:              {
 220:                  list = (from o in db.EmsOnts where o.Port.Board.Dev.Id == devId select o).ToList();
 221:              }
 222:  
 223:              return list;
 224:          }
 225:          */
 226:   
 227:          ////////////////////////////////////////////////////////////////////////////
 228:   
 229:          /// <summary>
 230:          ///
 231:          /// </summary>
 232:          public static Dictionary<string, string> IdToAccessIdDictionary
 233:          {
 234:              get
 235:              {
 236:                  Dictionary<string, string> dictionary, nullDictionary;
 237:   
 238:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 239:                  {
 240:                      dictionary = (from s in db.EmsOnts
 241:                                    where s.Access != null
 242:                                    select new
 243:                                    {
 244:                                        s.Id,
 245:                                        s.Access
 246:                                    }).ToDictionary(u => u.Id, u => u.Access.Id);
 247:   
 248:                      nullDictionary = (from s in db.Onts where s.Access == null select s.Id).ToDictionary(u => u, null);
 249:                  }
 250:   
 251:                  return dictionary.Union(nullDictionary).ToDictionary(u => u.Key, u => u.Value);
 252:              }
 253:          }
 254:   
 255:          ////////////////////////////////////////////////////////////////////////////
 256:   
 257:          /// <summary>
 258:          ///
 259:          /// </summary>
 260:          public static Dictionary<string, Ia.Ngn.Cl.Model.Huawei.EmsOnt> IdToOntDictionary
 261:          {
 262:              get
 263:              {
 264:                  Dictionary<string, Ia.Ngn.Cl.Model.Huawei.EmsOnt> dictionary;
 265:   
 266:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 267:                  {
 268:                      dictionary = (from s in db.EmsOnts
 269:                                    where s.Access != null
 270:                                    select new { OntId = s.Id, Ont = s }).ToDictionary(u => u.OntId, u => u.Ont);
 271:                  }
 272:   
 273:                  return dictionary;
 274:              }
 275:          }
 276:   
 277:          ////////////////////////////////////////////////////////////////////////////
 278:   
 279:          /// <summary>
 280:          ///
 281:          /// </summary>
 282:          public static Dictionary<string, Ia.Ngn.Cl.Model.Huawei.EmsOnt> AccessIdToOntDictionary
 283:          {
 284:              get
 285:              {
 286:                  Dictionary<string, Ia.Ngn.Cl.Model.Huawei.EmsOnt> dictionary;
 287:   
 288:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 289:                  {
 290:                      dictionary = (from s in db.EmsOnts
 291:                                    where s.Access != null
 292:                                    select new { OntAccessId = s.Access.Id, Ont = s }).ToDictionary(u => u.OntAccessId, u => u.Ont);
 293:                  }
 294:   
 295:                  return dictionary;
 296:              }
 297:          }
 298:   
 299:          ////////////////////////////////////////////////////////////////////////////
 300:   
 301:          /// <summary>
 302:          ///
 303:          /// </summary>
 304:          public static Hashtable IdWithNullAccessHashtable
 305:          {
 306:              get
 307:              {
 308:                  List<string> list;
 309:                  Hashtable ht;
 310:   
 311:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 312:                  {
 313:                      list = (from eo in db.EmsOnts where eo.Access == null select eo.Id).ToList();
 314:   
 315:                      if (list.Count > 0)
 316:                      {
 317:                          ht = new Hashtable(list.Count);
 318:   
 319:                          foreach (string s in list) ht[s] = null;
 320:                      }
 321:                      else ht = null;
 322:                  }
 323:   
 324:                  return ht;
 325:              }
 326:          }
 327:   
 328:          ////////////////////////////////////////////////////////////////////////////
 329:   
 330:          /// <summary>
 331:          ///
 332:          /// </summary>
 333:          public static Dictionary<string, string> IdToAliasForNonNullAccessDictionary
 334:          {
 335:              get
 336:              {
 337:                  Dictionary<string, string> dictionary;
 338:   
 339:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 340:                  {
 341:                      dictionary = (from eo in db.EmsOnts
 342:                                    where eo.Access != null
 343:                                    select new
 344:                                    {
 345:                                        eo.Id,
 346:                                        eo.ALIAS
 347:                                    }).ToDictionary(u => u.Id, u => u.ALIAS);
 348:                  }
 349:   
 350:                  return dictionary;
 351:              }
 352:          }
 353:   
 354:          ////////////////////////////////////////////////////////////////////////////
 355:   
 356:          /// <summary>
 357:          ///
 358:          /// </summary>
 359:          public static Dictionary<string, int> DistributionOfEquipmentIdInEmsOntWhereAccessIsNotNullDictionary
 360:          {
 361:              get
 362:              {
 363:                  Dictionary<string, int> dictionary;
 364:   
 365:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 366:                  {
 367:                      var v = (from s in db.EmsOnts where s.Access != null group s by s.EQUIPMENTID into g select new { EquipmentId = g.Key, Count = g.Count() });
 368:                      dictionary = v.ToDictionary(u => u.EquipmentId, u => u.Count);
 369:                  }
 370:   
 371:                  return dictionary;
 372:              }
 373:          }
 374:   
 375:          ////////////////////////////////////////////////////////////////////////////
 376:   
 377:          /// <summary>
 378:          ///
 379:          /// </summary>
 380:          public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
 381:          {
 382:              bool isUpdated;
 383:              int did, dictionaryDid, fn, sn, pn, ontId, queryFn, querySn, queryPn, queryOntId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 384:              string id, queryCommand, queryDev, accessName, accessId;
 385:              DataColumnCollection columns;
 386:              DataRow dataRow;
 387:              Dictionary<string, int> devToDidDictionary;
 388:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon;
 389:              Ia.Ngn.Cl.Model.Huawei.EmsOnt ont, newOnt;
 390:              Ia.Ngn.Cl.Model.Huawei.EmsPort port;
 391:              //List<string> itemIdList;
 392:              //List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ontList;
 393:   
 394:              isUpdated = false;
 395:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 396:              result = new Ia.Cl.Model.Result();
 397:   
 398:              queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
 399:   
 400:              // "LST-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::;";
 401:              queryDev = Ia.Cl.Model.Default.Match(queryCommand, @"DEV=(.+?),");
 402:              queryFn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"FN=(\d+)"));
 403:              querySn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"SN=(\d+)"));
 404:              queryPn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"PN=(\d+)"));
 405:              queryOntId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"ONTID=(\d+)"));
 406:   
 407:              if (response.CompletionCode == "COMPLD")
 408:              {
 409:                  devToDidDictionary = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevToDidDictionary;
 410:   
 411:                  if (devToDidDictionary.ContainsKey(queryDev))
 412:                  {
 413:                      dictionaryDid = devToDidDictionary[queryDev];
 414:   
 415:                      port = Ia.Ngn.Cl.Model.Data.Huawei.Port.ReadByDidFnSnPn(dictionaryDid, queryFn, querySn, queryPn);
 416:   
 417:                      if (port != null)
 418:                      {
 419:                          //itemIdList = new List<string>(readItemCount + 1);
 420:   
 421:                          pon = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PonByOltEmsNameAndSnAndPn(queryDev, querySn, queryPn);
 422:   
 423:                          if (pon != null)
 424:                          {
 425:                              accessName = pon.Name + "." + queryOntId;
 426:   
 427:                              id = Ia.Ngn.Cl.Model.Business.Huawei.Ont.OntId(pon.Id, queryOntId);
 428:   
 429:                              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 430:                              {
 431:                                  //ontList = (from eo in db.EmsOnts where eo.EmsPort.Id == port.Id select eo).ToList();
 432:   
 433:                                  ont = (from eo in db.EmsOnts where eo.Id == id select eo).SingleOrDefault();
 434:   
 435:                                  if (ont != null) existingItemCount = 1;
 436:   
 437:                                  if (response.QueryDataTable != null)
 438:                                  {
 439:                                      columns = response.QueryDataTable.Columns;
 440:                                      readItemCount = response.QueryDataTable.Rows.Count;
 441:   
 442:                                      if (readItemCount == 1)
 443:                                      {
 444:                                          dataRow = response.QueryDataTable.Rows[0];
 445:   
 446:                                          did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
 447:                                          fn = int.Parse(dataRow[columns.IndexOf("FN")].ToString());
 448:                                          sn = int.Parse(dataRow[columns.IndexOf("SN")].ToString());
 449:                                          pn = int.Parse(dataRow[columns.IndexOf("PN")].ToString());
 450:                                          ontId = int.Parse(dataRow[columns.IndexOf("ONTID")].ToString());
 451:   
 452:                                          if (fn == queryFn && sn == querySn && pn == queryPn && ontId == queryOntId)
 453:                                          {
 454:                                              newOnt = new Ia.Ngn.Cl.Model.Huawei.EmsOnt()
 455:                                              {
 456:                                                  Id = id,
 457:                                                  DID = did,
 458:                                                  ResultCode = (long)response.ResultCode,
 459:                                                  StateId = (int)Ia.Ngn.Cl.Model.Business.Huawei.Ems.BellcoreState.Unknown, // (int)response.ResultCode,
 460:                                                  FN = fn,
 461:                                                  SN = sn,
 462:                                                  PN = pn,
 463:                                                  ONTID = ontId,
 464:                                                  NAME = columns.Contains("NAME") ? dataRow[columns.IndexOf("NAME")].ToString() : string.Empty,
 465:                                                  ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 466:                                                  CAPABPROF = columns.Contains("CAPABPROF") ? dataRow[columns.IndexOf("CAPABPROF")].ToString() : string.Empty,
 467:                                                  VENDORID = columns.Contains("VENDORID") ? dataRow[columns.IndexOf("VENDORID")].ToString() : string.Empty,
 468:                                                  EQUIPMENTID = columns.Contains("EQUIPMENTID") ? dataRow[columns.IndexOf("EQUIPMENTID")].ToString() : string.Empty,
 469:                                                  MAINSOFTVERSION = columns.Contains("MAINSOFTVERSION") ? dataRow[columns.IndexOf("MAINSOFTVERSION")].ToString() : string.Empty,
 470:                                                  AUTH = columns.Contains("AUTH") ? dataRow[columns.IndexOf("AUTH")].ToString() : string.Empty,
 471:                                                  AUTHTIMEOUT = columns.Contains("AUTHTIMEOUT") ? Ia.Ngn.Cl.Model.Business.Huawei.Ont.SpecialIntegerParameterHandling("AUTHTIMEOUT", dataRow[columns.IndexOf("AUTHTIMEOUT")].ToString()) : 0,
 472:                                                  LINEPROF = columns.Contains("LINEPROF") ? dataRow[columns.IndexOf("LINEPROF")].ToString() : string.Empty,
 473:                                                  SRVPROF = columns.Contains("SRVPROF") ? dataRow[columns.IndexOf("SRVPROF")].ToString() : string.Empty,
 474:                                                  SERIALNUM = columns.Contains("SERIALNUM") ? dataRow[columns.IndexOf("SERIALNUM")].ToString() : string.Empty,
 475:                                                  LOID = columns.Contains("LOID") ? dataRow[columns.IndexOf("LOID")].ToString() : string.Empty,
 476:                                                  CHECKCODE = columns.Contains("CHECKCODE") ? dataRow[columns.IndexOf("CHECKCODE")].ToString() : string.Empty,
 477:                                                  PWD = columns.Contains("PWD") ? dataRow[columns.IndexOf("PWD")].ToString() : string.Empty,
 478:                                                  ALMPROF = columns.Contains("ALMPROF") ? dataRow[columns.IndexOf("ALMPROF")].ToString() : string.Empty,
 479:                                                  DEV = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty,
 480:                                                  VLAN = columns.Contains("VLAN") ? int.Parse(dataRow[columns.IndexOf("VLAN")].ToString()) : 0,
 481:                                                  PRI = columns.Contains("PRI") ? int.Parse(dataRow[columns.IndexOf("PRI")].ToString()) : 0,
 482:                                                  IP = columns.Contains("IP") ? dataRow[columns.IndexOf("IP")].ToString() : string.Empty,
 483:                                                  MASK = columns.Contains("MASK") ? dataRow[columns.IndexOf("MASK")].ToString() : string.Empty,
 484:                                                  GATE = columns.Contains("GATE") ? dataRow[columns.IndexOf("GATE")].ToString() : string.Empty,
 485:                                                  ROUTEIP = columns.Contains("ROUTEIP") ? dataRow[columns.IndexOf("ROUTEIP")].ToString() : string.Empty,
 486:                                                  ROUTEMASK = columns.Contains("ROUTEMASK") ? dataRow[columns.IndexOf("ROUTEMASK")].ToString() : string.Empty,
 487:                                                  NEXTHOP = columns.Contains("NEXTHOP") ? dataRow[columns.IndexOf("NEXTHOP")].ToString() : string.Empty,
 488:                                                  SNMPPROF = columns.Contains("SNMPPROF") ? dataRow[columns.IndexOf("SNMPPROF")].ToString() : string.Empty,
 489:                                                  OPTALMPROF = columns.Contains("OPTALMPROF") ? dataRow[columns.IndexOf("OPTALMPROF")].ToString() : string.Empty,
 490:                                                  VAPROF = columns.Contains("VAPROF") ? dataRow[columns.IndexOf("VAPROF")].ToString() : string.Empty,
 491:                                                  MACLEARN = columns.Contains("MACLEARN") ? dataRow[columns.IndexOf("MACLEARN")].ToString() : string.Empty,
 492:                                                  SRVLEVELPROF = columns.Contains("SRVLEVELPROF") ? dataRow[columns.IndexOf("SRVLEVELPROF")].ToString() : string.Empty,
 493:                                                  LSTUPTIME = columns.Contains("LSTUPTIME") ? int.Parse(dataRow[columns.IndexOf("LSTUPTIME")].ToString()) : 0,
 494:                                                  LSTDOWNTIME = columns.Contains("LSTDOWNTIME") ? int.Parse(dataRow[columns.IndexOf("LSTDOWNTIME")].ToString()) : 0,
 495:                                                  DEVCURRENTTIME = columns.Contains("DEVCURRENTTIME") ? int.Parse(dataRow[columns.IndexOf("DEVCURRENTTIME")].ToString()) : 0,
 496:                                                  VASPROFILESET = columns.Contains("VASPROFILESET") ? dataRow[columns.IndexOf("VASPROFILESET")].ToString() : string.Empty,
 497:                                                  HARDWAREVERSION = columns.Contains("HARDWAREVERSION") ? dataRow[columns.IndexOf("HARDWAREVERSION")].ToString() : string.Empty,
 498:                                                  OPERSTATE = columns.Contains("OPERSTATE") ? dataRow[columns.IndexOf("OPERSTATE")].ToString() : string.Empty,
 499:                                                  DEVNAME = columns.Contains("DEVNAME") ? dataRow[columns.IndexOf("DEVNAME")].ToString() : string.Empty,
 500:                                                  BINDWIDTHTYPE = columns.Contains("BINDWIDTHTYPE") ? int.Parse(dataRow[columns.IndexOf("BINDWIDTHTYPE")].ToString()) : 0,
 501:                                                  EmsPort = (from ep in db.EmsPorts where ep.Id == port.Id select ep).SingleOrDefault()
 502:                                              };
 503:   
 504:                                              accessId = Ia.Ngn.Cl.Model.Business.Access.AccessId(id);
 505:                                              if (accessId != null) newOnt.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 506:   
 507:                                              if (ont == null)
 508:                                              {
 509:                                                  newOnt.Created = newOnt.Updated = DateTime.UtcNow.AddHours(3);
 510:   
 511:                                                  db.EmsOnts.Add(newOnt);
 512:   
 513:                                                  insertedItemCount++;
 514:                                              }
 515:                                              else // update
 516:                                              {
 517:                                                  // below: copy values from newOnt to ont
 518:   
 519:                                                  if (ont.Update(newOnt))
 520:                                                  {
 521:                                                      db.EmsOnts.Attach(ont);
 522:                                                      db.Entry(ont).State = System.Data.Entity.EntityState.Modified;
 523:   
 524:                                                      updatedItemCount++;
 525:                                                  }
 526:                                              }
 527:                                          }
 528:                                          else
 529:                                          {
 530:                                              result.AddError("did, fn, sn, pn, and/or ontId is/are not equal to queryDid, queryFn, querySn, queryPn, and/or ontId. did: " + did + ", queryDid: " + queryDev + ", fn: " + fn + ", queryFn: " + queryFn + ", sn: " + sn + ", querySn: " + querySn + ", pn: " + pn + ", queryPn: " + queryPn + ", ontId: " + ontId + ", queryOntId: " + queryOntId);
 531:                                          }
 532:                                      }
 533:                                      else //if (readItemCount > 1)
 534:                                      {
 535:                                          result.AddError("dataTable.Rows.Count has more than 1 row");
 536:                                      }
 537:                                  }
 538:                                  else
 539:                                  {
 540:                                      // if DataTable is null or "Resource does not exist"
 541:                                      // delete element if exists
 542:   
 543:                                      if (ont != null)
 544:                                      {
 545:                                          db.EmsOnts.Remove(ont);
 546:   
 547:                                          deletedItemCount++;
 548:                                      }
 549:   
 550:                                      result.AddWarning("LST-ONT: " + accessName + " (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 551:                                  }
 552:   
 553:                                  db.SaveChanges();
 554:                              }
 555:   
 556:                              if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 557:                              else isUpdated = false;
 558:   
 559:                              result.AddSuccess("LST-ONT: " + accessName + " (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ") (" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 560:                          }
 561:                          else
 562:                          {
 563:                              result.AddWarning("NDD PON is null");
 564:                          }
 565:                      }
 566:                      else
 567:                      {
 568:                          result.AddWarning("port is null");
 569:                      }
 570:                  }
 571:                  else
 572:                  {
 573:                      result.AddError("devToDidDictionary does not contain key: " + queryDev);
 574:                  }
 575:              }
 576:              else
 577:              {
 578:                  result.AddWarning("LST-ONT: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 579:              }
 580:   
 581:              return isUpdated;
 582:          }
 583:   
 584:          ////////////////////////////////////////////////////////////////////////////
 585:   
 586:          /// <summary>
 587:          ///
 588:          /// </summary>
 589:          public static bool UpdateListWithDid(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
 590:          {
 591:              bool isUpdated;
 592:              int queryDid, did, fn, sn, pn, ontId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 593:              string id, queryCommand, accessId;
 594:              DataColumnCollection columns;
 595:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon;
 596:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt;
 597:              Ia.Ngn.Cl.Model.Huawei.EmsOnt ont, newOnt;
 598:              Ia.Ngn.Cl.Model.Huawei.EmsPort port;
 599:              List<string> itemIdList;
 600:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ontList;
 601:   
 602:              isUpdated = false;
 603:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 604:              result = new Ia.Cl.Model.Result();
 605:   
 606:              if (response.CompletionCode == "COMPLD")
 607:              {
 608:                  if (response.QueryDataTable != null)
 609:                  {
 610:                      queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
 611:   
 612:                      columns = response.QueryDataTable.Columns;
 613:                      readItemCount = response.QueryDataTable.Rows.Count;
 614:   
 615:                      // "LST-ONT::DID=" + olt.Did + ":{ctag}::;";
 616:                      queryDid = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"DID=(\d+):"));
 617:   
 618:                      olt = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltByDid(queryDid);
 619:   
 620:                      if (olt != null)
 621:                      {
 622:                          ontList = Ia.Ngn.Cl.Model.Data.Huawei.Ont.ListByDid(queryDid);
 623:                          existingItemCount = ontList.Count;
 624:   
 625:                          itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
 626:   
 627:                          using (var db = new Ia.Ngn.Cl.Model.Ngn())
 628:                          {
 629:                              foreach (DataRow dataRow in response.QueryDataTable.Rows)
 630:                              {
 631:                                  did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
 632:                                  fn = int.Parse(dataRow[columns.IndexOf("FN")].ToString());
 633:                                  sn = int.Parse(dataRow[columns.IndexOf("SN")].ToString());
 634:                                  pn = int.Parse(dataRow[columns.IndexOf("PN")].ToString());
 635:                                  ontId = int.Parse(dataRow[columns.IndexOf("ONTID")].ToString());
 636:   
 637:                                  port = Ia.Ngn.Cl.Model.Data.Huawei.Port.ReadByDidFnSnPn(queryDid, fn, sn, pn);
 638:   
 639:                                  if (port != null)
 640:                                  {
 641:                                      ontList = (from eo in db.EmsOnts where eo.EmsPort.Id == port.Id select eo).ToList();
 642:                                      // or ontList = Ia.Ngn.Cl.Model.Data.Huawei.Ont.List(port.Id);
 643:   
 644:                                      if (did == queryDid)
 645:                                      {
 646:                                          pon = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PonByOltEmsNameAndSnAndPn(olt.EmsName, sn, pn);
 647:   
 648:                                          if (pon != null)
 649:                                          {
 650:                                              id = Ia.Ngn.Cl.Model.Business.Huawei.Ont.OntId(pon.Id, ontId);
 651:   
 652:                                              newOnt = new Ia.Ngn.Cl.Model.Huawei.EmsOnt()
 653:                                              {
 654:                                                  Id = id,
 655:                                                  DID = did,
 656:                                                  FN = fn,
 657:                                                  SN = sn,
 658:                                                  PN = pn,
 659:                                                  ONTID = ontId,
 660:                                                  NAME = columns.Contains("NAME") ? dataRow[columns.IndexOf("NAME")].ToString() : string.Empty,
 661:                                                  ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 662:                                                  CAPABPROF = columns.Contains("CAPABPROF") ? dataRow[columns.IndexOf("CAPABPROF")].ToString() : string.Empty,
 663:                                                  VENDORID = columns.Contains("VENDORID") ? dataRow[columns.IndexOf("VENDORID")].ToString() : string.Empty,
 664:                                                  EQUIPMENTID = columns.Contains("EQUIPMENTID") ? dataRow[columns.IndexOf("EQUIPMENTID")].ToString() : string.Empty,
 665:                                                  MAINSOFTVERSION = columns.Contains("MAINSOFTVERSION") ? dataRow[columns.IndexOf("MAINSOFTVERSION")].ToString() : string.Empty,
 666:                                                  AUTH = columns.Contains("AUTH") ? dataRow[columns.IndexOf("AUTH")].ToString() : string.Empty,
 667:                                                  AUTHTIMEOUT = columns.Contains("AUTHTIMEOUT") ? Ia.Ngn.Cl.Model.Business.Huawei.Ont.SpecialIntegerParameterHandling("AUTHTIMEOUT", dataRow[columns.IndexOf("AUTHTIMEOUT")].ToString()) : 0,
 668:                                                  LINEPROF = columns.Contains("LINEPROF") ? dataRow[columns.IndexOf("LINEPROF")].ToString() : string.Empty,
 669:                                                  SRVPROF = columns.Contains("SRVPROF") ? dataRow[columns.IndexOf("SRVPROF")].ToString() : string.Empty,
 670:                                                  SERIALNUM = columns.Contains("SERIALNUM") ? dataRow[columns.IndexOf("SERIALNUM")].ToString() : string.Empty,
 671:                                                  LOID = columns.Contains("LOID") ? dataRow[columns.IndexOf("LOID")].ToString() : string.Empty,
 672:                                                  CHECKCODE = columns.Contains("CHECKCODE") ? dataRow[columns.IndexOf("CHECKCODE")].ToString() : string.Empty,
 673:                                                  PWD = columns.Contains("PWD") ? dataRow[columns.IndexOf("PWD")].ToString() : string.Empty,
 674:                                                  ALMPROF = columns.Contains("ALMPROF") ? dataRow[columns.IndexOf("ALMPROF")].ToString() : string.Empty,
 675:                                                  DEV = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty,
 676:                                                  VLAN = columns.Contains("VLAN") ? int.Parse(dataRow[columns.IndexOf("VLAN")].ToString()) : 0,
 677:                                                  PRI = columns.Contains("PRI") ? int.Parse(dataRow[columns.IndexOf("PRI")].ToString()) : 0,
 678:                                                  IP = columns.Contains("IP") ? dataRow[columns.IndexOf("IP")].ToString() : string.Empty,
 679:                                                  MASK = columns.Contains("MASK") ? dataRow[columns.IndexOf("MASK")].ToString() : string.Empty,
 680:                                                  GATE = columns.Contains("GATE") ? dataRow[columns.IndexOf("GATE")].ToString() : string.Empty,
 681:                                                  ROUTEIP = columns.Contains("ROUTEIP") ? dataRow[columns.IndexOf("ROUTEIP")].ToString() : string.Empty,
 682:                                                  ROUTEMASK = columns.Contains("ROUTEMASK") ? dataRow[columns.IndexOf("ROUTEMASK")].ToString() : string.Empty,
 683:                                                  NEXTHOP = columns.Contains("NEXTHOP") ? dataRow[columns.IndexOf("NEXTHOP")].ToString() : string.Empty,
 684:                                                  SNMPPROF = columns.Contains("SNMPPROF") ? dataRow[columns.IndexOf("SNMPPROF")].ToString() : string.Empty,
 685:                                                  OPTALMPROF = columns.Contains("OPTALMPROF") ? dataRow[columns.IndexOf("OPTALMPROF")].ToString() : string.Empty,
 686:                                                  VAPROF = columns.Contains("VAPROF") ? dataRow[columns.IndexOf("VAPROF")].ToString() : string.Empty,
 687:                                                  MACLEARN = columns.Contains("MACLEARN") ? dataRow[columns.IndexOf("MACLEARN")].ToString() : string.Empty,
 688:                                                  SRVLEVELPROF = columns.Contains("SRVLEVELPROF") ? dataRow[columns.IndexOf("SRVLEVELPROF")].ToString() : string.Empty,
 689:                                                  LSTUPTIME = columns.Contains("LSTUPTIME") ? int.Parse(dataRow[columns.IndexOf("LSTUPTIME")].ToString()) : 0,
 690:                                                  LSTDOWNTIME = columns.Contains("LSTDOWNTIME") ? int.Parse(dataRow[columns.IndexOf("LSTDOWNTIME")].ToString()) : 0,
 691:                                                  DEVCURRENTTIME = columns.Contains("DEVCURRENTTIME") ? int.Parse(dataRow[columns.IndexOf("DEVCURRENTTIME")].ToString()) : 0,
 692:                                                  VASPROFILESET = columns.Contains("VASPROFILESET") ? dataRow[columns.IndexOf("VASPROFILESET")].ToString() : string.Empty,
 693:                                                  HARDWAREVERSION = columns.Contains("HARDWAREVERSION") ? dataRow[columns.IndexOf("HARDWAREVERSION")].ToString() : string.Empty,
 694:                                                  OPERSTATE = columns.Contains("OPERSTATE") ? dataRow[columns.IndexOf("OPERSTATE")].ToString() : string.Empty,
 695:                                                  DEVNAME = columns.Contains("DEVNAME") ? dataRow[columns.IndexOf("DEVNAME")].ToString() : string.Empty,
 696:                                                  BINDWIDTHTYPE = columns.Contains("BINDWIDTHTYPE") ? int.Parse(dataRow[columns.IndexOf("BINDWIDTHTYPE")].ToString()) : 0,
 697:                                                  EmsPort = (from ep in db.EmsPorts where ep.Id == port.Id select ep).SingleOrDefault()
 698:                                              };
 699:   
 700:                                              accessId = Ia.Ngn.Cl.Model.Business.Access.AccessId(id);
 701:                                              if (accessId != null) newOnt.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 702:   
 703:                                              ont = (from eo in /*ontList*/ db.EmsOnts where eo.Id == id select eo).SingleOrDefault();
 704:   
 705:                                              if (ont == null)
 706:                                              {
 707:                                                  newOnt.Created = newOnt.Updated = DateTime.UtcNow.AddHours(3);
 708:   
 709:                                                  db.EmsOnts.Add(newOnt);
 710:   
 711:                                                  insertedItemCount++;
 712:                                              }
 713:                                              else
 714:                                              {
 715:                                                  // below: copy values from newOnt to ont
 716:   
 717:                                                  if (ont.Update(newOnt))
 718:                                                  {
 719:                                                      db.EmsOnts.Attach(ont);
 720:                                                      db.Entry(ont).State = System.Data.Entity.EntityState.Modified;
 721:   
 722:                                                      updatedItemCount++;
 723:                                                  }
 724:                                              }
 725:   
 726:                                              itemIdList.Add(id); // keep at the end
 727:                                          }
 728:                                          else
 729:                                          {
 730:                                              result.AddError("PON is null.");
 731:                                          }
 732:                                      }
 733:                                      else
 734:                                      {
 735:                                          result.AddError("did not equal to queryDid. did: " + did);
 736:                                      }
 737:                                  }
 738:                                  else
 739:                                  {
 740:                                      result.AddWarning("port is null");
 741:                                  }
 742:                              }
 743:   
 744:                              // below: this function will remove values that were not present in the reading
 745:                              if (ontList.Count > 0)
 746:                              {
 747:                                  foreach (Ia.Ngn.Cl.Model.Huawei.EmsOnt on in ontList)
 748:                                  {
 749:                                      if (!itemIdList.Contains(on.Id))
 750:                                      {
 751:                                          ont = (from o in db.EmsOnts where o.Id == @on.Id select o).SingleOrDefault();
 752:   
 753:                                          db.EmsOnts.Remove(ont);
 754:   
 755:                                          deletedItemCount++;
 756:                                      }
 757:                                  }
 758:                              }
 759:   
 760:                              db.SaveChanges();
 761:                          }
 762:   
 763:                          if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 764:                          else isUpdated = false;
 765:   
 766:                          result.AddSuccess("LST-ONT: (" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 767:                      }
 768:                      else
 769:                      {
 770:                          result.AddWarning("NDD OLT is null");
 771:                      }
 772:                  }
 773:                  else
 774:                  {
 775:                      result.AddWarning("LST-ONT: QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 776:                  }
 777:              }
 778:              else
 779:              {
 780:                  result.AddWarning("LST-ONT: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 781:              }
 782:   
 783:              return isUpdated;
 784:          }
 785:   
 786:          ////////////////////////////////////////////////////////////////////////////
 787:   
 788:          /// <summary>
 789:          ///
 790:          /// </summary>
 791:          public static bool UpdateResultCode(Ia.Ngn.Cl.Model.Huawei.EmsOnt emsOnt, Ia.Ngn.Cl.Model.Client.Huawei.Ems.ResultCode resultCode)
 792:          {
 793:              // similar to Ia.Ngn.Cl.Model.Data.Huawei.Dev.UpdateResultCode();
 794:              bool isUpdated;
 795:   
 796:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 797:              {
 798:                  if (emsOnt != null)
 799:                  {
 800:                      var updatedOnt = (from o in db.EmsOnts where o.Id == emsOnt.Id select o).SingleOrDefault();
 801:   
 802:                      if (updatedOnt != null)
 803:                      {
 804:                          if (updatedOnt.ResultCode != (long)resultCode)
 805:                          {
 806:                              updatedOnt.ResultCode = (long)resultCode;
 807:                              updatedOnt.Updated = DateTime.UtcNow.AddHours(3);
 808:   
 809:                              db.EmsOnts.Attach(updatedOnt);
 810:                              db.Entry(updatedOnt).Property(x => x.ResultCode).IsModified = true;
 811:                              db.Entry(updatedOnt).Property(x => x.Updated).IsModified = true;
 812:   
 813:                              db.SaveChanges();
 814:   
 815:                              isUpdated = true;
 816:                              //result.AddSuccess("EmsOnt.ResultCode updated. ");
 817:                          }
 818:                          else
 819:                          {
 820:                              isUpdated = false;
 821:                              // result.AddWarning("Warning: EmsOnt.ResultCode value was not updated because its the same. ");
 822:                          }
 823:                      }
 824:                      else
 825:                      {
 826:                          isUpdated = false;
 827:                          // result.AddError("Error: updatedOnt is null. ");
 828:                      }
 829:                  }
 830:                  else
 831:                  {
 832:                      isUpdated = false;
 833:                  }
 834:              }
 835:   
 836:              return isUpdated;
 837:          }
 838:   
 839:          ////////////////////////////////////////////////////////////////////////////
 840:   
 841:          /// <summary>
 842:          ///
 843:          /// </summary>
 844:          public static bool NullifyAccessIdByAccessId(string accessId, out string result)
 845:          {
 846:              bool b;
 847:              int numberOfRecordsWhereAccessIsNullified;
 848:              Ia.Ngn.Cl.Model.Huawei.EmsOnt ont;
 849:   
 850:              b = false;
 851:              numberOfRecordsWhereAccessIsNullified = 0;
 852:   
 853:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 854:              {
 855:                  // --update EmsOnts set Access_Id = null where Access_Id = '1040101010040004'
 856:                  //var query = (from eo in db.EmsOnts where eo.Access.Id == accessId select eo).ToList();
 857:   
 858:                  //foreach (var v in query)
 859:                  //{
 860:                  ont = (from o in db.EmsOnts where o.Access.Id == accessId select o).FirstOrDefault(); //.SingleOrDefault();
 861:   
 862:                  if (ont != null)
 863:                  {
 864:                      ont.Access = null;
 865:                      ont.Updated = DateTime.UtcNow.AddHours(3);
 866:   
 867:                      db.EmsOnts.Attach(ont);
 868:                      db.Entry(ont).Property(x => x.Updated).IsModified = true;
 869:   
 870:                      db.SaveChanges();
 871:   
 872:                      numberOfRecordsWhereAccessIsNullified++;
 873:                  }
 874:                  //}
 875:   
 876:                  b = true;
 877:              }
 878:   
 879:              result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 880:   
 881:              return b;
 882:          }
 883:   
 884:          ////////////////////////////////////////////////////////////////////////////
 885:   
 886:          /// <summary>
 887:          ///
 888:          /// </summary>
 889:          public static bool Delete(string id, out string result)
 890:          {
 891:              bool b;
 892:   
 893:              b = false;
 894:              result = string.Empty;
 895:   
 896:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 897:              {
 898:                  var v = (from em in db.EmsOnts where em.Id == id select em).FirstOrDefault();
 899:   
 900:                  if (v != null)
 901:                  {
 902:                      db.EmsOnts.Remove(v);
 903:                      db.SaveChanges();
 904:   
 905:                      b = true;
 906:                  }
 907:                  else b = false;
 908:              }
 909:   
 910:              return b;
 911:          }
 912:   
 913:          ////////////////////////////////////////////////////////////////////////////
 914:   
 915:          /// <summary>
 916:          ///
 917:          /// </summary>
 918:          public static bool DeleteByAccessId(string accessId, out string result)
 919:          {
 920:              bool b;
 921:   
 922:              b = false;
 923:              result = string.Empty;
 924:   
 925:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 926:              {
 927:                  var v = (from eo in db.EmsOnts where eo.Access.Id == accessId select eo).Include(u => u.Access).FirstOrDefault();
 928:   
 929:                  if (v != null)
 930:                  {
 931:                      db.EmsOnts.Remove(v);
 932:                      db.SaveChanges();
 933:   
 934:                      b = true;
 935:                  }
 936:                  else b = false;
 937:              }
 938:   
 939:              return b;
 940:          }
 941:   
 942:          ////////////////////////////////////////////////////////////////////////////
 943:          ////////////////////////////////////////////////////////////////////////////
 944:      }
 945:   
 946:      ////////////////////////////////////////////////////////////////////////////
 947:      ////////////////////////////////////////////////////////////////////////////
 948:  }