)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Provision (Ia.Ftn.Cl.Models.Data)

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

Provision support class for Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections;
    4: using System.Collections.Generic;
    5: using System.Data;
    6: using System.Linq;
    7:  
    8: namespace Ia.Ftn.Cl.Models.Data
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Provision support class for Fixed Telecommunications Network (FTN) data model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     /// </remarks> 
   19:     public class Provision
   20:     {
   21:         private static int nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex, nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex, allPossibleNddOntNotInAgcfGatewayRecordListIndex, allPossibleAgcfGatewayRecordFromWithinOltListIndex, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex, allPossibleAgcfGatewayRecordNoInOntListIndex;
   22:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> allPossibleNddOntNotInAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList, nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList;
   23:         private static List<Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord> allPossibleAgcfGatewayRecordFromWithinOltList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, allPossibleAgcfGatewayRecordNoInOntList;
   24:         private static List<string> provisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList;
   25:  
   26:         private static readonly object objectLock = new object();
   27:  
   28:         ////////////////////////////////////////////////////////////////////////////
   29:  
   30:         /// <summary>
   31:         ///
   32:         /// </summary>
   33:         public Provision() { }
   34:  
   35:         ////////////////////////////////////////////////////////////////////////////
   36:  
   37:         /// <summary>
   38:         ///
   39:         /// </summary>
   40:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecord(out string result)
   41:         {
   42:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
   43:  
   44:             if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList == null || nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex == 0)
   45:             {
   46:                 nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList = Ia.Ftn.Cl.Models.Data.Nokia.Ims.NddNokiaSwitchOntInNonSipOltWithAccessButNoAgcfGatewayRecordList();//.Where(u=>u.Access.Name.Contains("SLA")).ToList();
   47:  
   48:                 nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = 0;
   49:             }
   50:  
   51:             if (nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count > 0)
   52:             {
   53:                 ont = (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont)nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList[nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex];
   54:  
   55:                 nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList, nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex);
   56:             }
   57:             else ont = null;
   58:  
   59:             result = "(" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordListIndex + "/" + nddNokiaOntInNonSipOltWithAccessButNoAgcfGatewayRecordList.Count + ") ";
   60:  
   61:             return ont;
   62:         }
   63:  
   64:         ////////////////////////////////////////////////////////////////////////////
   65:  
   66:         /// <summary>
   67:         ///
   68:         /// </summary>
   69:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpoint(out string result)
   70:         {
   71:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
   72:  
   73:             if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList == null || agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex == 0)
   74:             {
   75:                 agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList = Ia.Ftn.Cl.Models.Data.Nokia.Ims.AgcfGatewayRecordWithNoNddNokiaSwitchOntInNonSipOltAndNullOrEmptyAgcfEndpointList();
   76:  
   77:                 agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = 0;
   78:             }
   79:  
   80:             if (agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count > 0)
   81:             {
   82:                 agcfGatewayRecord = (Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord)agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList[agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex];
   83:  
   84:                 agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList, agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex);
   85:             }
   86:             else agcfGatewayRecord = null;
   87:  
   88:             result = "(" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointListIndex + "/" + agcfGatewayRecordWithNoNddOntAndNullOrEmptyAgcfEndpointList.Count + ") ";
   89:  
   90:             return agcfGatewayRecord;
   91:         }
   92:  
   93:         ////////////////////////////////////////////////////////////////////////////
   94:  
   95:         /// <summary>
   96:         ///
   97:         /// </summary>
   98:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont NddOntNotInAgcfGatewayRecordList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt, out string result)
   99:         {
  100:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
  101:  
  102:             if (allPossibleNddOntNotInAgcfGatewayRecordList == null || allPossibleNddOntNotInAgcfGatewayRecordListIndex == 0)
  103:             {
  104:                 allPossibleNddOntNotInAgcfGatewayRecordList = Ia.Ftn.Cl.Models.Data.Nokia.Ims.NddOntNotInAgcfGatewayRecordList(olt);
  105:  
  106:                 allPossibleNddOntNotInAgcfGatewayRecordListIndex = 0;
  107:             }
  108:  
  109:             if (allPossibleNddOntNotInAgcfGatewayRecordList.Count > 0)
  110:             {
  111:                 ont = (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont)allPossibleNddOntNotInAgcfGatewayRecordList[allPossibleNddOntNotInAgcfGatewayRecordListIndex];
  112:  
  113:                 allPossibleNddOntNotInAgcfGatewayRecordListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(allPossibleNddOntNotInAgcfGatewayRecordList, allPossibleNddOntNotInAgcfGatewayRecordListIndex);
  114:             }
  115:             else ont = null;
  116:  
  117:             result = "(" + allPossibleNddOntNotInAgcfGatewayRecordListIndex + "/" + allPossibleNddOntNotInAgcfGatewayRecordList.Count + ") ";
  118:  
  119:             return ont;
  120:         }
  121:  
  122:         ////////////////////////////////////////////////////////////////////////////
  123:  
  124:         /// <summary>
  125:         ///
  126:         /// </summary>
  127:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord AgcfGatewayRecordFromWithinOltList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt, out string result)
  128:         {
  129:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  130:  
  131:             if (allPossibleAgcfGatewayRecordFromWithinOltList == null || allPossibleAgcfGatewayRecordFromWithinOltListIndex == 0)
  132:             {
  133:                 allPossibleAgcfGatewayRecordFromWithinOltList = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.List(olt);
  134:  
  135:                 allPossibleAgcfGatewayRecordFromWithinOltListIndex = 0;
  136:             }
  137:  
  138:             if (allPossibleAgcfGatewayRecordFromWithinOltList.Count > 0)
  139:             {
  140:                 agcfGatewayRecord = (Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordFromWithinOltList[allPossibleAgcfGatewayRecordFromWithinOltListIndex];
  141:  
  142:                 allPossibleAgcfGatewayRecordFromWithinOltListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordFromWithinOltList, allPossibleAgcfGatewayRecordFromWithinOltListIndex);
  143:             }
  144:             else agcfGatewayRecord = null;
  145:  
  146:             result = "(" + allPossibleAgcfGatewayRecordFromWithinOltListIndex + "/" + allPossibleAgcfGatewayRecordFromWithinOltList.Count + ") ";
  147:  
  148:             return agcfGatewayRecord;
  149:         }
  150:  
  151:         ////////////////////////////////////////////////////////////////////////////
  152:  
  153:         /// <summary>
  154:         ///
  155:         /// </summary>
  156:         public static Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord AgcfGatewayRecordNoInOntList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
  157:         {
  158:             Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord agcfGatewayRecord;
  159:  
  160:             if (allPossibleAgcfGatewayRecordNoInOntList == null || allPossibleAgcfGatewayRecordNoInOntListIndex == 0)
  161:             {
  162:                 allPossibleAgcfGatewayRecordNoInOntList = Ia.Ftn.Cl.Models.Data.Nokia.Ims.AllPossibleAgcfGatewayRecordsNoInOntsList(olt);
  163:  
  164:                 allPossibleAgcfGatewayRecordNoInOntListIndex = 0;
  165:             }
  166:  
  167:             agcfGatewayRecord = (Ia.Ftn.Cl.Models.Nokia.AgcfGatewayRecord)allPossibleAgcfGatewayRecordNoInOntList[allPossibleAgcfGatewayRecordNoInOntListIndex];
  168:  
  169:             allPossibleAgcfGatewayRecordNoInOntListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(allPossibleAgcfGatewayRecordNoInOntList, allPossibleAgcfGatewayRecordNoInOntListIndex);
  170:  
  171:             return agcfGatewayRecord;
  172:         }
  173:  
  174:         ////////////////////////////////////////////////////////////////////////////
  175:         ////////////////////////////////////////////////////////////////////////////
  176:  
  177:         /// <summary>
  178:         ///
  179:         /// </summary>
  180:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont NddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecord(out string result)
  181:         {
  182:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
  183:  
  184:             if (nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList == null || nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex == 0)
  185:             {
  186:                 nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList = Ia.Ftn.Cl.Models.Data.Huawei.Ims.NddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecord();//.Where(u=>u.Access.Name.Contains("SLA")).ToList();
  187:  
  188:                 nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex = 0;
  189:             }
  190:  
  191:             if (nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList.Count > 0)
  192:             {
  193:                 ont = (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont)nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList[nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex];
  194:  
  195:                 nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex = Ia.Cl.Models.Default.IncrementListIndexOrRestart(nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList, nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex);
  196:             }
  197:             else ont = null;
  198:  
  199:             result = "(" + nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordListIndex + "/" + nddHuaweiSwitchAndNokiaAccessOntWithAccessButNoMgwRecordList.Count + ") ";
  200:  
  201:             return ont;
  202:         }
  203:  
  204:         /*
  205:         ////////////////////////////////////////////////////////////////////////////
  206: 
  207:         /// <summary>
  208:         ///
  209:         /// </summary>
  210:         public static bool UpdateServiceRequestServiceServiceSuspensionWithNonNullAccess(out string result)
  211:         {
  212:             bool toTrue, toFalse;
  213:             StringBuilder sb;
  214:             List<string> srsCurrentList, toTrueList, toFalseList;
  215: 
  216:             toTrue = toFalse = false;
  217: 
  218:             srsCurrentList = Ia.Ftn.Cl.Model.Data.ServiceRequestService.ServiceSuspensionIsTrueStringNumberList;
  219: 
  220:             toTrueList = new List<string>(srsCurrentList.Count);
  221:             toFalseList = new List<string>(srsCurrentList.Count);
  222: 
  223:             sb = new StringBuilder(12 * (srsCurrentList.Count));
  224: 
  225:             // below: numbers that should be added to SRS barring
  226:             sb.Append("\r\nNumber(s) to be set in SRS as barred: ");
  227: 
  228:             toTrue = Ia.Ftn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toTrueList, true, Guid.Empty);
  229:             sb.Append("\r\nNumber(s) set?: " + toTrue.ToString());
  230: 
  231:             // below: numbres that should be removed from SRS barring
  232:             sb.Append("\r\nNumber(s) to be reset in SRS as not barred: ");
  233: 
  234:             toFalse = Ia.Ftn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspensionAndServiceSuspensionTypeIdToSpecifiedSuspensionStateForAServiceStringList(toFalseList, false, Guid.Empty);
  235:             sb.Append("\r\nNumber(s) reset?: " + toTrue.ToString());
  236: 
  237:             result = sb.ToString();
  238: 
  239:             return toTrue || toFalse;
  240:         }
  241:         */
  242:  
  243:         ////////////////////////////////////////////////////////////////////////////
  244:  
  245:         /// <summary>
  246:         ///
  247:         /// </summary>
  248:         private static List<Ia.Ftn.Cl.Models.ServiceRequestService> ServiceRequestServiceWithAccessesWithNullAgcfEndpointList
  249:         {
  250:             get
  251:             {
  252:                 List<Ia.Ftn.Cl.Models.ServiceRequestService> serviceRequestServiceList;
  253:  
  254:                 using (var db = new Ia.Ftn.Cl.Db())
  255:                 {
  256:                     serviceRequestServiceList = (from srs in db.ServiceRequestServices
  257:                                                  join e in db.AgcfEndpoints on Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PrividUser(srs.Service) equals e.PrividUser
  258:                                                  into gj
  259:                                                  from u in gj.DefaultIfEmpty()
  260:                                                  where u == null && srs.Access != null
  261:                                                  select srs).Include(u => u.Access).ToList();
  262:                 }
  263:  
  264:                 return serviceRequestServiceList;
  265:             }
  266:         }
  267:  
  268:         ////////////////////////////////////////////////////////////////////////////
  269:  
  270:         /// <summary>
  271:         ///
  272:         /// </summary>
  273:         public static List<string> ImsServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList()
  274:         {
  275:             return ServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService, out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList);
  276:         }
  277:  
  278:         ////////////////////////////////////////////////////////////////////////////
  279:  
  280:         /// <summary>
  281:         ///
  282:         /// </summary>
  283:         public static List<string> PstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList()
  284:         {
  285:             return ServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService, out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList);
  286:         }
  287:  
  288:         ////////////////////////////////////////////////////////////////////////////
  289:  
  290:         /// <summary>
  291:         ///
  292:         /// </summary>
  293:         public static void EricssonAxePstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList)
  294:         {
  295:             PstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.EricssonAxe, out serviceToSuspendList, out serviceToReleaseList, out serviceInternationalCallingToSuspendList, out serviceInternationalCallingToReleaseList);
  296:         }
  297:  
  298:         ////////////////////////////////////////////////////////////////////////////
  299:  
  300:         /// <summary>
  301:         ///
  302:         /// </summary>
  303:         public static void SiemensEwsdPstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList)
  304:         {
  305:             PstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.SiemensEwsd, out serviceToSuspendList, out serviceToReleaseList, out serviceInternationalCallingToSuspendList, out serviceInternationalCallingToReleaseList);
  306:         }
  307:  
  308:         ////////////////////////////////////////////////////////////////////////////
  309:  
  310:         /// <summary>
  311:         ///
  312:         /// </summary>
  313:         public static void PstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType pstnExchangeType, out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList)
  314:         {
  315:             ServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService, out List<string> serviceToSuspend0List, out List<string> serviceToRelease0List, out List<string> serviceInternationalCallingToSuspend0List, out List<string> serviceInternationalCallingToRelease0List);
  316:  
  317:             serviceToSuspendList = new List<string>();
  318:             serviceToReleaseList = new List<string>();
  319:  
  320:             serviceInternationalCallingToSuspendList = new List<string>();
  321:             serviceInternationalCallingToReleaseList = new List<string>();
  322:  
  323:             if (pstnExchangeType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.EricssonAxe)
  324:             {
  325:                 foreach (var s in serviceToSuspend0List)
  326:                 {
  327:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedEricssonAxeSwitchDomainList(s))
  328:                     {
  329:                         serviceToSuspendList.Add(s);
  330:                     }
  331:                 }
  332:  
  333:                 foreach (var s in serviceToRelease0List)
  334:                 {
  335:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedEricssonAxeSwitchDomainList(s))
  336:                     {
  337:                         serviceToReleaseList.Add(s);
  338:                     }
  339:                 }
  340:  
  341:                 foreach (var s in serviceInternationalCallingToSuspend0List)
  342:                 {
  343:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedEricssonAxeSwitchDomainList(s))
  344:                     {
  345:                         serviceInternationalCallingToSuspendList.Add(s);
  346:                     }
  347:                 }
  348:  
  349:                 foreach (var s in serviceInternationalCallingToRelease0List)
  350:                 {
  351:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedEricssonAxeSwitchDomainList(s))
  352:                     {
  353:                         serviceInternationalCallingToReleaseList.Add(s);
  354:                     }
  355:                 }
  356:             }
  357:             else if (pstnExchangeType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.SiemensEwsd)
  358:             {
  359:                 foreach (var s in serviceToSuspend0List)
  360:                 {
  361:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedSiemensEwsdSwitchDomainList(s))
  362:                     {
  363:                         serviceToSuspendList.Add(s);
  364:                     }
  365:                 }
  366:  
  367:                 foreach (var s in serviceToRelease0List)
  368:                 {
  369:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedSiemensEwsdSwitchDomainList(s))
  370:                     {
  371:                         serviceToReleaseList.Add(s);
  372:                     }
  373:                 }
  374:  
  375:                 foreach (var s in serviceInternationalCallingToSuspend0List)
  376:                 {
  377:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedSiemensEwsdSwitchDomainList(s))
  378:                     {
  379:                         serviceInternationalCallingToSuspendList.Add(s);
  380:                     }
  381:                 }
  382:  
  383:                 foreach (var s in serviceInternationalCallingToRelease0List)
  384:                 {
  385:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedSiemensEwsdSwitchDomainList(s))
  386:                     {
  387:                         serviceInternationalCallingToReleaseList.Add(s);
  388:                     }
  389:                 }
  390:             }
  391:             else throw new ArgumentOutOfRangeException(@"pstnExchangeType " + pstnExchangeType.ToString() + " is unknown.");
  392:         }
  393:  
  394:         ////////////////////////////////////////////////////////////////////////////
  395:  
  396:         /// <summary>
  397:         ///
  398:         /// </summary>
  399:         public static List<string> ServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(int serviceType, out List<string> serviceToSuspendList, out List<string> serviceToReleaseList, out List<string> serviceInternationalCallingToSuspendList, out List<string> serviceInternationalCallingToReleaseList)
  400:         {
  401:             List<string> serviceList;
  402:  
  403:             serviceToSuspendList = new List<string>();
  404:             serviceToReleaseList = new List<string>();
  405:  
  406:             serviceInternationalCallingToSuspendList = new List<string>();
  407:             serviceInternationalCallingToReleaseList = new List<string>();
  408:  
  409:             var programmedAccountingDisconnectionType = Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.DisconnectionType.ProgrammedAccounting;
  410:             var programmedInternationalCallingDisconnectionType = Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.DisconnectionType.ProgrammedInternationalCalling;
  411:  
  412:             using (var db = new Ia.Ftn.Cl.Db())
  413:             {
  414:                 serviceToSuspendList = (from srai in db.ServiceRequestAdministrativeIssues
  415:                                         join s in db.Service2 on srai.Id equals s.Id
  416:                                         where s.ServiceSuspension != true && s.ServiceType == serviceType && srai.Type == (int)programmedAccountingDisconnectionType
  417:                                         select s.Service).AsNoTracking().ToList();
  418:  
  419:                 serviceToReleaseList = (from s in db.Service2
  420:                                         join srai in db.ServiceRequestAdministrativeIssues on s.Id equals srai.Id into srais
  421:                                         from srai in srais.DefaultIfEmpty()
  422:                                         where srai == null && s.ServiceType == serviceType && s.ServiceSuspension == true
  423:                                         select s.Service).AsNoTracking().ToList();
  424:  
  425:                 serviceInternationalCallingToSuspendList = (from srai in db.ServiceRequestAdministrativeIssues
  426:                                                             join s in db.Service2 on srai.Id equals s.Id
  427:                                                             join srs in db.ServiceRequestServices on srai.Id equals srs.Id
  428:                                                             where s.ServiceType == serviceType && srs.InternationalCalling == true && s.InternationalCalling == true && srai.Type == (int)programmedInternationalCallingDisconnectionType
  429:                                                             select s.Service).AsNoTracking().ToList();
  430:  
  431:                 serviceInternationalCallingToReleaseList = (from s in db.Service2
  432:                                                             join srs in db.ServiceRequestServices on s.Id equals srs.Id
  433:                                                             join srai in db.ServiceRequestAdministrativeIssues on s.Id equals srai.Id into srais
  434:                                                             from srai in srais.DefaultIfEmpty()
  435:                                                             where srai == null && s.ServiceType == serviceType && srs.InternationalCalling == true && s.InternationalCalling == false
  436:                                                             select s.Service).AsNoTracking().ToList();
  437:             }
  438:  
  439:             var serviceExemptionList = ServiceOfServiceExemptFromProvisionProcessingList();
  440:             foreach (string s in serviceExemptionList)
  441:             {
  442:                 serviceToSuspendList.Remove(s);
  443:                 serviceToReleaseList.Remove(s);
  444:  
  445:                 serviceInternationalCallingToSuspendList.Remove(s);
  446:                 serviceInternationalCallingToReleaseList.Remove(s);
  447:             }
  448:  
  449:  
  450:             serviceList = serviceToSuspendList.Union(serviceToReleaseList).Union(serviceInternationalCallingToSuspendList).Union(serviceInternationalCallingToReleaseList).ToList();
  451:  
  452:             // temp until we settle issues with disconnection dept
  453:             var serviceToDeleteList = new List<string>();
  454:             foreach (string s in serviceList)
  455:             {
  456:                 if (!Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(s)) serviceToDeleteList.Add(s);
  457:             }
  458:             foreach (var s in serviceToDeleteList) serviceList.Remove(s);
  459:  
  460:             return serviceList;
  461:         }
  462:  
  463:         ////////////////////////////////////////////////////////////////////////////
  464:  
  465:         /// <summary>
  466:         ///
  467:         /// </summary>
  468:         public static Dictionary<string, string> ComplementaryImsServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(DateTime earliestRequestDateTime)
  469:         {
  470:             return Ia.Ftn.Cl.Models.Data.Provision.ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService, earliestRequestDateTime);
  471:         }
  472:  
  473:         ////////////////////////////////////////////////////////////////////////////
  474:  
  475:         /// <summary>
  476:         ///
  477:         /// </summary>
  478:         public static Dictionary<string, string> ComplementaryPstnServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(DateTime earliestRequestDateTime)
  479:         {
  480:             return Ia.Ftn.Cl.Models.Data.Provision.ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(Ia.Ftn.Cl.Models.Business.Service.ServiceType.PstnService, earliestRequestDateTime);
  481:         }
  482:  
  483:         ////////////////////////////////////////////////////////////////////////////
  484:  
  485:         /// <summary>
  486:         ///
  487:         /// </summary>
  488:         public static Dictionary<string, string> ComplementaryServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(int serviceType, DateTime earliestRequestDateTime)
  489:         {
  490:             Dictionary<string, string> serviceIdAccessIdDictionary;
  491:  
  492:             var allowedOltToBeProvisionedIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedOltIdList;
  493:  
  494:             using (var db = new Ia.Ftn.Cl.Db())
  495:             {
  496:                 var servicePbxList = Ia.Ftn.Cl.Models.Data.Service.ServicePbxList;
  497:                 //var huaweiSwitchDomainList = Ia.Ftn.Cl.Model.Data.Service.HuaweiSwitchDomainList.ConvertAll<string>(u => u.ToString());
  498:  
  499:                 // below: Service different from ServiceRequestService
  500:                 serviceIdAccessIdDictionary = (from s in db.Service2
  501:                                                    //join srs in db.ServiceRequestServices on s.Id equals srs.Id // this is faster, but I need to match Services to account for PSTN numbers
  502:                                                join srs in db.ServiceRequestServices on s.Service equals srs.Service
  503:                                                join srai in db.ServiceRequestAdministrativeIssues on s.Service equals srai.Service into srai2
  504:                                                from srai3 in srai2.DefaultIfEmpty()
  505:                                                where s.ServiceType == serviceType
  506:                                                && srs.Provisioned == true
  507:                                                && srs.LastRequestDateTime >= earliestRequestDateTime
  508:                                                && (s.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt) || s.Access == null)
  509:                                                &&
  510:                                                (
  511:                                                    s.AbbriviatedCalling != srs.AbbriviatedCalling
  512:                                                    || s.AlarmCall != srs.AlarmCall
  513:                                                    || s.WakeupCall != srs.WakeupCall
  514:                                                    || s.CallerId != srs.CallerId
  515:                                                    || s.CallForwarding != srs.CallForwarding
  516:                                                    || s.ConferenceCall != srs.ConferenceCall
  517:                                                    || s.InternationalCallingUserControlled != srs.InternationalCallingUserControlled
  518:                                                    || s.InternationalCalling != srs.InternationalCalling
  519:                                                    || s.SpeedDial != srs.SpeedDial
  520:                                                    //|| (Ia.Ftn.Cl.Model.Business.Administration.ServiceSuspensionIsEnabled && s.ServiceSuspension != srs.CallBarring)
  521:  
  522:                                                    // below: exclude PBX numbers from the Call Waiting service requirement
  523:                                                    || !servicePbxList.Contains(srs.Service) && s.CallWaiting != srs.CallWaiting
  524:  
  525:                                                /*
  526:                                                // below: exclude huawei from barring and service suspension operations
  527:                                                //|| !huaweiSwitchDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
  528:                                                || !huaweiSwitchDomainList.Contains(srs.Service.Substring(0, 4)) && !huaweiSwitchDomainList.Contains(srs.Service.Substring(0, 5))
  529:                                                &&
  530:                                                (
  531:                                                    srs.CallBarring == false && srs.ServiceSuspension == false && s.ServiceSuspension == true
  532:                                                    || srs.CallBarring == true && srs.ServiceSuspension == false && s.ServiceSuspension == false
  533:                                                    || srs.CallBarring == false && srs.ServiceSuspension == true && s.ServiceSuspension == false
  534:                                                    || srs.CallBarring == true && srs.ServiceSuspension == true && s.ServiceSuspension == false
  535:                                                )
  536:                                                */
  537:  
  538:                                                // below: check for numbers in which srs.Access != s.Access when s.Access != null
  539:                                                //|| (s.Access != null && s.Access.Id != srs.Access.Id) // not appropriate to compare s.Access and srs.Access here
  540:                                                )
  541:                                                && srai3.Id == null // srai3.Id == null means no ServiceRequestAdministrativeIssues
  542:                                                select new
  543:                                                {
  544:                                                    s.Id,
  545:                                                    AccessId = (s.Access != null) ? s.Access.Id : string.Empty
  546:                                                }).AsNoTracking().ToDictionary(n => n.Id, n => n.AccessId);
  547:             }
  548:  
  549:             return serviceIdAccessIdDictionary;
  550:         }
  551:  
  552:         ////////////////////////////////////////////////////////////////////////////
  553:  
  554:         /// <summary>
  555:         ///
  556:         /// </summary>
  557:         public static SortedList ProvisionedServiceRequestServiceAndServiceMismatchAccessServiceIdList()
  558:         {
  559:             SortedList serviceRequestServiceAndServiceMismatchAccessServiceIdList;
  560:             Dictionary<string, int> srsIdDictionary, sIdDictionary;
  561:  
  562:             using (var db = new Ia.Ftn.Cl.Db())
  563:             {
  564:                 // below: ServiceRequestService dictionary
  565:                 srsIdDictionary = (from srs in db.ServiceRequestServices
  566:                                    join s in db.Service2 on srs.Id equals s.Id
  567:                                    where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && srs.Provisioned == true && srs.Access != null && s.Access != null && srs.Access.Id != s.Access.Id
  568:                                    select srs.Id).ToDictionary(n => n, n => 1);
  569:  
  570:                 // below: Service dictionary
  571:                 sIdDictionary = (from s in db.Service2
  572:                                  join srs in db.ServiceRequestServices on s.Id equals srs.Id
  573:                                  where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && srs.Provisioned == true && s.Access != null && srs.Access != null && s.Access.Id != srs.Access.Id
  574:                                  select s.Id).ToDictionary(n => n, n => 1);
  575:             }
  576:  
  577:             serviceRequestServiceAndServiceMismatchAccessServiceIdList = new SortedList(srsIdDictionary.Count + sIdDictionary.Count);
  578:  
  579:             foreach (KeyValuePair<string, int> kvp in srsIdDictionary)
  580:                 if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
  581:                     serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
  582:  
  583:             foreach (KeyValuePair<string, int> kvp in sIdDictionary)
  584:                 if (!serviceRequestServiceAndServiceMismatchAccessServiceIdList.ContainsKey(kvp.Key))
  585:                     serviceRequestServiceAndServiceMismatchAccessServiceIdList.Add(kvp.Key, 1);
  586:  
  587:             return serviceRequestServiceAndServiceMismatchAccessServiceIdList;
  588:         }
  589:  
  590:         ////////////////////////////////////////////////////////////////////////////
  591:  
  592:         /// <summary>
  593:         ///
  594:         /// </summary>
  595:         public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(out Dictionary<string, string> serviceToUpdateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
  596:         {
  597:             ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(0, out serviceToUpdateServiceIdAccessIdDictionary, out serviceToCreateServiceIdAccessIdDictionary, out serviceToDeleteServiceIdAccessIdDictionary);
  598:         }
  599:  
  600:         ////////////////////////////////////////////////////////////////////////////
  601:  
  602:         /// <summary>
  603:         ///
  604:         /// </summary>
  605:         public static void ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(int provisionWithinLastNDays, out Dictionary<string, string> serviceToUpdateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary)
  606:         {
  607:             string service, serviceId;
  608:             Dictionary<string, string> mismatchServiceIdAccessIdDictionary, serviceRequestServiceProvisionedServiceIdAccessIdDictionary, serviceRequestServiceRemovedServiceIdAccessIdDictionary, serviceIdAccessIdDictionary;
  609:  
  610:             var earliestRequestDateTime = (provisionWithinLastNDays > 0) ? DateTime.UtcNow.AddHours(3).AddDays(-provisionWithinLastNDays) : Ia.Ftn.Cl.Models.Business.Administration.EarliestRequestDateTime;
  611:  
  612:             var allowedOltToBeProvisionedIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedOltIdList;
  613:  
  614:             using (var db = new Ia.Ftn.Cl.Db())
  615:             {
  616:                 // below: ServiceRequestService dictionary
  617:                 serviceRequestServiceProvisionedServiceIdAccessIdDictionary = (from srs in db.ServiceRequestServices
  618:                                                                                where srs.Provisioned == true && srs.LastRequestDateTime >= earliestRequestDateTime
  619:                                                                                && srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)
  620:                                                                                select new { srs.Id, AccessId = srs.Access.Id }).AsNoTracking().ToDictionary(n => n.Id, n => n.AccessId);
  621:  
  622:                 serviceRequestServiceRemovedServiceIdAccessIdDictionary = (from srs in db.ServiceRequestServices
  623:                                                                            where srs.Provisioned == false && srs.LastRequestDateTime >= earliestRequestDateTime
  624:                                                                            /*&& srs.Access != null && allowedOltToBeProvisionedIdList.Contains(srs.Access.Olt)*/
  625:                                                                            select new { srs.Id, AccessId = srs.Access.Id }).AsNoTracking().ToDictionary(n => n.Id, n => n.AccessId);
  626:  
  627:                 serviceIdAccessIdDictionary = (from s in db.Service2
  628:                                                where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  629:                                                && (s.Access != null && allowedOltToBeProvisionedIdList.Contains(s.Access.Olt) || s.Access == null)
  630:                                                select new { s.Id, AccessId = s.Access.Id }).AsNoTracking().ToDictionary(n => n.Id, n => n.AccessId);
  631:             }
  632:  
  633:             // services to provision (ServiceRequestService.Provisioned = true and not in Service list)
  634:             serviceToCreateServiceIdAccessIdDictionary = new Dictionary<string, string>();
  635:             foreach (KeyValuePair<string, string> kvp in serviceRequestServiceProvisionedServiceIdAccessIdDictionary)
  636:             {
  637:                 if (!serviceIdAccessIdDictionary.ContainsKey(kvp.Key))
  638:                 {
  639:                     if (!string.IsNullOrEmpty(kvp.Value))
  640:                     {
  641:                         serviceId = kvp.Key;
  642:                         service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
  643:  
  644:                         if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service) && !service.StartsWith("2489"))
  645:                         {
  646:                             serviceToCreateServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
  647:                         }
  648:                     }
  649:                 }
  650:             }
  651:  
  652:             // services to remove (Service has equivalent ServiceRequestService.Provisioned = false)
  653:             serviceToDeleteServiceIdAccessIdDictionary = new Dictionary<string, string>();
  654:             foreach (KeyValuePair<string, string> kvp in serviceIdAccessIdDictionary)
  655:             {
  656:                 if (serviceRequestServiceRemovedServiceIdAccessIdDictionary.ContainsKey(kvp.Key))
  657:                 {
  658:                     //if (!string.IsNullOrEmpty(kvp.Value)) // only delete numbers with accesses, to be removed later
  659:                     //{
  660:                     serviceId = kvp.Key;
  661:                     service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
  662:  
  663:                     if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service) && !service.StartsWith("2489"))
  664:                     {
  665:                         serviceToDeleteServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
  666:                     }
  667:                     //}
  668:                 }
  669:             }
  670:  
  671:  
  672:             mismatchServiceIdAccessIdDictionary = Ia.Ftn.Cl.Models.Data.Provision.ComplementaryImsServiceMismatchBetweenProvisionedServiceRequestServiceAndServiceServiceIdAccessIdList(earliestRequestDateTime);
  673:  
  674:  
  675:             // services to update
  676:             serviceToUpdateServiceIdAccessIdDictionary = new Dictionary<string, string>();
  677:             foreach (KeyValuePair<string, string> kvp in mismatchServiceIdAccessIdDictionary)
  678:             {
  679:                 serviceId = kvp.Key;
  680:                 service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
  681:  
  682:                 if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service) && !service.StartsWith("2489"))
  683:                 {
  684:                     serviceToUpdateServiceIdAccessIdDictionary.Add(kvp.Key, kvp.Value);
  685:                 }
  686:             }
  687:  
  688:             // 3. Update list (order is important behind create and delete lists)
  689:             foreach (KeyValuePair<string, string> kvp in mismatchServiceIdAccessIdDictionary)
  690:             {
  691:                 // I will exclude all numbers from complementary list that are in either serviceToProvision list or serviceToRemove list
  692:                 if (serviceToCreateServiceIdAccessIdDictionary.ContainsKey(kvp.Key) || serviceToDeleteServiceIdAccessIdDictionary.ContainsKey(kvp.Key))
  693:                 {
  694:                     serviceToUpdateServiceIdAccessIdDictionary.Remove(kvp.Key);
  695:                 }
  696:             }
  697:  
  698:             // will exclude exempt numbers
  699:             var serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
  700:             foreach (string s in serviceIdExemptionList)
  701:             {
  702:                 serviceToUpdateServiceIdAccessIdDictionary.Remove(s);
  703:                 serviceToCreateServiceIdAccessIdDictionary.Remove(s);
  704:                 serviceToDeleteServiceIdAccessIdDictionary.Remove(s);
  705:             }
  706:         }
  707:  
  708:         ////////////////////////////////////////////////////////////////////////////
  709:  
  710:         /// <summary>
  711:         ///
  712:         /// </summary>
  713:         public static void ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(out Dictionary<string, string> serviceToCreateServiceIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdDictionary)
  714:         {
  715:             ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(0, out serviceToCreateServiceIdDictionary, out serviceToDeleteServiceIdDictionary);
  716:         }
  717:  
  718:         ////////////////////////////////////////////////////////////////////////////
  719:  
  720:         /// <summary>
  721:         ///
  722:         /// </summary>
  723:         public static void ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(int provisionWithinLastNDays, out Dictionary<string, string> serviceToCreateServiceIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdDictionary)
  724:         {
  725:             /*
  726:             var siteList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.SiteList;
  727: 
  728:             var site0List = (from s in siteList
  729:                              where s.Name == "SLB" || s.Name == "ARD" || s.Name == "QRN" || s.Name == "MSF" || s.Name == "MGF" || s.Name == "JHB" || s.Name == "SKB"
  730:                              select s).ToList();
  731: 
  732:             var msanList = site0List.SelectMany(u => u.Msans).ToList();
  733:             */
  734:  
  735:             var msanList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.MsanList;
  736:  
  737:             ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(msanList, provisionWithinLastNDays, out serviceToCreateServiceIdDictionary, out serviceToDeleteServiceIdDictionary);
  738:         }
  739:  
  740:         ////////////////////////////////////////////////////////////////////////////
  741:  
  742:         /// <summary>
  743:         ///
  744:         /// </summary>
  745:         public static void ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan> msanList, int provisionWithinLastNDays, out Dictionary<string, string> serviceToCreateServiceIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdDictionary)
  746:         {
  747:             string service, serviceId;
  748:             Dictionary<string, string> serviceRequestServiceProvisionedServiceIdDictionary, serviceRequestServiceRemovedServiceIdDictionary;
  749:             Dictionary<string, string> serviceIdDictionary;
  750:  
  751:             var earliestRequestDateTime = (provisionWithinLastNDays > 0) ? DateTime.UtcNow.AddHours(3).AddDays(-provisionWithinLastNDays) : Ia.Ftn.Cl.Models.Business.Administration.EarliestRequestDateTime;
  752:  
  753:             var allowedOltToBeProvisionedIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedOltIdList;
  754:  
  755:             //var msanDomainList = Ia.Ftn.Cl.Model.Data.Service.MsanDomainList;
  756:             var msanDomainList = msanList.SelectMany(u => u.DomainList).ToList();
  757:  
  758:             var msanDomainStringList = msanDomainList.ConvertAll(delegate (int i) { return i.ToString(); });
  759:  
  760:             using (var db = new Ia.Ftn.Cl.Db())
  761:             {
  762:                 var serviceRequestServiceList = (from srs in db.ServiceRequestServices
  763:                                                  where srs.LastRequestDateTime >= earliestRequestDateTime
  764:                                                  && srs.Access == null
  765:                                                  select new { srs.Id, srs.Service, srs.Provisioned }).AsNoTracking().ToList();
  766:  
  767:                 serviceRequestServiceProvisionedServiceIdDictionary = (from l in serviceRequestServiceList
  768:                                                                        where l.Provisioned == true && (msanDomainStringList.Contains(l.Service.Substring(0, 4)) || msanDomainStringList.Contains(l.Service.Substring(0, 5)))
  769:                                                                        select new { l.Id }).ToDictionary(n => n.Id, n => n.Id);
  770:  
  771:                 serviceRequestServiceRemovedServiceIdDictionary = (from l in serviceRequestServiceList
  772:                                                                    where l.Provisioned == false && (msanDomainStringList.Contains(l.Service.Substring(0, 4)) || msanDomainStringList.Contains(l.Service.Substring(0, 5)))
  773:                                                                    select new { l.Id }).ToDictionary(n => n.Id, n => n.Id);
  774:  
  775:                 serviceIdDictionary = (from s in db.Service2
  776:                                        where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService
  777:                                        /*&& s.Access == null*/ && (msanDomainStringList.Contains(s.Service.Substring(0, 4)) || msanDomainStringList.Contains(s.Service.Substring(0, 5)))
  778:                                        select new { s.Id }).AsNoTracking().ToDictionary(n => n.Id, n => n.Id);
  779:             }
  780:  
  781:  
  782:             // services to provision (ServiceRequestService.Provisioned = true and not in Service list)
  783:             serviceToCreateServiceIdDictionary = new Dictionary<string, string>();
  784:             foreach (var kvp in serviceRequestServiceProvisionedServiceIdDictionary)
  785:             {
  786:                 if (!serviceIdDictionary.ContainsKey(kvp.Key))
  787:                 {
  788:                     if (!string.IsNullOrEmpty(kvp.Value))
  789:                     {
  790:                         serviceId = kvp.Key;
  791:                         service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
  792:  
  793:                         if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service) && !service.StartsWith("2489"))
  794:                         {
  795:                             serviceToCreateServiceIdDictionary.Add(kvp.Key, kvp.Value);
  796:                         }
  797:                     }
  798:                 }
  799:             }
  800:  
  801:             // If there is an entry in MSAN for number then I will create it on IMS even if it has a PSTN version (which will be deleted by net-manager or axe projects)
  802:             var pstnServiceIdList = Ia.Ftn.Cl.Models.Data.Service2.PstnServiceIdList;
  803:             var msanServiceDictionary = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.MsanServiceDictionary;
  804:  
  805:             foreach (var serviceId0 in pstnServiceIdList)
  806:             {
  807:                 service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId0);
  808:                 var service2Id = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService);
  809:  
  810:                 if (!msanServiceDictionary.ContainsKey(service)) serviceToCreateServiceIdDictionary.Remove(service2Id);
  811:             }
  812:             //serviceToCreateServiceIdDictionary = new Dictionary<string, string>();
  813:  
  814:  
  815:             // services to remove (Service has equivalent ServiceRequestService.Provisioned = false)
  816:             serviceToDeleteServiceIdDictionary = new Dictionary<string, string>();
  817:             foreach (var kvp in serviceIdDictionary)
  818:             {
  819:                 if (serviceRequestServiceRemovedServiceIdDictionary.ContainsKey(kvp.Key))
  820:                 {
  821:                     if (!string.IsNullOrEmpty(kvp.Value)) // only delete numbers with accesses, to be removed later
  822:                     {
  823:                         serviceId = kvp.Key;
  824:                         service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
  825:  
  826:                         if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service) && !service.StartsWith("2489"))
  827:                         {
  828:                             serviceToDeleteServiceIdDictionary.Add(kvp.Key, kvp.Value);
  829:                         }
  830:                     }
  831:                 }
  832:             }
  833:  
  834:             /*
  835:             // temp until I fix changed-to problems
  836:             var changedAndChangedToServiceIdList = Ia.Ftn.Cl.Model.Data.ServiceRequest.ChangedAndChangedToServiceIdList();
  837:             foreach (var serviceId in changedAndChangedToServiceIdList)
  838:             {
  839:                 serviceToCreateServiceIdDictionary.Remove(serviceId);
  840:                 serviceToDeleteServiceIdDictionary.Remove(serviceId);
  841:             }
  842:             */
  843:  
  844:             var serviceIdExemptionList = ServiceIdOfServiceExemptFromProvisionProcessingList();
  845:             foreach (var serviceId0 in serviceIdExemptionList)
  846:             {
  847:                 serviceToCreateServiceIdDictionary.Remove(serviceId0);
  848:                 serviceToDeleteServiceIdDictionary.Remove(serviceId0);
  849:             }
  850:         }
  851:  
  852:         ////////////////////////////////////////////////////////////////////////////
  853:  
  854:         /// <summary>
  855:         /// List of exempt number ids
  856:         /// </summary>
  857:         public static List<string> ServiceIdOfServiceExemptFromProvisionProcessingList()
  858:         {
  859:             List<string> list;
  860:  
  861:             list = new List<string>();
  862:  
  863:             foreach (string u in Ia.Ftn.Cl.Models.Data.ServiceExemption.ServiceIdList()) list.Add(u);
  864:  
  865:             return list;
  866:         }
  867:  
  868:         ////////////////////////////////////////////////////////////////////////////
  869:  
  870:         /// <summary>
  871:         /// List of exempt services
  872:         /// </summary>
  873:         public static List<string> ServiceOfServiceExemptFromProvisionProcessingList()
  874:         {
  875:             List<string> list;
  876:  
  877:             list = new List<string>();
  878:  
  879:             foreach (string u in Ia.Ftn.Cl.Models.Data.ServiceExemption.ServiceList()) list.Add(u);
  880:  
  881:             return list;
  882:         }
  883:  
  884:         ////////////////////////////////////////////////////////////////////////////
  885:         ////////////////////////////////////////////////////////////////////////////
  886:  
  887:         /// <summary>
  888:         ///
  889:         /// </summary>
  890:         public static List<string> ProvisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList(bool reloadData)
  891:         {
  892:             if (reloadData || provisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList == null || provisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList.Count == 0)
  893:             {
  894:                 lock (objectLock)
  895:                 {
  896:                     provisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList = _ProvisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList();
  897:                 }
  898:             }
  899:  
  900:             return provisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList;
  901:         }
  902:  
  903:         ////////////////////////////////////////////////////////////////////////////
  904:  
  905:         /// <summary>
  906:         ///
  907:         /// </summary>
  908:         private static List<string> _ProvisionedImsServiceWithNullAccessNotInPstnNorInNceOntSipInfoNorVoipPstnUserNorMsanWithinMsanDomainListList()
  909:         {
  910:             List<string> list;
  911:  
  912:             var imsServiceWithAccessNullList = Ia.Ftn.Cl.Models.Data.Service2.ImsServiceWithAccessNullList;
  913:             var serviceWithProvisionedTrueAndNullAccessList = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ServiceWithProvisionedTrueAndNullAccessList();
  914:  
  915:             var pstnServiceList = Ia.Ftn.Cl.Models.Data.Service2.PstnServiceList;
  916:             var emsOntSipInfoServiceList = Ia.Ftn.Cl.Models.Data.Huawei.OntSipInfo.ServiceList();
  917:             var emsVoipPstnUserServiceList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.ServiceList();
  918:  
  919:             var msanDomainList = Ia.Ftn.Cl.Models.Data.Service.MsanDomainList;
  920:  
  921:             var list0 = imsServiceWithAccessNullList.Intersect(serviceWithProvisionedTrueAndNullAccessList).ToList();
  922:             var list1 = pstnServiceList.Union(emsOntSipInfoServiceList).Union(emsVoipPstnUserServiceList).ToList();
  923:  
  924:             var list2 = list0.Except(list1).ToList();
  925:  
  926:             list = (from l in list2 where msanDomainList.Any(u => l.StartsWith(u.ToString())) select l).ToList();
  927:  
  928:             return list;
  929:         }
  930:  
  931:         ////////////////////////////////////////////////////////////////////////////
  932:         ////////////////////////////////////////////////////////////////////////////    
  933:     }
  934:  
  935:     ////////////////////////////////////////////////////////////////////////////
  936:     ////////////////////////////////////////////////////////////////////////////   
  937: }