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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Service2

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

Service support class for Next Generation Network (NGN) data model.

   1:  using System.Collections;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Data;
   5:  using System.Data.Entity;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Data
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Service support class for Next Generation Network (NGN) data model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2017 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 Service2
  29:      {
  30:          public Service2() { }
  31:   
  32:          ////////////////////////////////////////////////////////////////////////////
  33:   
  34:          /// <summary>
  35:          /// Read service from Id
  36:          /// </summary>
  37:          public static Ia.Ngn.Cl.Model.Service2 Read(string id)
  38:          {
  39:              Ia.Ngn.Cl.Model.Service2 service;
  40:   
  41:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  42:              {
  43:                  service = (from s in db.Service2s where s.Id == id select s).SingleOrDefault();
  44:              }
  45:   
  46:              return service;
  47:          }
  48:   
  49:          ////////////////////////////////////////////////////////////////////////////
  50:   
  51:          /// <summary>
  52:          /// Read service from Id
  53:          /// </summary>
  54:          public static Ia.Ngn.Cl.Model.Service2 ReadIncludeAccess(string id)
  55:          {
  56:              Ia.Ngn.Cl.Model.Service2 service;
  57:   
  58:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  59:              {
  60:                  service = (from s in db.Service2s.Include(a => a.Access) where s.Id == id select s).SingleOrDefault();
  61:              }
  62:   
  63:              return service;
  64:          }
  65:   
  66:          ////////////////////////////////////////////////////////////////////////////
  67:   
  68:          /// <summary>
  69:          /// Read service of a number
  70:          /// </summary>
  71:          public static Ia.Ngn.Cl.Model.Service2 Read(long number)
  72:          {
  73:              Ia.Ngn.Cl.Model.Service2 service;
  74:   
  75:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  76:              {
  77:                  service = (from s in db.Service2s where s.Service == number.ToString() select s).SingleOrDefault();
  78:              }
  79:   
  80:              return service;
  81:          }
  82:   
  83:          ////////////////////////////////////////////////////////////////////////////
  84:   
  85:          /// <summary>
  86:          /// Read service of a number
  87:          /// </summary>
  88:          public static Ia.Ngn.Cl.Model.Service2 ReadWithAccess(long number)
  89:          {
  90:              Ia.Ngn.Cl.Model.Service2 service;
  91:   
  92:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  93:              {
  94:                  service = (from s in db.Service2s.Include(a => a.Access) where s.Service == number.ToString() select s).SingleOrDefault();
  95:              }
  96:   
  97:              return service;
  98:          }
  99:   
 100:          ////////////////////////////////////////////////////////////////////////////
 101:   
 102:          /// <summary>
 103:          ///
 104:          /// </summary>
 105:          public static List<Ia.Ngn.Cl.Model.Service2> List()
 106:          {
 107:              List<Ia.Ngn.Cl.Model.Service2> serviceList;
 108:   
 109:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 110:              {
 111:                  serviceList = (from s in db.Service2s select s).ToList();
 112:              }
 113:   
 114:              return serviceList;
 115:          }
 116:   
 117:          ////////////////////////////////////////////////////////////////////////////
 118:   
 119:          /// <summary>
 120:          ///
 121:          /// </summary>
 122:          public static List<string> List(List<int> domainList)
 123:          {
 124:              List<string> stringDomainList;
 125:              List<string> serviceList;
 126:   
 127:              stringDomainList = new List<string>();
 128:   
 129:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 130:              {
 131:                  if (domainList != null)
 132:                  {
 133:                      foreach (int i in domainList) stringDomainList.Add(i.ToString());
 134:   
 135:                      serviceList = (from s in db.Service2s where stringDomainList.Any(u => s.Service.StartsWith(u.ToString())) select s.Service).ToList();
 136:                  }
 137:                  else
 138:                  {
 139:                      serviceList = (from s in db.Service2s select s.Service).ToList();
 140:                  }
 141:              }
 142:   
 143:              return serviceList;
 144:          }
 145:   
 146:          ////////////////////////////////////////////////////////////////////////////
 147:   
 148:          /// <summary>
 149:          ///
 150:          /// </summary>
 151:          public static List<string> StringList()
 152:          {
 153:              List<string> list;
 154:   
 155:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 156:              {
 157:                  list = (from s in db.Service2s select s.Service).ToList();
 158:              }
 159:   
 160:              return list;
 161:          }
 162:   
 163:          ////////////////////////////////////////////////////////////////////////////
 164:   
 165:          /// <summary>
 166:          /// 
 167:          /// </summary>
 168:          public static List<string> ServiceIdList()
 169:          {
 170:              List<string> list;
 171:   
 172:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 173:              {
 174:                  list = (from s in db.Service2s select s.Id).ToList();
 175:              }
 176:   
 177:              return list.ToList();
 178:          }
 179:   
 180:          ////////////////////////////////////////////////////////////////////////////
 181:   
 182:          /// <summary>
 183:          /// Read all services for a number list
 184:          /// </summary>
 185:          public static List<Ia.Ngn.Cl.Model.Service2> ReadList(ArrayList numberList)
 186:          {
 187:              long i;
 188:              long[] sp;
 189:              List<Ia.Ngn.Cl.Model.Service2> serviceList;
 190:   
 191:              i = 0;
 192:              sp = new long[numberList.Count];
 193:   
 194:              foreach (long l in numberList) sp[i++] = l;
 195:   
 196:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 197:              {
 198:                  //serviceList = (from q in db.Services where dnList.Contains(q.DN) select q).ToList();
 199:   
 200:                  // var pages = context.Pages.Where(x => keys.Any(key => x.Title.Contains(key)));
 201:                  serviceList = db.Service2s.Where(s => sp.Any(v => s.Service == v.ToString())).ToList();
 202:              }
 203:   
 204:              return serviceList;
 205:          }
 206:   
 207:          ////////////////////////////////////////////////////////////////////////////
 208:   
 209:          /// <summary>
 210:          ///
 211:          /// </summary>
 212:          public static Ia.Ngn.Cl.Model.Access ReadAccess(string id)
 213:          {
 214:              Ia.Ngn.Cl.Model.Access access;
 215:   
 216:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 217:              {
 218:                  access = (from s in db.Service2s where s.Id == id select s.Access).SingleOrDefault();
 219:              }
 220:   
 221:              return access;
 222:          }
 223:   
 224:          ////////////////////////////////////////////////////////////////////////////
 225:   
 226:          /// <summary>
 227:          ///
 228:          /// </summary>
 229:          public static Dictionary<string, string> ServiceLineCardDictionary
 230:          {
 231:              get
 232:              {
 233:                  Dictionary<string, string> dictionary;
 234:   
 235:                  dictionary = new Dictionary<string, string>();
 236:   
 237:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 238:                  {
 239:                      dictionary = (from s in db.Service2s where s.LineCard != null select new { s.Service, s.LineCard }).ToDictionary(m => m.Service, m => m.LineCard);
 240:                  }
 241:   
 242:                  return dictionary;
 243:              }
 244:          }
 245:   
 246:          ////////////////////////////////////////////////////////////////////////////
 247:   
 248:          /// <summary>
 249:          ///
 250:          /// </summary>
 251:          public static Ia.Ngn.Cl.Model.Access ReadAccess(Ia.Ngn.Cl.Model.Ngn db, string id)
 252:          {
 253:              Ia.Ngn.Cl.Model.Access access;
 254:   
 255:              access = (from s in db.Service2s where s.Id == id select s.Access).SingleOrDefault();
 256:   
 257:              return access;
 258:          }
 259:   
 260:          ////////////////////////////////////////////////////////////////////////////
 261:   
 262:          /// <summary>
 263:          ///
 264:          /// </summary>
 265:          public static bool UpdateLineCard(Ia.Ngn.Cl.Model.Service2 service, string lineCard, out string result)
 266:          {
 267:              bool b;
 268:   
 269:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 270:              {
 271:                  service = (from s in db.Service2s where s.Id == service.Id select s).SingleOrDefault();
 272:   
 273:                  if (service.LineCard != lineCard)
 274:                  {
 275:                      service.LineCard = lineCard;
 276:   
 277:                      db.Service2s.Attach(service);
 278:                      db.Entry(service).Property(x => x.LineCard).IsModified = true;
 279:   
 280:                      db.SaveChanges();
 281:   
 282:                      result = "Success: Service LineCard updated. ";
 283:                      b = true;
 284:                  }
 285:                  else
 286:                  {
 287:                      result = "Warning: Service LineCard value was not updated because its the same. ";
 288:   
 289:                      b = false;
 290:                  }
 291:              }
 292:   
 293:              return b;
 294:          }
 295:   
 296:          ////////////////////////////////////////////////////////////////////////////
 297:   
 298:          /// <summary>
 299:          ///
 300:          /// </summary>
 301:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceWithNullAccessList
 302:          {
 303:              get
 304:              {
 305:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 306:   
 307:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 308:                  {
 309:                      serviceList = (from s in db.Service2s where s.Access == null select s).ToList();
 310:                  }
 311:   
 312:                  return serviceList;
 313:              }
 314:          }
 315:   
 316:          ////////////////////////////////////////////////////////////////////////////
 317:   
 318:          /// <summary>
 319:          /// Services within a SIP designated OLT
 320:          /// </summary>
 321:          public static List<string> ServiceIdWithinSipOltList()
 322:          {
 323:              List<int> sipOltIdList;
 324:              List<string> list, list2;
 325:   
 326:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 327:   
 328:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 329:              {
 330:                  // services with access
 331:                  list = (from s in db.Service2s where s.Access != null && sipOltIdList.Contains(s.Access.Olt) select s.Id).ToList();
 332:   
 333:                  // services without access might be newly installed
 334:                  list2 = (from s in db.Service2s
 335:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 336:                           where s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 337:                           select s.Id).ToList();
 338:              }
 339:   
 340:              return list.Union(list2).Distinct().ToList();
 341:          }
 342:   
 343:          ////////////////////////////////////////////////////////////////////////////
 344:   
 345:          /// <summary>
 346:          /// Services within a SIP allowed to be provisioned OLT
 347:          /// </summary>
 348:          public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedList()
 349:          {
 350:              List<int> sipOltIdList;
 351:              List<string> list, list2;
 352:   
 353:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedSipOltToBeProvisionedIdList;
 354:   
 355:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 356:              {
 357:                  // services with access
 358:                  list = (from s in db.Service2s where s.Access != null && sipOltIdList.Contains(s.Access.Olt) select s.Id).ToList();
 359:   
 360:                  // services without access might be newly installed
 361:                  list2 = (from s in db.Service2s
 362:                           join srs in db.ServiceRequestServices on s.Service equals srs.Service
 363:                           where s.Access == null && srs.Access != null && srs.Provisioned == true && sipOltIdList.Contains(srs.Access.Olt)
 364:                           select s.Id).ToList();
 365:              }
 366:   
 367:              return list.Union(list2).Distinct().ToList();
 368:          }
 369:   
 370:          ////////////////////////////////////////////////////////////////////////////
 371:   
 372:          /// <summary>
 373:          /// Services within Huawei switch domain list
 374:          /// </summary>
 375:          public static List<string> ServiceIdWithinHuaweiSwitchDomainList()
 376:          {
 377:              List<int> huaweiSwitchDomainList;
 378:              List<string> list;
 379:   
 380:              huaweiSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList;
 381:   
 382:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 383:              {
 384:                  list = (from s in db.Service2s where huaweiSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString())) select s.Id).ToList();
 385:              }
 386:   
 387:              return list.ToList();
 388:          }
 389:   
 390:          ////////////////////////////////////////////////////////////////////////////
 391:   
 392:          /// <summary>
 393:          /// Services within Nokia switch domain list
 394:          /// </summary>
 395:          public static List<string> ServiceIdWithinNokiaSwitchDomainList()
 396:          {
 397:              List<int> nokiaSwitchDomainList;
 398:              List<string> list;
 399:   
 400:              nokiaSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service.NokiaSwitchDomainList;
 401:   
 402:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 403:              {
 404:                  list = (from s in db.Service2s where nokiaSwitchDomainList.Any(u => s.Service.StartsWith(u.ToString())) select s.Id).ToList();
 405:              }
 406:   
 407:              return list.ToList();
 408:          }
 409:   
 410:          ////////////////////////////////////////////////////////////////////////////
 411:   
 412:          /// <summary>
 413:          ///
 414:          /// </summary>
 415:          public static List<string> ServiceIdWithNullAccessList()
 416:          {
 417:              List<string> list;
 418:   
 419:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 420:              {
 421:                  list = (from s in db.Service2s where s.Access == null select s.Id).ToList();
 422:              }
 423:   
 424:              return list;
 425:          }
 426:   
 427:          ////////////////////////////////////////////////////////////////////////////
 428:   
 429:          /// <summary>
 430:          ///
 431:          /// </summary>
 432:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsTrueList
 433:          {
 434:              get
 435:              {
 436:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 437:   
 438:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 439:                  {
 440:                      serviceList = (from s in db.Service2s where s.ServiceSuspension == true select s).ToList();
 441:                  }
 442:   
 443:                  return serviceList;
 444:              }
 445:          }
 446:   
 447:          ////////////////////////////////////////////////////////////////////////////
 448:   
 449:          /// <summary>
 450:          ///
 451:          /// </summary>
 452:          public static int ServiceSuspensionIsTrueListCount
 453:          {
 454:              get
 455:              {
 456:                  int c;
 457:   
 458:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 459:                  {
 460:                      c = (from s in db.Service2s where s.ServiceSuspension == true select s).Count();
 461:                  }
 462:   
 463:                  return c;
 464:              }
 465:          }
 466:   
 467:          ////////////////////////////////////////////////////////////////////////////
 468:   
 469:          /// <summary>
 470:          ///
 471:          /// </summary>
 472:          public static List<Ia.Ngn.Cl.Model.Service2> ServiceSuspensionIsFalseList
 473:          {
 474:              get
 475:              {
 476:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 477:   
 478:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 479:                  {
 480:                      serviceList = (from s in db.Service2s where s.ServiceSuspension == false select s).ToList();
 481:                  }
 482:   
 483:                  return serviceList;
 484:              }
 485:          }
 486:   
 487:          ////////////////////////////////////////////////////////////////////////////
 488:   
 489:          /// <summary>
 490:          ///
 491:          /// </summary>
 492:          public static List<string> ServiceSuspensionIsTrueStringNumberList
 493:          {
 494:              get
 495:              {
 496:                  List<string> serviceNumberStringList;
 497:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 498:   
 499:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 500:                  {
 501:                      // below:                
 502:                      serviceList = ServiceSuspensionIsTrueList;
 503:   
 504:                      if (serviceList.Count > 0)
 505:                      {
 506:                          serviceNumberStringList = new List<string>(serviceList.Count);
 507:   
 508:                          foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
 509:                          {
 510:                              serviceNumberStringList.Add(srs.Service);
 511:                          }
 512:                      }
 513:                      else
 514:                      {
 515:                          // below: not null
 516:                          serviceNumberStringList = new List<string>(1);
 517:                      }
 518:                  }
 519:   
 520:                  return serviceNumberStringList;
 521:              }
 522:          }
 523:   
 524:          ////////////////////////////////////////////////////////////////////////////
 525:   
 526:          /// <summary>
 527:          ///
 528:          /// </summary>
 529:          public static List<string> ServiceSuspensionIsFalseStringNumberList
 530:          {
 531:              get
 532:              {
 533:                  List<string> serviceNumberStringList;
 534:                  List<Ia.Ngn.Cl.Model.Service2> serviceList;
 535:   
 536:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 537:                  {
 538:                      // below:                
 539:                      serviceList = ServiceSuspensionIsFalseList;
 540:   
 541:                      if (serviceList.Count > 0)
 542:                      {
 543:                          serviceNumberStringList = new List<string>(serviceList.Count);
 544:   
 545:                          foreach (Ia.Ngn.Cl.Model.Service2 srs in serviceList)
 546:                          {
 547:                              serviceNumberStringList.Add(srs.Service);
 548:                          }
 549:                      }
 550:                      else
 551:                      {
 552:                          // below: not null
 553:                          serviceNumberStringList = new List<string>(1);
 554:                      }
 555:                  }
 556:   
 557:                  return serviceNumberStringList;
 558:              }
 559:          }
 560:   
 561:          ////////////////////////////////////////////////////////////////////////////
 562:   
 563:          /// <summary>
 564:          ///
 565:          /// </summary>
 566:          public static Dictionary<string, string> ServiceIdToAccessIdDictionary
 567:          {
 568:              get
 569:              {
 570:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 571:   
 572:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 573:                  {
 574:                      dictionary = (from s in db.Service2s where s.Access != null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Id);
 575:                      nullAccessDictionary = (from s in db.Service2s where s.Access == null select s.Id).ToDictionary(u => u, null);
 576:                  }
 577:   
 578:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 579:              }
 580:          }
 581:   
 582:          ////////////////////////////////////////////////////////////////////////////
 583:   
 584:          /// <summary>
 585:          ///
 586:          /// </summary>
 587:          public static Dictionary<string, string> ServiceToAccessIdDictionary
 588:          {
 589:              get
 590:              {
 591:                  string key;
 592:                  Dictionary<string, string> serviceToAccessIdDictionary, serviceIdToAccessIdDictionary;
 593:   
 594:                  serviceIdToAccessIdDictionary = ServiceIdToAccessIdDictionary;
 595:   
 596:                  serviceToAccessIdDictionary = new Dictionary<string, string>(serviceIdToAccessIdDictionary.Count);
 597:   
 598:                  foreach(KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
 599:                  {
 600:                      key = Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(kvp.Key);
 601:   
 602:                      serviceToAccessIdDictionary[key] = kvp.Value;
 603:                  }
 604:   
 605:                  return serviceToAccessIdDictionary;
 606:              }
 607:          }
 608:   
 609:          ////////////////////////////////////////////////////////////////////////////
 610:   
 611:          /// <summary>
 612:          ///
 613:          /// </summary>
 614:          public static Dictionary<string, string> ServiceIdToAccessNameDictionary
 615:          {
 616:              get
 617:              {
 618:                  Dictionary<string, string> dictionary, nullAccessDictionary;
 619:   
 620:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 621:                  {
 622:                      dictionary = (from s in db.Service2s where s.Access != null select new { s.Id, s.Access }).ToDictionary(u => u.Id, u => u.Access.Name);
 623:                      nullAccessDictionary = (from s in db.Service2s where s.Access == null select s.Id).ToDictionary(u => u, null);
 624:                  }
 625:   
 626:                  return dictionary.Union(nullAccessDictionary).ToDictionary(u => u.Key, u => u.Value);
 627:              }
 628:          }
 629:   
 630:          ////////////////////////////////////////////////////////////////////////////
 631:          ////////////////////////////////////////////////////////////////////////////
 632:      }
 633:   
 634:      ////////////////////////////////////////////////////////////////////////////
 635:      ////////////////////////////////////////////////////////////////////////////
 636:  }