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

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

AGCF Gateway Records support class for Nokia data model.

    1: using System;
    2: using System.Collections;
    3: using System.Collections.Generic;
    4: using System.Linq;
    5: using Microsoft.EntityFrameworkCore;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Data.Nokia
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// AGCF Gateway Records support class for Nokia data model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright � 2014-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     /// </remarks> 
   18:     public class AgcfGatewayRecord
   19:     {
   20:         private static Dictionary<int, string> idToIp1Dictionary;
   21:         private static DateTime idToIp1DictionaryTimestamp = DateTime.MinValue;
   22:  
   23:         private static readonly object objectLock = new object();
   24:  
   25:         /// <summary>
   26:         /// 1360 COM WebAPI User Guide 255-400-419R3.X
   27:         /// ngfs-agcfgatewayrecord-v2(rtrv,ent,ed,dlt)
   28:         /// </summary>
   29:         public AgcfGatewayRecord() { }
   30:  
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public static bool Create(Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord, out string result)
   37:         {
   38:             bool b;
   39:  
   40:             b = false;
   41:             result = string.Empty;
   42:  
   43:             using (var db = new Ia.Ftn.Cl.Db())
   44:             {
   45:                 agcfGatewayRecord.Created = agcfGatewayRecord.Updated = DateTime.UtcNow.AddHours(3);
   46:  
   47:                 db.AgcfGatewayRecords.Add(agcfGatewayRecord);
   48:                 db.SaveChanges();
   49:  
   50:                 b = true;
   51:             }
   52:  
   53:             return b;
   54:         }
   55:  
   56:         ////////////////////////////////////////////////////////////////////////////
   57:  
   58:         /// <summary>
   59:         ///
   60:         /// </summary>
   61:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord Read(int id)
   62:         {
   63:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
   64:  
   65:             using (var db = new Ia.Ftn.Cl.Db())
   66:             {
   67:                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == id select gr).SingleOrDefault();
   68:             }
   69:  
   70:             return agcfGatewayRecord;
   71:         }
   72:  
   73:         ////////////////////////////////////////////////////////////////////////////
   74:  
   75:         /// <summary>
   76:         ///
   77:         /// </summary>
   78:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord ReadByGwId(int gwId)
   79:         {
   80:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
   81:  
   82:             using (var db = new Ia.Ftn.Cl.Db())
   83:             {
   84:                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.GwId == gwId select gr).SingleOrDefault();
   85:             }
   86:  
   87:             return agcfGatewayRecord;
   88:         }
   89:  
   90:         ////////////////////////////////////////////////////////////////////////////
   91:  
   92:         /// <summary>
   93:         ///
   94:         /// </summary>
   95:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord Read(string ip)
   96:         {
   97:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
   98:  
   99:             using (var db = new Ia.Ftn.Cl.Db())
  100:             {
  101:                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.IP1 == ip select gr).SingleOrDefault();
  102:             }
  103:  
  104:             return agcfGatewayRecord;
  105:         }
  106:  
  107:         ////////////////////////////////////////////////////////////////////////////
  108:  
  109:         /// <summary>
  110:         ///
  111:         /// </summary>
  112:         public static bool Update(Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord, out string result)
  113:         {
  114:             bool b;
  115:  
  116:             b = false;
  117:             result = string.Empty;
  118:  
  119:             using (var db = new Ia.Ftn.Cl.Db())
  120:             {
  121:                 agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == agcfGatewayRecord.Id select gr).SingleOrDefault();
  122:  
  123:                 agcfGatewayRecord.Updated = DateTime.UtcNow.AddHours(3);
  124:  
  125:                 db.AgcfGatewayRecords.Attach(agcfGatewayRecord);
  126:  
  127:                 db.Entry(agcfGatewayRecord).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  128:                 db.SaveChanges();
  129:  
  130:                 b = true;
  131:             }
  132:  
  133:             return b;
  134:         }
  135:  
  136:         ////////////////////////////////////////////////////////////////////////////
  137:  
  138:         /// <summary>
  139:         ///
  140:         /// </summary>
  141:         public static bool Delete(int id, out string result)
  142:         {
  143:             bool b;
  144:  
  145:             b = false;
  146:             result = string.Empty;
  147:  
  148:             using (var db = new Ia.Ftn.Cl.Db())
  149:             {
  150:                 var v = (from gr in db.AgcfGatewayRecords where gr.Id == id select gr).FirstOrDefault();
  151:  
  152:                 db.AgcfGatewayRecords.Remove(v);
  153:                 db.SaveChanges();
  154:  
  155:                 b = true;
  156:             }
  157:  
  158:             return b;
  159:         }
  160:  
  161:         ////////////////////////////////////////////////////////////////////////////
  162:  
  163:         /// <summary>
  164:         ///
  165:         /// </summary>
  166:         public static List<int> ReadGwIdList()
  167:         {
  168:             List<int> gwIdlist;
  169:  
  170:             using (var db = new Ia.Ftn.Cl.Db())
  171:             {
  172:                 gwIdlist = (from gr in db.AgcfGatewayRecords
  173:                             orderby gr.GwId ascending
  174:                             select gr.GwId).ToList();
  175:             }
  176:  
  177:             return gwIdlist;
  178:         }
  179:  
  180:         ////////////////////////////////////////////////////////////////////////////
  181:  
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         public static List<int> ReadUnusedGwIdList()
  186:         {
  187:             List<int> gwIdlist, allPossibleGwIdList, unusedGwIdlist;
  188:  
  189:             using (var db = new Ia.Ftn.Cl.Db())
  190:             {
  191:                 gwIdlist = (from gr in db.AgcfGatewayRecords
  192:                             orderby gr.GwId ascending
  193:                             select gr.GwId).ToList();
  194:             }
  195:  
  196:             allPossibleGwIdList = Ia.Ftn.Cl.Models.Data.Nokia.Ims.AllPossibleGatewayIdList;
  197:  
  198:             // below: extract the GwId in allPossibleGwIdList that are not in gwIdlist
  199:             unusedGwIdlist = allPossibleGwIdList.Except(gwIdlist).ToList();
  200:  
  201:             return unusedGwIdlist;
  202:         }
  203:  
  204:         ////////////////////////////////////////////////////////////////////////////
  205:  
  206:         /// <summary>
  207:         ///
  208:         /// </summary>
  209:         public static int GwIdFromIp(string ip)
  210:         {
  211:             int gwId;
  212:  
  213:             using (var db = new Ia.Ftn.Cl.Db())
  214:             {
  215:                 gwId = (from gr in db.AgcfGatewayRecords
  216:                         where gr.IP1 == ip
  217:                         select gr.GwId).SingleOrDefault();
  218:             }
  219:  
  220:             return gwId;
  221:         }
  222:  
  223:         ////////////////////////////////////////////////////////////////////////////
  224:  
  225:         /// <summary>
  226:         ///
  227:         /// </summary>
  228:         public static int GwIdFromPartyId(string partyId)
  229:         {
  230:             int gatewayId;
  231:  
  232:             using (var db = new Ia.Ftn.Cl.Db())
  233:             {
  234:                 /*
  235:                  * this query sometimes becomes slow. Note that:
  236:                  * 
  237:                 gatewayId = (from gr in db.AgcfGatewayRecords
  238:                              join ep in db.AgcfEndpoints on gr.Id equals ep.AgcfGatewayRecord.Id
  239:                              join sp in db.SubParties on ep.Id equals sp.AgcfEndpoint.Id
  240:                              join s in db.Subscribers on sp.Id equals s.SubParty.Id
  241:                              where s.PartyId == partyId
  242:                              select gr.GwId).SingleOrDefault();
  243: 
  244:                  * In SubParty, Id is PartyId (see Ia.Ftn.Cl.Model.Nokia.SubParty.SubPartyId())
  245:                  * And in Subscribers, Id is PartyId (see Ia.Ftn.Cl.Model.Nokia.Subscriber.SubscriberId())
  246:                 */
  247:                 gatewayId = (from gr in db.AgcfGatewayRecords
  248:                              join ep in db.AgcfEndpoints on gr.Id equals ep.AgcfGatewayRecord.Id
  249:                              join sp in db.SubParties on ep.Id equals sp.AgcfEndpoint.Id
  250:                              //join s in db.Subscribers on sp.Id equals s.SubParty.Id
  251:                              //where s.PartyId == partyId
  252:                              where sp.Id == partyId
  253:                              select gr.GwId).SingleOrDefault();
  254:             }
  255:  
  256:             return gatewayId;
  257:         }
  258:  
  259:         ////////////////////////////////////////////////////////////////////////////
  260:  
  261:         /// <summary>
  262:         ///
  263:         /// </summary>
  264:         public static string IpFromGatewayId(int gatewayId)
  265:         {
  266:             string ip;
  267:  
  268:             using (var db = new Ia.Ftn.Cl.Db())
  269:             {
  270:                 ip = (from gr in db.AgcfGatewayRecords
  271:                       where gr.GwId == gatewayId
  272:                       select gr.IP1).SingleOrDefault();
  273:             }
  274:  
  275:             return ip;
  276:         }
  277:  
  278:         ////////////////////////////////////////////////////////////////////////////
  279:  
  280:         /// <summary>
  281:         ///
  282:         /// </summary>
  283:         public static List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> List()
  284:         {
  285:             List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
  286:  
  287:             using (var db = new Ia.Ftn.Cl.Db())
  288:             {
  289:                 agcfGatewayRecordList = (from gr in db.AgcfGatewayRecords select gr).AsNoTracking().ToList();
  290:             }
  291:  
  292:             return agcfGatewayRecordList;
  293:         }
  294:  
  295:         ////////////////////////////////////////////////////////////////////////////
  296:  
  297:         /// <summary>
  298:         ///
  299:         /// </summary>
  300:         public static List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> List(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
  301:         {
  302:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontList;
  303:             List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
  304:  
  305:             // below: FTN ONT list
  306:             ontList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  307:                           where o.Pon.PonGroup.Olt.Id == olt.Id
  308:                           select o).ToList();
  309:  
  310:             using (var db = new Ia.Ftn.Cl.Db())
  311:             {
  312:                 // below: AgcfGatewayRecord list
  313:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).AsNoTracking().ToList();
  314:             }
  315:  
  316:             agcfGatewayRecordList = (from gr in agcfGatewayRecordList
  317:                                      join no in ontList on gr.IP1 equals no.Ip
  318:                                      select gr).ToList();
  319:  
  320:             return agcfGatewayRecordList;
  321:         }
  322:  
  323:         ////////////////////////////////////////////////////////////////////////////
  324:  
  325:         /// <summary>
  326:         ///
  327:         /// </summary>
  328:         public static List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> List(List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> oltList)
  329:         {
  330:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontList;
  331:             List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
  332:  
  333:             // below: FTN ONT list
  334:             ontList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  335:                           where oltList.Any(u => u.Id == o.Pon.PonGroup.Olt.Id)
  336:                           select o).ToList();
  337:  
  338:             using (var db = new Ia.Ftn.Cl.Db())
  339:             {
  340:                 // below: AgcfGatewayRecord list
  341:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).AsNoTracking().ToList();
  342:             }
  343:  
  344:             agcfGatewayRecordList = (from gr in agcfGatewayRecordList
  345:                                      join no in ontList on gr.IP1 equals no.Ip
  346:                                      select gr).ToList();
  347:  
  348:             return agcfGatewayRecordList;
  349:         }
  350:  
  351:         ////////////////////////////////////////////////////////////////////////////
  352:  
  353:         /// <summary>
  354:         ///
  355:         /// </summary>
  356:         public static List<string> IpList()
  357:         {
  358:             List<string> list;
  359:  
  360:             using (var db = new Ia.Ftn.Cl.Db())
  361:             {
  362:                 list = (from gr in db.AgcfGatewayRecords
  363:                         orderby gr.IP1 ascending
  364:                         select gr.IP1).AsNoTracking().Distinct().ToList();
  365:             }
  366:  
  367:             return list;
  368:         }
  369:  
  370:         ////////////////////////////////////////////////////////////////////////////
  371:  
  372:         /// <summary>
  373:         ///
  374:         /// </summary>
  375:         public static Dictionary<string, string> IpDictionary
  376:         {
  377:             get
  378:             {
  379:                 Dictionary<string, string> ipListDictionary;
  380:  
  381:                 using (var db = new Ia.Ftn.Cl.Db())
  382:                 {
  383:                     ipListDictionary = (from a in db.AgcfGatewayRecords
  384:                                         select a.IP1).AsNoTracking().ToDictionary(n => n, n => n);
  385:                 }
  386:  
  387:                 return ipListDictionary;
  388:             }
  389:         }
  390:  
  391:         ////////////////////////////////////////////////////////////////////////////
  392:  
  393:         /// <summary>
  394:         ///
  395:         /// </summary>
  396:         public static Dictionary<string, string> IpToMateExternalIPAddrDictionary
  397:         {
  398:             get
  399:             {
  400:                 Dictionary<string, string> dictionary;
  401:  
  402:                 using (var db = new Ia.Ftn.Cl.Db())
  403:                 {
  404:                     dictionary = (from a in db.AgcfGatewayRecords
  405:                                   select a).AsNoTracking().ToDictionary(n => n.IP1, n => n.MateExternalIPAddr);
  406:                 }
  407:  
  408:                 return dictionary;
  409:             }
  410:         }
  411:  
  412:         ////////////////////////////////////////////////////////////////////////////
  413:  
  414:         /// <summary>
  415:         ///
  416:         /// </summary>
  417:         public static SortedList AgcfGatewayRecordIpListNotInNetworkDesignDocument
  418:         {
  419:             get
  420:             {
  421:                 SortedList sl;
  422:                 Dictionary<string, string> ipDictionary, nddIpDictionary;
  423:  
  424:                 ipDictionary = IpDictionary;
  425:                 nddIpDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIpDictionary;
  426:  
  427:                 sl = new SortedList(ipDictionary.Count + nddIpDictionary.Count);
  428:  
  429:                 foreach (KeyValuePair<string, string> kvp in ipDictionary)
  430:                 {
  431:                     if (!nddIpDictionary.ContainsKey(kvp.Key))
  432:                     {
  433:                         if (!sl.ContainsKey(kvp.Key)) sl.Add(kvp.Key, "1");
  434:                     }
  435:                 }
  436:  
  437:                 return sl;
  438:             }
  439:         }
  440:  
  441:         ////////////////////////////////////////////////////////////////////////////
  442:  
  443:         /// <summary>
  444:         ///
  445:         /// </summary>
  446:         public static List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> ListByMateExternalIPAddr(string mateExternalIPAddr)
  447:         {
  448:             List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
  449:  
  450:             using (var db = new Ia.Ftn.Cl.Db())
  451:             {
  452:                 // below: AgcfGatewayRecord list
  453:                 agcfGatewayRecordList = (from a in db.AgcfGatewayRecords
  454:                                          where a.MateExternalIPAddr == mateExternalIPAddr
  455:                                          select a).AsNoTracking().ToList();
  456:             }
  457:  
  458:             return agcfGatewayRecordList;
  459:         }
  460:  
  461:         ////////////////////////////////////////////////////////////////////////////
  462:  
  463:         /// <summary>
  464:         ///
  465:         /// </summary>
  466:         public static List<string> IpWithinAgcfGatewayRecordsThatDoNotBelongToNetworkDesignDocumentList()
  467:         {
  468:             List<string> list;
  469:  
  470:             list = new List<string>();
  471:  
  472:             var w = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIpDictionary;
  473:  
  474:             foreach (KeyValuePair<string, string> kvp in Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.IpDictionary)
  475:             {
  476:                 if (!w.ContainsKey(kvp.Key)) list.Add(kvp.Key);
  477:             }
  478:  
  479:             return list;
  480:         }
  481:  
  482:         ////////////////////////////////////////////////////////////////////////////
  483:         ////////////////////////////////////////////////////////////////////////////
  484:     }
  485:  
  486:     ////////////////////////////////////////////////////////////////////////////
  487:     ////////////////////////////////////////////////////////////////////////////
  488: }