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:   
  34:          public static Dictionary<string, int> DevTypeToDevTypeIdDictionary
  35:          {
  36:              get
  37:              {
  38:                  if (devTypeToDevTypeIdDictionary == null || devTypeToDevTypeIdDictionary.Count == 0)
  39:                  {
  40:                      devTypeToDevTypeIdDictionary = new Dictionary<string, int>();
  41:   
  42:                      devTypeToDevTypeIdDictionary["UA5000(PVMV1)"] = 219;
  43:                      devTypeToDevTypeIdDictionary["MA5662"] = 37;
  44:                      devTypeToDevTypeIdDictionary["MA5600V3"] = 44;
  45:                      devTypeToDevTypeIdDictionary["MA5105(BSL)"] = 71;
  46:                      devTypeToDevTypeIdDictionary["MA5100V2"] = 72;
  47:                      devTypeToDevTypeIdDictionary["MA5300V1"] = 74;
  48:                      devTypeToDevTypeIdDictionary["MD5500V1"] = 75;
  49:                      devTypeToDevTypeIdDictionary["UA5000"] = 82;
  50:                      devTypeToDevTypeIdDictionary["MA5100V1"] = 86;
  51:                      devTypeToDevTypeIdDictionary["UA5000(IPMB)"] = 253;
  52:                      devTypeToDevTypeIdDictionary["MA5605"] = 30;
  53:                      devTypeToDevTypeIdDictionary["MA5680T"] = 34;
  54:                      devTypeToDevTypeIdDictionary["MA5606T"] = 57;
  55:                      devTypeToDevTypeIdDictionary["UA5000(PVU)"] = 232;
  56:                      devTypeToDevTypeIdDictionary["MA5600T"] = 249;
  57:                      devTypeToDevTypeIdDictionary["MA5615"] = 60;
  58:                      devTypeToDevTypeIdDictionary["MA5626E"] = 61;
  59:                      devTypeToDevTypeIdDictionary["MA5620E"] = 62;
  60:                      devTypeToDevTypeIdDictionary["MA5651"] = 64;
  61:                      devTypeToDevTypeIdDictionary["MA5620G"] = 65;
  62:                      devTypeToDevTypeIdDictionary["MA5626G"] = 66;
  63:                      devTypeToDevTypeIdDictionary["MA5651G"] = 67;
  64:                      devTypeToDevTypeIdDictionary["MA5610"] = 70;
  65:                      devTypeToDevTypeIdDictionary["MA5652G"] = 92;
  66:                      devTypeToDevTypeIdDictionary["MA5603U"] = 94;
  67:                      devTypeToDevTypeIdDictionary["MA5603T"] = 95;
  68:                      devTypeToDevTypeIdDictionary["MA5620"] = 96;
  69:                      devTypeToDevTypeIdDictionary["MA5626"] = 97;
  70:                      devTypeToDevTypeIdDictionary["MA5616"] = 100;
  71:                      devTypeToDevTypeIdDictionary["MA5635"] = 103;
  72:                      devTypeToDevTypeIdDictionary["MA5612"] = 104;
  73:                      devTypeToDevTypeIdDictionary["MA5621"] = 2319;
  74:                      devTypeToDevTypeIdDictionary["MA5628"] = 2312;
  75:                      devTypeToDevTypeIdDictionary["MA5652"] = 2313;
  76:                      devTypeToDevTypeIdDictionary["MA5631"] = 2317;
  77:                      devTypeToDevTypeIdDictionary["MA5612A"] = 2320;
  78:                      devTypeToDevTypeIdDictionary["MA5669"] = 2321;
  79:                      devTypeToDevTypeIdDictionary["MA5621A"] = 2322;
  80:                      devTypeToDevTypeIdDictionary["MA5622A"] = 2323;
  81:                      devTypeToDevTypeIdDictionary["MA5623"] = 2324;
  82:                      devTypeToDevTypeIdDictionary["MA5623A"] = 2326;
  83:                      devTypeToDevTypeIdDictionary["MA5632"] = 2318;
  84:                      devTypeToDevTypeIdDictionary["MA5608T"] = 2331;
  85:                      devTypeToDevTypeIdDictionary["MA5698"] = 2333;
  86:                      devTypeToDevTypeIdDictionary["MA5694"] = 2335;
  87:                      devTypeToDevTypeIdDictionary["MA5821"] = 2336;
  88:                      devTypeToDevTypeIdDictionary["MA5822"] = 2337;
  89:                      devTypeToDevTypeIdDictionary["MA5898"] = 2338;
  90:                      devTypeToDevTypeIdDictionary["MA5818"] = 2339;
  91:                      devTypeToDevTypeIdDictionary["MA5611S"] = 2340;
  92:                      devTypeToDevTypeIdDictionary["MA5694S"] = 2343;
  93:                      devTypeToDevTypeIdDictionary["RPS"] = 2344;
  94:                  }
  95:   
  96:                  return devTypeToDevTypeIdDictionary;
  97:              }
  98:          }
  99:   
 100:          /// <summary/>
 101:          public Dev() { }
 102:   
 103:          ////////////////////////////////////////////////////////////////////////////
 104:   
 105:          /// <summary>
 106:          ///
 107:          /// </summary>
 108:          public static Dictionary<int, string> DevTypeIdToDevTypeDictionary
 109:          {
 110:              get
 111:              {
 112:                  if (devTypeIdToDevTypeDictionary == null || devTypeIdToDevTypeDictionary.Count == 0)
 113:                  {
 114:                      devTypeIdToDevTypeDictionary = new Dictionary<int, string>();
 115:   
 116:                      foreach (KeyValuePair<string, int> kvp in DevTypeToDevTypeIdDictionary) devTypeIdToDevTypeDictionary[kvp.Value] = kvp.Key;
 117:                  }
 118:   
 119:                  return devTypeIdToDevTypeDictionary;
 120:              }
 121:          }
 122:   
 123:          ////////////////////////////////////////////////////////////////////////////
 124:   
 125:          /// <summary>
 126:          ///
 127:          /// </summary>
 128:          public static Dictionary<string, int> DevToDidDictionary
 129:          {
 130:              get
 131:              {
 132:                  if (devToDidDictionary == null || devToDidDictionary.Count == 0)
 133:                  {
 134:                      devToDidDictionary = new Dictionary<string, int>();
 135:   
 136:                      List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 137:   
 138:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 139:                      {
 140:                          list = (from ed in db.EmsDevs select ed).ToList();
 141:                      }
 142:   
 143:                      foreach (var d in list) devToDidDictionary[d.DEV] = d.DID;
 144:                  }
 145:   
 146:                  return devToDidDictionary;
 147:              }
 148:          }
 149:   
 150:          ////////////////////////////////////////////////////////////////////////////
 151:   
 152:          /// <summary>
 153:          ///
 154:          /// </summary>
 155:          public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
 156:          {
 157:              bool isUpdated;
 158:              int id, queryDtTypeId, did, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 159:              string queryCommand, dtType;
 160:              DataColumnCollection columns;
 161:              DataRow columnDataRow;
 162:              Ia.Ngn.Cl.Model.Huawei.EmsDev dev, newDev;
 163:              List<int> itemIdList;
 164:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> devList;
 165:   
 166:              isUpdated = false;
 167:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 168:              result = new Ia.Cl.Model.Result();
 169:   
 170:              if (response.QueryDataTable != null)
 171:              {
 172:                  queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
 173:   
 174:                  // LST-DEV::DT=100:{ctag}::;
 175:                  queryDtTypeId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"DT=(\d+)"));
 176:   
 177:                  if (Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary.ContainsKey(queryDtTypeId))
 178:                  {
 179:                      dtType = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary[queryDtTypeId];
 180:   
 181:                      columns = response.QueryDataTable.Columns;
 182:                      readItemCount = response.QueryDataTable.Rows.Count;
 183:   
 184:                      itemIdList = new List<int>(response.QueryDataTable.Rows.Count + 1);
 185:   
 186:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
 187:                      {
 188:                          devList = (from ed in db.EmsDevs where ed.DT == dtType select ed).ToList();
 189:   
 190:                          existingItemCount = devList.Count;
 191:   
 192:                          if (response.QueryDataTable.Rows.Count >= 1)
 193:                          {
 194:                              columnDataRow = response.QueryDataTable.Rows[0];
 195:   
 196:                              foreach (DataRow dataRow in response.QueryDataTable.Rows)
 197:                              {
 198:                                  did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
 199:   
 200:                                  id = Ia.Ngn.Cl.Model.Business.Huawei.Dev.DevId(did);
 201:   
 202:                                  dev = (from d in devList where d.Id == id select d).SingleOrDefault();
 203:   
 204:                                  newDev = new Ia.Ngn.Cl.Model.Huawei.EmsDev()
 205:                                  {
 206:                                      Id = id,
 207:                                      DID = did,
 208:                                      DEV = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty,
 209:                                      DEVIP = columns.Contains("DEVIP") ? dataRow[columns.IndexOf("DEVIP")].ToString() : string.Empty,
 210:                                      DT = columns.Contains("DT") ? dataRow[columns.IndexOf("DT")].ToString() : string.Empty,
 211:                                      DVER = columns.Contains("DVER") ? dataRow[columns.IndexOf("DVER")].ToString() : string.Empty,
 212:                                      DSTAT = columns.Contains("DSTAT") ? dataRow[columns.IndexOf("DSTAT")].ToString() : string.Empty,
 213:                                      DLOC = columns.Contains("DLOC") ? dataRow[columns.IndexOf("DLOC")].ToString() : string.Empty,
 214:                                      AdminStat = columns.Contains("AdminStat") ? dataRow[columns.IndexOf("AdminStat")].ToString() : string.Empty,
 215:                                      WorkMode = columns.Contains("WorkMode") ? dataRow[columns.IndexOf("WorkMode")].ToString() : string.Empty,
 216:                                      ADDITIONALINFO = columns.Contains("ADDITIONALINFO") ? dataRow[columns.IndexOf("ADDITIONALINFO")].ToString() : string.Empty,
 217:                                      CRTID = columns.Contains("CRTID") ? dataRow[columns.IndexOf("CRTID")].ToString() : string.Empty,
 218:                                      CRTADDR = columns.Contains("CRTADDR") ? dataRow[columns.IndexOf("CRTADDR")].ToString() : string.Empty,
 219:                                      CRTTEL = columns.Contains("CRTTEL") ? dataRow[columns.IndexOf("CRTTEL")].ToString() : string.Empty,
 220:                                      CRTDATE = columns.Contains("CRTDATE") ? dataRow[columns.IndexOf("CRTDATE")].ToString() : string.Empty,
 221:                                      REMARK = columns.Contains("REMARK") ? dataRow[columns.IndexOf("REMARK")].ToString() : string.Empty,
 222:                                      TYPE = columns.Contains("TYPE") ? dataRow[columns.IndexOf("TYPE")].ToString() : string.Empty,
 223:                                      NERATELIST = columns.Contains("NERATELIST") ? dataRow[columns.IndexOf("NERATELIST")].ToString() : string.Empty,
 224:                                      NEPROV = columns.Contains("NEPROV") ? dataRow[columns.IndexOf("NEPROV")].ToString() : string.Empty,
 225:                                      TOPXY = columns.Contains("TOPXY") ? dataRow[columns.IndexOf("TOPXY")].ToString() : string.Empty,
 226:                                      EMSID = columns.Contains("EMSID") ? dataRow[columns.IndexOf("EMSID")].ToString() : string.Empty,
 227:                                      ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 228:                                      PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
 229:                                      MAINTAINID = columns.Contains("MAINTAINID") ? dataRow[columns.IndexOf("MAINTAINID")].ToString() : string.Empty,
 230:                                      MAINTAINADDR = columns.Contains("MAINTAINADDR") ? dataRow[columns.IndexOf("MAINTAINADDR")].ToString() : string.Empty,
 231:                                      MAINTAINTEL = columns.Contains("MAINTAINTEL") ? dataRow[columns.IndexOf("MAINTAINTEL")].ToString() : string.Empty,
 232:                                      REGISTERSTAT = columns.Contains("REGISTERSTAT") ? dataRow[columns.IndexOf("REGISTERSTAT")].ToString() : string.Empty,
 233:                                  };
 234:   
 235:                                  if (dev == null)
 236:                                  {
 237:                                      newDev.Created = newDev.Updated = DateTime.UtcNow.AddHours(3);
 238:   
 239:                                      db.EmsDevs.Add(newDev);
 240:   
 241:                                      insertedItemCount++;
 242:                                  }
 243:                                  else // update
 244:                                  {
 245:                                      // below: copy values from newDev to dev
 246:   
 247:                                      if (dev.Update(newDev))
 248:                                      {
 249:                                          db.EmsDevs.Attach(dev);
 250:                                          db.Entry(dev).State = System.Data.Entity.EntityState.Modified;
 251:   
 252:                                          updatedItemCount++;
 253:                                      }
 254:                                  }
 255:   
 256:                                  itemIdList.Add(id); // keep at the end
 257:                              }
 258:   
 259:                              // below: this function will remove values that were not present in the reading
 260:                              if (devList.Count > 0)
 261:                              {
 262:                                  foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 263:                                  {
 264:                                      if (!itemIdList.Contains(de.Id))
 265:                                      {
 266:                                          dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 267:   
 268:                                          db.EmsDevs.Remove(dev);
 269:   
 270:                                          deletedItemCount++;
 271:                                      }
 272:                                  }
 273:                              }
 274:                          }
 275:                          else
 276:                          {
 277:                              // below: remove all values since reading was empty
 278:   
 279:                              if (devList.Count > 0)
 280:                              {
 281:                                  foreach (Ia.Ngn.Cl.Model.Huawei.EmsDev de in devList)
 282:                                  {
 283:                                      dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
 284:   
 285:                                      db.EmsDevs.Remove(dev);
 286:   
 287:                                      deletedItemCount++;
 288:                                  }
 289:                              }
 290:                          }
 291:   
 292:                          db.SaveChanges();
 293:                      }
 294:   
 295:                      if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 296:                      else isUpdated = false;
 297:   
 298:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 299:                  }
 300:                  else
 301:                  {
 302:                      result.AddWarning("Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary does not contain key queryDtTypeId: " + queryDtTypeId);
 303:                  }
 304:              }
 305:              else
 306:              {
 307:                  result.AddWarning("response.QueryDataTable is null");
 308:              }
 309:   
 310:              return isUpdated;
 311:          }
 312:   
 313:          ////////////////////////////////////////////////////////////////////////////
 314:   
 315:          /// <summary>
 316:          ///
 317:          /// </summary>
 318:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsDev> List()
 319:          {
 320:              List<Ia.Ngn.Cl.Model.Huawei.EmsDev> list;
 321:   
 322:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 323:              {
 324:                  list = (from ed in db.EmsDevs select ed).ToList();
 325:              }
 326:   
 327:              return list;
 328:          }
 329:   
 330:          ////////////////////////////////////////////////////////////////////////////
 331:   
 332:          /// <summary>
 333:          ///
 334:          /// </summary>
 335:          public static List<string> DevList()
 336:          {
 337:              List<string> list;
 338:   
 339:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 340:              {
 341:                  list = (from ed in db.EmsDevs select ed.DEV).ToList();
 342:              }
 343:   
 344:              return list;
 345:          }
 346:   
 347:          ////////////////////////////////////////////////////////////////////////////
 348:   
 349:          /// <summary>
 350:          ///
 351:          /// </summary>
 352:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev Read(int id)
 353:          {
 354:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 355:   
 356:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 357:              {
 358:                  item = (from ed in db.EmsDevs where ed.Id == id select ed).SingleOrDefault();
 359:              }
 360:   
 361:              return item;
 362:          }
 363:   
 364:          ////////////////////////////////////////////////////////////////////////////
 365:   
 366:          /// <summary>
 367:          ///
 368:          /// </summary>
 369:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByEmsName(string emsName)
 370:          {
 371:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 372:   
 373:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 374:              {
 375:                  item = (from ed in db.EmsDevs where ed.DEV == emsName select ed).SingleOrDefault();
 376:              }
 377:   
 378:              return item;
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDev(string dev)
 387:          {
 388:              Ia.Ngn.Cl.Model.Huawei.EmsDev item;
 389:   
 390:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 391:              {
 392:                  item = (from ed in db.EmsDevs where ed.DEV == dev select ed).SingleOrDefault();
 393:              }
 394:   
 395:              return item;
 396:          }
 397:   
 398:          ////////////////////////////////////////////////////////////////////////////
 399:   
 400:          /// <summary>
 401:          ///
 402:          /// </summary>
 403:          public static Ia.Ngn.Cl.Model.Huawei.EmsDev ReadByDevType(string devType)
 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.DT == devType 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 ReadByDid(int did)
 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.DID == did select ed).SingleOrDefault();
 427:              }
 428:   
 429:              return item;
 430:          }
 431:   
 432:          ////////////////////////////////////////////////////////////////////////////
 433:          ////////////////////////////////////////////////////////////////////////////
 434:      }
 435:   
 436:      ////////////////////////////////////////////////////////////////////////////
 437:      ////////////////////////////////////////////////////////////////////////////
 438:  }