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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Board

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

Huawei's Board 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.Data.Entity;
   5:  using System.Linq;
   6:  using System.Text;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Huawei's Board 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), Integrated 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 Board
  30:      {
  31:          /// <summary/>
  32:          public Board() { }
  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 did, fn, sn, queryFn, querySn, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
  43:              string id, queryCommand, queryDev;
  44:              DataColumnCollection columns;
  45:              DataRow columnDataRow;
  46:              Ia.Ngn.Cl.Model.Huawei.EmsBoard board, newBoard;
  47:              Ia.Ngn.Cl.Model.Huawei.EmsDev dev;
  48:              List<string> itemIdList;
  49:              List<Ia.Ngn.Cl.Model.Huawei.EmsBoard> boardList;
  50:   
  51:              isUpdated = false;
  52:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  53:              result = new Ia.Cl.Model.Result();
  54:   
  55:              if (response.CompletionCode == "COMPLD")
  56:              {
  57:                  if (response.QueryDataTable != null)
  58:                  {
  59:                      queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
  60:                      //queryCommand = "LST-BOARD::DEV=MDU-SMC-1126-002,FN=0:{ctag}::SHOWOPTION=BNAME;"; // debug
  61:   
  62:                      // LST-BOARD::DEV=MDU-FNT-806-002,FN=0:{ctag}::SHOWOPTION=BNAME;
  63:                      // LST-BOARD::DEV=MDU-FNT-806-002,FN=0,SN=3:{ctag}::SHOWOPTION=BNAME;
  64:                      queryDev = Ia.Cl.Model.Default.Match(queryCommand, @"DEV=(.+?),");
  65:                      queryFn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"FN=(\d+)"));
  66:                      querySn = int.TryParse(Ia.Cl.Model.Default.Match(queryCommand, @"SN=(\d+)"), out int i) ? i : 0;
  67:   
  68:                      columns = response.QueryDataTable.Columns;
  69:                      readItemCount = response.QueryDataTable.Rows.Count;
  70:   
  71:                      dev = Ia.Ngn.Cl.Model.Data.Huawei.Dev.ReadByDev(queryDev);
  72:   
  73:                      if (dev != null)
  74:                      {
  75:                          itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
  76:   
  77:                          using (var db = new Ia.Ngn.Cl.Model.Ngn())
  78:                          {
  79:                              boardList = (from eb in db.EmsBoards where eb.EmsDev.DEV == queryDev select eb).ToList();
  80:   
  81:                              existingItemCount = boardList.Count;
  82:   
  83:                              if (response.QueryDataTable.Rows.Count >= 1)
  84:                              {
  85:                                  columnDataRow = response.QueryDataTable.Rows[0];
  86:   
  87:                                  foreach (DataRow dataRow in response.QueryDataTable.Rows)
  88:                                  {
  89:                                      did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
  90:                                      fn = int.Parse(dataRow[columns.IndexOf("FN")].ToString());
  91:                                      sn = int.Parse(dataRow[columns.IndexOf("SN")].ToString());
  92:   
  93:                                      id = Ia.Ngn.Cl.Model.Business.Huawei.Board.BoardId(dev.Id, fn, sn);
  94:   
  95:                                      board = (from b in boardList where b.Id == id select b).SingleOrDefault();
  96:   
  97:                                      newBoard = new Ia.Ngn.Cl.Model.Huawei.EmsBoard()
  98:                                      {
  99:                                          Id = id,
 100:                                          DID = did,
 101:                                          FN = fn,
 102:                                          SN = sn,
 103:                                          BT = columns.Contains("BT") ? dataRow[columns.IndexOf("BT")].ToString() : string.Empty,
 104:                                          BVER = columns.Contains("BVER") ? dataRow[columns.IndexOf("BVER")].ToString() : string.Empty,
 105:                                          BSTAT = columns.Contains("BSTAT") ? dataRow[columns.IndexOf("BSTAT")].ToString() : string.Empty,
 106:                                          DEV = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty,
 107:                                          BNAME = columns.Contains("BNAME") ? dataRow[columns.IndexOf("BNAME")].ToString() : string.Empty,
 108:                                          NAME = columns.Contains("NAME") ? dataRow[columns.IndexOf("NAME")].ToString() : string.Empty,
 109:                                          ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 110:                                          ELABEL = columns.Contains("ELABEL") ? dataRow[columns.IndexOf("ELABEL")].ToString() : string.Empty,
 111:                                          PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
 112:                                          SWVER = columns.Contains("SWVER") ? dataRow[columns.IndexOf("SWVER")].ToString() : string.Empty,
 113:                                          ROLE = columns.Contains("ROLE") ? dataRow[columns.IndexOf("ROLE")].ToString() : string.Empty,
 114:                                          ALARM = columns.Contains("ALARM") ? dataRow[columns.IndexOf("ALARM")].ToString() : string.Empty,
 115:                                          ST = columns.Contains("ST") ? dataRow[columns.IndexOf("ST")].ToString() : string.Empty,
 116:                                          PROTECTMODE = columns.Contains("PROTECTMODE") ? dataRow[columns.IndexOf("PROTECTMODE")].ToString() : string.Empty,
 117:                                          PORTCOUNT = columns.Contains("PORTCOUNT") ? dataRow[columns.IndexOf("PORTCOUNT")].ToString() : string.Empty,
 118:                                          PORTTYPE = columns.Contains("PORTTYPE") ? dataRow[columns.IndexOf("PORTTYPE")].ToString() : string.Empty,
 119:                                          WORKMODE = columns.Contains("WORKMODE") ? dataRow[columns.IndexOf("WORKMODE")].ToString() : string.Empty,
 120:                                          REPLACE = columns.Contains("REPLACE") ? dataRow[columns.IndexOf("REPLACE")].ToString() : string.Empty,
 121:                                          EmsDev = (from ed in db.EmsDevs where ed.Id == dev.Id select ed).SingleOrDefault()
 122:                                      };
 123:   
 124:                                      if (board == null)
 125:                                      {
 126:                                          newBoard.Created = newBoard.Updated = DateTime.UtcNow.AddHours(3);
 127:   
 128:                                          db.EmsBoards.Add(newBoard);
 129:   
 130:                                          insertedItemCount++;
 131:                                      }
 132:                                      else // update
 133:                                      {
 134:                                          // below: copy values from newBoard to board
 135:   
 136:                                          if (board.Update(newBoard))
 137:                                          {
 138:                                              db.EmsBoards.Attach(board);
 139:                                              db.Entry(board).State = System.Data.Entity.EntityState.Modified;
 140:   
 141:                                              updatedItemCount++;
 142:                                          }
 143:                                      }
 144:   
 145:                                      itemIdList.Add(id); // keep at the end
 146:                                  }
 147:   
 148:                                  // below: this function will remove values that were not present in the reading
 149:                                  if (boardList.Count > 0)
 150:                                  {
 151:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsBoard bo in boardList)
 152:                                      {
 153:                                          if (!itemIdList.Contains(bo.Id))
 154:                                          {
 155:                                              board = (from eb in db.EmsBoards where eb.Id == bo.Id select eb).SingleOrDefault();
 156:   
 157:                                              db.EmsBoards.Remove(board);
 158:   
 159:                                              deletedItemCount++;
 160:                                          }
 161:                                      }
 162:                                  }
 163:                              }
 164:                              else
 165:                              {
 166:                                  // below: remove all values since reading was empty
 167:   
 168:                                  if (boardList.Count > 0)
 169:                                  {
 170:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsBoard bo in boardList)
 171:                                      {
 172:                                          board = (from eb in db.EmsBoards where eb.Id == bo.Id select eb).SingleOrDefault();
 173:   
 174:                                          db.EmsBoards.Remove(board);
 175:   
 176:                                          deletedItemCount++;
 177:                                      }
 178:                                  }
 179:                              }
 180:   
 181:                              db.SaveChanges();
 182:                          }
 183:   
 184:                          if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 185:                          else isUpdated = false;
 186:   
 187:                          result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 188:                      }
 189:                      else
 190:                      {
 191:                          result.AddError("Dev is null for dev: " + queryDev);
 192:                      }
 193:                  }
 194:                  else
 195:                  {
 196:                      result.AddWarning("LST-BOARD: QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 197:                  }
 198:              }
 199:              else
 200:              {
 201:                  result.AddWarning("LST-BOARD: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 202:              }
 203:   
 204:              return isUpdated;
 205:          }
 206:   
 207:          ////////////////////////////////////////////////////////////////////////////
 208:   
 209:          /// <summary>
 210:          ///
 211:          /// </summary>
 212:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsBoard> List()
 213:          {
 214:              List<Ia.Ngn.Cl.Model.Huawei.EmsBoard> list;
 215:   
 216:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 217:              {
 218:                  list = (from eb in db.EmsBoards select eb).Include(x => x.EmsDev).ToList();
 219:              }
 220:   
 221:              return list.ToList();
 222:          }
 223:   
 224:          ////////////////////////////////////////////////////////////////////////////
 225:   
 226:          /// <summary>
 227:          ///
 228:          /// </summary>
 229:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsBoard> List(int devId)
 230:          {
 231:              List<Ia.Ngn.Cl.Model.Huawei.EmsBoard> list;
 232:   
 233:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 234:              {
 235:                  list = (from b in db.EmsBoards where b.EmsDev.Id == devId select b).ToList();
 236:              }
 237:   
 238:              return list;
 239:          }
 240:   
 241:          ////////////////////////////////////////////////////////////////////////////
 242:   
 243:          /// <summary>
 244:          ///
 245:          /// </summary>
 246:          public static Ia.Ngn.Cl.Model.Huawei.EmsBoard ReadByEmsNameFnSn(string emsName, int fn, int sn)
 247:          {
 248:              Ia.Ngn.Cl.Model.Huawei.EmsBoard item;
 249:   
 250:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 251:              {
 252:                  item = (from b in db.EmsBoards where b.DEV == emsName && b.FN == fn && b.SN == sn select b).SingleOrDefault();
 253:              }
 254:   
 255:              return item;
 256:          }
 257:   
 258:          ////////////////////////////////////////////////////////////////////////////
 259:   
 260:          /// <summary>
 261:          ///
 262:          /// </summary>
 263:          public static Ia.Ngn.Cl.Model.Huawei.EmsBoard ReadByDidFnSn(int did, int fn, int sn)
 264:          {
 265:              Ia.Ngn.Cl.Model.Huawei.EmsBoard item;
 266:   
 267:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 268:              {
 269:                  item = (from b in db.EmsBoards where b.DID == did && b.FN == fn && b.SN == sn select b).SingleOrDefault();
 270:              }
 271:   
 272:              return item;
 273:          }
 274:   
 275:          ////////////////////////////////////////////////////////////////////////////
 276:          ////////////////////////////////////////////////////////////////////////////
 277:   
 278:          /// <summary>
 279:          ///
 280:          /// </summary>
 281:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Huawei.EmsBoard emdBoard)
 282:          {
 283:              StringBuilder sb;
 284:   
 285:              sb = new StringBuilder();
 286:   
 287:              sb.AppendLine("DID: " + emdBoard.DID);
 288:              sb.AppendLine("FN: " + emdBoard.FN);
 289:              sb.AppendLine("SN: " + emdBoard.SN);
 290:              sb.AppendLine("BT: " + emdBoard.BT);
 291:              sb.AppendLine("BVER: " + emdBoard.BVER);
 292:              sb.AppendLine("BSTAT: " + emdBoard.BSTAT);
 293:   
 294:              return sb.ToString();
 295:          }
 296:   
 297:          ////////////////////////////////////////////////////////////////////////////
 298:          ////////////////////////////////////////////////////////////////////////////
 299:      }
 300:   
 301:      ////////////////////////////////////////////////////////////////////////////
 302:      ////////////////////////////////////////////////////////////////////////////
 303:  }