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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Dev

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

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

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Linq;
   5:  using System.Text;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Huawei's Dev support class of Next Generation Network'a (NGN's) data model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2016-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  17:      ///
  18:      /// 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
  19:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  20:      ///
  21:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23:      /// 
  24:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  25:      /// 
  26:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  27:      /// </remarks> 
  28:      public partial class Dev
  29:      {
  30:          private static Dictionary<string, int> devTypeToDevTypeIdDictionary;
  31:          private static Dictionary<int, string> devTypeIdToDevTypeDictionary;
  32:   
  33:          private static Dictionary<string, int> devToDidDictionary;
  34:          private static Dictionary<int, string> didToDevDictionary;
  35:   
  36:          public static Dictionary<string, int> DevTypeToDevTypeIdDictionary
  37:          {
  38:              get
  39:              {
  40:                  if (devTypeToDevTypeIdDictionary == null || devTypeToDevTypeIdDictionary.Count == 0)
  41:                  {
  42:                      devTypeToDevTypeIdDictionary = new Dictionary<string, int>();
  43:   
  44:                      devTypeToDevTypeIdDictionary["UA5000(PVMV1)"] = 219;
  45:                      devTypeToDevTypeIdDictionary["MA5662"] = 37;
  46:                      devTypeToDevTypeIdDictionary["MA5600V3"] = 44;
  47:                      devTypeToDevTypeIdDictionary["MA5105(BSL)"] = 71;
  48:                      devTypeToDevTypeIdDictionary["MA5100V2"] = 72;
  49:                      devTypeToDevTypeIdDictionary["MA5300V1"] = 74;
  50:                      devTypeToDevTypeIdDictionary["MD5500V1"] = 75;
  51:                      devTypeToDevTypeIdDictionary["UA5000"] = 82;
  52:                      devTypeToDevTypeIdDictionary["MA5100V1"] = 86;
  53:                      devTypeToDevTypeIdDictionary["UA5000(IPMB)"] = 253;
  54:                      devTypeToDevTypeIdDictionary["MA5605"] = 30;
  55:                      devTypeToDevTypeIdDictionary["MA5680T"] = 34;
  56:                      devTypeToDevTypeIdDictionary["MA5606T"] = 57;
  57:                      devTypeToDevTypeIdDictionary["UA5000(PVU)"] = 232;
  58:                      devTypeToDevTypeIdDictionary["MA5600T"] = 249;
  59:                      devTypeToDevTypeIdDictionary["MA5615"] = 60;
  60:                      devTypeToDevTypeIdDictionary["MA5626E"] = 61;
  61:                      devTypeToDevTypeIdDictionary["MA5620E"] = 62;
  62:                      devTypeToDevTypeIdDictionary["MA5651"] = 64;
  63:                      devTypeToDevTypeIdDictionary["MA5620G"] = 65;
  64:                      devTypeToDevTypeIdDictionary["MA5626G"] = 66;
  65:                      devTypeToDevTypeIdDictionary["MA5651G"] = 67;
  66:                      devTypeToDevTypeIdDictionary["MA5610"] = 70;
  67:                      devTypeToDevTypeIdDictionary["MA5652G"] = 92;
  68:                      devTypeToDevTypeIdDictionary["MA5603U"] = 94;
  69:                      devTypeToDevTypeIdDictionary["MA5603T"] = 95;
  70:                      devTypeToDevTypeIdDictionary["MA5620"] = 96;
  71:                      devTypeToDevTypeIdDictionary["MA5626"] = 97;
  72:                      devTypeToDevTypeIdDictionary["MA5616"] = 100;
  73:                      devTypeToDevTypeIdDictionary["MA5635"] = 103;
  74:                      devTypeToDevTypeIdDictionary["MA5612"] = 104;
  75:                      devTypeToDevTypeIdDictionary["MA5621"] = 2319;
  76:                      devTypeToDevTypeIdDictionary["MA5628"] = 2312;
  77:                      devTypeToDevTypeIdDictionary["MA5652"] = 2313;
  78:                      devTypeToDevTypeIdDictionary["MA5631"] = 2317;
  79:                      devTypeToDevTypeIdDictionary["MA5612A"] = 2320;
  80:                      devTypeToDevTypeIdDictionary["MA5669"] = 2321;
  81:                      devTypeToDevTypeIdDictionary["MA5621A"] = 2322;
  82:                      devTypeToDevTypeIdDictionary["MA5622A"] = 2323;
  83:                      devTypeToDevTypeIdDictionary["MA5623"] = 2324;
  84:                      devTypeToDevTypeIdDictionary["MA5623A"] = 2326;
  85:                      devTypeToDevTypeIdDictionary["MA5632"] = 2318;
  86:                      devTypeToDevTypeIdDictionary["MA5608T"] = 2331;
  87:                      devTypeToDevTypeIdDictionary["MA5698"] = 2333;
  88:                      devTypeToDevTypeIdDictionary["MA5694"] = 2335;
  89:                      devTypeToDevTypeIdDictionary["MA5821"] = 2336;
  90:                      devTypeToDevTypeIdDictionary["MA5822"] = 2337;
  91:                      devTypeToDevTypeIdDictionary["MA5898"] = 2338;
  92:                      devTypeToDevTypeIdDictionary["MA5818"] = 2339;
  93:                      devTypeToDevTypeIdDictionary["MA5611S"] = 2340;
  94:                      devTypeToDevTypeIdDictionary["MA5694S"] = 2343;
  95:                      devTypeToDevTypeIdDictionary["RPS"] = 2344;
  96:                  }
  97:   
  98:                  return devTypeToDevTypeIdDictionary;
  99:              }
 100:          }
 101:   
 102:          /// <summary/>
 103:          public Dev() { }
 104:   
 105:          ////////////////////////////////////////////////////////////////////////////
 106:   
 107:          /// <summary>
 108:          ///
 109:          /// </summary>
 110:          public static Dictionary<int, string> DevTypeIdToDevTypeDictionary
 111:          {
 112:              get
 113:              {
 114:                  if (devTypeIdToDevTypeDictionary == null || devTypeIdToDevTypeDictionary.Count == 0)
 115:                  {
 116:                      devTypeIdToDevTypeDictionary = new Dictionary<int, string>();
 117:   
 118:                      foreach (KeyValuePair<string, int> kvp in DevTypeToDevTypeIdDictionary) devTypeIdToDevTypeDictionary[kvp.Value] = kvp.Key;
 119:                  }
 120:   
 121:                  return devTypeIdToDevTypeDictionary;
 122:              }
 123:          }
 124:   
 125:          ////////////////////////////////////////////////////////////////////////////
 126:   
 127:          /// <summary>
 128:          ///
 129:          /// </summary>
 130:          public static Dictionary<string, int> DevToDidDictionary
 131:          {
 132:              get
 133:              {
 134:                  if (devToDidDictionary == null || devToDidDictionary.Count == 0)
 135:                  {
 136:                      devToDidDictionary = new Dictionary<string, int>();
 137:   
 138:                      List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 139:   
 140:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 141:                      {
 142:                          // this will list the Disconnecting devs first so that if there is an override it will allow the Connecting to be in dictionary
 143:                          list = (from ed in db.EmsDevs select ed).OrderBy(u => u.DSTAT == "Connecting").ToList();
 144:                      }
 145:   
 146:                      foreach (var d in list) devToDidDictionary[d.DEV] = d.DID;
 147:                  }
 148:   
 149:                  return devToDidDictionary;
 150:              }
 151:          }
 152:   
 153:          ////////////////////////////////////////////////////////////////////////////
 154:   
 155:          /// <summary>
 156:          ///
 157:          /// </summary>
 158:          public static Dictionary<int, string> DidToDevDictionary
 159:          {
 160:              get
 161:              {
 162:                  if (didToDevDictionary == null || didToDevDictionary.Count == 0)
 163:                  {
 164:                      didToDevDictionary = new Dictionary<int, string>();
 165:   
 166:                      foreach (KeyValuePair<string, int> kvp in DevToDidDictionary) didToDevDictionary[kvp.Value] = kvp.Key;
 167:                  }
 168:   
 169:                  return didToDevDictionary;
 170:              }
 171:          }
 172:   
 173:          ////////////////////////////////////////////////////////////////////////////
 174:   
 175:          /// <summary>
 176:          ///
 177:          /// </summary>
 178:          public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
 179:          {
 180:              bool isUpdated;
 181:              int id, queryDtTypeId, did, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 182:              string queryCommand, queryDev, devDev, dtType;
 183:              DataColumnCollection columns;
 184:              DataRow columnDataRow;
 185:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 186:              Ia.Ngn.Cl.Model.Huawei.EmsDev dev, newDev;
 187:              List<int> itemIdList;
 188:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devList;
 189:   
 190:              isUpdated = false;
 191:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 192:              result = new Ia.Cl.Model.Result();
 193:   
 194:              if (response.CompletionCode == "COMPLD")
 195:              {
 196:                  if (response.QueryDataTable != null)
 197:                  {
 198:                      queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
 199:   
 200:                      columns = response.QueryDataTable.Columns;
 201:                      readItemCount = response.QueryDataTable.Rows.Count;
 202:   
 203:                      itemIdList = new List<int>(response.QueryDataTable.Rows.Count + 1);
 204:   
 205:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 206:                      {
 207:                          if (queryCommand.Contains("LST-DEV::DT") || queryCommand.Contains("LST-DEV::DEV"))
 208:                          {
 209:                              if (queryCommand.Contains("LST-DEV::DT"))
 210:                              {
 211:                                  // LST-DEV::DT=100:{ctag}::;
 212:                                  queryDtTypeId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"DT=(\d+)"));
 213:   
 214:                                  //if (Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary.ContainsKey(queryDtTypeId))
 215:                                  //{
 216:                                  dtType = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary[queryDtTypeId];
 217:   
 218:                                  devList = (from ed in db.EmsDevs where ed.DT == dtType select ed).ToList();
 219:                                  //}
 220:                                  //else
 221:                                  //{
 222:                                  //    result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary does not contain key queryDtTypeId: " + queryDtTypeId);
 223:                                  //}
 224:                              }
 225:                              else //if (queryCommand.Contains("LST-DEV::DEV"))
 226:                              {
 227:                                  // LST-DEV::DEV=MDU-SAB-1443-001:{ctag}::;
 228:   
 229:                                  queryDev = Ia.Cl.Model.Default.Match(queryCommand, @"DEV=(.+?):");
 230:   
 231:                                  devList = (from ed in db.EmsDevs where ed.DEV == queryDev select ed).ToList();
 232:                              }
 233:   
 234:                              existingItemCount = devList.Count;
 235:   
 236:                              if (response.QueryDataTable.Rows.Count >= 1)
 237:                              {
 238:                                  columnDataRow = response.QueryDataTable.Rows[0];
 239:   
 240:                                  foreach (DataRow dataRow in response.QueryDataTable.Rows)
 241:                                  {
 242:                                      did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
 243:   
 244:                                      id = Ia.Ngn.Cl.Model.Business.Huawei.Dev.DevId(did);
 245:   
 246:                                      dev = (from d in devList where d.Id == id select d).SingleOrDefault();
 247:   
 248:                                      devDev = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty;
 249:   
 250:                                      newDev = new Ia.Ngn.Cl.Model.Huawei.EmsDev()
 251:                                      {
 252:                                          Id = id,
 253:                                          DID = did,
 254:                                          ResultCode = (long)response.ResultCode,
 255:                                          DEV = devDev,
 256:                                          DEVIP = columns.Contains("DEVIP") ? dataRow[columns.IndexOf("DEVIP")].ToString() : string.Empty,
 257:                                          DT = columns.Contains("DT") ? dataRow[columns.IndexOf("DT")].ToString() : string.Empty,
 258:                                          DVER = columns.Contains("DVER") ? dataRow[columns.IndexOf("DVER")].ToString() : string.Empty,
 259:                                          DSTAT = columns.Contains("DSTAT") ? dataRow[columns.IndexOf("DSTAT")].ToString() : string.Empty,
 260:                                          DLOC = columns.Contains("DLOC") ? dataRow[columns.IndexOf("DLOC")].ToString() : string.Empty,
 261:                                          AdminStat = columns.Contains("AdminStat") ? dataRow[columns.IndexOf("AdminStat")].ToString() : string.Empty,
 262:                                          WorkMode = columns.Contains("WorkMode") ? dataRow[columns.IndexOf("WorkMode")].ToString() : string.Empty,
 263:                                          ADDITIONALINFO = columns.Contains("ADDITIONALINFO") ? dataRow[columns.IndexOf("ADDITIONALINFO")].ToString() : string.Empty,
 264:                                          CRTID = columns.Contains("CRTID") ? dataRow[columns.IndexOf("CRTID")].ToString() : string.Empty,
 265:                                          CRTADDR = columns.Contains("CRTADDR") ? dataRow[columns.IndexOf("CRTADDR")].ToString() : string.Empty,
 266:                                          CRTTEL = columns.Contains("CRTTEL") ? dataRow[columns.IndexOf("CRTTEL")].ToString() : string.Empty,
 267:                                          CRTDATE = columns.Contains("CRTDATE") ? dataRow[columns.IndexOf("CRTDATE")].ToString() : string.Empty,
 268:                                          REMARK = columns.Contains("REMARK") ? dataRow[columns.IndexOf("REMARK")].ToString() : string.Empty,
 269:                                          TYPE = columns.Contains("TYPE") ? dataRow[columns.IndexOf("TYPE")].ToString() : string.Empty,
 270:                                          NERATELIST = columns.Contains("NERATELIST") ? dataRow[columns.IndexOf("NERATELIST")].ToString() : string.Empty,
 271:                                          NEPROV = columns.Contains("NEPROV") ? dataRow[columns.IndexOf("NEPROV")].ToString() : string.Empty,
 272:                                          TOPXY = columns.Contains("TOPXY") ? dataRow[columns.IndexOf("TOPXY")].ToString() : string.Empty,
 273:                                          EMSID = columns.Contains("EMSID") ? dataRow[columns.IndexOf("EMSID")].ToString() : string.Empty,
 274:                                          ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 275:                                          PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
 276:                                          MAINTAINID = columns.Contains("MAINTAINID") ? dataRow[columns.IndexOf("MAINTAINID")].ToString() : string.Empty,
 277:                                          MAINTAINADDR = columns.Contains("MAINTAINADDR") ? dataRow[columns.IndexOf("MAINTAINADDR")].ToString() : string.Empty,
 278:                                          MAINTAINTEL = columns.Contains("MAINTAINTEL") ? dataRow[columns.IndexOf("MAINTAINTEL")].ToString() : string.Empty,
 279:                                          REGISTERSTAT = columns.Contains("REGISTERSTAT") ? dataRow[columns.IndexOf("REGISTERSTAT")].ToString() : string.Empty,
 280:                                      };
 281:   
 282:                                      nddOnt = Ia.Ngn.Cl.Model.Business.Default.NddOntFromHuaweiEmsAccessNameFormat(devDev);
 283:                                      if (nddOnt != null) newDev.Access = (from a in db.Accesses where a.Id == nddOnt.Access.Id select a).SingleOrDefault();
 284:   
 285:                                      if (dev == null)
 286:                                      {
 287:                                          newDev.Created = newDev.Updated = DateTime.UtcNow.AddHours(3);
 288:   
 289:                                          db.EmsDevs.Add(newDev);
 290:   
 291:                                          insertedItemCount++;
 292:                                      }
 293:                                      else // update
 294:                                      {
 295:                                          // below: copy values from newDev to dev
 296:   
 297:                                          if (dev.Update(newDev))
 298:                                          {
 299:                                              db.EmsDevs.Attach(dev);
 300:                                              db.Entry(dev).State = System.Data.Entity.EntityState.Modified;
 301:   
 302:                                              updatedItemCount++;
 303:                                          }
 304:                                      }
 305:   
 306:                                      itemIdList.Add(id); // keep at the end
 307:                                  }
 308:   
 309:                                  // below: this function will remove values that were not present in the reading
 310:                                  if (devList.Count > 0)
 311:                                  {
 312:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 313:                                      {
 314:                                          if (!itemIdList.Contains(de.Id))
 315:                                          {
 316:                                              dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 317:   
 318:                                              db.EmsDevs.Remove(dev);
 319:   
 320:                                              deletedItemCount++;
 321:                                          }
 322:                                      }
 323:                                  }
 324:                              }
 325:                              else
 326:                              {
 327:                                  // below: remove all values since reading was empty
 328:   
 329:                                  if (devList.Count > 0)
 330:                                  {
 331:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 332:                                      {
 333:                                          dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 334:   
 335:                                          db.EmsDevs.Remove(dev);
 336:   
 337:                                          deletedItemCount++;
 338:                                      }
 339:                                  }
 340:                              }
 341:                          }
 342:                          else
 343:                          {
 344:                              result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.Update() Unknown parameters in command: " + queryCommand);
 345:                          }
 346:   
 347:                          db.SaveChanges();
 348:                      }
 349:   
 350:                      if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 351:                      else isUpdated = false;
 352:   
 353:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 354:                  }
 355:                  else
 356:                  {
 357:                      result.AddWarning("LST-DEV: QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 358:                  }
 359:              }
 360:              else
 361:              {
 362:                  result.AddWarning("LST-DEV: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 363:              }
 364:   
 365:              return isUpdated;
 366:          }
 367:   
 368:          ////////////////////////////////////////////////////////////////////////////
 369:   
 370:          /// <summary>
 371:          ///
 372:          /// </summary>
 373:          public static bool UpdateResultCode(int emsDevDid, Ia.Ngn.Cl.Model.Client.Huawei.Ems.ResultCode resultCode)
 374:          {
 375:              // similar to Ia.Ngn.Cl.Model.Data.Huawei.Ont.UpdateResultCode();
 376:              bool isUpdated;
 377:   
 378:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 379:              {
 380:                  if (emsDevDid > 0)
 381:                  {
 382:                      var updatedDev = (from o in db.EmsDevs where o.DID == emsDevDid select o).SingleOrDefault();
 383:   
 384:                      if (updatedDev != null)
 385:                      {
 386:                          if (updatedDev.ResultCode != (long)resultCode)
 387:                          {
 388:                              updatedDev.ResultCode = (long)resultCode;
 389:                              updatedDev.Updated = DateTime.UtcNow.AddHours(3);
 390:   
 391:                              db.EmsDevs.Attach(updatedDev);
 392:                              db.Entry(updatedDev).Property(x => x.ResultCode).IsModified = true;
 393:                              db.Entry(updatedDev).Property(x => x.Updated).IsModified = true;
 394:   
 395:                              db.SaveChanges();
 396:   
 397:                              isUpdated = true;
 398:                              //result.AddSuccess("EmsDevs.ResultCode updated. ");
 399:                          }
 400:                          else
 401:                          {
 402:                              isUpdated = false;
 403:                              // result.AddWarning("Warning: EmsDevs.ResultCode value was not updated because its the same. ");
 404:                          }
 405:                      }
 406:                      else
 407:                      {
 408:                          isUpdated = false;
 409:                          // result.AddError("Error: updatedDev is null. ");
 410:                      }
 411:                  }
 412:                  else
 413:                  {
 414:                      isUpdated = false;
 415:                  }
 416:              }
 417:   
 418:              return isUpdated;
 419:          }
 420:   
 421:          ////////////////////////////////////////////////////////////////////////////
 422:   
 423:          /// <summary>
 424:          ///
 425:          /// </summary>
 426:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> List()
 427:          {
 428:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 429:   
 430:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 431:              {
 432:                  list = (from ed in db.EmsDevs select ed).ToList();
 433:              }
 434:   
 435:              return list;
 436:          }
 437:   
 438:          ////////////////////////////////////////////////////////////////////////////
 439:   
 440:          /// <summary>
 441:          ///
 442:          /// </summary>
 443:          public static List<string> DevList()
 444:          {
 445:              List<string> list;
 446:   
 447:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 448:              {
 449:                  list = (from ed in db.EmsDevs select ed.DEV).ToList();
 450:              }
 451:   
 452:              return list;
 453:          }
 454:   
 455:          ////////////////////////////////////////////////////////////////////////////
 456:   
 457:          /// <summary>
 458:          ///
 459:          /// </summary>
 460:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByMA5616DevType()
 461:          {
 462:              return ListByDevType("MA5616");
 463:          }
 464:   
 465:          ////////////////////////////////////////////////////////////////////////////
 466:   
 467:          /// <summary>
 468:          ///
 469:          /// </summary>
 470:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByDevType(string devType)
 471:          {
 472:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 473:   
 474:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 475:              {
 476:                  list = (from ed in db.EmsDevs where ed.DT == devType select ed).ToList();
 477:              }
 478:   
 479:              return list;
 480:          }
 481:   
 482:          ////////////////////////////////////////////////////////////////////////////
 483:   
 484:          /// <summary>
 485:          ///
 486:          /// </summary>
 487:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev Read(int id)
 488:          {
 489:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 490:   
 491:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 492:              {
 493:                  item = (from ed in db.EmsDevs where ed.Id == id select ed).SingleOrDefault();
 494:              }
 495:   
 496:              return item;
 497:          }
 498:   
 499:          ////////////////////////////////////////////////////////////////////////////
 500:   
 501:          /// <summary>
 502:          ///
 503:          /// </summary>
 504:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByEmsName(string emsName)
 505:          {
 506:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 507:   
 508:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 509:              {
 510:                  item = (from ed in db.EmsDevs where ed.DEV == emsName select ed).SingleOrDefault();
 511:              }
 512:   
 513:              return item;
 514:          }
 515:   
 516:          ////////////////////////////////////////////////////////////////////////////
 517:   
 518:          /// <summary>
 519:          ///
 520:          /// </summary>
 521:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDev(string dev)
 522:          {
 523:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 524:   
 525:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 526:              {
 527:                  item = (from ed in db.EmsDevs where ed.DEV == dev select ed).SingleOrDefault();
 528:              }
 529:   
 530:              return item;
 531:          }
 532:   
 533:          ////////////////////////////////////////////////////////////////////////////
 534:   
 535:          /// <summary>
 536:          ///
 537:          /// </summary>
 538:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDid(int did)
 539:          {
 540:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 541:   
 542:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 543:              {
 544:                  item = (from ed in db.EmsDevs where ed.DID == did select ed).SingleOrDefault();
 545:              }
 546:   
 547:              return item;
 548:          }
 549:   
 550:          ////////////////////////////////////////////////////////////////////////////
 551:   
 552:          /// <summary>
 553:          ///
 554:          /// </summary>
 555:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByAccessId(string accessId)
 556:          {
 557:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 558:   
 559:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 560:              {
 561:                  item = (from ed in db.EmsDevs where ed.Access != null && ed.Access.Id == accessId select ed).SingleOrDefault();
 562:              }
 563:   
 564:              return item;
 565:          }
 566:   
 567:          ////////////////////////////////////////////////////////////////////////////
 568:   
 569:          /// <summary>
 570:          /// Return Devs with similar names
 571:          /// </summary>
 572:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> RedundantDevList()
 573:          {
 574:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devs;
 575:   
 576:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 577:              {
 578:                  // select * from EmsDevs ed1 left outer join EmsDevs ed2 on ed1.DEV = ed2.DEV where ed1.Id <> ed2.Id
 579:   
 580:                  devs = (from ed1 in db.EmsDevs join ed2 in db.EmsDevs on ed1.DEV equals ed2.DEV where ed2.DID != ed2.DID select ed1).ToList();
 581:              }
 582:   
 583:              return devs;
 584:          }
 585:   
 586:          ////////////////////////////////////////////////////////////////////////////
 587:   
 588:          /// <summary>
 589:          ///
 590:          /// </summary>
 591:          public static bool NullifyAccessIdByAccessId(string accessId, out string result)
 592:          {
 593:              bool b;
 594:              int numberOfRecordsWhereAccessIsNullified;
 595:              Ia.Ngn.Cl.Model.Huawei.EmsDev dev;
 596:   
 597:              b = false;
 598:              numberOfRecordsWhereAccessIsNullified = 0;
 599:   
 600:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 601:              {
 602:                  // --update EmsOnts set Access_Id = null where Access_Id = '1040101010040004'
 603:                  //var query = (from eo in db.EmsOnts where eo.Access.Id == accessId select eo).ToList();
 604:   
 605:                  //foreach (var v in query)
 606:                  //{
 607:                  dev = (from o in db.EmsDevs where o.Access.Id == accessId select o).FirstOrDefault(); //.SingleOrDefault();
 608:   
 609:                  if (dev != null)
 610:                  {
 611:                      dev.Access = null;
 612:                      dev.Updated = DateTime.UtcNow.AddHours(3);
 613:   
 614:                      db.EmsDevs.Attach(dev);
 615:                      db.Entry(dev).Property(x => x.Updated).IsModified = true;
 616:   
 617:                      db.SaveChanges();
 618:   
 619:                      numberOfRecordsWhereAccessIsNullified++;
 620:                  }
 621:                  //}
 622:   
 623:                  b = true;
 624:              }
 625:   
 626:              result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
 627:   
 628:              return b;
 629:          }
 630:   
 631:          ////////////////////////////////////////////////////////////////////////////
 632:          ////////////////////////////////////////////////////////////////////////////
 633:   
 634:          /// <summary>
 635:          ///
 636:          /// </summary>
 637:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Huawei.EmsDev emsDev)
 638:          {
 639:              StringBuilder sb;
 640:   
 641:              sb = new StringBuilder();
 642:   
 643:              sb.AppendLine("DID: " + emsDev.DID);
 644:              sb.AppendLine("DEV: " + emsDev.DEV);
 645:              sb.AppendLine("DEVIP: " + emsDev.DEVIP);
 646:              sb.AppendLine("DT: " + emsDev.DT);
 647:              sb.AppendLine("DVER: " + emsDev.DVER);
 648:              sb.AppendLine("DSTAT: " + emsDev.DSTAT);
 649:   
 650:              return sb.ToString();
 651:          }
 652:   
 653:          ////////////////////////////////////////////////////////////////////////////
 654:          ////////////////////////////////////////////////////////////////////////////
 655:      }
 656:   
 657:      ////////////////////////////////////////////////////////////////////////////
 658:      ////////////////////////////////////////////////////////////////////////////
 659:  }