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

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-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 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
 261:                                                  // below: include only allowed domains that are allowed for provisioning
 262:                                                  //Ia.Ngn.Cl.Model.Data.Service.ProvisioningEnabledFourDigitNumberDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 263:                                                  //&& srs.Provisioned == true
 264:                                                  //&&
 265:   
 266:                                                  // below: exclude huawei from barring and service suspension operations
 267:                                                  !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 268:   
 269:                                                  &&
 270:                                   (
 271:                                   srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 272:                                   || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 273:                                   || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 274:                                   || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 275:                                   )
 276:                                   select s.Id).ToList();
 277:              }
 278:   
 279:   
 280:              // Testing
 281:              // exclude all Huawei and MSFT numbers
 282:              foreach (string serviceId in serviceIdList)
 283:              {
 284:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(serviceId);
 285:   
 286:                  if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service)) serviceIdList.Remove(service);
 287:                  else if ("2537".StartsWith(service) || "2538".StartsWith(service)) serviceIdList.Remove(service);
 288:              }
 289:   
 290:              // will exclude exempt numbers
 291:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 292:              foreach (string s in serviceIdExemptionList) serviceIdList.Remove(s);
 293:   
 294:              return serviceIdList;
 295:          }
 296:   
 297:          ////////////////////////////////////////////////////////////////////////////
 298:   
 299:          /// <summary>
 300:          ///
 301:          /// </summary>
 302:          private static Dictionary<string, string> ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(DateTime backDateTime)
 303:          {
 304:              List<string> servicePbxList;
 305:              List<int> allowedOltToBeProvisionedIdList;
 306:              Dictionary<string, string> serviceIdAccessIdDictionary, serviceIdAccessIdWithNonNullAccessDictionary, serviceIdWithNullAccessDictionary;
 307:   
 308:              allowedOltToBeProvisionedIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedOltToBeProvisionedIdList;
 309:   
 310:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 311:              {
 312:                  servicePbxList = Ia.Ngn.Cl.Model.Data.Service.ServicePbxList;
 313:   
 314:                  // below: Service different from ServiceRequestService
 315:                  serviceIdAccessIdWithNonNullAccessDictionary = (from s in db.Service2s
 316:                                                                  join srs in db.ServiceRequestServices on s.Id equals srs.Id
 317:                                                                  where
 318:                                                                  srs.Provisioned == true
 319:                                                                  && srs.LastRequestDateTime > backDateTime
 320:                                                                  && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt)
 321:                                                                  && (s.AbbriviatedCalling != srs.AbbriviatedCalling
 322:                                                                  || s.AlarmCall != srs.AlarmCall
 323:                                                                  || s.WakeupCall != srs.WakeupCall
 324:   
 325:                                                                  // below: exclude huawei from barring and service suspension operations
 326:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 327:                                                                  &&
 328:                                                                  (
 329:                                                                  srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 330:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 331:                                                                  || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 332:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 333:                                                                  )
 334:   
 335:                                                                  || s.CallerId != srs.CallerId
 336:                                                                  || s.CallForwarding != srs.CallForwarding
 337:   
 338:                                                                  // below: exclude PBX numbers from the Call Waiting service requirement
 339:                                                                  || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
 340:   
 341:                                                                  || s.ConferenceCall != srs.ConferenceCall
 342:                                                                  || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
 343:   
 344:                                                                  // below: exclude huawei from international calling
 345:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) && s.InternationalCalling != srs.InternationalCalling
 346:   
 347:                                                                  || s.SpeedDial != srs.SpeedDial
 348:                                                                  )
 349:                                                                  select new { Id = s.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 350:                  /*
 351:                  serviceIdWithNullAccessDictionary = (from s in db.Service2s // remove?
 352:                                                       join srs in db.ServiceRequestServices on s.Id equals srs.Id
 353:                                                       where
 354:                                                       srs.Provisioned == true
 355:                                                       && srs.LastRequestDateTime > backDateTime
 356:                                                       && srs.Access == null
 357:                                                       &&
 358:                                                       (s.AbbriviatedCalling != srs.AbbriviatedCalling
 359:                                                       || s.AlarmCall != srs.AlarmCall
 360:                                                       || s.WakeupCall != srs.WakeupCall
 361:  
 362:                                                       // below: exclude huawei from barring and service suspension operations
 363:                                                       || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 364:                                                       &&
 365:                                                       (
 366:                                                       srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 367:                                                       || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 368:                                                       || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 369:                                                       || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 370:                                                       )
 371:  
 372:                                                       || s.CallerId != srs.CallerId
 373:                                                       || s.CallForwarding != srs.CallForwarding
 374:  
 375:                                                       // below: exclude PBX numbers from the Call Waiting service requirement
 376:                                                       || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
 377:  
 378:                                                       || s.ConferenceCall != srs.ConferenceCall
 379:                                                       || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
 380:  
 381:                                                       // below: exclude huawei from international calling
 382:                                                       || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) && s.InternationalCalling != srs.InternationalCalling
 383:  
 384:                                                       || s.SpeedDial != srs.SpeedDial
 385:                                                       )
 386:                                                       select s.Id).ToDictionary(n => n, n => (string)null);
 387:                                                       */
 388:   
 389:                  serviceIdAccessIdDictionary = serviceIdAccessIdWithNonNullAccessDictionary;//.Union(serviceIdWithNullAccessDictionary).ToDictionary(k => k.Key, v => v.Value);
 390:              }
 391:   
 392:              return serviceIdAccessIdDictionary;
 393:          }
 394:   
 395:          ////////////////////////////////////////////////////////////////////////////
 396:   
 397:          /// <summary>
 398:          ///
 399:          /// </summary>
 400:          public static SortedList ProvisionedServiceRequestServiceAndServiceMismatchAccessServiceIdList()
 401:          {
 402:              SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 403:              Dictionary<string, int> srsIdDictionary, sIdDictionary;
 404:   
 405:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 406:              {
 407:                  // below: ServiceRequestService dictionary
 408:                  srsIdDictionary = (from srs in db.ServiceRequestServices join s in db.Service2s on srs.Id equals s.Id where srs.Provisioned == true && srs.Access != null && s.Access != null && srs.Access.Id != s.Access.Id select srs.Id).ToDictionary(n => n, n => 1);
 409:   
 410:                  // below: Service dictionary
 411:                  sIdDictionary = (from s in db.Service2s join srs in db.ServiceRequestServices on s.Id equals srs.Id where srs.Provisioned == true && s.Access != null && srs.Access != null && s.Access.Id != srs.Access.Id select s.Id).ToDictionary(n => n, n => 1);
 412:              }
 413:   
 414:              serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
 415:   
 416:              foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
 417:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 418:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 419:   
 420:              foreach (KeyValuePair<string, int> kvp in sIdDictionary)
 421:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 422:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 423:   
 424:              return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 425:          }
 426:   
 427:          ////////////////////////////////////////////////////////////////////////////
 428:   
 429:          /// <summary>
 430:          ///
 431:          /// </summary>
 432:          public static SortedList ServiceRequestServiceAndServiceMismatchAccessServiceIdList(List<string> testServicePrefixList)
 433:          {
 434:              SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 435:              Dictionary<string, int> srsIdDictionary, sIdDictionary;
 436:   
 437:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 438:              {
 439:                  // below: ServiceRequestService dictionary
 440:                  srsIdDictionary = (from srs in db.ServiceRequestServices join s in db.Service2s on srs.Id equals s.Id where testServicePrefixList.Any(u => srs.Service.StartsWith(u)) && srs.Access != null && s.Access != null && srs.Access.Id != s.Access.Id select srs.Id).ToDictionary(n => n, n => 1);
 441:   
 442:                  // below: Service dictionary
 443:                  sIdDictionary = (from s in db.Service2s join srs in db.ServiceRequestServices on s.Id equals srs.Id where testServicePrefixList.Any(u => s.Service.StartsWith(u)) && s.Access != null && srs.Access != null && s.Access.Id != srs.Access.Id select s.Id).ToDictionary(n => n, n => 1);
 444:              }
 445:   
 446:              serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
 447:   
 448:              foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
 449:              {
 450:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key)) serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 451:              }
 452:   
 453:              foreach (KeyValuePair<string, int> kvp in sIdDictionary)
 454:              {
 455:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key)) serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 456:              }
 457:   
 458:              return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 459:          }
 460:   
 461:          ////////////////////////////////////////////////////////////////////////////
 462:   
 463:          /// <summary>
 464:          ///
 465:          /// </summary>
 466:          public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(out Dictionary<string, string> serviceToUpdateIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
 467:          {
 468:              ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(false, Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime, Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime, out serviceToUpdateIdAccessIdDictionary, out serviceToCreateServiceIdAccessIdDictionary, out serviceToDeleteServiceIdAccessIdDictionary);
 469:          }
 470:   
 471:          ////////////////////////////////////////////////////////////////////////////
 472:   
 473:          /// <summary>
 474:          ///
 475:          /// </summary>
 476:          public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(bool isTest, DateTime serviceDeleteAfterDateTime, DateTime serviceDeleteBeforeDateTime, out Dictionary<string, string> serviceToUpdateIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
 477:          {
 478:              string service, serviceId, areaSymbol;
 479:              List<int> allowedOltToBeProvisionedIdList;
 480:              List<string> serviceIdExemptionList;
 481:              Dictionary<string, string> dictionary, nullDictionary, mismatchIdDictionary, srsProvisionedIdDictionary, srsRemovedIdDictionary, sIdDictionary, accessIdToKuwaitNgnAreaSymbolDictionary;
 482:   
 483:              allowedOltToBeProvisionedIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedOltToBeProvisionedIdList;
 484:   
 485:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 486:              {
 487:                  // below: ServiceRequestService dictionary
 488:                  dictionary = (from srs in db.ServiceRequestServices
 489:                                where srs.Provisioned == true && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime
 490:                                && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)
 491:                                select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 492:                  /*
 493:                  nullDictionary = (from srs in db.ServiceRequestServices
 494:                                    where srs.Provisioned == true && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime 
 495:                                    && srs.Access == null
 496:                                    select srs.Id).ToDictionary(n => n, n => (string)null);
 497:                                    */
 498:   
 499:                  srsProvisionedIdDictionary = dictionary;//.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 500:   
 501:   
 502:                  dictionary = (from srs in db.ServiceRequestServices
 503:                                where srs.Provisioned == false && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime && (srs.LastRequestDateTime >= serviceDeleteAfterDateTime || srs.LastRequestDateTime < serviceDeleteBeforeDateTime)
 504:                                && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)
 505:                                select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 506:                  /*
 507:                  nullDictionary = (from srs in db.ServiceRequestServices
 508:                                    where srs.Provisioned == false && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime && (srs.LastRequestDateTime >= serviceDeleteAfterDateTime || srs.LastRequestDateTime < serviceDeleteBeforeDateTime) 
 509:                                    && srs.Access == null
 510:                                    select srs.Id).ToDictionary(n => n, n => (string)null);
 511:                                    */
 512:   
 513:                  srsRemovedIdDictionary = dictionary;//.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 514:   
 515:   
 516:                  // below: Service dictionary
 517:                  dictionary = (from s in db.Service2s
 518:                                where s.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt)
 519:                                select new { s.Id, AccessId = s.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 520:   
 521:                  /*
 522:                  nullDictionary = (from s in db.Service2s
 523:                                    where s.Access == null
 524:                                    select s.Id).ToDictionary(n => n, n => (string)null);
 525:                                    */
 526:   
 527:                  sIdDictionary = dictionary;//.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 528:              }
 529:   
 530:              // services to provision (ServiceRequestService.Provisioned = true and not in Service list)
 531:              serviceToCreateServiceIdAccessIdDictionary = new Dictionary<string, string>(srsProvisionedIdDictionary.Count);
 532:              foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 533:              {
 534:                  if (!sIdDictionary.ContainsKey(kvp.Key)) serviceToCreateServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 535:              }
 536:   
 537:              // services to remove (Service has equivalent ServiceRequestService.Provisioned = false)
 538:              serviceToDeleteServiceIdAccessIdDictionary = new Dictionary<string, string>(srsRemovedIdDictionary.Count);
 539:              foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 540:              {
 541:                  if (srsRemovedIdDictionary.ContainsKey(kvp.Key)) serviceToDeleteServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 542:              }
 543:   
 544:   
 545:              mismatchIdDictionary = Ia.Ngn.Cl.Model.Data.Provision.ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(Ia.Ngn.Cl.Model.Business.Administration.EarliestRequestDateTime); // backDateTime);
 546:   
 547:              // services to update
 548:              serviceToUpdateIdAccessIdDictionary = new Dictionary<string, string>(mismatchIdDictionary.Count);
 549:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 550:              {
 551:                  serviceToUpdateIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 552:              }
 553:   
 554:   
 555:              //accessIdToKuwaitNgnAreaSymbolDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaSymbolDictionary;
 556:   
 557:              /*
 558:              // REMOVE EVERYTHING BELOW
 559:              // 1. Create list
 560:              foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 561:              {
 562:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 563:  
 564:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 565:  
 566:                  if (!Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAnAllowedOltToBeProvisionedDomainList(service) || !Ia.Ngn.Cl.Model.Business.Service.AreaSymbolIsWithinAnAllowedOltToBeProvisionedDomainList(areaSymbol))
 567:                  {
 568:                      serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 569:                  }
 570:              }
 571:              */
 572:   
 573:              /*
 574:              // REMOVE EVERYTHING BELOW
 575:              // 2. Delete list
 576:              foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 577:              {
 578:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 579:  
 580:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 581:  
 582:                  if (!Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAnAllowedOltToBeProvisionedDomainList(service) || !Ia.Ngn.Cl.Model.Business.Service.AreaSymbolIsWithinAnAllowedOltToBeProvisionedDomainList(areaSymbol))
 583:                  {
 584:                      serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 585:                  }
 586:              }
 587:              */
 588:   
 589:              // CHECK THEN REMOVE EVERYTHING BELOW
 590:              // 3. Update list (order is important behind create and delete lists)
 591:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 592:              {
 593:                  //service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 594:   
 595:                  /*
 596:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 597:  
 598:                  if (!Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAnAllowedOltToBeProvisionedDomainList(service) || !Ia.Ngn.Cl.Model.Business.Service.AreaSymbolIsWithinAnAllowedOltToBeProvisionedDomainList(areaSymbol))
 599:                  {
 600:                      serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 601:                  }
 602:                  else
 603:                  {
 604:                  */
 605:                  // KEEP
 606:                  // I will exclude all numbers from complementary list that are in either serviceToProvision list or serviceToRemove list
 607:                  if (serviceToCreateServiceIdAccessIdDictionary.ContainsKey(kvp.Key) || serviceToDeleteServiceIdAccessIdDictionary.ContainsKey(kvp.Key))
 608:                  {
 609:                      serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 610:                  }
 611:                  //}
 612:              }
 613:   
 614:   
 615:              /*
 616:              // REMOVE EVERYTHING BELOW
 617:              // Testing:
 618:              if (isTest)
 619:              {
 620:                  // If isTest is true we will exclude all numbers not within MSFT
 621:  
 622:                  foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 623:                  {
 624:                      serviceId = kvp.Key;
 625:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 626:  
 627:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 628:  
 629:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 630:                          serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 631:                  }
 632:  
 633:                  foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 634:                  {
 635:                      serviceId = kvp.Key;
 636:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 637:  
 638:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 639:  
 640:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 641:                          serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 642:                  }
 643:  
 644:                  foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 645:                  {
 646:                      serviceId = kvp.Key;
 647:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 648:  
 649:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 650:  
 651:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 652:                          serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 653:                  }
 654:              }
 655:              else
 656:              {
 657:                  // If isTest is false we will exclude all MSFT numbers
 658:  
 659:                  foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 660:                  {
 661:                      serviceId = kvp.Key;
 662:  
 663:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 664:                  }
 665:  
 666:                  foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 667:                  {
 668:                      serviceId = kvp.Key;
 669:  
 670:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 671:                  }
 672:  
 673:                  foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 674:                  {
 675:                      serviceId = kvp.Key;
 676:  
 677:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 678:                  }
 679:              }
 680:              */
 681:   
 682:              // will exclude exempt numbers
 683:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 684:              foreach (string s in serviceIdExemptionList)
 685:              {
 686:                  serviceToUpdateIdAccessIdDictionary.Remove(s);
 687:                  serviceToCreateServiceIdAccessIdDictionary.Remove(s);
 688:                  serviceToDeleteServiceIdAccessIdDictionary.Remove(s);
 689:              }
 690:          }
 691:   
 692:          ////////////////////////////////////////////////////////////////////////////
 693:   
 694:          /// <summary>
 695:          /// List of exempt number ids
 696:          /// </summary>
 697:          public static List<string> ServiceIdOfServiceExemptFromProvisionProcessingList()
 698:          {
 699:              List<string> list;
 700:   
 701:              list = new List<string>();
 702:   
 703:              foreach (string u in Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceIdList) list.Add(u);
 704:   
 705:              return list;
 706:          }
 707:   
 708:          ////////////////////////////////////////////////////////////////////////////
 709:          ////////////////////////////////////////////////////////////////////////////    
 710:      }
 711:   
 712:      ////////////////////////////////////////////////////////////////////////////
 713:      ////////////////////////////////////////////////////////////////////////////   
 714:  }