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

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

EWSD Subscriber support class for 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.Siemens
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// EWSD Subscriber support class for 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 Subscriber
   30:     {
   31:         /// <summary/>
   32:         public Subscriber() { }
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public static bool Update(Ia.Ftn.Cl.Models.Business.Siemens.Ewsd.Response response, out Ia.Cl.Models.Result result)
   40:         {
   41:             bool isUpdated;
   42:             int queryDn, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
   43:             string id, queryDnString, queryCommand;
   44:             Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber subscriber, newSubscriber;
   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:             // DISPSUB:DN=25421113;
   53:             queryDnString = Ia.Cl.Models.Default.Match(queryCommand, @"DN=(\d{8})");
   54:  
   55:             queryDn = int.Parse(queryDnString);
   56:  
   57:             readItemCount = 1; // response.Count;
   58:  
   59:             using (var db = new Ia.Ftn.Cl.Db())
   60:             {
   61:                 id = Ia.Ftn.Cl.Models.Business.Siemens.Subscriber.SubscriberId(queryDn);
   62:  
   63:                 subscriber = (from es in db.EwsdSubscribers where es.Id == id select es).SingleOrDefault();
   64:                 //subscriber = (from es in db.EwsdSubscribers where es.DN == queryDn select es).SingleOrDefault(); very slow.
   65:  
   66:                 existingItemCount = (subscriber != null) ? 1 : 0;
   67:  
   68:                 if (response.IsSuccess) //.Count >= 1)
   69:                 {
   70:                     newSubscriber = new Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber()
   71:                     {
   72:                         Id = id,
   73:                         DN = response.Dn,
   74:                         LAC = response.Lac,
   75:                         EQN = response.Eqn,
   76:                         CAT = response.Cat,
   77:                         LTT = response.Ltt,
   78:                         OPTRCL = response.Optrcl,
   79:                         SUBTRCL = response.Subtrcl,
   80:                         NUMCAL = response.Numcal,
   81:                         ORIG1 = response.Orig1,
   82:                         TRARSTR = response.Trarstr,
   83:                         LNATT = response.Lnatt,
   84:                         DIV = response.Div,
   85:                         COS = response.Cos,
   86:                         ADDINF = response.Addinf,
   87:                         NUMBCH = response.Numbch,
   88:                         CTDIVI = response.Ctdivi,
   89:                         BLK = response.Blk,
   90:                         Content = string.Empty// response.Content
   91:                     };
   92:  
   93:                     if (subscriber == null)
   94:                     {
   95:                         newSubscriber.Created = newSubscriber.Updated = DateTime.UtcNow.AddHours(3);
   96:  
   97:                         db.EwsdSubscribers.Add(newSubscriber);
   98:  
   99:                         insertedItemCount++;
  100:                     }
  101:                     else
  102:                     {
  103:                         if (subscriber.Update(newSubscriber))
  104:                         {
  105:                             db.EwsdSubscribers.Attach(subscriber);
  106:                             db.Entry(subscriber).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  107:  
  108:                             updatedItemCount++;
  109:                         }
  110:                     }
  111:                 }
  112:                 else
  113:                 {
  114:                     // below: remove since reading was empty
  115:  
  116:                     if (subscriber != null)
  117:                     {
  118:                         subscriber = (from es in db.EwsdSubscribers where es.Id == id select es).SingleOrDefault();
  119:                         //subscriber = (from es in db.EwsdSubscribers where es.DN == queryDn select es).SingleOrDefault(); very slow.
  120:  
  121:                         db.EwsdSubscribers.Remove(subscriber);
  122:  
  123:                         deletedItemCount++;
  124:                     }
  125:                 }
  126:  
  127:                 db.SaveChanges();
  128:             }
  129:  
  130:             if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  131:             else isUpdated = false;
  132:  
  133:             result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  134:  
  135:             return isUpdated;
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////
  139:  
  140:         /// <summary>
  141:         ///
  142:         /// </summary>
  143:         public static List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> List()
  144:         {
  145:             List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> list;
  146:  
  147:             using (var db = new Ia.Ftn.Cl.Db())
  148:             {
  149:                 list = (from es in db.EwsdSubscribers select es).ToList();
  150:             }
  151:  
  152:             return list;
  153:         }
  154:  
  155:         ////////////////////////////////////////////////////////////////////////////
  156:  
  157:         /// <summary>
  158:         ///
  159:         /// </summary>
  160:         public static List<int> DnList()
  161:         {
  162:             List<int> list;
  163:  
  164:             using (var db = new Ia.Ftn.Cl.Db())
  165:             {
  166:                 list = (from es in db.EwsdSubscribers select es.DN).ToList();
  167:             }
  168:  
  169:             return list;
  170:         }
  171:  
  172:         ////////////////////////////////////////////////////////////////////////////
  173:  
  174:         /// <summary>
  175:         ///
  176:         /// </summary>
  177:         public static List<int> ProvisionedDnList()
  178:         {
  179:             List<int> list;
  180:  
  181:             using (var db = new Ia.Ftn.Cl.Db())
  182:             {
  183:                 list = (from es in db.EwsdSubscribers where es.LAC != null && es.EQN != null select es.DN).ToList();
  184:             }
  185:  
  186:             return list;
  187:         }
  188:  
  189:         ////////////////////////////////////////////////////////////////////////////
  190:  
  191:         /// <summary>
  192:         ///
  193:         /// </summary>
  194:         public static List<string> ProvisionedServiceList()
  195:         {
  196:             List<string> list;
  197:  
  198:             using (var db = new Ia.Ftn.Cl.Db())
  199:             {
  200:                 list = (from es in db.EwsdSubscribers
  201:                         where es.LAC != null && es.EQN != null
  202:                         select es.DN.ToString()).AsNoTracking().ToList();
  203:             }
  204:  
  205:             return list;
  206:         }
  207:  
  208:         ////////////////////////////////////////////////////////////////////////////
  209:  
  210:         /// <summary>
  211:         /// 
  212:         /// </summary>
  213:         public static List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> List(List<string> serviceList)
  214:         {
  215:             List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> list;
  216:  
  217:             if (serviceList.Count > 0)
  218:             {
  219:                 var dnList = serviceList.ConvertAll(int.Parse);
  220:                 var idList = new List<string>();
  221:  
  222:                 foreach (var dn in dnList)
  223:                 {
  224:                     idList.Add(Ia.Ftn.Cl.Models.Business.Siemens.Subscriber.SubscriberId(dn));
  225:                 }
  226:  
  227:                 using (var db = new Ia.Ftn.Cl.Db())
  228:                 {
  229:                     list = (from es in db.EwsdSubscribers
  230:                             where idList.Contains(es.Id)
  231:                             select es).ToList();
  232:                 }
  233:             }
  234:             else list = new List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber>();
  235:  
  236:             return list;
  237:         }
  238:  
  239:         ////////////////////////////////////////////////////////////////////////////
  240:  
  241:         /// <summary>
  242:         ///
  243:         /// </summary>
  244:         public static List<Ia.Ftn.Cl.Models.Ui.Siemens.Subscriber> ListWithoutContent()
  245:         {
  246:             List<Ia.Ftn.Cl.Models.Ui.Siemens.Subscriber> list;
  247:  
  248:             using (var db = new Ia.Ftn.Cl.Db())
  249:             {
  250:                 list = (from es in db.EwsdSubscribers
  251:                         select new Ia.Ftn.Cl.Models.Ui.Siemens.Subscriber()
  252:                         {
  253:                             DN = es.DN,
  254:                             LAC = es.LAC,
  255:                             EQN = es.EQN,
  256:                             CAT = es.CAT,
  257:                             LTT = es.LTT,
  258:                             OPTRCL = es.OPTRCL,
  259:                             SUBTRCL = es.SUBTRCL,
  260:                             NUMCAL = es.NUMCAL,
  261:                             ORIG1 = es.ORIG1,
  262:                             TRARSTR = es.TRARSTR,
  263:                             LNATT = es.LNATT,
  264:                             DIV = es.DIV,
  265:                             COS = es.COS,
  266:                             ADDINF = es.ADDINF,
  267:                             NUMBCH = es.NUMBCH,
  268:                             CTDIVI = es.CTDIVI,
  269:                             BLK = es.BLK
  270:                         }).ToList();
  271:  
  272:                 return list;
  273:             }
  274:         }
  275:  
  276:         ////////////////////////////////////////////////////////////////////////////
  277:  
  278:         /// <summary>
  279:         ///
  280:         /// </summary>
  281:         public static List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> InServicePstnServiceList()
  282:         {
  283:             List<Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber> list;
  284:  
  285:             // select * from EwsdSubscribers a inner join Service2 s on a.DN = s.Service where s.ServiceType = 2
  286:  
  287:             var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService;
  288:  
  289:             using (var db = new Ia.Ftn.Cl.Db())
  290:             {
  291:                 list = (from es in db.EwsdSubscribers
  292:                         join s in db.Service2 on es.DN.ToString() equals s.Service
  293:                         where s.ServiceType == serviceType
  294:                         select es).ToList();
  295:             }
  296:  
  297:             return list;
  298:         }
  299:  
  300:         ////////////////////////////////////////////////////////////////////////////
  301:  
  302:         /// <summary>
  303:         ///
  304:         /// </summary>
  305:         public static List<string> InServiceImsServiceList()
  306:         {
  307:             List<string> list;
  308:  
  309:             // select DN from EwsdSubscribers a inner join Service2 s on a.DN = s.Service where s.ServiceType = 1
  310:  
  311:             var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  312:  
  313:             using (var db = new Ia.Ftn.Cl.Db())
  314:             {
  315:                 list = (from es in db.EwsdSubscribers
  316:                         join s in db.Service2 on es.DN.ToString() equals s.Service
  317:                         where s.ServiceType == serviceType
  318:                         select es.DN.ToString()).ToList();
  319:             }
  320:  
  321:             return list;
  322:         }
  323:  
  324:         ////////////////////////////////////////////////////////////////////////////
  325:  
  326:         /// <summary>
  327:         ///
  328:         /// </summary>
  329:         public static List<string> ServiceNotWithinEwsdPstnDomainList()
  330:         {
  331:             var list = new List<string>();
  332:  
  333:             var ewsdPstnDomainList = Ia.Ftn.Cl.Models.Data.Service.EwsdPstnDomainList;
  334:  
  335:             var dnList = Ia.Ftn.Cl.Models.Data.Siemens.Subscriber.DnList();
  336:  
  337:             var serviceList = dnList.ConvertAll(delegate (int i) { return i.ToString(); });
  338:  
  339:             foreach (var s in serviceList)
  340:             {
  341:                 if (!ewsdPstnDomainList.Any(u => s.StartsWith(u.ToString()))) list.Add(s);
  342:             }
  343:  
  344:             list.Sort();
  345:  
  346:             return list;
  347:         }
  348:  
  349:         ////////////////////////////////////////////////////////////////////////////
  350:  
  351:         /// <summary>
  352:         ///
  353:         /// </summary>
  354:         public static List<string> DnWhereBlkIsNotEmptyList()
  355:         {
  356:             List<string> list;
  357:  
  358:             // select * from EwsdSubscribers where BLK <> ''
  359:  
  360:             using (var db = new Ia.Ftn.Cl.Db())
  361:             {
  362:                 list = (from es in db.EwsdSubscribers
  363:                         where es.BLK != null && es.BLK != ""
  364:                         select es.DN.ToString()).ToList();
  365:             }
  366:  
  367:             return list;
  368:         }
  369:  
  370:         ////////////////////////////////////////////////////////////////////////////
  371:         ////////////////////////////////////////////////////////////////////////////
  372:  
  373:         /// <summary>
  374:         ///
  375:         /// </summary>
  376:         public static string ToSimpleTextString(Ia.Ftn.Cl.Models.Siemens.EwsdSubscriber subscriber)
  377:         {
  378:             StringBuilder sb;
  379:  
  380:             sb = new StringBuilder();
  381:  
  382:             sb.AppendLine("DN: " + subscriber.DN);
  383:             sb.AppendLine("LAC: " + subscriber.LAC);
  384:             sb.AppendLine("EQN: " + subscriber.EQN);
  385:             sb.AppendLine("CAT: " + subscriber.CAT);
  386:             sb.AppendLine("LTT: " + subscriber.LTT);
  387:             sb.AppendLine("OPTRCL: " + subscriber.OPTRCL);
  388:             sb.AppendLine("SUBTRCL: " + subscriber.SUBTRCL);
  389:             sb.AppendLine("NUMCAL: " + subscriber.NUMCAL);
  390:             sb.AppendLine("ORIG1: " + subscriber.ORIG1);
  391:             sb.AppendLine("TRARSTR: " + subscriber.TRARSTR);
  392:             sb.AppendLine("LNATT: " + subscriber.LNATT);
  393:             sb.AppendLine("DIV: " + subscriber.DIV);
  394:             sb.AppendLine("COS: " + subscriber.COS);
  395:             sb.AppendLine("ADDINF: " + subscriber.ADDINF);
  396:             sb.AppendLine("NUMBCH: " + subscriber.NUMBCH);
  397:             sb.AppendLine("CTDIVI: " + subscriber.CTDIVI);
  398:             sb.AppendLine("BLK: " + subscriber.BLK);
  399:             //sb.AppendLine("Content: " + subscriber.Content);
  400:  
  401:             return sb.ToString();
  402:         }
  403:  
  404:         ////////////////////////////////////////////////////////////////////////////
  405:         ////////////////////////////////////////////////////////////////////////////
  406:     }
  407:  
  408:     ////////////////////////////////////////////////////////////////////////////
  409:     ////////////////////////////////////////////////////////////////////////////
  410: }