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

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

AXE 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.Ericsson
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// AXE 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:     /// </remarks> 
   19:     public class Subscriber
   20:     {
   21:         /// <summary/>
   22:         public Subscriber() { }
   23:  
   24:         ////////////////////////////////////////////////////////////////////////////
   25:  
   26:         /// <summary>
   27:         ///
   28:         /// </summary>
   29:         public static bool Update(Ia.Ftn.Cl.Models.Business.Ericsson.Axe.Response response, out Ia.Cl.Models.Result result)
   30:         {
   31:             bool wasUpdated;
   32:             int querySnb, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
   33:             string id, querySnbString, queryCommand;
   34:             Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber subscriber, newSubscriber;
   35:  
   36:             wasUpdated = false;
   37:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
   38:             result = new Ia.Cl.Models.Result();
   39:  
   40:             queryCommand = response.CommandString;
   41:  
   42:             // SUSCP:SNB=25382234;
   43:             querySnbString = Ia.Cl.Models.Default.Match(queryCommand, @"SNB=(\d{8})");
   44:  
   45:             querySnb = int.Parse(querySnbString);
   46:  
   47:             readItemCount = 1; // response.Count;
   48:  
   49:             using (var db = new Ia.Ftn.Cl.Db())
   50:             {
   51:                 subscriber = (from s in db.AxeSubscribers where s.SNB == querySnb select s).SingleOrDefault();
   52:  
   53:                 existingItemCount = (subscriber != null) ? 1 : 0;
   54:  
   55:                 if (response.IsSuccess) //.Count >= 1)
   56:                 {
   57:                     id = Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.SubscriberId(querySnb);
   58:  
   59:                     newSubscriber = new Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber()
   60:                     {
   61:                         Id = id,
   62:                         SNB = response.Snb,
   63:                         DEV = response.Dev,
   64:                         DETY = response.Dety,
   65:                         SUT = response.Sut,
   66:                         SCL = response.Scl,
   67:                         MIS = response.Mis,
   68:                         COS = response.Cos,
   69:                         Content = string.Empty// response.Content
   70:                     };
   71:  
   72:                     if (subscriber == null)
   73:                     {
   74:                         newSubscriber.Created = newSubscriber.Updated = DateTime.UtcNow.AddHours(3);
   75:  
   76:                         db.AxeSubscribers.Add(newSubscriber);
   77:  
   78:                         insertedItemCount++;
   79:                     }
   80:                     else
   81:                     {
   82:                         if (subscriber.Update(newSubscriber))
   83:                         {
   84:                             db.AxeSubscribers.Attach(subscriber);
   85:                             db.Entry(subscriber).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
   86:  
   87:                             updatedItemCount++;
   88:                         }
   89:                     }
   90:                 }
   91:                 else
   92:                 {
   93:                     // below: remove since reading was empty
   94:  
   95:                     if (subscriber != null)
   96:                     {
   97:                         subscriber = (from s in db.AxeSubscribers where s.SNB == querySnb select s).SingleOrDefault();
   98:  
   99:                         db.AxeSubscribers.Remove(subscriber);
  100:  
  101:                         deletedItemCount++;
  102:                     }
  103:                 }
  104:  
  105:                 db.SaveChanges();
  106:             }
  107:  
  108:             if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) wasUpdated = true;
  109:             else wasUpdated = false;
  110:  
  111:             result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  112:  
  113:             return wasUpdated;
  114:         }
  115:  
  116:         ////////////////////////////////////////////////////////////////////////////
  117:  
  118:         /// <summary>
  119:         ///
  120:         /// </summary>
  121:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> List()
  122:         {
  123:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  124:  
  125:             using (var db = new Ia.Ftn.Cl.Db())
  126:             {
  127:                 list = (from s in db.AxeSubscribers select s).ToList();
  128:             }
  129:  
  130:             return list;
  131:         }
  132:  
  133:         ////////////////////////////////////////////////////////////////////////////
  134:  
  135:         /// <summary>
  136:         ///
  137:         /// </summary>
  138:         public static List<int> SnbList()
  139:         {
  140:             List<int> list;
  141:  
  142:             using (var db = new Ia.Ftn.Cl.Db())
  143:             {
  144:                 list = (from s in db.AxeSubscribers select s.SNB).ToList();
  145:             }
  146:  
  147:             return list;
  148:         }
  149:  
  150:         ////////////////////////////////////////////////////////////////////////////
  151:  
  152:         /// <summary>
  153:         ///
  154:         /// </summary>
  155:         public static List<int> SnbWhereSclHasIcs3AndSutNotNcList()
  156:         {
  157:             List<int> list;
  158:  
  159:             // select SNB from AxeSubscribers where SCL like '%ICS-3%' and SUT <> 'NC'
  160:  
  161:             using (var db = new Ia.Ftn.Cl.Db())
  162:             {
  163:                 list = (from s in db.AxeSubscribers
  164:                         where s.SCL.Contains("ICS-3") && s.SUT != "NC"
  165:                         select s.SNB).ToList();
  166:             }
  167:  
  168:             return list;
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:  
  173:         /// <summary>
  174:         ///
  175:         /// </summary>
  176:         public static List<int> SnbWhereSclHasTbiOrTboOrBicAndSutNotNcList()
  177:         {
  178:             List<int> list;
  179:  
  180:             // select * from AxeSubscribers where SUT <> 'NC' and (scl like '%TBO%' or scl like '%TBI%' or scl like '%BIC%')
  181:  
  182:             using (var db = new Ia.Ftn.Cl.Db())
  183:             {
  184:                 list = (from s in db.AxeSubscribers
  185:                         where (s.SCL.Contains("TBI") || s.SCL.Contains("TBO") || s.SCL.Contains("BIC")) && s.SUT != "NC"
  186:                         select s.SNB).ToList();
  187:             }
  188:  
  189:             return list;
  190:         }
  191:  
  192:         ////////////////////////////////////////////////////////////////////////////
  193:  
  194:         /// <summary>
  195:         /// 
  196:         /// </summary>
  197:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> List(List<string> serviceList)
  198:         {
  199:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  200:  
  201:             if (serviceList.Count > 0)
  202:             {
  203:                 var sbnList = serviceList.ConvertAll(int.Parse);
  204:                 var idList = new List<string>();
  205:  
  206:                 foreach (var snb in sbnList)
  207:                 {
  208:                     idList.Add(Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.SubscriberId(snb));
  209:                 }
  210:  
  211:                 using (var db = new Ia.Ftn.Cl.Db())
  212:                 {
  213:                     list = (from s in db.AxeSubscribers
  214:                             where idList.Contains(s.Id)
  215:                             select s).ToList();
  216:                 }
  217:             }
  218:             else list = new List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber>();
  219:  
  220:             return list;
  221:         }
  222:  
  223:         ////////////////////////////////////////////////////////////////////////////
  224:  
  225:         /// <summary>
  226:         /// 
  227:         /// </summary>
  228:         public static List<int> ServiceList(List<string> serviceList)
  229:         {
  230:             List<int> list, sbnList;
  231:  
  232:             if (serviceList.Count > 0)
  233:             {
  234:                 sbnList = serviceList.ConvertAll(int.Parse);
  235:  
  236:                 using (var db = new Ia.Ftn.Cl.Db())
  237:                 {
  238:                     list = (from s in db.AxeSubscribers
  239:                             where sbnList.Contains(s.SNB)
  240:                             select s.SNB).ToList();
  241:                 }
  242:             }
  243:             else list = new List<int>();
  244:  
  245:             return list;
  246:         }
  247:  
  248:         ////////////////////////////////////////////////////////////////////////////
  249:  
  250:         /// <summary>
  251:         ///
  252:         /// </summary>
  253:         public static List<Ia.Ftn.Cl.Models.Ui.Ericsson.Subscriber> ListWithoutContent()
  254:         {
  255:             List<Ia.Ftn.Cl.Models.Ui.Ericsson.Subscriber> list;
  256:  
  257:             // select SNB, DEV, DETY, SUT, SCL, MIS, COS from AxeSubscribers
  258:  
  259:             using (var db = new Ia.Ftn.Cl.Db())
  260:             {
  261:                 list = (from s in db.AxeSubscribers
  262:                         select new Ia.Ftn.Cl.Models.Ui.Ericsson.Subscriber() { SNB = s.SNB, DEV = s.DEV, DETY = s.DETY, SUT = s.SUT, SCL = s.SCL, MIS = s.MIS, COS = s.COS }).ToList();
  263:  
  264:                 return list;
  265:             }
  266:         }
  267:  
  268:         ////////////////////////////////////////////////////////////////////////////
  269:  
  270:         /// <summary>
  271:         ///
  272:         /// </summary>
  273:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> InServicePstnServiceList()
  274:         {
  275:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  276:  
  277:             // select * from AxeSubscribers a inner join Service2 s on a.SNB = s.Service where s.ServiceType = 2
  278:  
  279:             var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService;
  280:  
  281:             using (var db = new Ia.Ftn.Cl.Db())
  282:             {
  283:                 list = (from s in db.AxeSubscribers
  284:                         join se in db.Service2 on s.SNB.ToString() equals se.Service
  285:                         where se.ServiceType == serviceType
  286:                         select s).ToList();
  287:             }
  288:  
  289:             return list;
  290:         }
  291:  
  292:         ////////////////////////////////////////////////////////////////////////////
  293:  
  294:         /// <summary>
  295:         ///
  296:         /// </summary>
  297:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> InServiceImsServiceList()
  298:         {
  299:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  300:  
  301:             // select * from AxeSubscribers a inner join Service2 s on a.SNB = s.Service where s.ServiceType = 1
  302:  
  303:             var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  304:  
  305:             using (var db = new Ia.Ftn.Cl.Db())
  306:             {
  307:                 list = (from s in db.AxeSubscribers
  308:                         join se in db.Service2 on s.SNB.ToString() equals se.Service
  309:                         where se.ServiceType == serviceType
  310:                         select s).ToList();
  311:             }
  312:  
  313:             return list;
  314:         }
  315:  
  316:         ////////////////////////////////////////////////////////////////////////////
  317:  
  318:         /// <summary>
  319:         ///
  320:         /// </summary>
  321:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> WithSclIcs3List()
  322:         {
  323:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  324:  
  325:             //     select * from AxeSubscribers where SCL like '%ICS-3%'
  326:  
  327:             using (var db = new Ia.Ftn.Cl.Db())
  328:             {
  329:                 list = (from s in db.AxeSubscribers where s.SCL.Contains("ICS-3") select s).ToList();
  330:             }
  331:  
  332:             return list;
  333:         }
  334:  
  335:         ////////////////////////////////////////////////////////////////////////////
  336:  
  337:         /// <summary>
  338:         ///
  339:         /// </summary>
  340:         public static List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> InServiceImsServiceButHasNotSclIcs3List()
  341:         {
  342:             List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber> list;
  343:  
  344:             /*
  345:              * select * from AxeSubscribers [as] 
  346:              * inner join Service2 s on [as].SNB = s.Service 
  347:              * where s.ServiceType = 1 and [as].SCL not like '%ICS-3%'
  348:              */
  349:  
  350:             var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  351:  
  352:             using (var db = new Ia.Ftn.Cl.Db())
  353:             {
  354:                 list = (from s in db.AxeSubscribers
  355:                         join se in db.Service2 on s.SNB.ToString() equals se.Service
  356:                         where se.ServiceType == serviceType && !s.SCL.Contains("ICS-3")
  357:                         select s).ToList();
  358:             }
  359:  
  360:             return list;
  361:         }
  362:  
  363:         ////////////////////////////////////////////////////////////////////////////
  364:  
  365:         /// <summary>
  366:         ///
  367:         /// </summary>
  368:         public static Dictionary<string, string> ServiceToRouteNameDictionary()
  369:         {
  370:             Dictionary<string, string> dictionary;
  371:  
  372:             dictionary = new Dictionary<string, string>();
  373:  
  374:             using (var db = new Ia.Ftn.Cl.Db())
  375:             {
  376:                 var list = (from s in db.AxeSubscribers select s).ToList();
  377:  
  378:                 foreach (var l in list)
  379:                 {
  380:                     dictionary[l.SNB.ToString()] = Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.RouteName(l.SCL);
  381:                 }
  382:             }
  383:  
  384:             return dictionary;
  385:         }
  386:  
  387:         ////////////////////////////////////////////////////////////////////////////
  388:  
  389:         /// <summary>
  390:         ///
  391:         /// </summary>
  392:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute> PstnServiceToSwitchRouteDictionary()
  393:         {
  394:             int icsRoute;
  395:             Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute> dictionary;
  396:  
  397:             dictionary = new Dictionary<string, Ia.Ftn.Cl.Models.Business.Default.SwitchRoute>();
  398:  
  399:             using (var db = new Ia.Ftn.Cl.Db())
  400:             {
  401:                 // I have to read even NC numbers because they will still have routing
  402:                 var list = (from s in db.AxeSubscribers select new { s.SNB, s.SCL }).AsNoTracking().ToList();
  403:  
  404:                 foreach (var l in list)
  405:                 {
  406:                     icsRoute = Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.IcsRouteFromSubscriberScl(l.SCL);
  407:  
  408:                     dictionary[l.SNB.ToString()] = Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.IcsxRouteToSwitchRoute(icsRoute);
  409:                 }
  410:             }
  411:  
  412:             return dictionary;
  413:         }
  414:  
  415:         ////////////////////////////////////////////////////////////////////////////
  416:  
  417:         /// <summary>
  418:         ///
  419:         /// </summary>
  420:         public static bool UpdateSnbSetSclToEmptyWhereSclHasIcs3AndSutNotNc()
  421:         {
  422:             var updatedItemCount = 0;
  423:             var wasUpdated = false;
  424:             var subscriberList = new List<Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber>();
  425:  
  426:             // select SNB from AxeSubscribers where SCL like '%ICS-3%' and SUT <> 'NC'
  427:  
  428:             using (var db = new Ia.Ftn.Cl.Db())
  429:             {
  430:                 subscriberList = (from s in db.AxeSubscribers
  431:                                   where s.SCL.Contains("ICS-3") && s.SUT != "NC"
  432:                                   select s).ToList();
  433:  
  434:                 foreach (var subscriber in subscriberList)
  435:                 {
  436:                     subscriber.SCL = string.Empty;
  437:                     subscriber.Updated = DateTime.UtcNow.AddHours(3);
  438:  
  439:                     db.AxeSubscribers.Attach(subscriber);
  440:                     db.Entry(subscriber).Property(u => u.SCL).IsModified = true;
  441:  
  442:  
  443:                     updatedItemCount++;
  444:                 }
  445:  
  446:                 db.SaveChanges();
  447:             }
  448:  
  449:             if (updatedItemCount != 0) wasUpdated = true;
  450:             else wasUpdated = false;
  451:  
  452:             return wasUpdated;
  453:         }
  454:  
  455:         ////////////////////////////////////////////////////////////////////////////
  456:  
  457:         /// <summary>
  458:         ///
  459:         /// </summary>
  460:         public static List<string> ServiceNotWithinAxePstnDomainList()
  461:         {
  462:             var list = new List<string>();
  463:  
  464:             var axePstnDomainList = Ia.Ftn.Cl.Models.Data.Service.AxePstnDomainList;
  465:  
  466:             var snbList = Ia.Ftn.Cl.Models.Data.Ericsson.Subscriber.SnbList();
  467:  
  468:             var serviceList = snbList.ConvertAll(delegate (int i) { return i.ToString(); });
  469:  
  470:             foreach (var s in serviceList)
  471:             {
  472:                 if (!axePstnDomainList.Any(u => s.StartsWith(u.ToString()))) list.Add(s);
  473:             }
  474:  
  475:             list.Sort();
  476:  
  477:             return list;
  478:         }
  479:  
  480:         ////////////////////////////////////////////////////////////////////////////
  481:         ////////////////////////////////////////////////////////////////////////////
  482:  
  483:         /// <summary>
  484:         ///
  485:         /// </summary>
  486:         public static string ToSimpleTextString(Ia.Ftn.Cl.Models.Ericsson.AxeSubscriber subscriber)
  487:         {
  488:             StringBuilder sb;
  489:  
  490:             sb = new StringBuilder();
  491:  
  492:             sb.AppendLine("SNB: " + subscriber.SNB);
  493:             sb.AppendLine("DEV: " + subscriber.DEV);
  494:             sb.AppendLine("DETY: " + subscriber.DETY);
  495:             sb.AppendLine("SUT: " + subscriber.SUT);
  496:             sb.AppendLine("SCL: " + subscriber.SCL);
  497:             sb.AppendLine("MIS: " + subscriber.MIS);
  498:             sb.AppendLine("COS: " + subscriber.COS);
  499:             //sb.AppendLine("Content: " + subscriber.Content);
  500:             sb.AppendLine("Route: " + Ia.Ftn.Cl.Models.Business.Ericsson.Subscriber.RouteName(subscriber.SCL));
  501:  
  502:             return sb.ToString();
  503:         }
  504:  
  505:         ////////////////////////////////////////////////////////////////////////////
  506:         ////////////////////////////////////////////////////////////////////////////
  507:     }
  508:  
  509:     ////////////////////////////////////////////////////////////////////////////
  510:     ////////////////////////////////////////////////////////////////////////////
  511: }