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