شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » AgcfGatewayRecord

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:   
   6:  namespace Ia.Ngn.Cl.Model.Data.Nokia
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// AGCF Gateway Records support class for Nokia data model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright � 2014-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class AgcfGatewayRecord
  28:      {
  29:          /// <summary>
  30:          /// 1360 COM WebAPI User Guide 255-400-419R3.X
  31:          /// ngfs-agcfgatewayrecord-v2(rtrv,ent,ed,dlt)
  32:          /// </summary>
  33:          public AgcfGatewayRecord() { }
  34:   
  35:          ////////////////////////////////////////////////////////////////////////////
  36:   
  37:          /// <summary>
  38:          ///
  39:          /// </summary>
  40:          public static bool Create(Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord, out string result)
  41:          {
  42:              bool b;
  43:   
  44:              b = false;
  45:              result = string.Empty;
  46:   
  47:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  48:              {
  49:                  agcfGatewayRecord.Created = agcfGatewayRecord.Updated = DateTime.UtcNow.AddHours(3);
  50:   
  51:                  db.AgcfGatewayRecords.Add(agcfGatewayRecord);
  52:                  db.SaveChanges();
  53:   
  54:                  b = true;
  55:              }
  56:   
  57:              return b;
  58:          }
  59:   
  60:          ////////////////////////////////////////////////////////////////////////////
  61:   
  62:          /// <summary>
  63:          ///
  64:          /// </summary>
  65:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord Read(int id)
  66:          {
  67:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  68:   
  69:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  70:              {
  71:                  agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == id select gr).SingleOrDefault();
  72:              }
  73:   
  74:              return agcfGatewayRecord;
  75:          }
  76:   
  77:          ////////////////////////////////////////////////////////////////////////////
  78:   
  79:          /// <summary>
  80:          ///
  81:          /// </summary>
  82:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord ReadByGwId(int gwId)
  83:          {
  84:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  85:   
  86:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  87:              {
  88:                  agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.GwId == gwId select gr).SingleOrDefault();
  89:              }
  90:   
  91:              return agcfGatewayRecord;
  92:          }
  93:   
  94:          ////////////////////////////////////////////////////////////////////////////
  95:   
  96:          /// <summary>
  97:          ///
  98:          /// </summary>
  99:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord Read(string ip)
 100:          {
 101:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
 102:   
 103:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 104:              {
 105:                  agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.IP1 == ip select gr).SingleOrDefault();
 106:              }
 107:   
 108:              return agcfGatewayRecord;
 109:          }
 110:   
 111:          ////////////////////////////////////////////////////////////////////////////
 112:   
 113:          /// <summary>
 114:          ///
 115:          /// </summary>
 116:          public static bool Update(Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord, out string result)
 117:          {
 118:              bool b;
 119:   
 120:              b = false;
 121:              result = string.Empty;
 122:   
 123:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 124:              {
 125:                  agcfGatewayRecord = (from gr in db.AgcfGatewayRecords where gr.Id == agcfGatewayRecord.Id select gr).SingleOrDefault();
 126:   
 127:                  agcfGatewayRecord.Updated = DateTime.UtcNow.AddHours(3);
 128:   
 129:                  db.AgcfGatewayRecords.Attach(agcfGatewayRecord);
 130:   
 131:                  db.Entry(agcfGatewayRecord).State = System.Data.Entity.EntityState.Modified;
 132:                  db.SaveChanges();
 133:   
 134:                  b = true;
 135:              }
 136:   
 137:              return b;
 138:          }
 139:   
 140:          ////////////////////////////////////////////////////////////////////////////
 141:   
 142:          /// <summary>
 143:          ///
 144:          /// </summary>
 145:          public static bool Delete(int id, out string result)
 146:          {
 147:              bool b;
 148:   
 149:              b = false;
 150:              result = string.Empty;
 151:   
 152:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 153:              {
 154:                  var v = (from gr in db.AgcfGatewayRecords where gr.Id == id select gr).FirstOrDefault();
 155:   
 156:                  db.AgcfGatewayRecords.Remove(v);
 157:                  db.SaveChanges();
 158:   
 159:                  b = true;
 160:              }
 161:   
 162:              return b;
 163:          }
 164:   
 165:          ////////////////////////////////////////////////////////////////////////////
 166:   
 167:          /// <summary>
 168:          ///
 169:          /// </summary>
 170:          public static List<int> ReadGwIdList()
 171:          {
 172:              List<int> gwIdlist;
 173:   
 174:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 175:              {
 176:                  gwIdlist = (from gr in db.AgcfGatewayRecords orderby gr.GwId ascending select gr.GwId).ToList();
 177:              }
 178:   
 179:              return gwIdlist;
 180:          }
 181:   
 182:          ////////////////////////////////////////////////////////////////////////////
 183:   
 184:          /// <summary>
 185:          ///
 186:          /// </summary>
 187:          public static List<int> ReadUnusedGwIdList()
 188:          {
 189:              List<int> gwIdlist, allPossibleGwIdList, unusedGwIdlist;
 190:   
 191:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 192:              {
 193:                  gwIdlist = (from gr in db.AgcfGatewayRecords orderby gr.GwId ascending select gr.GwId).ToList();
 194:              }
 195:   
 196:              allPossibleGwIdList = Ia.Ngn.Cl.Model.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.Ngn.Cl.Model.Ngn())
 214:              {
 215:                  gwId = (from gr in db.AgcfGatewayRecords where gr.IP1 == ip select gr.GwId).SingleOrDefault();
 216:              }
 217:   
 218:              return gwId;
 219:          }
 220:   
 221:          ////////////////////////////////////////////////////////////////////////////
 222:   
 223:          /// <summary>
 224:          ///
 225:          /// </summary>
 226:          public static int GwIdFromPartyId(string partyId)
 227:          {
 228:              int gatewayId;
 229:   
 230:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 231:              {
 232:                  gatewayId = (from gr in db.AgcfGatewayRecords
 233:                               join ep in db.AgcfEndpoints on gr.Id equals ep.AgcfGatewayRecord.Id
 234:                               join sp in db.SubParties on ep.Id equals sp.AgcfEndpoint.Id
 235:                               join s in db.Subscribers on sp.Id equals s.SubParty.Id
 236:                               where s.PartyId == partyId
 237:                               select gr.GwId).SingleOrDefault();
 238:              }
 239:   
 240:              return gatewayId;
 241:          }
 242:   
 243:          ////////////////////////////////////////////////////////////////////////////
 244:   
 245:          /// <summary>
 246:          ///
 247:          /// </summary>
 248:          public static string IpFromGatewayId(int gatewayId)
 249:          {
 250:              string ip;
 251:   
 252:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 253:              {
 254:                  ip = (from gr in db.AgcfGatewayRecords where gr.GwId == gatewayId select gr.IP1).SingleOrDefault();
 255:              }
 256:   
 257:              return ip;
 258:          }
 259:   
 260:          ////////////////////////////////////////////////////////////////////////////
 261:   
 262:          /// <summary>
 263:          ///
 264:          /// </summary>
 265:          public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> List()
 266:          {
 267:              List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 268:   
 269:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 270:              {
 271:                  agcfGatewayRecordList = (from gr in db.AgcfGatewayRecords select gr).ToList();
 272:              }
 273:   
 274:              return agcfGatewayRecordList;
 275:          }
 276:   
 277:          ////////////////////////////////////////////////////////////////////////////
 278:   
 279:          /// <summary>
 280:          ///
 281:          /// </summary>
 282:          public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> List(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 283:          {
 284:              List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntList;
 285:              List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 286:   
 287:              // below: NGN ONT list
 288:              ngnOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == olt.Id select o).ToList();
 289:   
 290:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 291:              {
 292:                  // below: AgcfGatewayRecord list
 293:                  agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).ToList();
 294:              }
 295:   
 296:              agcfGatewayRecordList = (from gr in agcfGatewayRecordList join no in ngnOntList on gr.IP1 equals no.Ip select gr).ToList();
 297:   
 298:              return agcfGatewayRecordList;
 299:          }
 300:   
 301:          ////////////////////////////////////////////////////////////////////////////
 302:   
 303:          /// <summary>
 304:          ///
 305:          /// </summary>
 306:          public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> List(List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt> oltList)
 307:          {
 308:              List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ngnOntList;
 309:              List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 310:   
 311:              // below: NGN ONT list
 312:              ngnOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where oltList.Any(u => u.Id == o.Pon.PonGroup.Olt.Id) select o).ToList();
 313:   
 314:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 315:              {
 316:                  // below: AgcfGatewayRecord list
 317:                  agcfGatewayRecordList = (from a in db.AgcfGatewayRecords select a).ToList();
 318:              }
 319:   
 320:              agcfGatewayRecordList = (from gr in agcfGatewayRecordList join no in ngnOntList on gr.IP1 equals no.Ip select gr).ToList();
 321:   
 322:              return agcfGatewayRecordList;
 323:          }
 324:   
 325:          ////////////////////////////////////////////////////////////////////////////
 326:   
 327:          /// <summary>
 328:          ///
 329:          /// </summary>
 330:          public static List<string> IpList()
 331:          {
 332:              List<string> iplist;
 333:   
 334:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 335:              {
 336:                  iplist = (from gr in db.AgcfGatewayRecords orderby gr.IP1 ascending select gr.IP1).Distinct().ToList();
 337:              }
 338:   
 339:              return iplist;
 340:          }
 341:   
 342:          ////////////////////////////////////////////////////////////////////////////
 343:   
 344:          /// <summary>
 345:          ///
 346:          /// </summary>
 347:          public static Dictionary<string, string> IpDictionary
 348:          {
 349:              get
 350:              {
 351:                  Dictionary<string, string> ipListDictionary;
 352:   
 353:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 354:                  {
 355:                      ipListDictionary = (from a in db.AgcfGatewayRecords select a.IP1).ToDictionary(n => n, n => n);
 356:                  }
 357:   
 358:                  return ipListDictionary;
 359:              }
 360:          }
 361:   
 362:          ////////////////////////////////////////////////////////////////////////////
 363:   
 364:          /// <summary>
 365:          ///
 366:          /// </summary>
 367:          public static Dictionary<string, string> IpToMateExternalIPAddrDictionary
 368:          {
 369:              get
 370:              {
 371:                  Dictionary<string, string> dictionary;
 372:   
 373:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 374:                  {
 375:                      dictionary = (from a in db.AgcfGatewayRecords select a).ToDictionary(n => n.IP1, n => n.MateExternalIPAddr);
 376:                  }
 377:   
 378:                  return dictionary;
 379:              }
 380:          }
 381:   
 382:          ////////////////////////////////////////////////////////////////////////////
 383:   
 384:          /// <summary>
 385:          ///
 386:          /// </summary>
 387:          public static SortedList AgcfGatewayRecordIpListNotInNetworkDesignDocument
 388:          {
 389:              get
 390:              {
 391:                  SortedList sl;
 392:                  Dictionary<string, string> ipDictionary, nddIpDictionary;
 393:   
 394:                  ipDictionary = IpDictionary;
 395:                  nddIpDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpDictionary;
 396:   
 397:                  sl = new SortedList(ipDictionary.Count + nddIpDictionary.Count);
 398:   
 399:                  foreach (KeyValuePair<string, string> kvp in ipDictionary)
 400:                  {
 401:                      if (!nddIpDictionary.ContainsKey(kvp.Key))
 402:                      {
 403:                          if (!sl.ContainsKey(kvp.Key)) sl.Add(kvp.Key, "1");
 404:                      }
 405:                  }
 406:   
 407:                  return sl;
 408:              }
 409:          }
 410:   
 411:          ////////////////////////////////////////////////////////////////////////////
 412:   
 413:          /// <summary>
 414:          ///
 415:          /// </summary>
 416:          public static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> ListByMateExternalIPAddr(string mateExternalIPAddr)
 417:          {
 418:              List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> agcfGatewayRecordList;
 419:   
 420:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 421:              {
 422:                  // below: AgcfGatewayRecord list
 423:                  agcfGatewayRecordList = (from a in db.AgcfGatewayRecords where a.MateExternalIPAddr == mateExternalIPAddr select a).ToList();
 424:              }
 425:   
 426:              return agcfGatewayRecordList;
 427:          }
 428:   
 429:          ////////////////////////////////////////////////////////////////////////////
 430:   
 431:          /// <summary>
 432:          ///
 433:          /// </summary>
 434:          public static List<string> IpWithinAgcfGatewayRecordsThatDoNotBelongToNetworkDesignDocumentList()
 435:          {
 436:              List<string> list;
 437:   
 438:              list = new List<string>();
 439:   
 440:              var w = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIpDictionary;
 441:   
 442:              foreach (KeyValuePair<string, string> kvp in Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.IpDictionary)
 443:              {
 444:                  if (!w.ContainsKey(kvp.Key)) list.Add(kvp.Key);
 445:              }
 446:   
 447:              return list;
 448:          }
 449:   
 450:          ////////////////////////////////////////////////////////////////////////////
 451:          ////////////////////////////////////////////////////////////////////////////
 452:      }
 453:   
 454:      ////////////////////////////////////////////////////////////////////////////
 455:      ////////////////////////////////////////////////////////////////////////////
 456:  }