Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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.Web;
   3:  using System.Xml;
   4:  using System.Xml.Linq;
   5:  using System.IO;
   6:  using System.Configuration;
   7:  using System.Text;
   8:  using System.Text.RegularExpressions;
   9:  using System.Data;
  10:  using System.Data.SqlClient;
  11:  using System.Web.UI;
  12:  using System.Web.UI.WebControls;
  13:  using System.Collections;
  14:  using System.Collections.Generic;
  15:  using System.Linq;
  16:  using System.Reflection;
  17:   
  18:  namespace Ia.Ngn.Cl.Model.Data
  19:  {
  20:      ////////////////////////////////////////////////////////////////////////////
  21:   
  22:      /// <summary publish="true">
  23:      /// Provision support class for Next Generation Network (NGN) data model.
  24:      /// </summary>
  25:      /// 
  26:      /// <remarks> 
  27:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  28:      ///
  29:      /// 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
  30:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  31:      ///
  32:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  33:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  34:      /// 
  35:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  36:      /// 
  37:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  38:      /// </remarks> 
  39:      public class Provision
  40:      {
  41:          private static int nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex, allPossibleNddOntNotInAgcfGatewayRecordListIndex, allPossibleAgcfGatewayRecordFromWithinOltListIndex, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex, allPossibleAgcfGatewayRecordNoInOntListIndex;
  42:          private static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> allPossibleNddOntNotInAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList;
  43:          private static List<Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord> allPossibleAgcfGatewayRecordFromWithinOltList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, allPossibleAgcfGatewayRecordNoInOntList;
  44:   
  45:          ////////////////////////////////////////////////////////////////////////////
  46:   
  47:          /// <summary>
  48:          ///
  49:          /// </summary>
  50:          public Provision() { }
  51:   
  52:          ////////////////////////////////////////////////////////////////////////////
  53:   
  54:          /// <summary>
  55:          ///
  56:          /// </summary>
  57:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecord(out string result)
  58:          {
  59:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
  60:   
  61:              if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList == null || nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex == 0)
  62:              {
  63:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecordList();//.Where(u=>u.Access.Name.Contains("SLA")).ToList();
  64:   
  65:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = 0;
  66:              }
  67:   
  68:              if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count > 0)
  69:              {
  70:                  ont = (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont)nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList[nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex];
  71:   
  72:                  nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex);
  73:              }
  74:              else ont = null;
  75:   
  76:              result = "(" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex + "/" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count + ") ";
  77:   
  78:              return ont;
  79:          }
  80:   
  81:          ////////////////////////////////////////////////////////////////////////////
  82:   
  83:          /// <summary>
  84:          ///
  85:          /// </summary>
  86:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpoint(out string result)
  87:          {
  88:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  89:   
  90:              if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList == null || agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex == 0)
  91:              {
  92:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpointList();
  93:   
  94:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = 0;
  95:              }
  96:   
  97:              if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count > 0)
  98:              {
  99:                  agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList[agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex];
 100:   
 101:                  agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex);
 102:              }
 103:              else agcfGatewayRecord = null;
 104:   
 105:              result = "(" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex + "/" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count + ") ";
 106:   
 107:              return agcfGatewayRecord;
 108:          }
 109:   
 110:          ////////////////////////////////////////////////////////////////////////////
 111:   
 112:          /// <summary>
 113:          ///
 114:          /// </summary>
 115:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddOntNotInAgcfGatewayRecordList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt, out string result)
 116:          {
 117:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
 118:   
 119:              if (allPossibleNddOntNotInAgcfGatewayRecordList == null || allPossibleNddOntNotInAgcfGatewayRecordListIndex == 0)
 120:              {
 121:                  allPossibleNddOntNotInAgcfGatewayRecordList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.NddOntNotInAgcfGatewayRecordList(olt);
 122:   
 123:                  allPossibleNddOntNotInAgcfGatewayRecordListIndex = 0;
 124:              }
 125:   
 126:              if (allPossibleNddOntNotInAgcfGatewayRecordList.Count > 0)
 127:              {
 128:                  ont = (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont)allPossibleNddOntNotInAgcfGatewayRecordList[allPossibleNddOntNotInAgcfGatewayRecordListIndex];
 129:   
 130:                  allPossibleNddOntNotInAgcfGatewayRecordListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleNddOntNotInAgcfGatewayRecordList, allPossibleNddOntNotInAgcfGatewayRecordListIndex);
 131:              }
 132:              else ont = null;
 133:   
 134:              result = "(" + allPossibleNddOntNotInAgcfGatewayRecordListIndex + "/" + allPossibleNddOntNotInAgcfGatewayRecordList.Count + ") ";
 135:   
 136:              return ont;
 137:          }
 138:   
 139:          ////////////////////////////////////////////////////////////////////////////
 140:   
 141:          /// <summary>
 142:          ///
 143:          /// </summary>
 144:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordFromWithinOltList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt, out string result)
 145:          {
 146:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
 147:   
 148:              if (allPossibleAgcfGatewayRecordFromWithinOltList == null || allPossibleAgcfGatewayRecordFromWithinOltListIndex == 0)
 149:              {
 150:                  allPossibleAgcfGatewayRecordFromWithinOltList = Ia.Ngn.Cl.Model.Data.Nokia.AgcfGatewayRecord.List(olt);
 151:   
 152:                  allPossibleAgcfGatewayRecordFromWithinOltListIndex = 0;
 153:              }
 154:   
 155:              if (allPossibleAgcfGatewayRecordFromWithinOltList.Count > 0)
 156:              {
 157:                  agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordFromWithinOltList[allPossibleAgcfGatewayRecordFromWithinOltListIndex];
 158:   
 159:                  allPossibleAgcfGatewayRecordFromWithinOltListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordFromWithinOltList, allPossibleAgcfGatewayRecordFromWithinOltListIndex);
 160:              }
 161:              else agcfGatewayRecord = null;
 162:   
 163:              result = "(" + allPossibleAgcfGatewayRecordFromWithinOltListIndex + "/" + allPossibleAgcfGatewayRecordFromWithinOltList.Count + ") ";
 164:   
 165:              return agcfGatewayRecord;
 166:          }
 167:   
 168:          ////////////////////////////////////////////////////////////////////////////
 169:   
 170:          /// <summary>
 171:          ///
 172:          /// </summary>
 173:          public static Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord AgcfGatewayRecordNoInOntList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 174:          {
 175:              Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord agcfGatewayRecord;
 176:   
 177:              if (allPossibleAgcfGatewayRecordNoInOntList == null || allPossibleAgcfGatewayRecordNoInOntListIndex == 0)
 178:              {
 179:                  allPossibleAgcfGatewayRecordNoInOntList = Ia.Ngn.Cl.Model.Data.Nokia.Ims.AllPossibleAgcfGatewayRecordsNoInOntsList(olt);
 180:   
 181:                  allPossibleAgcfGatewayRecordNoInOntListIndex = 0;
 182:              }
 183:   
 184:              agcfGatewayRecord = (Ia.Ngn.Cl.Model.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordNoInOntList[allPossibleAgcfGatewayRecordNoInOntListIndex];
 185:   
 186:              allPossibleAgcfGatewayRecordNoInOntListIndex = Ia.Cl.Model.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordNoInOntList, allPossibleAgcfGatewayRecordNoInOntListIndex);
 187:   
 188:              return agcfGatewayRecord;
 189:          }
 190:   
 191:          /*
 192:          ////////////////////////////////////////////////////////////////////////////
 193:  
 194:          /// <summary>
 195:          ///
 196:          /// </summary>
 197:          public static bool UpdateServiceRequestServiceServiceSuspensionWithNonNullAccess(out string result)
 198:          {
 199:              bool toTrue, toFalse;
 200:              StringBuilder sb;
 201:              List<string> srsCurrentList, toTrueList, toFalseList;
 202:  
 203:              toTrue = toFalse = false;
 204:  
 205:              srsCurrentList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceSuspensionIsTrueStringNumberList;
 206:  
 207:              toTrueList = new List<string>(srsCurrentList.Count);
 208:              toFalseList = new List<string>(srsCurrentList.Count);
 209:  
 210:              sb = new StringBuilder(12 * (srsCurrentList.Count));
 211:  
 212:              // below: numbers that should be added to SRS barring
 213:              sb.Append("\r\nNumber(s) to be set in SRS as barred: ");
 214:  
 215:              toTrue = Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toTrueList, true, Guid.Empty);
 216:              sb.Append("\r\nNumber(s) set?: " + toTrue.ToString());
 217:  
 218:              // below: numbres that should be removed from SRS barring
 219:              sb.Append("\r\nNumber(s) to be reset in SRS as not barred: ");
 220:  
 221:              toFalse = Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toFalseList, false, Guid.Empty);
 222:              sb.Append("\r\nNumber(s) reset?: " + toTrue.ToString());
 223:  
 224:              result = sb.ToString();
 225:  
 226:              return toTrue || toFalse;
 227:          }
 228:          */
 229:   
 230:          ////////////////////////////////////////////////////////////////////////////
 231:   
 232:          /// <summary>
 233:          ///
 234:          /// </summary>
 235:          private static List<Ia.Ngn.Cl.Model.ServiceRequestService> ServiceRequestServiceWithAccessesWithNullAgcfEndpointList
 236:          {
 237:              get
 238:              {
 239:                  List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 240:   
 241:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 242:                  {
 243:                      serviceRequestServiceList = (from srs in db.ServiceRequestServices
 244:                                                   join e in db.AgcfEndpoints on Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(srs.Service) equals e.PrividUser
 245:                                                   into gj
 246:                                                   from u in gj.DefaultIfEmpty()
 247:                                                   where u == null && srs.Access != null
 248:                                                   select srs).ToList();
 249:                  }
 250:   
 251:                  return serviceRequestServiceList;
 252:              }
 253:          }
 254:   
 255:          ////////////////////////////////////////////////////////////////////////////
 256:   
 257:          /// <summary>
 258:          ///
 259:          /// </summary>
 260:          public static List<string> ServiceSuspensionMismatchBetweenServiceRequestServiceAndServiceServiceIdList()
 261:          {
 262:              string service;
 263:              List<string> serviceIdList;
 264:              List<string> serviceIdPbxList, serviceIdExemptionList;
 265:   
 266:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 267:              {
 268:                  // below:
 269:                  serviceIdList = (from s in db.Service2s
 270:                                   join srs in db.ServiceRequestServices on s.Id equals srs.Id
 271:                                   where
 272:                                                  // below: include only allowed domains that are allowed for provisioning
 273:                                                  //Ia.Ngn.Cl.Model.Data.Service.ProvisioningEnabledFourDigitNumberDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 274:                                                  //&& srs.Provisioned == true
 275:                                                  //&&
 276:   
 277:                                                  // below: exclude huawei from barring and service suspension operations
 278:                                                  !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 279:   
 280:                                                  &&
 281:                                   (
 282:                                   srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 283:                                   || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 284:                                   || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 285:                                   || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 286:                                   )
 287:                                   select s.Id).ToList();
 288:              }
 289:   
 290:   
 291:              // Testing
 292:              // exclude all Huawei and MSFT numbers
 293:              foreach (string serviceId in serviceIdList)
 294:              {
 295:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(serviceId);
 296:   
 297:                  if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service)) serviceIdList.Remove(service);
 298:                  else if ("2537".StartsWith(service) || "2538".StartsWith(service)) serviceIdList.Remove(service);
 299:              }
 300:   
 301:              // will exclude exempt numbers
 302:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 303:              foreach (string s in serviceIdExemptionList) serviceIdList.Remove(s);
 304:   
 305:              return serviceIdList;
 306:          }
 307:   
 308:          ////////////////////////////////////////////////////////////////////////////
 309:   
 310:          /// <summary>
 311:          ///
 312:          /// </summary>
 313:          private static Dictionary<string, string> ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(DateTime backDateTime)
 314:          {
 315:              List<string> servicePbxList;
 316:              Dictionary<string, string> serviceIdAccessIdDictionary, serviceIdAccessIdWithNonNullAccessDictionary, serviceIdWithNullAccessDictionary;
 317:   
 318:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 319:              {
 320:                  servicePbxList = Ia.Ngn.Cl.Model.Data.Service.ServicePbxList;
 321:   
 322:                  // below: Service different from ServiceRequestService
 323:                  serviceIdAccessIdWithNonNullAccessDictionary = (from s in db.Service2s
 324:                                                                  join srs in db.ServiceRequestServices on s.Id equals srs.Id
 325:                                                                  where
 326:                                                                  srs.Provisioned == true
 327:                                                                  && srs.LastRequestDateTime > backDateTime
 328:                                                                  && srs.Access != null
 329:                                                                  &&
 330:                                                                  (s.AbbriviatedCalling != srs.AbbriviatedCalling
 331:                                                                  || s.AlarmCall != srs.AlarmCall
 332:                                                                  || s.WakeupCall != srs.WakeupCall
 333:   
 334:                                                                  // below: exclude huawei from barring and service suspension operations
 335:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 336:                                                                  &&
 337:                                                                  (
 338:                                                                  srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 339:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 340:                                                                  || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 341:                                                                  || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 342:                                                                  )
 343:   
 344:                                                                  || s.CallerId != srs.CallerId
 345:                                                                  || s.CallForwarding != srs.CallForwarding
 346:   
 347:                                                                  // below: exclude PBX numbers from the Call Waiting service requirement
 348:                                                                  || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
 349:   
 350:                                                                  || s.ConferenceCall != srs.ConferenceCall
 351:                                                                  || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
 352:   
 353:                                                                  // below: exclude huawei from international calling
 354:                                                                  || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) && s.InternationalCalling != srs.InternationalCalling
 355:   
 356:                                                                  || s.SpeedDial != srs.SpeedDial
 357:                                                                  )
 358:                                                                  select new { Id = s.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 359:   
 360:                  serviceIdWithNullAccessDictionary = (from s in db.Service2s
 361:                                                       join srs in db.ServiceRequestServices on s.Id equals srs.Id
 362:                                                       where
 363:                                                       srs.Provisioned == true
 364:                                                       && srs.LastRequestDateTime > backDateTime
 365:                                                       && srs.Access == null
 366:                                                       &&
 367:                                                       (s.AbbriviatedCalling != srs.AbbriviatedCalling
 368:                                                       || s.AlarmCall != srs.AlarmCall
 369:                                                       || s.WakeupCall != srs.WakeupCall
 370:   
 371:                                                       // below: exclude huawei from barring and service suspension operations
 372:                                                       || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 373:                                                       &&
 374:                                                       (
 375:                                                       srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
 376:                                                       || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
 377:                                                       || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
 378:                                                       || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
 379:                                                       )
 380:   
 381:                                                       || s.CallerId != srs.CallerId
 382:                                                       || s.CallForwarding != srs.CallForwarding
 383:   
 384:                                                       // below: exclude PBX numbers from the Call Waiting service requirement
 385:                                                       || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
 386:   
 387:                                                       || s.ConferenceCall != srs.ConferenceCall
 388:                                                       || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
 389:   
 390:                                                       // below: exclude huawei from international calling
 391:                                                       || !Ia.Ngn.Cl.Model.Data.Service.HuaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString())) && s.InternationalCalling != srs.InternationalCalling
 392:   
 393:                                                       || s.SpeedDial != srs.SpeedDial
 394:                                                       )
 395:                                                       select s.Id).ToDictionary(n => n, n => (string)null);
 396:   
 397:                  serviceIdAccessIdDictionary = serviceIdAccessIdWithNonNullAccessDictionary.Union(serviceIdWithNullAccessDictionary).ToDictionary(k => k.Key, v => v.Value);
 398:              }
 399:   
 400:              return serviceIdAccessIdDictionary;
 401:          }
 402:   
 403:          ////////////////////////////////////////////////////////////////////////////
 404:   
 405:          /// <summary>
 406:          ///
 407:          /// </summary>
 408:          public static SortedList ProvisionedServiceRequestServiceAndServiceMismatchAccessServiceIdList()
 409:          {
 410:              SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 411:              Dictionary<string, int> srsIdDictionary, sIdDictionary;
 412:   
 413:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 414:              {
 415:                  // below: ServiceRequestService dictionary
 416:                  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);
 417:   
 418:                  // below: Service dictionary
 419:                  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);
 420:              }
 421:   
 422:              serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
 423:   
 424:              foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
 425:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 426:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 427:   
 428:              foreach (KeyValuePair<string, int> kvp in sIdDictionary)
 429:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
 430:                      serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 431:   
 432:              return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 433:          }
 434:   
 435:          ////////////////////////////////////////////////////////////////////////////
 436:   
 437:          /// <summary>
 438:          ///
 439:          /// </summary>
 440:          public static SortedList ServiceRequestServiceAndServiceMismatchAccessServiceIdList(List<string> testServicePrefixList)
 441:          {
 442:              SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 443:              Dictionary<string, int> srsIdDictionary, sIdDictionary;
 444:   
 445:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 446:              {
 447:                  // below: ServiceRequestService dictionary
 448:                  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);
 449:   
 450:                  // below: Service dictionary
 451:                  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);
 452:              }
 453:   
 454:              serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
 455:   
 456:              foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
 457:              {
 458:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key)) serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 459:              }
 460:   
 461:              foreach (KeyValuePair<string, int> kvp in sIdDictionary)
 462:              {
 463:                  if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key)) serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
 464:              }
 465:   
 466:              return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
 467:          }
 468:   
 469:          ////////////////////////////////////////////////////////////////////////////
 470:   
 471:          /// <summary>
 472:          ///
 473:          /// </summary>
 474:          public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(out Dictionary<string, string> serviceToUpdateIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
 475:          {
 476:              ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(false, Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime, Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime, out serviceToUpdateIdAccessIdDictionary, out serviceToCreateServiceIdAccessIdDictionary, out serviceToDeleteServiceIdAccessIdDictionary);
 477:          }
 478:   
 479:          ////////////////////////////////////////////////////////////////////////////
 480:   
 481:          /// <summary>
 482:          ///
 483:          /// </summary>
 484:          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)
 485:          {
 486:              string service, serviceId, domain, areaSymbol;
 487:              List<string> serviceIdExemptionList;
 488:              Dictionary<string, string> dictionary, nullDictionary, mismatchIdDictionary, srsProvisionedIdDictionary, srsRemovedIdDictionary, sIdDictionary, accessIdToKuwaitNgnAreaSymbolDictionary;
 489:   
 490:              mismatchIdDictionary = Ia.Ngn.Cl.Model.Data.Provision.ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdList(Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime); // backDateTime);
 491:   
 492:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 493:              {
 494:                  // below: ServiceRequestService dictionary
 495:                  dictionary = (from srs in db.ServiceRequestServices
 496:                                where srs.Provisioned == true && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime && srs.Access != null
 497:                                select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 498:   
 499:                  nullDictionary = (from srs in db.ServiceRequestServices
 500:                                    where srs.Provisioned == true && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime && srs.Access == null
 501:                                    select srs.Id).ToDictionary(n => n, n => (string)null);
 502:   
 503:                  srsProvisionedIdDictionary = dictionary.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 504:   
 505:   
 506:                  dictionary = (from srs in db.ServiceRequestServices
 507:                                where srs.Provisioned == false && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime && (srs.LastRequestDateTime >= serviceDeleteAfterDateTime || srs.LastRequestDateTime < serviceDeleteBeforeDateTime) && srs.Access != null
 508:                                select new { srs.Id, AccessId = srs.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 509:   
 510:                  nullDictionary = (from srs in db.ServiceRequestServices
 511:                                    where srs.Provisioned == false && srs.LastRequestDateTime > Ia.Ngn.Cl.Model.Business.Service.EarliestRequestDateTime && (srs.LastRequestDateTime >= serviceDeleteAfterDateTime || srs.LastRequestDateTime < serviceDeleteBeforeDateTime) && srs.Access == null
 512:                                    select srs.Id).ToDictionary(n => n, n => (string)null);
 513:   
 514:                  srsRemovedIdDictionary = dictionary.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 515:   
 516:   
 517:                  // below: Service dictionary
 518:                  dictionary = (from s in db.Service2s
 519:                                where s.Access != null
 520:                                select new { s.Id, AccessId = s.Access.Id }).ToDictionary(n => n.Id, n => n.AccessId);
 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:                  sIdDictionary = dictionary.Union(nullDictionary).ToDictionary(k => k.Key, v => v.Value);
 527:              }
 528:   
 529:              // below: services to provision (ServiceRequestService.Provisioned = true and not in Service list)
 530:              serviceToCreateServiceIdAccessIdDictionary = new Dictionary<string, string>(srsProvisionedIdDictionary.Count);
 531:              foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 532:              {
 533:                  if (!sIdDictionary.ContainsKey(kvp.Key)) serviceToCreateServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 534:              }
 535:   
 536:              // below: services to remove (Service has equivalent ServiceRequestService.Provisioned = false)
 537:              serviceToDeleteServiceIdAccessIdDictionary = new Dictionary<string, string>(srsRemovedIdDictionary.Count);
 538:              foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 539:              {
 540:                  if (srsRemovedIdDictionary.ContainsKey(kvp.Key)) serviceToDeleteServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 541:              }
 542:   
 543:              // below: services to update
 544:              serviceToUpdateIdAccessIdDictionary = new Dictionary<string, string>(mismatchIdDictionary.Count);
 545:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 546:              {
 547:                  serviceToUpdateIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
 548:              }
 549:   
 550:   
 551:              accessIdToKuwaitNgnAreaSymbolDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaSymbolDictionary;
 552:   
 553:              // filter for allowed domains and areas only
 554:              // 1. Create list
 555:              foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 556:              {
 557:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 558:   
 559:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 560:   
 561:                  if (!Ia.Ngn.Cl.Model.Business.Service.AllowedDomainsToBeCreatedList.Any(u => service.StartsWith(u)) || !Ia.Ngn.Cl.Model.Business.Service.AllowedAccessAreaToBeCreatedList.Any(u => areaSymbol.StartsWith(u)))
 562:                  {
 563:                      serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 564:                  }
 565:              }
 566:   
 567:              // 2. Delete list
 568:              foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 569:              {
 570:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 571:   
 572:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 573:   
 574:                  if (!Ia.Ngn.Cl.Model.Business.Service.AllowedDomainsToBeDeletedList.Any(u => service.StartsWith(u)) || !Ia.Ngn.Cl.Model.Business.Service.AllowedAccessAreaToBeDeletedList.Any(u => areaSymbol.StartsWith(u)))
 575:                  {
 576:                      serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 577:                  }
 578:              }
 579:   
 580:              // 3. Update list (order is important behind create and delete lists)
 581:              foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 582:              {
 583:                  service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 584:   
 585:                  areaSymbol = (kvp.Value != null && accessIdToKuwaitNgnAreaSymbolDictionary.ContainsKey(kvp.Value)) ? accessIdToKuwaitNgnAreaSymbolDictionary[kvp.Value] : string.Empty;
 586:   
 587:                  if (!Ia.Ngn.Cl.Model.Business.Service.AllowedDomainsToBeUpdatedList.Any(u => service.StartsWith(u)) || !Ia.Ngn.Cl.Model.Business.Service.AllowedAccessAreaToBeUpdatedList.Any(u => areaSymbol.StartsWith(u)))
 588:                  {
 589:                      serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 590:                  }
 591:                  else
 592:                  {
 593:                      // I will exclude all numbers from complementary list that are in either serviceToProvision list or serviceToRemove list
 594:                      if (serviceToCreateServiceIdAccessIdDictionary.ContainsKey(kvp.Key) || serviceToDeleteServiceIdAccessIdDictionary.ContainsKey(kvp.Key))
 595:                      {
 596:                          serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 597:                      }
 598:                  }
 599:              }
 600:   
 601:   
 602:   
 603:              // Testing:
 604:              if (isTest)
 605:              {
 606:                  // If isTest is true we will exclude all numbers not within MSFT
 607:   
 608:                  foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 609:                  {
 610:                      serviceId = kvp.Key;
 611:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 612:   
 613:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 614:   
 615:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 616:                          serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 617:                  }
 618:   
 619:                  foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 620:                  {
 621:                      serviceId = kvp.Key;
 622:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 623:   
 624:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 625:   
 626:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 627:                          serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 628:                  }
 629:   
 630:                  foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 631:                  {
 632:                      serviceId = kvp.Key;
 633:                      service = Ia.Ngn.Cl.Model.Business.Service2.ServiceIdToService(kvp.Key);
 634:   
 635:                      if (!serviceId.StartsWith("2537") && !serviceId.StartsWith("2538")) serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 636:   
 637:                      if (service != "25370000" && service != "25371119" && service != "25371156" && service != "25371226")
 638:                          serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 639:                  }
 640:              }
 641:              else
 642:              {
 643:                  // If isTest is false we will exclude all MSFT numbers
 644:   
 645:                  foreach (KeyValuePair<string, string> kvp in mismatchIdDictionary)
 646:                  {
 647:                      serviceId = kvp.Key;
 648:   
 649:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToUpdateIdAccessIdDictionary.Remove(kvp.Key);
 650:                  }
 651:   
 652:                  foreach (KeyValuePair<string, string> kvp in srsProvisionedIdDictionary)
 653:                  {
 654:                      serviceId = kvp.Key;
 655:   
 656:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToCreateServiceIdAccessIdDictionary.Remove(kvp.Key);
 657:                  }
 658:   
 659:                  foreach (KeyValuePair<string, string> kvp in sIdDictionary)
 660:                  {
 661:                      serviceId = kvp.Key;
 662:   
 663:                      if (serviceId.StartsWith("2537") || serviceId.StartsWith("2538")) serviceToDeleteServiceIdAccessIdDictionary.Remove(kvp.Key);
 664:                  }
 665:              }
 666:   
 667:              // will exclude exempt numbers
 668:              serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
 669:              foreach (string s in serviceIdExemptionList)
 670:              {
 671:                  serviceToUpdateIdAccessIdDictionary.Remove(s);
 672:                  serviceToCreateServiceIdAccessIdDictionary.Remove(s);
 673:                  serviceToDeleteServiceIdAccessIdDictionary.Remove(s);
 674:              }
 675:          }
 676:   
 677:          ////////////////////////////////////////////////////////////////////////////
 678:   
 679:          /// <summary>
 680:          /// List of exempt number ids
 681:          /// </summary>
 682:          public static List<string> ServiceIdOfServiceExemptFromProvisionProcessingList()
 683:          {
 684:              List<string> list;
 685:   
 686:              list = new List<string>();
 687:   
 688:              foreach (string u in Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceIdList) list.Add(u);
 689:   
 690:              return list;
 691:          }
 692:   
 693:          ////////////////////////////////////////////////////////////////////////////
 694:          ////////////////////////////////////////////////////////////////////////////    
 695:      }
 696:   
 697:      ////////////////////////////////////////////////////////////////////////////
 698:      ////////////////////////////////////////////////////////////////////////////   
 699:  }