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