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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Provision

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

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

   1:  using System;
   2:  using System.Data;
   3:  using System.Collections;
   4:  using System.Collections.Generic;
   5:  using System.Linq;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Data
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Provision support class for Next Generation Network (NGN) data model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2019 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 class Provision
  29:      {
  30:          private static int nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex, allPossibleNddOntNotInAgcfGatewayRecordListIndex, allPossibleAgcfGatewayRecordFromWithinOltListIndex, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex, allPossibleAgcfGatewayRecordNoInOntListIndex;
  31:          private static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> allPossibleNddOntNotInAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList;
  32:          private static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> allPossibleAgcfGatewayRecordFromWithinOltList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, allPossibleAgcfGatewayRecordNoInOntList;
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public Provision() { }
  40:   
  41:          ////////////////////////////////////////////////////////////////////////////
  42:   
  43:          /// <summary>
  44:          ///
  45:          /// </summary>
  46:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecord(out string result)
  47:          {
  48:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
  49:   
  50:              if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList == null || nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex == 0)
  51:              {
  52:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecordList();//.Where(u=>u.Access.Name.Contains("SLA")).ToList();
  53:   
  54:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = 0;
  55:              }
  56:   
  57:              if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count > 0)
  58:              {
  59:                  ont = (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont)nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList[nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex];
  60:   
  61:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex);
  62:              }
  63:              else ont = null;
  64:   
  65:              result = "(" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex + "/" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count + ") ";
  66:   
  67:              return ont;
  68:          }
  69:   
  70:          ////////////////////////////////////////////////////////////////////////////
  71:   
  72:          /// <summary>
  73:          ///
  74:          /// </summary>
  75:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpoint(out string result)
  76:          {
  77:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  78:   
  79:              if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList == null || agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex == 0)
  80:              {
  81:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpointList();
  82:   
  83:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = 0;
  84:              }
  85:   
  86:              if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count > 0)
  87:              {
  88:                  agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList[agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex];
  89:   
  90:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex);
  91:              }
  92:              else agcfGatewayRecord = null;
  93:   
  94:              result = "(" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex + "/" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count + ") ";
  95:   
  96:              return agcfGatewayRecord;
  97:          }
  98:   
  99:          ////////////////////////////////////////////////////////////////////////////
 100:   
 101:          /// <summary>
 102:          ///
 103:          /// </summary>
 104:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddOntNotInAgcfGatewayRecordList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt, out string result)
 105:          {
 106:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
 107:   
 108:              if (allPossibleNddOntNotInAgcfGatewayRecordList == null || allPossibleNddOntNotInAgcfGatewayRecordListIndex == 0)
 109:              {
 110:                  allPossibleNddOntNotInAgcfGatewayRecordList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.NddOntNotInAgcfGatewayRecordList(olt);
 111:   
 112:                  allPossibleNddOntNotInAgcfGatewayRecordListIndex = 0;
 113:              }
 114:   
 115:              if (allPossibleNddOntNotInAgcfGatewayRecordList.Count > 0)
 116:              {
 117:                  ont = (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont)allPossibleNddOntNotInAgcfGatewayRecordList[allPossibleNddOntNotInAgcfGatewayRecordListIndex];
 118:   
 119:                  allPossibleNddOntNotInAgcfGatewayRecordListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleNddOntNotInAgcfGatewayRecordList, allPossibleNddOntNotInAgcfGatewayRecordListIndex);
 120:              }
 121:              else ont = null;
 122:   
 123:              result = "(" + allPossibleNddOntNotInAgcfGatewayRecordListIndex + "/" + allPossibleNddOntNotInAgcfGatewayRecordList.Count + ") ";
 124:   
 125:              return ont;
 126:          }
 127:   
 128:          ////////////////////////////////////////////////////////////////////////////
 129:   
 130:          /// <summary>
 131:          ///
 132:          /// </summary>
 133:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordFromWithinOltList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt, out string result)
 134:          {
 135:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
 136:   
 137:              if (allPossibleAgcfGatewayRecordFromWithinOltList == null || allPossibleAgcfGatewayRecordFromWithinOltListIndex == 0)
 138:              {
 139:                  allPossibleAgcfGatewayRecordFromWithinOltList = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.List(olt);
 140:   
 141:                  allPossibleAgcfGatewayRecordFromWithinOltListIndex = 0;
 142:              }
 143:   
 144:              if (allPossibleAgcfGatewayRecordFromWithinOltList.Count > 0)
 145:              {
 146:                  agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordFromWithinOltList[allPossibleAgcfGatewayRecordFromWithinOltListIndex];
 147:   
 148:                  allPossibleAgcfGatewayRecordFromWithinOltListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordFromWithinOltList, allPossibleAgcfGatewayRecordFromWithinOltListIndex);
 149:              }
 150:              else agcfGatewayRecord = null;
 151:   
 152:              result = "(" + allPossibleAgcfGatewayRecordFromWithinOltListIndex + "/" + allPossibleAgcfGatewayRecordFromWithinOltList.Count + ") ";
 153:   
 154:              return agcfGatewayRecord;
 155:          }
 156:   
 157:          ////////////////////////////////////////////////////////////////////////////
 158:   
 159:          /// <summary>
 160:          ///
 161:          /// </summary>
 162:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordNoInOntList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 163:          {
 164:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
 165:   
 166:              if (allPossibleAgcfGatewayRecordNoInOntList == null || allPossibleAgcfGatewayRecordNoInOntListIndex == 0)
 167:              {
 168:                  allPossibleAgcfGatewayRecordNoInOntList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AllPossibleAgcfGatewayRecordsNoInOntsList(olt);
 169:   
 170:                  allPossibleAgcfGatewayRecordNoInOntListIndex = 0;
 171:              }
 172:   
 173:              agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordNoInOntList[allPossibleAgcfGatewayRecordNoInOntListIndex];
 174:   
 175:              allPossibleAgcfGatewayRecordNoInOntListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordNoInOntList, allPossibleAgcfGatewayRecordNoInOntListIndex);
 176:   
 177:              return agcfGatewayRecord;
 178:          }
 179:   
 180:          /*
 181:          ////////////////////////////////////////////////////////////////////////////
 182:  
 183:          /// <summary>
 184:          ///
 185:          /// </summary>
 186:          public static bool UpdateServiceRequestServiceServiceSuspensionWithNonNullAccess(out string result)
 187:          {
 188:              bool toTrue, toFalse;
 189:              StringBuilder sb;
 190:              List<string> srsCurrentList, toTrueList, toFalseList;
 191:  
 192:              toTrue = toFalse = false;
 193:  
 194:              srsCurrentList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceSuspensionIsTrueStringNumberList;
 195:  
 196:              toTrueList = new List<string>(srsCurrentList.Count);
 197:              toFalseList = new List<string>(srsCurrentList.Count);
 198:  
 199:              sb = new StringBuilder(12 * (srsCurrentList.Count));
 200:  
 201:              // below: numbers that should be added to SRS barring
 202:              sb.Append("\r\nNumber(s) to be set in SRS as barred: ");
 203:  
 204:              toTrue = Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toTrueList, true, Guid.Empty);
 205:              sb.Append("\r\nNumber(s) set?: " + toTrue.ToString());
 206:  
 207:              // below: numbres that should be removed from SRS barring
 208:              sb.Append("\r\nNumber(s) to be reset in SRS as not barred: ");
 209:  
 210:              toFalse = Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toFalseList, false, Guid.Empty);
 211:              sb.Append("\r\nNumber(s) reset?: " + toTrue.ToString());
 212:  
 213:              result = sb.ToString();
 214:  
 215:              return toTrue || toFalse;
 216:          }
 217:          */
 218:   
 219:          ////////////////////////////////////////////////////////////////////////////
 220:   
 221:          /// <summary>
 222:          ///
 223:          /// </summary>
 224:          private static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithAccessesWithNullAgcfEndpointList
 225:          {
 226:              get
 227:              {
 228:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 229:   
 230:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 231:                  {
 232:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices
 233:                                                   join e in db.AgcfEndpoints on Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(srs.Service) equals e.PrividUser
 234:                                                   into gj
 235:                                                   from u in gj.DefaultIfEmpty()
 236:                                                   where u == null && srs.Access != null
 237:                                                   select srs).ToList();
 238:                  }
 239:   
 240:                  return serviceRequestServiceList;
 241:              }
 242:          }
 243:   
 244:          ////////////////////////////////////////////////////////////////////////////
 245:   
 246:          /// <summary>
 247:          ///
 248:          /// </summary>
 249:          public static List<string> ServiceSuspensionMismatchBetweenServiceRequestServiceAndServiceServiceIdList()
 250:          {
 251:              string service;
 252:              List<string> serviceIdList;
 253:              List<string> serviceIdPbxList, serviceIdExemptionList;
 254:   
 255:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 256:              {
 257:                  // below:
 258:                  serviceIdList = (from s in db.Service2s
 259:                                   join srs in db.ServiceRequestServices on s.Id equals srs.Id
 260:                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService &&
 261:   
 262:                                   // below: include only allowed domains that are allowed for provisioning
 263:                                   //Ia.Ngn.Cl.Model.Data.Service.ProvisioningEnabledFourDigitNumberDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 264:                                   //&& srs.Provisioned == true
 265:                                   //&&
 266:   
 267:                                   // below: exclude huawei from barring and service suspension operations
 268:                                   !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) &&
 269:                                   (
 270:                                   srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 271:                                   || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 272:                                   || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 273:                                   || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 274:                                   )
 275:                                   select s.Id).ToList();
 276:              }
 277:   
 278:              // Testing
 279:              // exclude all Huawei and MSFT numbers
 280:              foreach (string serviceId in serviceIdList)
 281:              {
 282:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(serviceId);
 283:   
 284:                  if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service)) serviceIdList.Remove(service);
 285:                  else if ("2537".StartsWith(service) || "2538".StartsWith(service)) serviceIdList.Remove(service);
 286:              }
 287:   
 288:              // will exclude exempt numbers
 289:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 290:              foreach (string s in serviceIdExemptionList) serviceIdList.Remove(s);
 291:   
 292:              return serviceIdList;
 293:          }
 294:   
 295:          ////////////////////////////////////////////////////////////////////////////
 296:   
 297:          /// <summary>
 298:          ///
 299:          /// </summary>
 300:          private static Dictionary<string, string> ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(DateTime backDateTime)
 301:          {
 302:              List<string> servicePbxList;
 303:              List<int> allowedOltToBeProvisionedIdList;
 304:              Dictionary<string, string> serviceIdAccessIdDictionary, serviceIdAccessIdWithNonNullAccessDictionary;
 305:   
 306:              allowedOltToBeProvisionedIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedOltIdList;
 307:   
 308:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 309:              {
 310:                  servicePbxList = Ia.Ngn.Cl.Model.Data.Service.ServicePbxList;
 311:   
 312:                  // below: Service different from ServiceRequestService
 313:                  serviceIdAccessIdWithNonNullAccessDictionary = (from s in db.Service2s
 314:                                                                  join srs in db.ServiceRequestServices on s.Id equals srs.Id
 315:                                                                  where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService
 316:                                                                  && srs.Provisioned == true
 317:                                                                  && srs.LastRequestDateTime >= backDateTime
 318:                                                                  && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt)
 319:                                                                  && (s.AbbriviatedCalling != srs.AbbriviatedCalling
 320:                                                                  || s.AlarmCall != srs.AlarmCall
 321:                                                                  || s.WakeupCall != srs.WakeupCall
 322:   
 323:                                                                  // below: exclude huawei from barring and service suspension operations
 324:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 325:                                                                  &&
 326:                                                                  (
 327:                                                                  srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 328:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 329:                                                                  || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 330:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 331:                                                                  )
 332:   
 333:                                                                  || s.CallerId != srs.CallerId
 334:                                                                  || s.CallForwarding != srs.CallForwarding
 335:   
 336:                                                                  // below: exclude PBX numbers from the Call Waiting service requirement
 337:                                                                  || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
 338:   
 339:                                                                  || s.ConferenceCall != srs.ConferenceCall
 340:                                                                  || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
 341:   
 342:                                                                  // below: exclude huawei from international calling
 343:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) && s.InternationalCalling != srs.InternationalCalling
 344:   
 345:                                                                  || s.SpeedDial != srs.SpeedDial
 346:   
 347:                                                                  // below: check for numbers in which srs.Access != s.Access when s.Access != null
 348:                                                                  || (s.Access != null && s.Access.Id != srs.Access.Id)
 349:                                                                  )
 350:                                                                  select new { Id = s.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 351:   
 352:                  serviceIdAccessIdDictionary = serviceIdAccessIdWithNonNullAccessDictionary;
 353:              }
 354:   
 355:              return serviceIdAccessIdDictionary;
 356:          }
 357:   
 358:          ////////////////////////////////////////////////////////////////////////////
 359:   
 360:          /// <summary>
 361:          ///
 362:          /// </summary>
 363:          public static SortedList ProvisionedServiceRequestServiceAndServiceMismatchAccessServiceIdList()
 364:          {
 365:              SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 366:              Dictionary<string, int> srsIdDictionary, sIdDictionary;
 367:   
 368:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 369:              {
 370:                  // below: ServiceRequestService dictionary
 371:                  srsIdDictionary = (from srs in db.ServiceRequestServices
 372:                                     join s in db.Service2s on srs.Id equals s.Id
 373:                                     where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && srs.Provisioned == true && srs.Access != null && s.Access != null && srs.Access.Id != s.Access.Id
 374:                                     select srs.Id).ToDictionary(n => n, n => 1);
 375:   
 376:                  // below: Service dictionary
 377:                  sIdDictionary = (from s in db.Service2s
 378:                                   join srs in db.ServiceRequestServices on s.Id equals srs.Id
 379:                                   where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && srs.Provisioned == true && s.Access != null && srs.Access != null && s.Access.Id != srs.Access.Id
 380:                                   select s.Id).ToDictionary(n => n, n => 1);
 381:              }
 382:   
 383:              serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
 384:   
 385:              foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
 386:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 387:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 388:   
 389:              foreach (KeyValuePair<string, int> kvp in sIdDictionary)
 390:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 391:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 392:   
 393:              return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 394:          }
 395:   
 396:          ////////////////////////////////////////////////////////////////////////////
 397:   
 398:          /// <summary>
 399:          ///
 400:          /// </summary>
 401:          public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(out Dictionary<string, string> serviceToUpdateIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
 402:          {
 403:              ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(0, out serviceToUpdateIdAccessIdDictionary, out serviceToCreateServiceIdAccessIdDictionary, out serviceToDeleteServiceIdAccessIdDictionary);
 404:          }
 405:   
 406:          ////////////////////////////////////////////////////////////////////////////
 407:   
 408:          /// <summary>
 409:          ///
 410:          /// </summary>
 411:          public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(int provisionWithinLastNDays, out Dictionary<string, string> serviceToUpdateIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
 412:          {
 413:              DateTime dateTime;
 414:              List<int> allowedOltToBeProvisionedIdList;
 415:              List<string> serviceIdExemptionList;
 416:              Dictionary<string, string> mismatchIdDictionary, serviceRequestServiceProvisionedIdDictionary, serviceRequestServiceRemovedIdDictionary, serviceIdDictionary;
 417:   
 418:              dateTime = (provisionWithinLastNDays > 0) ? DateTime.UtcNow.AddHours(3).AddDays(-provisionWithinLastNDays) : Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime;
 419:   
 420:              allowedOltToBeProvisionedIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedOltIdList;
 421:   
 422:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 423:              {
 424:                  // below: ServiceRequestService dictionary
 425:                  serviceRequestServiceProvisionedIdDictionary = (from srs in db.ServiceRequestServices
 426:                                                                  where srs.Provisioned == true && srs.LastRequestDateTime >= dateTime
 427:                                                                  && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)
 428:                                                                  select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 429:   
 430:                  serviceRequestServiceRemovedIdDictionary = (from srs in db.ServiceRequestServices
 431:                                                              where srs.Provisioned == false && srs.LastRequestDateTime >= dateTime
 432:                                                              && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)
 433:                                                              select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 434:   
 435:                  // below: Service dictionary
 436:                  serviceIdDictionary = (from s in db.Service2s
 437:                                         where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService && s.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt)
 438:                                         select new { s.Id, AccessId = s.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 439:              }
 440:   
 441:              // services to provision (ServiceRequestService.Provisioned = true and not in Service list)
 442:              serviceToCreateServiceIdAccessIdDictionary = new Dictionary<string, string>(serviceRequestServiceProvisionedIdDictionary.Count);
 443:              foreach (KeyValuePair<string, string> kvp in serviceRequestServiceProvisionedIdDictionary)
 444:              {
 445:                  if (!serviceIdDictionary.ContainsKey(kvp.Key)) serviceToCreateServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 446:              }
 447:   
 448:              // services to remove (Service has equivalent ServiceRequestService.Provisioned = false)
 449:              serviceToDeleteServiceIdAccessIdDictionary = new Dictionary<string, string>(serviceRequestServiceRemovedIdDictionary.Count);
 450:              foreach (KeyValuePair<string, string> kvp in serviceIdDictionary)
 451:              {
 452:                  if (serviceRequestServiceRemovedIdDictionary.ContainsKey(kvp.Key)) serviceToDeleteServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 453:              }
 454:   
 455:   
 456:              mismatchIdDictionary = Ia.Ngn.Cl.Model.Data.Provision.ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(dateTime);
 457:   
 458:              // services to update
 459:              serviceToUpdateIdAccessIdDictionary = new Dictionary<string, string>(mismatchIdDictionary.Count);
 460:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 461:              {
 462:                  serviceToUpdateIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 463:              }
 464:   
 465:              // 3. Update list (order is important behind create and delete lists)
 466:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 467:              {
 468:                  // I will exclude all numbers from complementary list that are in either serviceToProvision list or serviceToRemove list
 469:                  if (serviceToCreateServiceIdAccessIdDictionary.ContainsKey(kvp.Key) || serviceToDeleteServiceIdAccessIdDictionary.ContainsKey(kvp.Key))
 470:                  {
 471:                      serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 472:                  }
 473:              }
 474:   
 475:   
 476:              // will exclude exempt numbers
 477:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 478:              foreach (string s in serviceIdExemptionList)
 479:              {
 480:                  serviceToUpdateIdAccessIdDictionary.Remove(s);
 481:                  serviceToCreateServiceIdAccessIdDictionary.Remove(s);
 482:                  serviceToDeleteServiceIdAccessIdDictionary.Remove(s);
 483:              }
 484:          }
 485:   
 486:          ////////////////////////////////////////////////////////////////////////////
 487:   
 488:          /// <summary>
 489:          /// List of exempt number ids
 490:          /// </summary>
 491:          public static List<string> ServiceIdOfServiceExemptFromProvisionProcessingList()
 492:          {
 493:              List<string> list;
 494:   
 495:              list = new List<string>();
 496:   
 497:              foreach (string u in Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceIdList) list.Add(u);
 498:   
 499:              return list;
 500:          }
 501:   
 502:          ////////////////////////////////////////////////////////////////////////////
 503:   
 504:          /// <summary>
 505:          /// List of exempt services
 506:          /// </summary>
 507:          public static List<string> ServiceOfServiceExemptFromProvisionProcessingList()
 508:          {
 509:              List<string> list;
 510:   
 511:              list = new List<string>();
 512:   
 513:              foreach (string u in Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceList) list.Add(u);
 514:   
 515:              return list;
 516:          }
 517:   
 518:          ////////////////////////////////////////////////////////////////////////////
 519:          ////////////////////////////////////////////////////////////////////////////    
 520:      }
 521:   
 522:      ////////////////////////////////////////////////////////////////////////////
 523:      ////////////////////////////////////////////////////////////////////////////   
 524:  }