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

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