Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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.Linq;
   4:  using System.Data;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Huawei's Dev support class of Next Generation Network'a (NGN's) data model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2016-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class Dev
  28:      {
  29:          private static Dictionary<string, int> devTypeToDevTypeIdDictionary;
  30:          private static Dictionary<int, string> devTypeIdToDevTypeDictionary;
  31:   
  32:          private static Dictionary<string, int> devToDidDictionary;
  33:          private static Dictionary<int, string> didToDevDictionary;
  34:   
  35:          public static Dictionary<string, int> DevTypeToDevTypeIdDictionary
  36:          {
  37:              get
  38:              {
  39:                  if (devTypeToDevTypeIdDictionary == null || devTypeToDevTypeIdDictionary.Count == 0)
  40:                  {
  41:                      devTypeToDevTypeIdDictionary = new Dictionary<string, int>();
  42:   
  43:                      devTypeToDevTypeIdDictionary["UA5000(PVMV1)"] = 219;
  44:                      devTypeToDevTypeIdDictionary["MA5662"] = 37;
  45:                      devTypeToDevTypeIdDictionary["MA5600V3"] = 44;
  46:                      devTypeToDevTypeIdDictionary["MA5105(BSL)"] = 71;
  47:                      devTypeToDevTypeIdDictionary["MA5100V2"] = 72;
  48:                      devTypeToDevTypeIdDictionary["MA5300V1"] = 74;
  49:                      devTypeToDevTypeIdDictionary["MD5500V1"] = 75;
  50:                      devTypeToDevTypeIdDictionary["UA5000"] = 82;
  51:                      devTypeToDevTypeIdDictionary["MA5100V1"] = 86;
  52:                      devTypeToDevTypeIdDictionary["UA5000(IPMB)"] = 253;
  53:                      devTypeToDevTypeIdDictionary["MA5605"] = 30;
  54:                      devTypeToDevTypeIdDictionary["MA5680T"] = 34;
  55:                      devTypeToDevTypeIdDictionary["MA5606T"] = 57;
  56:                      devTypeToDevTypeIdDictionary["UA5000(PVU)"] = 232;
  57:                      devTypeToDevTypeIdDictionary["MA5600T"] = 249;
  58:                      devTypeToDevTypeIdDictionary["MA5615"] = 60;
  59:                      devTypeToDevTypeIdDictionary["MA5626E"] = 61;
  60:                      devTypeToDevTypeIdDictionary["MA5620E"] = 62;
  61:                      devTypeToDevTypeIdDictionary["MA5651"] = 64;
  62:                      devTypeToDevTypeIdDictionary["MA5620G"] = 65;
  63:                      devTypeToDevTypeIdDictionary["MA5626G"] = 66;
  64:                      devTypeToDevTypeIdDictionary["MA5651G"] = 67;
  65:                      devTypeToDevTypeIdDictionary["MA5610"] = 70;
  66:                      devTypeToDevTypeIdDictionary["MA5652G"] = 92;
  67:                      devTypeToDevTypeIdDictionary["MA5603U"] = 94;
  68:                      devTypeToDevTypeIdDictionary["MA5603T"] = 95;
  69:                      devTypeToDevTypeIdDictionary["MA5620"] = 96;
  70:                      devTypeToDevTypeIdDictionary["MA5626"] = 97;
  71:                      devTypeToDevTypeIdDictionary["MA5616"] = 100;
  72:                      devTypeToDevTypeIdDictionary["MA5635"] = 103;
  73:                      devTypeToDevTypeIdDictionary["MA5612"] = 104;
  74:                      devTypeToDevTypeIdDictionary["MA5621"] = 2319;
  75:                      devTypeToDevTypeIdDictionary["MA5628"] = 2312;
  76:                      devTypeToDevTypeIdDictionary["MA5652"] = 2313;
  77:                      devTypeToDevTypeIdDictionary["MA5631"] = 2317;
  78:                      devTypeToDevTypeIdDictionary["MA5612A"] = 2320;
  79:                      devTypeToDevTypeIdDictionary["MA5669"] = 2321;
  80:                      devTypeToDevTypeIdDictionary["MA5621A"] = 2322;
  81:                      devTypeToDevTypeIdDictionary["MA5622A"] = 2323;
  82:                      devTypeToDevTypeIdDictionary["MA5623"] = 2324;
  83:                      devTypeToDevTypeIdDictionary["MA5623A"] = 2326;
  84:                      devTypeToDevTypeIdDictionary["MA5632"] = 2318;
  85:                      devTypeToDevTypeIdDictionary["MA5608T"] = 2331;
  86:                      devTypeToDevTypeIdDictionary["MA5698"] = 2333;
  87:                      devTypeToDevTypeIdDictionary["MA5694"] = 2335;
  88:                      devTypeToDevTypeIdDictionary["MA5821"] = 2336;
  89:                      devTypeToDevTypeIdDictionary["MA5822"] = 2337;
  90:                      devTypeToDevTypeIdDictionary["MA5898"] = 2338;
  91:                      devTypeToDevTypeIdDictionary["MA5818"] = 2339;
  92:                      devTypeToDevTypeIdDictionary["MA5611S"] = 2340;
  93:                      devTypeToDevTypeIdDictionary["MA5694S"] = 2343;
  94:                      devTypeToDevTypeIdDictionary["RPS"] = 2344;
  95:                  }
  96:   
  97:                  return devTypeToDevTypeIdDictionary;
  98:              }
  99:          }
 100:   
 101:          /// <summary/>
 102:          public Dev() { }
 103:   
 104:          ////////////////////////////////////////////////////////////////////////////
 105:   
 106:          /// <summary>
 107:          ///
 108:          /// </summary>
 109:          public static Dictionary<int, string> DevTypeIdToDevTypeDictionary
 110:          {
 111:              get
 112:              {
 113:                  if (devTypeIdToDevTypeDictionary == null || devTypeIdToDevTypeDictionary.Count == 0)
 114:                  {
 115:                      devTypeIdToDevTypeDictionary = new Dictionary<int, string>();
 116:   
 117:                      foreach (KeyValuePair<string, int> kvp in DevTypeToDevTypeIdDictionary) devTypeIdToDevTypeDictionary[kvp.Value] = kvp.Key;
 118:                  }
 119:   
 120:                  return devTypeIdToDevTypeDictionary;
 121:              }
 122:          }
 123:   
 124:          ////////////////////////////////////////////////////////////////////////////
 125:   
 126:          /// <summary>
 127:          ///
 128:          /// </summary>
 129:          public static Dictionary<string, int> DevToDidDictionary
 130:          {
 131:              get
 132:              {
 133:                  if (devToDidDictionary == null || devToDidDictionary.Count == 0)
 134:                  {
 135:                      devToDidDictionary = new Dictionary<string, int>();
 136:   
 137:                      List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 138:   
 139:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 140:                      {
 141:                          list = (from ed in db.EmsDevs select ed).ToList();
 142:                      }
 143:   
 144:                      foreach (var d in list) devToDidDictionary[d.DEV] = d.DID;
 145:                  }
 146:   
 147:                  return devToDidDictionary;
 148:              }
 149:          }
 150:   
 151:          ////////////////////////////////////////////////////////////////////////////
 152:   
 153:          /// <summary>
 154:          ///
 155:          /// </summary>
 156:          public static Dictionary<int, string> DidToDevDictionary
 157:          {
 158:              get
 159:              {
 160:                  if (didToDevDictionary == null || didToDevDictionary.Count == 0)
 161:                  {
 162:                      didToDevDictionary = new Dictionary<int, string>();
 163:   
 164:                      foreach (KeyValuePair<string, int> kvp in DevToDidDictionary) didToDevDictionary[kvp.Value] = kvp.Key;
 165:                  }
 166:   
 167:                  return didToDevDictionary;
 168:              }
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
 177:          {
 178:              bool isUpdated;
 179:              int id, queryDtTypeId, did, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 180:              string queryCommand, dtType;
 181:              DataColumnCollection columns;
 182:              DataRow columnDataRow;
 183:              Ia.Ngn.Cl.Model.Huawei.EmsDev dev, newDev;
 184:              List<int> itemIdList;
 185:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devList;
 186:   
 187:              isUpdated = false;
 188:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 189:              result = new Ia.Cl.Model.Result();
 190:   
 191:              if (response.QueryDataTable != null)
 192:              {
 193:                  queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
 194:   
 195:                  // LST-DEV::DT=100:{ctag}::;
 196:                  queryDtTypeId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"DT=(\d+)"));
 197:   
 198:                  if (Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary.ContainsKey(queryDtTypeId))
 199:                  {
 200:                      dtType = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary[queryDtTypeId];
 201:   
 202:                      columns = response.QueryDataTable.Columns;
 203:                      readItemCount = response.QueryDataTable.Rows.Count;
 204:   
 205:                      itemIdList = new List<int>(response.QueryDataTable.Rows.Count + 1);
 206:   
 207:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 208:                      {
 209:                          devList = (from ed in db.EmsDevs where ed.DT == dtType select ed).ToList();
 210:   
 211:                          existingItemCount = devList.Count;
 212:   
 213:                          if (response.QueryDataTable.Rows.Count >= 1)
 214:                          {
 215:                              columnDataRow = response.QueryDataTable.Rows[0];
 216:   
 217:                              foreach (DataRow dataRow in response.QueryDataTable.Rows)
 218:                              {
 219:                                  did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
 220:   
 221:                                  id = Ia.Ngn.Cl.Model.Business.Huawei.Dev.DevId(did);
 222:   
 223:                                  dev = (from d in devList where d.Id == id select d).SingleOrDefault();
 224:   
 225:                                  newDev = new Ia.Ngn.Cl.Model.Huawei.EmsDev()
 226:                                  {
 227:                                      Id = id,
 228:                                      DID = did,
 229:                                      DEV = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty,
 230:                                      DEVIP = columns.Contains("DEVIP") ? dataRow[columns.IndexOf("DEVIP")].ToString() : string.Empty,
 231:                                      DT = columns.Contains("DT") ? dataRow[columns.IndexOf("DT")].ToString() : string.Empty,
 232:                                      DVER = columns.Contains("DVER") ? dataRow[columns.IndexOf("DVER")].ToString() : string.Empty,
 233:                                      DSTAT = columns.Contains("DSTAT") ? dataRow[columns.IndexOf("DSTAT")].ToString() : string.Empty,
 234:                                      DLOC = columns.Contains("DLOC") ? dataRow[columns.IndexOf("DLOC")].ToString() : string.Empty,
 235:                                      AdminStat = columns.Contains("AdminStat") ? dataRow[columns.IndexOf("AdminStat")].ToString() : string.Empty,
 236:                                      WorkMode = columns.Contains("WorkMode") ? dataRow[columns.IndexOf("WorkMode")].ToString() : string.Empty,
 237:                                      ADDITIONALINFO = columns.Contains("ADDITIONALINFO") ? dataRow[columns.IndexOf("ADDITIONALINFO")].ToString() : string.Empty,
 238:                                      CRTID = columns.Contains("CRTID") ? dataRow[columns.IndexOf("CRTID")].ToString() : string.Empty,
 239:                                      CRTADDR = columns.Contains("CRTADDR") ? dataRow[columns.IndexOf("CRTADDR")].ToString() : string.Empty,
 240:                                      CRTTEL = columns.Contains("CRTTEL") ? dataRow[columns.IndexOf("CRTTEL")].ToString() : string.Empty,
 241:                                      CRTDATE = columns.Contains("CRTDATE") ? dataRow[columns.IndexOf("CRTDATE")].ToString() : string.Empty,
 242:                                      REMARK = columns.Contains("REMARK") ? dataRow[columns.IndexOf("REMARK")].ToString() : string.Empty,
 243:                                      TYPE = columns.Contains("TYPE") ? dataRow[columns.IndexOf("TYPE")].ToString() : string.Empty,
 244:                                      NERATELIST = columns.Contains("NERATELIST") ? dataRow[columns.IndexOf("NERATELIST")].ToString() : string.Empty,
 245:                                      NEPROV = columns.Contains("NEPROV") ? dataRow[columns.IndexOf("NEPROV")].ToString() : string.Empty,
 246:                                      TOPXY = columns.Contains("TOPXY") ? dataRow[columns.IndexOf("TOPXY")].ToString() : string.Empty,
 247:                                      EMSID = columns.Contains("EMSID") ? dataRow[columns.IndexOf("EMSID")].ToString() : string.Empty,
 248:                                      ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 249:                                      PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
 250:                                      MAINTAINID = columns.Contains("MAINTAINID") ? dataRow[columns.IndexOf("MAINTAINID")].ToString() : string.Empty,
 251:                                      MAINTAINADDR = columns.Contains("MAINTAINADDR") ? dataRow[columns.IndexOf("MAINTAINADDR")].ToString() : string.Empty,
 252:                                      MAINTAINTEL = columns.Contains("MAINTAINTEL") ? dataRow[columns.IndexOf("MAINTAINTEL")].ToString() : string.Empty,
 253:                                      REGISTERSTAT = columns.Contains("REGISTERSTAT") ? dataRow[columns.IndexOf("REGISTERSTAT")].ToString() : string.Empty,
 254:                                  };
 255:   
 256:                                  if (dev == null)
 257:                                  {
 258:                                      newDev.Created = newDev.Updated = DateTime.UtcNow.AddHours(3);
 259:   
 260:                                      db.EmsDevs.Add(newDev);
 261:   
 262:                                      insertedItemCount++;
 263:                                  }
 264:                                  else // update
 265:                                  {
 266:                                      // below: copy values from newDev to dev
 267:   
 268:                                      if (dev.Update(newDev))
 269:                                      {
 270:                                          db.EmsDevs.Attach(dev);
 271:                                          db.Entry(dev).State = System.Data.Entity.EntityState.Modified;
 272:   
 273:                                          updatedItemCount++;
 274:                                      }
 275:                                  }
 276:   
 277:                                  itemIdList.Add(id); // keep at the end
 278:                              }
 279:   
 280:                              // below: this function will remove values that were not present in the reading
 281:                              if (devList.Count > 0)
 282:                              {
 283:                                  foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 284:                                  {
 285:                                      if (!itemIdList.Contains(de.Id))
 286:                                      {
 287:                                          /*
 288:                                           * First check that this is correct and there is no output paging issues, then I need to delete the boards and ports 
 289:                                          dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 290:  
 291:                                          db.EmsDevs.Remove(dev);
 292:  
 293:                                          deletedItemCount++;
 294:                                          */
 295:                                      }
 296:                                  }
 297:                              }
 298:                          }
 299:                          else
 300:                          {
 301:                              // below: remove all values since reading was empty
 302:   
 303:                              if (devList.Count > 0)
 304:                              {
 305:                                  foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 306:                                  {
 307:                                      dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 308:   
 309:                                      db.EmsDevs.Remove(dev);
 310:   
 311:                                      deletedItemCount++;
 312:                                  }
 313:                              }
 314:                          }
 315:   
 316:                          db.SaveChanges();
 317:                      }
 318:   
 319:                      if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 320:                      else isUpdated = false;
 321:   
 322:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 323:                  }
 324:                  else
 325:                  {
 326:                      result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary does not contain key queryDtTypeId: " + queryDtTypeId);
 327:                  }
 328:              }
 329:              else
 330:              {
 331:                  result.AddWarning("response.QueryDataTable is null");
 332:              }
 333:   
 334:              return isUpdated;
 335:          }
 336:   
 337:          ////////////////////////////////////////////////////////////////////////////
 338:   
 339:          /// <summary>
 340:          ///
 341:          /// </summary>
 342:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> List()
 343:          {
 344:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 345:   
 346:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 347:              {
 348:                  list = (from ed in db.EmsDevs select ed).ToList();
 349:              }
 350:   
 351:              return list;
 352:          }
 353:   
 354:          ////////////////////////////////////////////////////////////////////////////
 355:   
 356:          /// <summary>
 357:          ///
 358:          /// </summary>
 359:          public static List<string> DevList()
 360:          {
 361:              List<string> list;
 362:   
 363:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 364:              {
 365:                  list = (from ed in db.EmsDevs select ed.DEV).ToList();
 366:              }
 367:   
 368:              return list;
 369:          }
 370:   
 371:          ////////////////////////////////////////////////////////////////////////////
 372:   
 373:          /// <summary>
 374:          ///
 375:          /// </summary>
 376:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByMA5616DevType()
 377:          {
 378:              return ListByDevType("MA5616");
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> ListByDevType(string devType)
 387:          {
 388:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 389:   
 390:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 391:              {
 392:                  list = (from ed in db.EmsDevs where ed.DT == devType select ed).ToList();
 393:              }
 394:   
 395:              return list;
 396:          }
 397:   
 398:          ////////////////////////////////////////////////////////////////////////////
 399:   
 400:          /// <summary>
 401:          ///
 402:          /// </summary>
 403:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev Read(int id)
 404:          {
 405:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 406:   
 407:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 408:              {
 409:                  item = (from ed in db.EmsDevs where ed.Id == id select ed).SingleOrDefault();
 410:              }
 411:   
 412:              return item;
 413:          }
 414:   
 415:          ////////////////////////////////////////////////////////////////////////////
 416:   
 417:          /// <summary>
 418:          ///
 419:          /// </summary>
 420:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByEmsName(string emsName)
 421:          {
 422:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 423:   
 424:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 425:              {
 426:                  item = (from ed in db.EmsDevs where ed.DEV == emsName select ed).SingleOrDefault();
 427:              }
 428:   
 429:              return item;
 430:          }
 431:   
 432:          ////////////////////////////////////////////////////////////////////////////
 433:   
 434:          /// <summary>
 435:          ///
 436:          /// </summary>
 437:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDev(string dev)
 438:          {
 439:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 440:   
 441:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 442:              {
 443:                  item = (from ed in db.EmsDevs where ed.DEV == dev select ed).SingleOrDefault();
 444:              }
 445:   
 446:              return item;
 447:          }
 448:   
 449:          ////////////////////////////////////////////////////////////////////////////
 450:   
 451:          /// <summary>
 452:          ///
 453:          /// </summary>
 454:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDid(int did)
 455:          {
 456:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 457:   
 458:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 459:              {
 460:                  item = (from ed in db.EmsDevs where ed.DID == did select ed).SingleOrDefault();
 461:              }
 462:   
 463:              return item;
 464:          }
 465:   
 466:          ////////////////////////////////////////////////////////////////////////////
 467:          ////////////////////////////////////////////////////////////////////////////
 468:      }
 469:   
 470:      ////////////////////////////////////////////////////////////////////////////
 471:      ////////////////////////////////////////////////////////////////////////////
 472:  }