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

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