)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Vag (Ia.Ftn.Cl.Model.Data.Huawei)

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

Huawei's EMS VAG Entity Framework class for Fixed Telecommunications Network (FTN) 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.Ftn.Cl.Model.Data.Huawei
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Huawei's EMS VAG Entity Framework class for Fixed Telecommunications Network (FTN) data model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2019-2020 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 class Vag
   29:     {
   30:         /// <summary/>
   31:         public Vag() { }
   32:  
   33:         ////////////////////////////////////////////////////////////////////////////
   34:  
   35:         /// <summary>
   36:         ///
   37:         /// </summary>
   38:         public static bool Update(Ia.Ftn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Models.Result result)
   39:         {
   40:             bool isUpdated;
   41:             int did, queryDid, queryVagId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, vagId;
   42:             string id, queryCommand;
   43:             DataColumnCollection columns;
   44:             DataRow columnDataRow;
   45:             Ia.Ftn.Cl.Model.Huawei.EmsVag emsVag, newVag;
   46:             Ia.Ftn.Cl.Model.Huawei.EmsOnt emsOnt;
   47:             Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev;
   48:             List<string> itemIdList;
   49:             List<Ia.Ftn.Cl.Model.Huawei.EmsVag> emsVagList;
   50:  
   51:             isUpdated = false;
   52:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
   53:  
   54:             result = new Ia.Cl.Models.Result(); // remove initially then add to test all return paths
   55:  
   56:             queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
   57:  
   58:             // LST-VAG::DEV=MDU-SAA-748-002,VAGID=0:1::;
   59:             //queryDev = Ia.Cl.Models.Default.Match(queryCommand, @"DEV=(.+?),");
   60:  
   61:             // LST-VAG::DID=7340164,VAGID=0:1::;
   62:             queryDid = int.TryParse(Ia.Cl.Models.Default.Match(queryCommand, @"DID=(\d+)"), out int i) ? i : 0;
   63:             queryVagId = int.TryParse(Ia.Cl.Models.Default.Match(queryCommand, @"VAGID=(\d+)"), out i) ? i : 0;
   64:  
   65:             var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Huawei.Default.AccessNameToMduDevDictionary;
   66:  
   67:             mduDev = (from m in accessNameToMduDevDictionary where m.Value.Did == queryDid select m.Value).SingleOrDefault();
   68:  
   69:             if (mduDev != null)
   70:             {
   71:                 if (mduDev.Dev != null)
   72:                 {
   73:                     //nddOnt = Ia.Ftn.Cl.Model.Business.Default.NddOntFromHuaweiEmsAccessNameFormat(queryDev);
   74:  
   75:                     //if (nddOnt != null)
   76:                     //{
   77:                     using (var db = new Ia.Ftn.Cl.Model.Db())
   78:                     {
   79:                         did = queryDid;
   80:                         vagId = queryVagId;
   81:  
   82:                         emsOnt = (from eo in db.EmsOnts where eo.Id == mduDev.NddOntId select eo).SingleOrDefault();
   83:  
   84:                         if (emsOnt != null)
   85:                         {
   86:                             emsVagList = (from v in db.EmsVags where v.EmsOnt.Id == emsOnt.Id && v.VAGID == vagId select v).ToList();
   87:  
   88:                             existingItemCount = emsVagList.Count;
   89:  
   90:                             if (response.CompletionCode == "COMPLD")
   91:                             {
   92:                                 if (response.QueryDataTable != null)
   93:                                 {
   94:                                     itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
   95:  
   96:                                     columns = response.QueryDataTable.Columns;
   97:                                     readItemCount = response.QueryDataTable.Rows.Count;
   98:  
   99:                                     if (response.QueryDataTable.Rows.Count >= 1)
  100:                                     {
  101:                                         columnDataRow = response.QueryDataTable.Rows[0];
  102:  
  103:                                         foreach (DataRow dataRow in response.QueryDataTable.Rows)
  104:                                         {
  105:                                             did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
  106:                                             vagId = int.Parse(dataRow[columns.IndexOf("VAGID")].ToString());
  107:  
  108:                                             if (did == queryDid && vagId == queryVagId)
  109:                                             {
  110:                                                 id = Ia.Ftn.Cl.Model.Business.Huawei.Vag.VagId(emsOnt.Id, vagId);
  111:  
  112:                                                 emsVag = (from v in emsVagList where v.Id == id select v).SingleOrDefault();
  113:  
  114:                                                 newVag = new Ia.Ftn.Cl.Model.Huawei.EmsVag()
  115:                                                 {
  116:                                                     Id = id,
  117:                                                     DID = did,
  118:                                                     VAGNAME = columns.Contains("VAGNAME") ? dataRow[columns.IndexOf("VAGNAME")].ToString() : string.Empty,
  119:                                                     VAGID = vagId,
  120:                                                     SIGIP = columns.Contains("SIGIP") ? dataRow[columns.IndexOf("SIGIP")].ToString() : string.Empty,
  121:                                                     SIGMASK = columns.Contains("SIGMASK") ? dataRow[columns.IndexOf("SIGMASK")].ToString() : string.Empty,
  122:                                                     SIGGW = columns.Contains("SIGGW") ? dataRow[columns.IndexOf("SIGGW")].ToString() : string.Empty,
  123:                                                     SIGPORT = columns.Contains("SIGPORT") ? int.Parse(dataRow[columns.IndexOf("SIGPORT")].ToString()) : 0,
  124:                                                     SIGVLANID = columns.Contains("SIGVLANID") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("SIGVLANID", dataRow[columns.IndexOf("SIGVLANID")].ToString()) : 0,
  125:                                                     SIGQOS = columns.Contains("SIGQOS") ? dataRow[columns.IndexOf("SIGQOS")].ToString() : string.Empty,
  126:                                                     SIGDSCP = columns.Contains("SIGDSCP") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("SIGDSCP", dataRow[columns.IndexOf("SIGDSCP")].ToString()) : 0,
  127:                                                     SIGIPPRI = columns.Contains("SIGIPPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("SIGIPPRI", dataRow[columns.IndexOf("SIGIPPRI")].ToString()) : 0,
  128:                                                     SIGTOSPRI = columns.Contains("SIGTOSPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("SIGTOSPRI", dataRow[columns.IndexOf("SIGTOSPRI")].ToString()) : 0,
  129:                                                     SIGVLANPRI = columns.Contains("SIGVLANPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("SIGVLANPRI", dataRow[columns.IndexOf("SIGVLANPRI")].ToString()) : 0,
  130:                                                     MEDIAIP = columns.Contains("MEDIAIP") ? dataRow[columns.IndexOf("MEDIAIP")].ToString() : string.Empty,
  131:                                                     MEDIAMASK = columns.Contains("MEDIAMASK") ? dataRow[columns.IndexOf("MEDIAMASK")].ToString() : string.Empty,
  132:                                                     MEDIAGW = columns.Contains("MEDIAGW") ? dataRow[columns.IndexOf("MEDIAGW")].ToString() : string.Empty,
  133:                                                     MEDIAPORT = columns.Contains("MEDIAPORT") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIAPORT", dataRow[columns.IndexOf("MEDIAPORT")].ToString()) : 0,
  134:                                                     MEDIAVLANID = columns.Contains("MEDIAVLANID") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIAVLANID", dataRow[columns.IndexOf("MEDIAVLANID")].ToString()) : 0,
  135:                                                     MEDIAQOS = columns.Contains("MEDIAQOS") ? dataRow[columns.IndexOf("MEDIAQOS")].ToString() : string.Empty,
  136:                                                     MEDIADSCP = columns.Contains("MEDIADSCP") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIADSCP", dataRow[columns.IndexOf("MEDIADSCP")].ToString()) : 0,
  137:                                                     MEDIAIPPRI = columns.Contains("MEDIAIPPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIAIPPRI", dataRow[columns.IndexOf("MEDIAIPPRI")].ToString()) : 0,
  138:                                                     MEDIATOSPRI = columns.Contains("MEDIATOSPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIATOSPRI", dataRow[columns.IndexOf("MEDIATOSPRI")].ToString()) : 0,
  139:                                                     MEDIAVLANPRI = columns.Contains("MEDIAVLANPRI") ? Ia.Ftn.Cl.Model.Business.Huawei.Vag.SpecialIntegerParameterHandling("MEDIAVLANPRI", dataRow[columns.IndexOf("MEDIAVLANPRI")].ToString()) : 0,
  140:                                                     DOMAINNAME = columns.Contains("DOMAINNAME") ? dataRow[columns.IndexOf("DOMAINNAME")].ToString() : string.Empty,
  141:                                                     ACTIVEMGCDNAME = columns.Contains("ACTIVEMGCDNAME") ? dataRow[columns.IndexOf("ACTIVEMGCDNAME")].ToString() : string.Empty,
  142:                                                     STANDBYMGCDNAME = columns.Contains("STANDBYMGCDNAME") ? dataRow[columns.IndexOf("STANDBYMGCDNAME")].ToString() : string.Empty,
  143:                                                     VAGSTAT = columns.Contains("VAGSTAT") ? dataRow[columns.IndexOf("VAGSTAT")].ToString() : string.Empty,
  144:                                                     PROTOCOLTYPE = columns.Contains("PROTOCOLTYPE") ? dataRow[columns.IndexOf("PROTOCOLTYPE")].ToString() : string.Empty,
  145:                                                     TIDLAYER = columns.Contains("TIDLAYER") ? dataRow[columns.IndexOf("TIDLAYER")].ToString() : string.Empty,
  146:                                                     H248PFNAME = columns.Contains("H248PFNAME") ? dataRow[columns.IndexOf("H248PFNAME")].ToString() : string.Empty,
  147:                                                     SIPPFNAME = columns.Contains("SIPPFNAME") ? dataRow[columns.IndexOf("SIPPFNAME")].ToString() : string.Empty,
  148:                                                     REGMODE = columns.Contains("REGMODE") ? dataRow[columns.IndexOf("REGMODE")].ToString() : string.Empty,
  149:  
  150:                                                     EmsOnt = (from eo in db.EmsOnts where eo.Id == mduDev.NddOntId select eo).SingleOrDefault()
  151:                                                 };
  152:  
  153:                                                 if (emsVag == null)
  154:                                                 {
  155:                                                     newVag.Created = newVag.Updated = DateTime.UtcNow.AddHours(3);
  156:  
  157:                                                     db.EmsVags.Add(newVag);
  158:  
  159:                                                     insertedItemCount++;
  160:                                                 }
  161:                                                 else // update
  162:                                                 {
  163:                                                     if (emsVag.Update(newVag))
  164:                                                     {
  165:                                                         db.EmsVags.Attach(emsVag);
  166:  
  167:                                                         db.Entry(emsVag).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  168:                                                         //vag.Update(newVag); does not update
  169:  
  170:                                                         updatedItemCount++;
  171:                                                     }
  172:                                                 }
  173:  
  174:                                                 itemIdList.Add(id); // keep at the end
  175:                                             }
  176:                                             else
  177:                                             {
  178:                                                 result.AddError("LST-VAG (" + response.Ctag + "): did != queryDid and/or vagId != queryVagId for mduDev.AccessName: " + mduDev.AccessName);
  179:                                             }
  180:                                         }
  181:  
  182:                                         // below: this function will remove values that were not present in the reading
  183:                                         if (emsVagList.Count > 0)
  184:                                         {
  185:                                             foreach (var v in emsVagList)
  186:                                             {
  187:                                                 if (!itemIdList.Contains(v.Id))
  188:                                                 {
  189:                                                     emsVag = (from vi in db.EmsVags where vi.Id == v.Id select vi).SingleOrDefault();
  190:  
  191:                                                     db.EmsVags.Remove(emsVag);
  192:  
  193:                                                     deletedItemCount++;
  194:                                                 }
  195:                                             }
  196:                                         }
  197:                                     }
  198:                                     else
  199:                                     {
  200:                                         if (emsVagList.Count > 0)
  201:                                         {
  202:                                             foreach (Ia.Ftn.Cl.Model.Huawei.EmsVag v in emsVagList)
  203:                                             {
  204:                                                 emsVag = (from ev in db.EmsVags where ev.Id == v.Id select ev).SingleOrDefault();
  205:  
  206:                                                 db.EmsVags.Remove(emsVag);
  207:  
  208:                                                 deletedItemCount++;
  209:                                             }
  210:                                         }
  211:                                     }
  212:  
  213:                                     db.SaveChanges();
  214:                                 }
  215:                                 else
  216:                                 {
  217:                                     result.AddWarning("LST-VAG (" + response.Ctag + "): (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  218:                                 }
  219:                             }
  220:                             else
  221:                             {
  222:                                 if (response.ResultCode == Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode.DeviceOfflineError)
  223:                                 {
  224:                                     var emsDevResultCodeIsUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Dev.UpdateResultCode(mduDev.Did, response.ResultCode);
  225:  
  226:                                     result.AddWarning("LST-VAG (" + response.Ctag + "): (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ") EmsOnt.ResultCode updated?: " + emsDevResultCodeIsUpdated.ToString().ToLower());
  227:                                 }
  228:                                 else
  229:                                 {
  230:                                     result.AddWarning("LST-VAG (" + response.Ctag + "): (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  231:                                 }
  232:                             }
  233:                         }
  234:                         else
  235:                         {
  236:                             result.AddWarning("LST-VAG (" + response.Ctag + "): EmsOnt is null for mduDev.AccessName: " + mduDev.AccessName);
  237:                         }
  238:                     }
  239:  
  240:                     if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  241:                     else isUpdated = false;
  242:  
  243:                     result.AddSuccess("LST-VAG (" + response.Ctag + "): (" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  244:                     //}
  245:                     //else
  246:                     //{
  247:                     //    result.AddError("nddOnt is null");
  248:                     //}
  249:                 }
  250:                 else
  251:                 {
  252:                     result.AddError("LST-VAG (" + response.Ctag + "): mduDev.Dev is null for did: " + queryDid);
  253:                 }
  254:             }
  255:             else
  256:             {
  257:                 result.AddError("LST-VAG (" + response.Ctag + "): mduDev is null for did: " + queryDid);
  258:             }
  259:  
  260:             return isUpdated;
  261:         }
  262:  
  263:         ////////////////////////////////////////////////////////////////////////////
  264:  
  265:         /// <summary>
  266:         ///
  267:         /// </summary>
  268:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsVag> List()
  269:         {
  270:             List<Ia.Ftn.Cl.Model.Huawei.EmsVag> list;
  271:  
  272:             using (var db = new Ia.Ftn.Cl.Model.Db())
  273:             {
  274:                 list = (from v in db.EmsVags select v).ToList();
  275:             }
  276:  
  277:             return list;
  278:         }
  279:  
  280:         ////////////////////////////////////////////////////////////////////////////
  281:  
  282:         /// <summary>
  283:         ///
  284:         /// </summary>
  285:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsVag> List(string ontId)
  286:         {
  287:             List<Ia.Ftn.Cl.Model.Huawei.EmsVag> list;
  288:  
  289:             using (var db = new Ia.Ftn.Cl.Model.Db())
  290:             {
  291:                 list = (from v in db.EmsVags where v.EmsOnt.Id == ontId select v).ToList();
  292:             }
  293:  
  294:             return list;
  295:         }
  296:  
  297:         ////////////////////////////////////////////////////////////////////////////
  298:  
  299:         /// <summary>
  300:         ///
  301:         /// </summary>
  302:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsVag> ListByDid(int did)
  303:         {
  304:             List<Ia.Ftn.Cl.Model.Huawei.EmsVag> list;
  305:  
  306:             using (var db = new Ia.Ftn.Cl.Model.Db())
  307:             {
  308:                 list = (from v in db.EmsVags where v.DID == did select v).ToList();
  309:             }
  310:  
  311:             return list;
  312:         }
  313:  
  314:         ////////////////////////////////////////////////////////////////////////////
  315:         ////////////////////////////////////////////////////////////////////////////
  316:  
  317:         /// <summary>
  318:         ///
  319:         /// </summary>
  320:         public static string ToSimpleTextString(Ia.Ftn.Cl.Model.Huawei.EmsVag vag)
  321:         {
  322:             StringBuilder sb;
  323:  
  324:             sb = new StringBuilder();
  325:  
  326:             sb.AppendLine("DID: " + vag.DID);
  327:             sb.AppendLine("VAGSTAT: " + vag.VAGSTAT);
  328:             sb.AppendLine("PROTOCOLTYPE: " + vag.PROTOCOLTYPE);
  329:             //sb.AppendLine("Route: " + Ia.Ftn.Cl.Model.Business.Huawei.Vag.RnidxRouteName[vag.RNIDX2]);
  330:  
  331:             return sb.ToString();
  332:         }
  333:  
  334:         ////////////////////////////////////////////////////////////////////////////
  335:         ////////////////////////////////////////////////////////////////////////////
  336:     }
  337:  
  338:     ////////////////////////////////////////////////////////////////////////////
  339:     ////////////////////////////////////////////////////////////////////////////
  340: }