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

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

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