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

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

SERUATTR Signaling Service Processing System (SPS) support class for Huawei's Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6: using System.Text;
    7:  
    8: namespace Ia.Ftn.Cl.Models.Data.Huawei
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// SERUATTR Signaling Service Processing System (SPS) support class for Huawei's Fixed Telecommunications Network (FTN) data model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2018-2020 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 class Seruattr
   30:     {
   31:         /// <summary/>
   32:         public Seruattr() { }
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public static bool Update(Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response response, out Ia.Cl.Models.Result result)
   40:         {
   41:             bool isUpdated;
   42:             int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
   43:             string id, queryUsrnum, queryCommand;
   44:             Ia.Ftn.Cl.Models.Huawei.Seruattr seruattr, newSeruattr;
   45:  
   46:             isUpdated = false;
   47:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
   48:             result = new Ia.Cl.Models.Result();
   49:  
   50:             queryCommand = response.CommandString;
   51:  
   52:             // LST SERUATTR:MODE=NUM,USRNUM="26660019";
   53:             queryUsrnum = Ia.Cl.Models.Default.Match(queryCommand, @"USRNUM=""(\d+?)""");
   54:  
   55:             readItemCount = response.Count;
   56:  
   57:             using (var db = new Ia.Ftn.Cl.Db())
   58:             {
   59:                 seruattr = (from s in db.Seruattrs where s.USRNUM == queryUsrnum select s).SingleOrDefault();
   60:  
   61:                 existingItemCount = 1;
   62:  
   63:                 if (response.Count >= 1)
   64:                 {
   65:                     id = Ia.Ftn.Cl.Models.Business.Huawei.Seruattr.SeruattrId(queryUsrnum);
   66:  
   67:                     newSeruattr = new Ia.Ftn.Cl.Models.Huawei.Seruattr()
   68:                     {
   69:                         Id = id,
   70:                         SERVATTR = response.QueryDictionary.ContainsKey("SERVATTR") ? int.Parse(response.QueryDictionary["SERVATTR"]) : 0,
   71:                         NUMTYPE = response.QueryDictionary.ContainsKey("NUMTYPE") ? int.Parse(response.QueryDictionary["NUMTYPE"]) : 0,
   72:                         USRNUM = response.QueryDictionary.ContainsKey("USRNUM") ? response.QueryDictionary["USRNUM"] : string.Empty,
   73:                         IMSINUM = response.QueryDictionary.ContainsKey("IMSINUM") ? response.QueryDictionary["IMSINUM"] : string.Empty,
   74:                         DESC = response.QueryDictionary.ContainsKey("DESC") ? response.QueryDictionary["DESC"] : string.Empty,
   75:                         RNIDXTYPE = response.QueryDictionary.ContainsKey("RNIDXTYPE") ? int.Parse(response.QueryDictionary["RNIDXTYPE"]) : 0,
   76:                         HLRIDX = response.QueryDictionary.ContainsKey("HLRIDX") ? int.Parse(response.QueryDictionary["HLRIDX"]) : 0,
   77:                         RNIDX = response.QueryDictionary.ContainsKey("RNIDX") ? int.Parse(response.QueryDictionary["RNIDX"]) : 0,
   78:                         RNIDX2 = response.QueryDictionary.ContainsKey("RNIDX2") ? int.Parse(response.QueryDictionary["RNIDX2"]) : 0,
   79:                         RN = response.QueryDictionary.ContainsKey("RN") ? response.QueryDictionary["RN"] : string.Empty
   80:                     };
   81:  
   82:                     if (seruattr == null)
   83:                     {
   84:                         newSeruattr.Created = newSeruattr.Updated = DateTime.UtcNow.AddHours(3);
   85:  
   86:                         db.Seruattrs.Add(newSeruattr);
   87:  
   88:                         insertedItemCount++;
   89:                     }
   90:                     else
   91:                     {
   92:                         if (seruattr.Update(newSeruattr))
   93:                         {
   94:                             db.Seruattrs.Attach(seruattr);
   95:                             db.Entry(seruattr).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
   96:  
   97:                             updatedItemCount++;
   98:                         }
   99:                     }
  100:                 }
  101:                 else
  102:                 {
  103:                     // below: remove since reading was empty
  104:  
  105:                     if (seruattr != null)
  106:                     {
  107:                         seruattr = (from s in db.Seruattrs where s.USRNUM == queryUsrnum select s).SingleOrDefault();
  108:  
  109:                         db.Seruattrs.Remove(seruattr);
  110:  
  111:                         deletedItemCount++;
  112:                     }
  113:                 }
  114:  
  115:                 db.SaveChanges();
  116:             }
  117:  
  118:             if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  119:             else isUpdated = false;
  120:  
  121:             result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  122:  
  123:             return isUpdated;
  124:         }
  125:  
  126:         ////////////////////////////////////////////////////////////////////////////
  127:  
  128:         /// <summary>
  129:         ///
  130:         /// </summary>
  131:         public static List<Ia.Ftn.Cl.Models.Huawei.Seruattr> List()
  132:         {
  133:             List<Ia.Ftn.Cl.Models.Huawei.Seruattr> list;
  134:  
  135:             using (var db = new Ia.Ftn.Cl.Db())
  136:             {
  137:                 list = (from s in db.Seruattrs select s).ToList();
  138:             }
  139:  
  140:             return list;
  141:         }
  142:  
  143:         ////////////////////////////////////////////////////////////////////////////
  144:  
  145:         /// <summary>
  146:         ///
  147:         /// </summary>
  148:         public static List<int> UsrnumList()
  149:         {
  150:             List<int> list;
  151:  
  152:             using (var db = new Ia.Ftn.Cl.Db())
  153:             {
  154:                 var usrnumList = (from s in db.Seruattrs select s.USRNUM).AsNoTracking().ToList();
  155:  
  156:                 list = new List<int>();
  157:  
  158:                 foreach (string usrnum in usrnumList)
  159:                 {
  160:                     list.Add(int.Parse(usrnum));
  161:                 }
  162:             }
  163:  
  164:             return list;
  165:         }
  166:  
  167:         ////////////////////////////////////////////////////////////////////////////
  168:  
  169:         /// <summary>
  170:         ///
  171:         /// </summary>
  172:         public static List<string> ServiceList()
  173:         {
  174:             var usrnumList = UsrnumList();
  175:  
  176:             var list = usrnumList.ConvertAll<string>(u => u.ToString());
  177:  
  178:             return list;
  179:         }
  180:  
  181:         ////////////////////////////////////////////////////////////////////////////
  182:  
  183:         /// <summary>
  184:         /// 
  185:         /// </summary>
  186:         public static List<Ia.Ftn.Cl.Models.Huawei.Seruattr> List(List<string> serviceList)
  187:         {
  188:             List<Ia.Ftn.Cl.Models.Huawei.Seruattr> list;
  189:  
  190:             using (var db = new Ia.Ftn.Cl.Db())
  191:             {
  192:                 if (serviceList.Count > 0)
  193:                 {
  194:                     list = (from s in db.Seruattrs
  195:                             where serviceList.Contains(s.USRNUM)
  196:                             select s).ToList();
  197:                 }
  198:                 else list = new List<Ia.Ftn.Cl.Models.Huawei.Seruattr>();
  199:             }
  200:  
  201:             return list;
  202:         }
  203:  
  204:         ////////////////////////////////////////////////////////////////////////////
  205:  
  206:         /// <summary>
  207:         ///
  208:         /// </summary>
  209:         public static List<string> ServiceNotWithinSpsDomainList()
  210:         {
  211:             var list = new List<string>();
  212:  
  213:             var spsDomainList = Ia.Ftn.Cl.Models.Data.Service.SpsDomainList;
  214:  
  215:             var serviceList = Ia.Ftn.Cl.Models.Data.Huawei.Seruattr.ServiceList();
  216:  
  217:             foreach (var s in serviceList)
  218:             {
  219:                 if (!spsDomainList.Any(u => s.StartsWith(u.ToString()))) list.Add(s);
  220:             }
  221:  
  222:             list.Sort();
  223:  
  224:             return list;
  225:         }
  226:  
  227:         ////////////////////////////////////////////////////////////////////////////
  228:  
  229:         /// <summary>
  230:         ///
  231:         /// </summary>
  232:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute> PstnServiceToSwitchRouteDictionary()
  233:         {
  234:             var dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute>();
  235:  
  236:             using (var db = new Ia.Ftn.Cl.Db())
  237:             {
  238:                 var list = (from s in db.Seruattrs
  239:                             select new { s.USRNUM, s.RNIDX2 }).AsNoTracking().ToList();
  240:  
  241:                 foreach (var l in list)
  242:                 {
  243:                     dictionary[l.USRNUM] = Ia.Ftn.Cl.Models.Business.Huawei.Seruattr.RnidxRouteToSwitchRoute(l.RNIDX2);
  244:                 }
  245:             }
  246:  
  247:             return dictionary;
  248:         }
  249:  
  250:         ////////////////////////////////////////////////////////////////////////////
  251:  
  252:         /// <summary>
  253:         ///
  254:         /// </summary>
  255:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute> PstnThatUsesNpServerServiceToSwitchRouteDictionary()
  256:         {
  257:             var dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute>();
  258:  
  259:             var pstnThatUsesNpServerDomainList = Ia.Ftn.Cl.Models.Data.Service.PstnThatUsesNpServerDomainList;
  260:  
  261:             using (var db = new Ia.Ftn.Cl.Db())
  262:             {
  263:                 var list = (from s in db.Seruattrs
  264:                             select new { s.USRNUM, s.RNIDX2 }).AsNoTracking().ToList();
  265:  
  266:                 foreach (var l in list)
  267:                 {
  268:                     if (pstnThatUsesNpServerDomainList.Any(u => l.USRNUM.StartsWith(u.ToString())))
  269:                     {
  270:                         dictionary[l.USRNUM] = Ia.Ftn.Cl.Models.Business.Huawei.Seruattr.RnidxRouteToSwitchRoute(l.RNIDX2);
  271:                     }
  272:                 }
  273:             }
  274:  
  275:             return dictionary;
  276:         }
  277:  
  278:         ////////////////////////////////////////////////////////////////////////////
  279:         ////////////////////////////////////////////////////////////////////////////
  280:  
  281:         /// <summary>
  282:         ///
  283:         /// </summary>
  284:         public static string ToSimpleTextString(Ia.Ftn.Cl.Models.Huawei.Seruattr seruattr)
  285:         {
  286:             StringBuilder sb;
  287:  
  288:             sb = new StringBuilder();
  289:  
  290:             sb.AppendLine("SERVATTR: " + seruattr.SERVATTR);
  291:             sb.AppendLine("NUMTYPE: " + seruattr.NUMTYPE);
  292:             sb.AppendLine("USRNUM: " + seruattr.USRNUM);
  293:             sb.AppendLine("IMSINUM: " + seruattr.IMSINUM);
  294:             sb.AppendLine("DESC: " + seruattr.DESC);
  295:             sb.AppendLine("RNIDXTYPE: " + seruattr.RNIDXTYPE);
  296:             sb.AppendLine("HLRIDX: " + seruattr.HLRIDX);
  297:             sb.AppendLine("RNIDX: " + seruattr.RNIDX);
  298:             sb.AppendLine("RNIDX2: " + seruattr.RNIDX2);
  299:             sb.AppendLine("Route: " + Ia.Ftn.Cl.Models.Business.Huawei.Seruattr.RnidxRouteName[seruattr.RNIDX2]);
  300:             sb.AppendLine("RN: " + seruattr.RN);
  301:  
  302:             return sb.ToString();
  303:         }
  304:  
  305:         ////////////////////////////////////////////////////////////////////////////
  306:         ////////////////////////////////////////////////////////////////////////////
  307:     }
  308:  
  309:     ////////////////////////////////////////////////////////////////////////////
  310:     ////////////////////////////////////////////////////////////////////////////
  311: }