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

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