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

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

Provision support class of Fixed Telecommunications Network (FTN) business model.

    1: using System;
    2: using System.Collections;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6: using System.Text.RegularExpressions;
    7: using System.Threading.Tasks;
    8:  
    9: namespace Ia.Ftn.Cl.Models.Business
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Provision support class of Fixed Telecommunications Network (FTN) business model.
   15:     /// </summary>
   16:     /// 
   17:     /// <remarks> 
   18:     /// Copyright © 2006-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     /// </remarks> 
   20:     public class Provision
   21:     {
   22:         private static int imsServiceRequestAdministrativeIssueQueueOriginalCount, axePstnServiceSuspensionQueueOriginalCount, ewsdPstnServiceSuspensionQueueOriginalCount, aperiodicQueueOriginalCount;
   23:         private static int discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueueOriginalCount;
   24:  
   25:         private static Queue<KeyValuePair<string, string>> discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue = new Queue<KeyValuePair<string, string>>();
   26:         private static Queue<string> imsServiceRequestAdministrativeIssueQueue = new Queue<string>();
   27:         private static Queue<string> axePstnServiceSuspensionQueue = new Queue<string>();
   28:         private static Queue<string> ewsdPstnServiceSuspensionQueue = new Queue<string>();
   29:         private static Queue<string> aperiodicQueue = new Queue<string>();
   30:  
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public Provision() { }
   37:  
   38:         ////////////////////////////////////////////////////////////////////////////
   39:  
   40:         /// <summary>
   41:         ///
   42:         /// </summary>
   43:         public static bool CreateReadNokiaSwitchSubscriber(Ia.Ftn.Cl.Models.Client.Nokia.Ims ims, string accessName, string service, int port, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
   44:         {
   45:             bool executed, isSip;
   46:             int gatewayId;
   47:             string r;
   48:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
   49:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
   50:             Ia.Ftn.Cl.Models.Ont ont;
   51:             Ia.Ftn.Cl.Models.Huawei.EmsOnt emsOnt;
   52:  
   53:             executed = false;
   54:             result = string.Empty;
   55:  
   56:             switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
   57:  
   58:             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
   59:             {
   60:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
   61:                 {
   62:                     nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
   63:  
   64:                     if (nddOnt != null)
   65:                     {
   66:                         if (protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd) isSip = nddOnt.Pon.PonGroup.Olt.IsSip;
   67:                         else isSip = protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.Sip;
   68:  
   69:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service) || overrideRouterDomainRestriction)
   70:                         {
   71:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
   72:  
   73:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
   74:                             {
   75:                                 ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
   76:  
   77:                                 if (ont != null)
   78:                                 {
   79:                                     if (!isSip) // if H.248
   80:                                     {
   81:                                         gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
   82:  
   83:                                         if (gatewayId > 0)
   84:                                         {
   85:                                             port = (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown) ? port : Ia.Ftn.Cl.Models.Data.Nokia.Ams.NextVacantFlatTermIdForOnt(ont.FamilyTypeId, ont);
   86:  
   87:                                             if (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown)
   88:                                             {
   89:                                                 Ia.Ftn.Cl.Models.Data.Nokia.Ims.CreateH248SubscriberAndSubPartyAndAgcfEndpoint(ims, gatewayId, service, port, nddOnt, out r);
   90:                                                 result += r + ",";
   91:  
   92:                                                 Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
   93:                                                 result += r + ",";
   94:  
   95:                                                 executed = true;
   96:                                             }
   97:                                             else
   98:                                             {
   99:                                                 result += "port is invalid or does not exist,";
  100:                                             }
  101:                                         }
  102:                                         else
  103:                                         {
  104:                                             result += "gatewayId is invalid or does not exist,";
  105:                                         }
  106:                                     }
  107:                                     else // if IsSip == true
  108:                                     {
  109:                                         result += "No procedure defined for a SIP Nokia-Nokia IMS-Access setting,";
  110:                                     }
  111:                                 }
  112:                                 else
  113:                                 {
  114:                                     result += "ONT is null for access:" + nddOnt.Access.Name + ",";
  115:                                 }
  116:                             }
  117:                             else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  118:                             {
  119:                                 emsOnt = Ia.Ftn.Cl.Models.Data.Huawei.Ont.Read(nddOnt.Id);
  120:  
  121:                                 if (emsOnt != null)
  122:                                 {
  123:                                     if (!isSip) // if H.248
  124:                                     {
  125:                                         gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
  126:  
  127:                                         if (gatewayId > 0)
  128:                                         {
  129:                                             port = (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown) ? port : Ia.Ftn.Cl.Models.Data.Default.NextVacantFlatTermIdForHuaweiEmsOntEquipmentTypeIdAndNokiaGatewayId(emsOnt.EquipmentType, gatewayId);
  130:  
  131:                                             if (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown)
  132:                                             {
  133:                                                 Ia.Ftn.Cl.Models.Data.Nokia.Ims.CreateH248SubscriberAndSubPartyAndAgcfEndpoint(ims, gatewayId, service, port, nddOnt, out r);
  134:                                                 result += r + ",";
  135:  
  136:                                                 Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
  137:                                                 result += r + ",";
  138:  
  139:                                                 executed = true;
  140:                                             }
  141:                                             else
  142:                                             {
  143:                                                 result += "port is invalid or does not exist,";
  144:                                             }
  145:                                         }
  146:                                         else
  147:                                         {
  148:                                             result += "gatewayId is invalid or does not exist,";
  149:                                         }
  150:                                     }
  151:                                     else // if IsSip == true
  152:                                     {
  153:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.CreateSipSubscriber(ims, service, nddOnt, out r);
  154:                                         result += r + ",";
  155:  
  156:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(ims, service, nddOnt, out r);
  157:                                         result += r + ",";
  158:  
  159:                                         executed = true;
  160:                                     }
  161:                                 }
  162:                                 else
  163:                                 {
  164:                                     result += "EmsOnt is null, does not exist for access:" + nddOnt.Access.Name + ",";
  165:                                 }
  166:                             }
  167:                             else
  168:                             {
  169:                                 throw new Exception("accessVendor is unknown. ");
  170:                             }
  171:                         }
  172:                         else result += "Service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
  173:                     }
  174:                     else result += "nddOnt is null, does not exist for access:" + accessName + ",";
  175:                 }
  176:                 else result += "service number does not belong to a Nokia switch.";
  177:             }
  178:             else
  179:             {
  180:                 throw new Exception("switchVendor is null or not Nokia. ");
  181:             }
  182:  
  183:             return executed;
  184:         }
  185:  
  186:         ////////////////////////////////////////////////////////////////////////////
  187:  
  188:         /// <summary>
  189:         ///
  190:         /// </summary>
  191:         public static bool DeleteReadNokiaSwitchSubscriber(Ia.Ftn.Cl.Models.Client.Nokia.Ims ims, string accessName, string service, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
  192:         {
  193:             bool executed, isSip;
  194:             int gatewayId;
  195:             string r;
  196:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
  197:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
  198:             Ia.Ftn.Cl.Models.Ont ont;
  199:  
  200:             executed = false;
  201:             result = string.Empty;
  202:  
  203:             switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
  204:  
  205:             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  206:             {
  207:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
  208:                 {
  209:                     nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
  210:  
  211:                     if (nddOnt != null)
  212:                     {
  213:                         if (protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd) isSip = nddOnt.Pon.PonGroup.Olt.IsSip;
  214:                         else isSip = protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.Sip;
  215:  
  216:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service) || overrideRouterDomainRestriction)
  217:                         {
  218:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
  219:  
  220:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  221:                             {
  222:                                 ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
  223:  
  224:                                 if (ont != null)
  225:                                 {
  226:                                     if (!isSip) // if H.248
  227:                                     {
  228:                                         gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
  229:  
  230:                                         if (gatewayId > 0)
  231:                                         {
  232:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.DeleteAgcfEndpointAndH248SubscriberAndSubParty(ims, service, nddOnt, out r);
  233:                                             result += r + ",";
  234:  
  235:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
  236:                                             result += r + ",";
  237:  
  238:                                             executed = true;
  239:                                         }
  240:                                         else
  241:                                         {
  242:                                             result += "gatewayId is invalid or does not exist,";
  243:                                         }
  244:                                     }
  245:                                     else // if IsSip == true
  246:                                     {
  247:                                         result += "No procedure defined for a SIP Nokia-Nokia IMS-Access setting,";
  248:                                     }
  249:                                 }
  250:                                 else
  251:                                 {
  252:                                     result += "ont is null for access:" + nddOnt.Access.Name + ",";
  253:                                 }
  254:                             }
  255:                             else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  256:                             {
  257:                                 if (!isSip) // if H.248
  258:                                 {
  259:                                     gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
  260:  
  261:                                     if (gatewayId > 0)
  262:                                     {
  263:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.DeleteAgcfEndpointAndH248SubscriberAndSubParty(ims, service, nddOnt, out r);
  264:                                         result += r + ",";
  265:  
  266:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
  267:                                         result += r + ",";
  268:  
  269:                                         executed = true;
  270:                                     }
  271:                                     else
  272:                                     {
  273:                                         result += "gatewayId is invalid or does not exist,";
  274:                                     }
  275:                                 }
  276:                                 else // if IsSip == true
  277:                                 {
  278:                                     Ia.Ftn.Cl.Models.Data.Nokia.Ims.DeleteSipSubscriber(ims, service, nddOnt, out r);
  279:                                     result += r + ",";
  280:  
  281:                                     Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(ims, service, nddOnt, out r);
  282:                                     result += r + ",";
  283:                                 }
  284:                             }
  285:                             else
  286:                             {
  287:                                 throw new Exception("accessVendor is unknown. ");
  288:                             }
  289:                         }
  290:                         else
  291:                         {
  292:                             result += "Service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
  293:                         }
  294:                     }
  295:                     else
  296:                     {
  297:                         result += "nddOnt is null, does not exist for access:" + accessName + ",";
  298:                     }
  299:                 }
  300:                 else result += "service number does not belong to a Nokia switch.";
  301:             }
  302:             else
  303:             {
  304:                 throw new Exception("switchVendor is null or not Nokia. ");
  305:             }
  306:  
  307:             return executed;
  308:         }
  309:  
  310:         ////////////////////////////////////////////////////////////////////////////
  311:         ////////////////////////////////////////////////////////////////////////////
  312:  
  313:         /// <summary>
  314:         ///
  315:         /// </summary>
  316:         public static bool DeleteReadNokiaSwitchAgcfEndpointAndH248SubscriberFromAnyFsdb(Ia.Ftn.Cl.Models.Client.Nokia.Ims ims, string service, out string result)
  317:         {
  318:             bool executed;
  319:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
  320:  
  321:             executed = false;
  322:             result = string.Empty;
  323:  
  324:             if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  325:             {
  326:                 switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
  327:  
  328:                 if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  329:                 {
  330:                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
  331:                     {
  332:                         foreach (Ia.Ftn.Cl.Models.Business.Nokia.Ims.ImsBasicService ibs in Ia.Ftn.Cl.Models.Business.Nokia.Ims.ImsBasicServiceList)
  333:                         {
  334:                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.DeleteAgcfEndpointAndH248SubscriberAndSubParty(ims, service, ibs.PrimarySwitch, ibs.Fsdb, out string r);
  335:                             result += r + ",";
  336:  
  337:                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadSubPartyAndSubscriber(ims, service, ibs.PrimarySwitch, ibs.Fsdb, ibs.Service, out r);
  338:                             result += r + ",";
  339:                         }
  340:  
  341:                         executed = true;
  342:                     }
  343:                     else result += "Error: service number does not belong to a valid Nokia switch. ";
  344:                 }
  345:                 else result += "Error: switchVendor is null or not Nokia. ";
  346:             }
  347:             else result += "Error: service \"" + service + "\" does not belong to the network.";
  348:  
  349:             return executed;
  350:         }
  351:  
  352:         ////////////////////////////////////////////////////////////////////////////
  353:         ////////////////////////////////////////////////////////////////////////////
  354:  
  355:         /// <summary>
  356:         ///
  357:         /// </summary>
  358:         public static bool ModifyReadNokiaSwitchSubscriberH248ToSip(Ia.Ftn.Cl.Models.Client.Nokia.Ims ims, string service, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt, out string result)
  359:         {
  360:             bool executed;
  361:             int gatewayId;
  362:             string r;
  363:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
  364:             Ia.Ftn.Cl.Models.Ont ont;
  365:             Ia.Ftn.Cl.Models.Huawei.EmsOnt emsOnt;
  366:  
  367:             executed = false;
  368:             result = string.Empty;
  369:  
  370:             switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
  371:  
  372:             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  373:             {
  374:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
  375:                 {
  376:                     if (nddOnt != null)
  377:                     {
  378:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service))
  379:                         {
  380:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
  381:  
  382:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  383:                             {
  384:                                 ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
  385:  
  386:                                 if (ont != null)
  387:                                 {
  388:                                     if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
  389:                                     {
  390:                                         gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
  391:  
  392:                                         if (gatewayId > 0)
  393:                                         {
  394:                                             //Ia.Ftn.Cl.Model.Data.Nokia.Ims.Modify248SubscriberAndSubPartyAndAgcfEndpointToSip(ims, gatewayId, service, nddOnt, out r);
  395:                                             //result += r + ",";
  396:  
  397:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
  398:                                             result += r + ",";
  399:  
  400:                                             executed = true;
  401:                                         }
  402:                                         else
  403:                                         {
  404:                                             result += "gatewayId is invalid or does not exist,";
  405:                                         }
  406:                                     }
  407:                                     else // if IsSip == true
  408:                                     {
  409:                                         result += "error: OLT is already SIP,";
  410:                                     }
  411:                                 }
  412:                                 else
  413:                                 {
  414:                                     result += "ONT is null for access:" + nddOnt.Access.Name + ",";
  415:                                 }
  416:                             }
  417:                             else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  418:                             {
  419:                                 emsOnt = Ia.Ftn.Cl.Models.Data.Huawei.Ont.Read(nddOnt.Id);
  420:  
  421:                                 if (emsOnt != null)
  422:                                 {
  423:                                     if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
  424:                                     {
  425:                                         gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
  426:  
  427:                                         if (gatewayId > 0)
  428:                                         {
  429:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.Modify248SubscriberAndSubPartyAndDeleteAgcfEndpointToSip(ims, service, nddOnt, out r);
  430:                                             result += r + ",";
  431:  
  432:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(ims, gatewayId, out r);
  433:                                             result += r + ",";
  434:  
  435:                                             executed = true;
  436:                                         }
  437:                                         else
  438:                                         {
  439:                                             result += "gatewayId is invalid or does not exist,";
  440:                                         }
  441:                                     }
  442:                                     else // if IsSip == true
  443:                                     {
  444:                                         result += "error: OLT is already SIP,";
  445:                                     }
  446:                                 }
  447:                                 else
  448:                                 {
  449:                                     result += "EmsOnt is null, does not exist for access:" + nddOnt.Access.Name + ",";
  450:                                 }
  451:                             }
  452:                             else
  453:                             {
  454:                                 throw new Exception("accessVendor is unknown. ");
  455:                             }
  456:                         }
  457:                         else
  458:                         {
  459:                             result += "Service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
  460:                         }
  461:                     }
  462:                     else
  463:                     {
  464:                         result += "nddOnt is null,";
  465:                     }
  466:                 }
  467:                 else result += "service number does not belong to a Nokia switch.";
  468:             }
  469:             else
  470:             {
  471:                 throw new Exception("switchVendor is null or not Nokia. ");
  472:             }
  473:  
  474:             return executed;
  475:         }
  476:  
  477:         ////////////////////////////////////////////////////////////////////////////
  478:         ////////////////////////////////////////////////////////////////////////////
  479:  
  480:         /// <summary>
  481:         ///
  482:         /// </summary>
  483:         public static bool CreateReadHuaweiSwitchSubscriber(Ia.Ftn.Cl.Models.Client.Huawei.Ims ims, string accessName, string service, int port, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
  484:         {
  485:             bool executed, created, isSip;
  486:             string r;
  487:             Ia.Ftn.Cl.Models.Business.Huawei.Default.FnSnPnPort fnSnPnPort;
  488:             Ia.Ftn.Cl.Models.Business.Huawei.Dev.MduDev mdu;
  489:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
  490:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
  491:             Ia.Ftn.Cl.Models.Huawei.EmsOnt emsOnt;
  492:             Ia.Ftn.Cl.Models.Ont ont;
  493:  
  494:             executed = false;
  495:             result = string.Empty;
  496:  
  497:             switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
  498:  
  499:             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  500:             {
  501:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service))
  502:                 {
  503:                     nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
  504:  
  505:                     if (nddOnt != null)
  506:                     {
  507:                         if (protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd) isSip = nddOnt.Pon.PonGroup.Olt.IsSip;
  508:                         else isSip = protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.Sip;
  509:  
  510:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service) || overrideRouterDomainRestriction)
  511:                         {
  512:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
  513:  
  514:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  515:                             {
  516:                                 ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
  517:  
  518:                                 if (ont != null)
  519:                                 {
  520:                                     if (isSip) // if SIP
  521:                                     {
  522:                                         result += "No procedure defined for a SIP Huawei-Nokia IMS-Access setting,";
  523:                                     }
  524:                                     else // if fsSip == false
  525:                                     {
  526:                                         port = (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown) ? port : Ia.Ftn.Cl.Models.Data.Nokia.Ams.NextVacantFlatTermIdForOnt(ont.FamilyTypeId, ont);
  527:  
  528:                                         if (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown)
  529:                                         {
  530:                                             Ia.Ftn.Cl.Models.Data.Huawei.Ims.CreateSubscriber(ims, service, out r);
  531:                                             result += r + ",";
  532:  
  533:                                             Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadSbrForService(ims, service, out r);
  534:                                             result += r + ",";
  535:  
  536:                                             // other commands will be issued through NCE NBI to configure H.248 in SKB and TEC softswitch
  537:  
  538:                                             executed = true;
  539:                                         }
  540:                                         else
  541:                                         {
  542:                                             result += "Port is invalid or does not exist,";
  543:                                         }
  544:                                     }
  545:                                 }
  546:                                 else
  547:                                 {
  548:                                     result += "Ont is null, does not exist for access:" + nddOnt.Access.Name + ",";
  549:                                 }
  550:                             }
  551:                             else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  552:                             {
  553:                                 emsOnt = Ia.Ftn.Cl.Models.Data.Huawei.Ont.Read(nddOnt.Id);
  554:  
  555:                                 if (emsOnt != null)
  556:                                 {
  557:                                     if (isSip)
  558:                                     {
  559:                                         if (emsOnt.FamilyType == Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Mdu)
  560:                                         {
  561:                                             var accessNameToMduDevDictionary = Ia.Ftn.Cl.Models.Data.Huawei.Default.AccessNameToMduDevDictionary;
  562:  
  563:                                             if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
  564:                                             {
  565:                                                 var pn = port;
  566:  
  567:                                                 mdu = accessNameToMduDevDictionary[nddOnt.Access.Name];
  568:  
  569:                                                 var vacantFnSnPnList = Ia.Ftn.Cl.Models.Data.Huawei.Ems.VacantMduFnSnPnForOntList(mdu, emsOnt);
  570:  
  571:                                                 if (pn != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown) fnSnPnPort = vacantFnSnPnList.Where(f => f.Pn == pn).SingleOrDefault();
  572:                                                 else fnSnPnPort = Ia.Ftn.Cl.Models.Data.Huawei.Ems.NextVacantMduFnSnPnForOnt(mdu, emsOnt);
  573:  
  574:                                                 if (fnSnPnPort != null)
  575:                                                 {
  576:                                                     port = (port < 0) ? fnSnPnPort.Pn : port;
  577:  
  578:                                                     created = Ia.Ftn.Cl.Models.Data.Huawei.Ims.CreateSubscriber(ims, service, out r);
  579:  
  580:                                                     result += r + ",";
  581:                                                 }
  582:                                                 else result += "MDU sn and/or tel is invalid or does not exist. ";
  583:                                             }
  584:                                             else result += "emsOnt.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service: " + service + ", and access: " + nddOnt.Access.Name;
  585:                                         }
  586:                                         else // if not MDU
  587:                                         {
  588:                                             port = (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown) ? port : Ia.Ftn.Cl.Models.Data.Huawei.Ems.NextVacantTelForOnt(emsOnt);
  589:  
  590:                                             if (port != Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown)
  591:                                             {
  592:                                                 created = Ia.Ftn.Cl.Models.Data.Huawei.Ims.CreateSubscriber(ims, service, out r);
  593:  
  594:                                                 result += r + ",";
  595:                                             }
  596:                                             else result += "Port is invalid or does not exist,";
  597:                                         }
  598:                                     }
  599:                                     else // if H.248
  600:                                     {
  601:                                         result += "No procedure defined for an H.248 non-SIP Huawei-Huawei IMS-Access setting,";
  602:                                     }
  603:                                 }
  604:                                 else
  605:                                 {
  606:                                     result += "emsOnt is null, does not exist for access:" + nddOnt.Access.Name + ",";
  607:                                 }
  608:  
  609:                                 Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(ims, service, nddOnt.Access.Id, out r);
  610:                                 result += r + ",";
  611:                             }
  612:                             else
  613:                             {
  614:                                 throw new Exception("accessVendor is unknown. ");
  615:                             }
  616:                         }
  617:                         else
  618:                         {
  619:                             result += "Service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
  620:                         }
  621:                     }
  622:                     else
  623:                     {
  624:                         Ia.Ftn.Cl.Models.Data.Huawei.Ims.CreateSubscriber(ims, service, out r);
  625:                         result += r + ",";
  626:  
  627:                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadSbrForService(ims, service, out r);
  628:                         result += r + ",";
  629:  
  630:                         executed = true;
  631:                     }
  632:                 }
  633:                 else result += "service number does not belong to a Huawei switch.";
  634:             }
  635:             else
  636:             {
  637:                 throw new Exception("switchVendor is null or not Huawei. ");
  638:             }
  639:  
  640:             return executed;
  641:         }
  642:  
  643:         ////////////////////////////////////////////////////////////////////////////
  644:  
  645:         /// <summary>
  646:         ///
  647:         /// </summary>
  648:         public static bool DeleteReadHuaweiSwitchSubscriber(Ia.Ftn.Cl.Models.Client.Huawei.Ims ims, string accessName, string service, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
  649:         {
  650:             bool executed, isSip;
  651:             string r;
  652:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
  653:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
  654:             Ia.Ftn.Cl.Models.Ont ont;
  655:  
  656:             executed = false;
  657:             result = string.Empty;
  658:  
  659:             switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
  660:  
  661:             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  662:             {
  663:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service))
  664:                 {
  665:                     nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
  666:  
  667:                     if (nddOnt != null)
  668:                     {
  669:                         if (protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd) isSip = nddOnt.Pon.PonGroup.Olt.IsSip;
  670:                         else isSip = protocol == Ia.Ftn.Cl.Models.Business.Default.Protocol.Sip;
  671:  
  672:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service) || overrideRouterDomainRestriction)
  673:                         {
  674:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
  675:  
  676:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
  677:                             {
  678:                                 ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
  679:  
  680:                                 if (ont != null)
  681:                                 {
  682:                                     if (isSip)
  683:                                     {
  684:                                         result += "No procedure defined for a SIP Huawei-Nokia IMS-Access setting,";
  685:                                     }
  686:                                     else // if H.248
  687:                                     {
  688:                                         Ia.Ftn.Cl.Models.Data.Huawei.Ims.DeleteSubscriber(ims, service, out r);
  689:                                         result += r + ",";
  690:  
  691:                                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(ims, service, nddOnt.Access.Id, out r);
  692:                                         result += r + ",";
  693:  
  694:                                         // other commands will be issued through NCE NBI to configure H.248 in SKB and TEC softswitch
  695:                                     }
  696:                                 }
  697:                                 else
  698:                                 {
  699:                                     result += "ont is null,";
  700:                                 }
  701:                             }
  702:                             else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
  703:                             {
  704:                                 if (isSip)
  705:                                 {
  706:                                     Ia.Ftn.Cl.Models.Data.Huawei.Ims.DeleteSubscriber(ims, service, out r);
  707:                                     result += r + ",";
  708:  
  709:                                     Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(ims, service, nddOnt.Access.Id, out r);
  710:                                     result += r + ",";
  711:                                 }
  712:                                 else // if H.248
  713:                                 {
  714:                                     result += "No procedure defined for an H.248 non-SIP Huawei-Huawei IMS-Access setting,";
  715:                                 }
  716:                             }
  717:                             else
  718:                             {
  719:                                 throw new Exception("accessVendor is unknown. ");
  720:                             }
  721:                         }
  722:                         else
  723:                         {
  724:                             result += "Service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
  725:                         }
  726:                     }
  727:                     else
  728:                     {
  729:                         Ia.Ftn.Cl.Models.Data.Huawei.Ims.DeleteSubscriber(ims, service, out r);
  730:                         result += r + ",";
  731:  
  732:                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(ims, service, string.Empty, out r);
  733:                         result += r + ",";
  734:                     }
  735:                 }
  736:                 else result += "service number does not belong to a Huawei switch.";
  737:             }
  738:             else
  739:             {
  740:                 throw new Exception("switchVendor is null or not Huawei. ");
  741:             }
  742:  
  743:             return executed;
  744:         }
  745:  
  746:         ////////////////////////////////////////////////////////////////////////////
  747:         ////////////////////////////////////////////////////////////////////////////
  748:  
  749:         /// <summary>
  750:         ///
  751:         /// </summary>
  752:         public static string ImsServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceListItem(out int serviceRequestAdministrativeIssueQueueCount, out string progressCounterString)
  753:         {
  754:             string service;
  755:  
  756:             if (imsServiceRequestAdministrativeIssueQueue.Count == 0)
  757:             {
  758:                 imsServiceRequestAdministrativeIssueQueue = new Queue<string>(Ia.Ftn.Cl.Models.Data.Provision.ImsServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList());
  759:  
  760:                 imsServiceRequestAdministrativeIssueQueueOriginalCount = imsServiceRequestAdministrativeIssueQueue.Count;
  761:             }
  762:  
  763:             if (imsServiceRequestAdministrativeIssueQueue.Count > 0) service = imsServiceRequestAdministrativeIssueQueue.Dequeue();
  764:             else service = null;
  765:  
  766:             progressCounterString = "(" + imsServiceRequestAdministrativeIssueQueue.Count + "/" + imsServiceRequestAdministrativeIssueQueueOriginalCount + ") ";
  767:  
  768:             serviceRequestAdministrativeIssueQueueCount = imsServiceRequestAdministrativeIssueQueue.Count;
  769:  
  770:             return service;
  771:         }
  772:  
  773:         /*
  774:         ////////////////////////////////////////////////////////////////////////////
  775: 
  776:         /// <summary>
  777:         ///
  778:         /// </summary>
  779:         public static string SequentialEricssonAxePstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(out int serviceSuspensionQueueCount, out string result)
  780:         {
  781:             string service;
  782: 
  783:             if (axePstnServiceSuspensionQueue.Count == 0)
  784:             {
  785:                 axePstnServiceSuspensionQueue = new Queue<string>(Ia.Ftn.Cl.Model.Data.Provision.EricssonAxePstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList());
  786: 
  787:                 axePstnServiceSuspensionQueueOriginalCount = axePstnServiceSuspensionQueue.Count;
  788:             }
  789: 
  790:             if (axePstnServiceSuspensionQueue.Count > 0) service = axePstnServiceSuspensionQueue.Dequeue();
  791:             else service = null;
  792: 
  793:             result = "(" + axePstnServiceSuspensionQueue.Count + "/" + axePstnServiceSuspensionQueueOriginalCount + ") ";
  794: 
  795:             serviceSuspensionQueueCount = axePstnServiceSuspensionQueue.Count;
  796: 
  797:             return service;
  798:         }
  799: 
  800:         ////////////////////////////////////////////////////////////////////////////
  801: 
  802:         /// <summary>
  803:         ///
  804:         /// </summary>
  805:         public static string SequentialSiemensEwsdPstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList(out int serviceSuspensionQueueCount, out string result)
  806:         {
  807:             string service;
  808: 
  809:             if (ewsdPstnServiceSuspensionQueue.Count == 0)
  810:             {
  811:                 ewsdPstnServiceSuspensionQueue = new Queue<string>(Ia.Ftn.Cl.Model.Data.Provision.SiemensEwsdPstnServiceSuspensionMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceList());
  812: 
  813:                 ewsdPstnServiceSuspensionQueueOriginalCount = ewsdPstnServiceSuspensionQueue.Count;
  814:             }
  815: 
  816:             if (ewsdPstnServiceSuspensionQueue.Count > 0) service = ewsdPstnServiceSuspensionQueue.Dequeue();
  817:             else service = null;
  818: 
  819:             result = "(" + ewsdPstnServiceSuspensionQueue.Count + "/" + ewsdPstnServiceSuspensionQueueOriginalCount + ") ";
  820: 
  821:             serviceSuspensionQueueCount = ewsdPstnServiceSuspensionQueue.Count;
  822: 
  823:             return service;
  824:         }
  825:         */
  826:  
  827:         ////////////////////////////////////////////////////////////////////////////
  828:         ////////////////////////////////////////////////////////////////////////////
  829:  
  830:         /// <summary>
  831:         ///
  832:         /// </summary>
  833:         public static KeyValuePair<string, string> DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceItem(Ia.Ftn.Cl.Models.Business.Default.Procedure procedure, out int discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceQueueCount, out string progressCounterString)
  834:         {
  835:             return DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceItem(procedure, 0, out discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceQueueCount, out progressCounterString);
  836:         }
  837:  
  838:         ////////////////////////////////////////////////////////////////////////////
  839:  
  840:         /// <summary>
  841:         ///
  842:         /// </summary>
  843:         public static KeyValuePair<string, string> DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceItem(Ia.Ftn.Cl.Models.Business.Default.Procedure procedure, int provisionWithinLastNDays, out int discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceServiceIdQueueCount, out string progressCounterString)
  844:         {
  845:             KeyValuePair<string, string> serviceIdAccessId;
  846:  
  847:             if (discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Count == 0 && procedure == Ia.Ftn.Cl.Models.Business.Default.Procedure.InitializeOrIterate)
  848:             {
  849:                 var dictionary1 = DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceServiceIdAccessIdDictionary(provisionWithinLastNDays);
  850:                 var dictionary2 = DiscrepancyBetweenServiceRequestServiceAndServiceServiceIdDictionary(provisionWithinLastNDays);
  851:  
  852:                 var dictionary = new Dictionary<string, string>();
  853:  
  854:                 foreach (var kvp in dictionary1) dictionary[kvp.Key] = kvp.Value;
  855:  
  856:                 foreach (var kvp in dictionary2)
  857:                 {
  858:                     if (!dictionary.ContainsKey(kvp.Key))
  859:                     {
  860:                         dictionary[kvp.Key] = kvp.Value;
  861:                     }
  862:                 }
  863:  
  864:                 discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue = new Queue<KeyValuePair<string, string>>(dictionary);
  865:  
  866:                 discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueueOriginalCount = discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Count;
  867:             }
  868:  
  869:             if (discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Count > 0) serviceIdAccessId = discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Dequeue();
  870:             else serviceIdAccessId = new KeyValuePair<string, string>();
  871:  
  872:             progressCounterString = "(" + discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Count + "/" + discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueueOriginalCount + ")";
  873:  
  874:             discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceServiceIdQueueCount = discrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceQueue.Count;
  875:  
  876:             return serviceIdAccessId;
  877:         }
  878:  
  879:         ////////////////////////////////////////////////////////////////////////////
  880:  
  881:         /// <summary>
  882:         ///
  883:         /// </summary>
  884:         public static Dictionary<string, string> DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceServiceIdAccessIdDictionary(int provisionWithinLastNDays)
  885:         {
  886:             Ia.Ftn.Cl.Models.Data.Provision.ServiceToUpdateServiceIdAccessIdDictionary_ServiceToCreateServiceIdAccessIdDictionary_ServiceToDeleteServiceIdAccessIdDictionary(provisionWithinLastNDays, out Dictionary<string, string> serviceToUpdateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToCreateServiceIdAccessIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdAccessIdDictionary);
  887:  
  888:             var dictionary = new Dictionary<string, string>();
  889:  
  890:             foreach (KeyValuePair<string, string> s in serviceToUpdateServiceIdAccessIdDictionary) dictionary.Add(s.Key, s.Value);
  891:             foreach (KeyValuePair<string, string> s in serviceToCreateServiceIdAccessIdDictionary) dictionary.Add(s.Key, s.Value);
  892:             foreach (KeyValuePair<string, string> s in serviceToDeleteServiceIdAccessIdDictionary) dictionary.Add(s.Key, s.Value);
  893:  
  894:             return dictionary;
  895:         }
  896:  
  897:         ////////////////////////////////////////////////////////////////////////////
  898:  
  899:         /// <summary>
  900:         ///
  901:         /// </summary>
  902:         public static Dictionary<string, string> DiscrepancyBetweenServiceRequestServiceAndServiceServiceIdDictionary(int provisionWithinLastNDays)
  903:         {
  904:             Ia.Ftn.Cl.Models.Data.Provision.ServiceToCreateServiceIdDictionary_ServiceToDeleteServiceIdDictionary(provisionWithinLastNDays, out Dictionary<string, string> serviceToCreateServiceIdDictionary, out Dictionary<string, string> serviceToDeleteServiceIdDictionary);
  905:  
  906:             var dictionary = new Dictionary<string, string>();
  907:  
  908:             foreach (KeyValuePair<string, string> s in serviceToCreateServiceIdDictionary) dictionary.Add(s.Key, s.Value);
  909:             foreach (KeyValuePair<string, string> s in serviceToDeleteServiceIdDictionary) dictionary.Add(s.Key, s.Value);
  910:  
  911:             //return dictionary.Where(u => u.Key.StartsWith("2390")).ToDictionary(u => u.Key, u => u.Value); // to work with || s.Name == "RKK"
  912:             return dictionary;
  913:         }
  914:  
  915:         ////////////////////////////////////////////////////////////////////////////
  916:  
  917:         /// <summary>
  918:         ///
  919:         /// </summary>
  920:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> ServiceOntToCreateAndToDeleteInEmsOntSipInfoOrVoipPstnUserListFromThePastNHourList(int provisioningWithinPastNHours, List<string> priorityServiceList)
  921:         {
  922:             DateTime pastNHoursDateTime;
  923:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList, laterProcessList;
  924:  
  925:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
  926:             laterProcessList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
  927:  
  928:             pastNHoursDateTime = (provisioningWithinPastNHours > 0) ? DateTime.UtcNow.AddHours(3).AddHours(-provisioningWithinPastNHours) : DateTime.MinValue;
  929:  
  930:             Ia.Ftn.Cl.Models.Business.Provision.ServiceOntToCreateInEmsOntSipInfoOrVoipPstnUserList_ServiceOntToAnnulInEmsOntSipInfoOrVoipPstnUserList(out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList, out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList);
  931:  
  932:             foreach (var serviceOnt in serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList)
  933:             {
  934:                 if (serviceOnt.CreatedDateTime >= pastNHoursDateTime || priorityServiceList.Contains(serviceOnt.Service))
  935:                 {
  936:                     var p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Create, DateTime = serviceOnt.CreatedDateTime };
  937:                     processList.Add(p);
  938:  
  939:                     p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime };
  940:                     processList.Add(p);
  941:                     laterProcessList.Add(p);
  942:                 }
  943:             }
  944:  
  945:             foreach (var serviceOnt in serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList)
  946:             {
  947:                 if (serviceOnt.CreatedDateTime >= pastNHoursDateTime || priorityServiceList.Contains(serviceOnt.Service))
  948:                 {
  949:                     var p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Delete, DateTime = serviceOnt.CreatedDateTime };
  950:                     processList.Add(p);
  951:  
  952:                     p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime };
  953:                     processList.Add(p);
  954:                     laterProcessList.Add(p);
  955:                 }
  956:             }
  957:  
  958:             processList = processList.OrderByDescending(l => l.DateTime).ToList();
  959:  
  960:             processList.AddRange(laterProcessList);
  961:  
  962:             return processList;
  963:         }
  964:  
  965:         ////////////////////////////////////////////////////////////////////////////
  966:  
  967:         /// <summary>
  968:         ///
  969:         /// </summary>
  970:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> _ServiceOntToCreateAndToDeleteInEmsOntSipInfoOrVoipPstnUserListFromThePastNHourList(int provisioningWithinPastNHours, List<string> priorityServiceList)
  971:         {
  972:             DateTime pastNHoursDateTime;
  973:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList, laterProcessList;
  974:  
  975:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
  976:             laterProcessList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
  977:  
  978:             pastNHoursDateTime = (provisioningWithinPastNHours > 0) ? DateTime.UtcNow.AddHours(3).AddHours(-provisioningWithinPastNHours) : DateTime.MinValue;
  979:  
  980:             /*
  981:             Ia.Ftn.Cl.Model.Business.Provision.ServiceOntToCreateInEmsOntSipInfoOrVoipPstnUserList_ServiceOntToAnnulInEmsOntSipInfoOrVoipPstnUserList(out List<Ia.Ftn.Cl.Model.Business.ServiceAccessIpOntCreated> serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList, out List<Ia.Ftn.Cl.Model.Business.ServiceAccessIpOntCreated> serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList);
  982: 
  983:             foreach (var serviceOnt in serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList)
  984:             {
  985:                 if (serviceOnt.CreatedDateTime >= pastNHoursDateTime || priorityServiceList.Contains(serviceOnt.Service))
  986:                 {
  987:                     var p = new Ia.Ftn.Cl.Model.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Model.Business.Procedure.ProcessType.Create, DateTime = serviceOnt.CreatedDateTime };
  988:                     processList.Add(p);
  989: 
  990:                     p = new Ia.Ftn.Cl.Model.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Model.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime };
  991:                     processList.Add(p);
  992:                     laterProcessList.Add(p);
  993:                 }
  994:             }
  995: 
  996:             foreach (var serviceOnt in serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList)
  997:             {
  998:                 if (serviceOnt.CreatedDateTime >= pastNHoursDateTime || priorityServiceList.Contains(serviceOnt.Service))
  999:                 {
 1000:                     var p = new Ia.Ftn.Cl.Model.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Model.Business.Procedure.ProcessType.Delete, DateTime = serviceOnt.CreatedDateTime };
 1001:                     processList.Add(p);
 1002: 
 1003:                     p = new Ia.Ftn.Cl.Model.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Model.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime };
 1004:                     processList.Add(p);
 1005:                     laterProcessList.Add(p);
 1006:                 }
 1007:             }
 1008: 
 1009:             processList = processList.OrderByDescending(l => l.DateTime).ToList();
 1010: 
 1011:             processList.AddRange(laterProcessList);
 1012:             */
 1013:  
 1014:             return processList;
 1015:         }
 1016:  
 1017:         ////////////////////////////////////////////////////////////////////////////
 1018:  
 1019:         /// <summary>
 1020:         ///
 1021:         /// </summary>
 1022:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> MsanServiceEmsVoipPstnUserDidFnSnPnDnToDeleteBecauseItHasProvisionedImsServiceOrHasNoEquivalentInServiceList()
 1023:         {
 1024:             string dn;
 1025:             List<string> serviceExemptionList;
 1026:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList, laterProcessList;
 1027:  
 1028:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1029:             laterProcessList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1030:  
 1031:             var list1 = Ia.Ftn.Cl.Models.Business.Provision.MsanServicesThatHaveProvisionedImsServiceExceptWhereEmsOntSipInfoEmsOntIsOfflineOrDeviceOfflineErrorAndExceptWhereEmsVoipPstnUserEmsDevHasDeviceOfflineErrorAndIgnoringNonSipNokiaOntList();
 1032:             var list2 = Ia.Ftn.Cl.Models.Business.Provision.MsanServiceInVoipPstnUserThatHaveNoEquivalentInServiceList();
 1033:  
 1034:             var list = list1.Union(list2).ToList();
 1035:  
 1036:             // will exclude exempt numbers
 1037:             serviceExemptionList = Ia.Ftn.Cl.Models.Data.Provision.ServiceOfServiceExemptFromProvisionProcessingList();
 1038:  
 1039:             foreach (string service in serviceExemptionList) list.Remove(service);
 1040:  
 1041:             var voipPstnUserDidFnSnPnDnMsanList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.DidFnSnPnDnMsanList();
 1042:  
 1043:             foreach (var service in list)
 1044:             {
 1045:                 dn = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.ImpuAid(service);
 1046:  
 1047:                 var voipPstnUserDidFnSnPnDnMsan = (from vpudfspdm in voipPstnUserDidFnSnPnDnMsanList
 1048:                                                    where vpudfspdm.Dn == dn
 1049:                                                    select vpudfspdm).FirstOrDefault();
 1050:  
 1051:                 if (voipPstnUserDidFnSnPnDnMsan != null)
 1052:                 {
 1053:                     var p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = service, EmsVoipPstnUserDidFnSnPnDn = voipPstnUserDidFnSnPnDnMsan, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Delete };
 1054:                     processList.Add(p);
 1055:  
 1056:                     p = new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = service, EmsVoipPstnUserDidFnSnPnDn = voipPstnUserDidFnSnPnDnMsan, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read };
 1057:                     processList.Add(p);
 1058:                     laterProcessList.Add(p);
 1059:                 }
 1060:             }
 1061:  
 1062:             processList = processList.OrderByDescending(l => l.DateTime).ToList();
 1063:  
 1064:             processList.AddRange(laterProcessList);
 1065:  
 1066:             return processList;
 1067:         }
 1068:  
 1069:         ////////////////////////////////////////////////////////////////////////////
 1070:  
 1071:         /// <summary>
 1072:         ///
 1073:         /// </summary>
 1074:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> ServiceOntToAddAndToRemoveInAsbrList()
 1075:         {
 1076:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList;
 1077:  
 1078:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1079:  
 1080:             Ia.Ftn.Cl.Models.Business.Provision.ServiceOntToAddToAsbrList_ServiceOntToRemoveFromAsbrList(out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToAddToAsbrList, out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToRemoveFromAsbrList);
 1081:  
 1082:             // issue read, execute, then read again commands
 1083:             foreach (var serviceOnt in serviceOntToAddToAsbrList)
 1084:             {
 1085:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Create, DateTime = serviceOnt.CreatedDateTime });
 1086:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime });
 1087:             }
 1088:  
 1089:             foreach (var serviceOnt in serviceOntToRemoveFromAsbrList)
 1090:             {
 1091:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Delete, DateTime = serviceOnt.CreatedDateTime });
 1092:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { ServiceId = serviceOnt.ServiceId, Service = serviceOnt.Service, Ont = serviceOnt.Ont, Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read, DateTime = serviceOnt.CreatedDateTime });
 1093:             }
 1094:  
 1095:             return processList;
 1096:         }
 1097:  
 1098:         ////////////////////////////////////////////////////////////////////////////
 1099:  
 1100:         /// <summary>
 1101:         /// Find the provisioned services within SIP OLTs that do not have equivalent OntSipInfo or VoipPstnUser records, and all OntSipInfo and VoipPstnUser records that do note have equivalent services within SIP OLTs.
 1102:         /// </summary>
 1103:         private static void ServiceOntToCreateInEmsOntSipInfoOrVoipPstnUserList_ServiceOntToAnnulInEmsOntSipInfoOrVoipPstnUserList(out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList, out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList)
 1104:         {
 1105:             Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated serviceOnt2;
 1106:             List<string> serviceIdExemptionList;
 1107:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntList, serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList;
 1108:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ontSipInfoServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList, voipPstnUserServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList;
 1109:  
 1110:             serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
 1111:             serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
 1112:  
 1113:             serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList = Ia.Ftn.Cl.Models.Data.Service2.ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList;
 1114:             serviceOntList = Ia.Ftn.Cl.Models.Data.Service2.ServiceOntList;
 1115:             ontSipInfoServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList = Ia.Ftn.Cl.Models.Data.Huawei.OntSipInfo.ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList();
 1116:             voipPstnUserServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList();
 1117:  
 1118:             foreach (var serviceOnt in serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList)
 1119:             {
 1120:                 if (!ontSipInfoServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId)
 1121:                     && !voipPstnUserServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId))
 1122:                 {
 1123:                     if (!serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1124:                     {
 1125:                         serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList.Add(serviceOnt);
 1126:                     }
 1127:                 }
 1128:             }
 1129:  
 1130:  
 1131:             // In serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList I must make sure that serviceId does not belong to any current service in serviceOntList
 1132:             // this is to allow NCE and POTS to Access migration without interruption or feedback from the vendor. Any number deleted from IMS will be deleted from NCE.
 1133:  
 1134:             foreach (var ontSipInfoServiceOnt in ontSipInfoServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList)
 1135:             {
 1136:                 if (!serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == ontSipInfoServiceOnt.ServiceId && u.AccessId == ontSipInfoServiceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1137:                 {
 1138:                     if (!serviceOntList.Any(u => u.ServiceId == ontSipInfoServiceOnt.ServiceId /*&& u.AccessId == serviceOnt.AccessId*/)) // .Contains(serviceOnt) is disastrous here
 1139:                     {
 1140:                         if (!serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Any(u => u.ServiceId == ontSipInfoServiceOnt.ServiceId && u.AccessId == ontSipInfoServiceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1141:                         {
 1142:                             serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Add(ontSipInfoServiceOnt);
 1143:                         }
 1144:                     }
 1145:                 }
 1146:                 /*
 1147:                 else if (serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == ontSipInfoServiceOnt.ServiceId && u.CreatedDateTime > ontSipInfoServiceOnt.CreatedDateTime))
 1148:                 {
 1149:                     // below: we will check for and add all NCE records that were created *before* the IMS records
 1150: 
 1151:                     if (!serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Any(u => u.ServiceId == ontSipInfoServiceOnt.ServiceId))
 1152:                     {
 1153:                         serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Add(ontSipInfoServiceOnt);
 1154:                     }
 1155:                 }
 1156:                 */
 1157:             }
 1158:  
 1159:             foreach (var voipPstnUserServiceOnt in voipPstnUserServiceOntWithinAllowedToBeProvisionedOrMigratedSipOltList)
 1160:             {
 1161:                 if (!serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == voipPstnUserServiceOnt.ServiceId && u.AccessId == voipPstnUserServiceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1162:                 {
 1163:                     if (!serviceOntList.Any(u => u.ServiceId == voipPstnUserServiceOnt.ServiceId /*&& u.AccessId == serviceOnt.AccessId*/)) // .Contains(serviceOnt) is disastrous here
 1164:                     {
 1165:                         if (!serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Any(u => u.ServiceId == voipPstnUserServiceOnt.ServiceId && u.AccessId == voipPstnUserServiceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1166:                         {
 1167:                             serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Add(voipPstnUserServiceOnt);
 1168:                         }
 1169:                     }
 1170:                 }
 1171:                 /*
 1172:                 else if (serviceOntWithinAllowedToBeProvisionedOrMigratedSipOltList.Any(u => u.ServiceId == voipPstnUserServiceOnt.ServiceId && u.CreatedDateTime > voipPstnUserServiceOnt.CreatedDateTime))
 1173:                 {
 1174:                     // below: we will check for and add all NCE records that were created *before* the IMS records
 1175: 
 1176:                     if (!serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Any(u => u.ServiceId == voipPstnUserServiceOnt.ServiceId))
 1177:                     {
 1178:                         serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Add(voipPstnUserServiceOnt);
 1179:                     }
 1180:                 }
 1181:                 */
 1182:             }
 1183:  
 1184:             // will exclude exempt numbers
 1185:             serviceIdExemptionList = Ia.Ftn.Cl.Models.Data.Provision.ServiceIdOfServiceExemptFromProvisionProcessingList();
 1186:             foreach (string serviceId in serviceIdExemptionList)
 1187:             {
 1188:                 serviceOnt2 = serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList.SingleOrDefault(u => u.ServiceId == serviceId);
 1189:                 if (serviceOnt2 != null) serviceOntToCreateInEmsOntSipInfoOrVoipPstnUserList.Remove(serviceOnt2);
 1190:  
 1191:                 serviceOnt2 = serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.SingleOrDefault(u => u.ServiceId == serviceId);
 1192:                 if (serviceOnt2 != null) serviceOntToAnnulInEmsOntSipInfoOrVoipPstnUseList.Remove(serviceOnt2);
 1193:             }
 1194:         }
 1195:  
 1196:         ////////////////////////////////////////////////////////////////////////////
 1197:  
 1198:         /// <summary>
 1199:         ///
 1200:         /// </summary>
 1201:         public static List<string> MsanServicesThatHaveProvisionedImsServiceExceptWhereEmsOntSipInfoEmsOntIsOfflineOrDeviceOfflineErrorAndExceptWhereEmsVoipPstnUserEmsDevHasDeviceOfflineErrorAndIgnoringNonSipNokiaOntList()
 1202:         {
 1203:             var serviceList = Ia.Ftn.Cl.Models.Data.Service2.ImsServiceInAllowedToBeMigratedOltList;
 1204:             var msanServiceList = Ia.Ftn.Cl.Models.Data.Service2.MsanServiceList;
 1205:  
 1206:             var serviceWhereEmsOntIsOfflineList = Ia.Ftn.Cl.Models.Data.Huawei.OntSipInfo.ServiceWithinEmsOntSipInfoWhereEmsOntResultCodeOntIsOfflineOrDeviceOfflineErrorList();
 1207:             var serviceWhereEmsDevDeviceOfflineError = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.ServiceWithinEmsVoipPstnUserWhereEmsDevResultCodeDeviceOfflineError();
 1208:  
 1209:             //var serviceWhereOntIsOfflineList = Ia.Ftn.Cl.Model.Data.Nokia.Ont.ServiceWhereOntIsOfflineList();
 1210:  
 1211:             var list = msanServiceList.Intersect(serviceList).ToList();
 1212:  
 1213:             list = list.Except(serviceWhereEmsOntIsOfflineList).ToList();
 1214:             list = list.Except(serviceWhereEmsDevDeviceOfflineError).ToList();
 1215:  
 1216:             return list;
 1217:         }
 1218:  
 1219:         ////////////////////////////////////////////////////////////////////////////
 1220:  
 1221:         /// <summary>
 1222:         ///
 1223:         /// </summary>
 1224:         public static List<string> MsanServiceInVoipPstnUserThatHaveNoEquivalentInServiceList()
 1225:         {
 1226:             List<string> list;
 1227:  
 1228:             var serviceList = Ia.Ftn.Cl.Models.Data.Service2.ServiceList;
 1229:             var msanServiceList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.MsanServiceList;
 1230:  
 1231:             list = msanServiceList.Except(serviceList).ToList();
 1232:  
 1233:             return list;
 1234:         }
 1235:  
 1236:         ////////////////////////////////////////////////////////////////////////////
 1237:  
 1238:         /// <summary>
 1239:         ///
 1240:         /// </summary>
 1241:         public static void ServiceOntToAddToAsbrList_ServiceOntToRemoveFromAsbrList(out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> addList, out List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> removeList)
 1242:         {
 1243:             Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated serviceOnt2;
 1244:             List<string> serviceIdExemptionList;
 1245:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> serviceOntList, serviceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList;
 1246:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> asbrServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList;
 1247:  
 1248:             addList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
 1249:             removeList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
 1250:  
 1251:             //List<string> list;
 1252:  
 1253:             /*
 1254: select s.Service from Service2 s
 1255: inner join ServiceRequestServices srs on s.Id = srs.Id
 1256: inner join Accesses a on a.Id = srs.Access_Id
 1257: inner join Sbrs sb on 'sip:+965'+ s.Service +'@ims.moc.kw' = sb.IMPU
 1258: left outer join Asbrs asb on sb.IMPU = asb.PUI
 1259: where (a.Olt = 102010101 or a.Olt = 102010201) -- OLT ids MUB:102010101 QRN:102010201
 1260: and srs.Provisioned = 1
 1261: and asb.Id is null
 1262: order by s.Service
 1263:              */
 1264:  
 1265:             /*
 1266:             // for oltId intersect AllowedToBeMigrated with Hu-No OLTs
 1267:             var oltIdList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.HuaweiSwitchNokiaAccessOltIdList;
 1268: 
 1269:             //var i = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 1270: 
 1271:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1272:             {
 1273:                 var list = (from s in db.Service2s
 1274:                             join srs in db.ServiceRequestServices on s.Id equals srs.Id
 1275:                             join a in db.Accesses on srs.Access.Id equals a.Id
 1276:                             //join sbr in db.Sbrs on "sip:+965" + s.Service + "@ims.moc.kw" equals sbr.IMPU
 1277:                             //join asbr in db.Asbrs on sbr.IMPU equals asbr.PUI into gj
 1278:                             //from u in gj.DefaultIfEmpty()
 1279:                             where oltIdList.Contains(a.Olt) && srs.Provisioned == true //&& u == null
 1280:                             orderby s.Service
 1281:                             select new { s.Service, AccessId = a.Id }).ToList();
 1282: 
 1283:                 //var l = (from a in list select i[a.AccessId]).Distinct().ToList();
 1284:                 var l = (from a in list select a.AccessId).Distinct().ToList();
 1285:             }
 1286: 
 1287: 
 1288:             //return list;
 1289:             */
 1290:  
 1291:             serviceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList = Ia.Ftn.Cl.Models.Data.Service2.ServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList();
 1292:             serviceOntList = Ia.Ftn.Cl.Models.Data.Service2.ServiceOntList;
 1293:             asbrServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList = Ia.Ftn.Cl.Models.Data.Huawei.Asbr.ServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList();
 1294:  
 1295:             foreach (var serviceOnt in serviceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList)
 1296:             {
 1297:                 if (!asbrServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId))
 1298:                 {
 1299:                     if (!addList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1300:                     {
 1301:                         addList.Add(serviceOnt);
 1302:                     }
 1303:                 }
 1304:             }
 1305:  
 1306:             foreach (var serviceOnt in asbrServiceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList)
 1307:             {
 1308:                 if (!serviceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1309:                 {
 1310:                     if (!serviceOntList.Any(u => u.ServiceId == serviceOnt.ServiceId /*&& u.AccessId == serviceOnt.AccessId*/)) // .Contains(serviceOnt) is disastrous here
 1311:                     {
 1312:                         if (!removeList.Any(u => u.ServiceId == serviceOnt.ServiceId && u.AccessId == serviceOnt.AccessId)) // .Contains(serviceOnt) is disastrous here
 1313:                         {
 1314:                             removeList.Add(serviceOnt);
 1315:                         }
 1316:                     }
 1317:                 }
 1318:                 else if (serviceOntWithinAllowedToBeProvisionedOrMigratedHuaweiSwitchNokiaAccessOltList.Any(u => u.ServiceId == serviceOnt.ServiceId /*&& u.AccessId == serviceOnt.AccessId*/ && u.CreatedDateTime > serviceOnt.CreatedDateTime))
 1319:                 {
 1320:                     // below: we will check for and add all NCE records that were created *before* the IMS records
 1321:  
 1322:                     if (!removeList.Any(u => u.ServiceId == serviceOnt.ServiceId /*&& u.AccessId == serviceOnt.AccessId*/))
 1323:                     {
 1324:                         removeList.Add(serviceOnt);
 1325:                     }
 1326:                 }
 1327:             }
 1328:  
 1329:             // will exclude exempt numbers
 1330:             serviceIdExemptionList = Ia.Ftn.Cl.Models.Data.Provision.ServiceIdOfServiceExemptFromProvisionProcessingList();
 1331:             foreach (string serviceId in serviceIdExemptionList)
 1332:             {
 1333:                 serviceOnt2 = addList.SingleOrDefault(u => u.ServiceId == serviceId);
 1334:                 if (serviceOnt2 != null) addList.Remove(serviceOnt2);
 1335:  
 1336:                 serviceOnt2 = removeList.SingleOrDefault(u => u.ServiceId == serviceId);
 1337:                 if (serviceOnt2 != null) removeList.Remove(serviceOnt2);
 1338:             }
 1339:         }
 1340:  
 1341:         /*
 1342:         ////////////////////////////////////////////////////////////////////////////
 1343:         ////////////////////////////////////////////////////////////////////////////
 1344: 
 1345:         /// <summary>
 1346:         ///
 1347:         /// </summary>
 1348:         public static List<string> ServiceSuspendedInServiceRequestServiceButNotInServiceStringNumberList
 1349:         {
 1350:             get
 1351:             {
 1352:                 List<string> list, sList, srsList;
 1353:                 SortedList sl;
 1354: 
 1355:                 sList = Ia.Ftn.Cl.Model.Data.Service2.ServiceSuspensionIsTrueStringNumberList;
 1356:                 srsList = Ia.Ftn.Cl.Model.Data.ServiceRequestService.ServiceSuspensionIsTrueAndProvisionedIsTrueStringNumberList;
 1357: 
 1358:                 if (sList != null && sList.Count > 0)
 1359:                 {
 1360:                     if (srsList != null && srsList.Count > 0)
 1361:                     {
 1362:                         list = new List<string>(sList.Count);
 1363: 
 1364:                         sl = new SortedList(sList.ToDictionary(s => s));
 1365: 
 1366:                         foreach (string s in srsList)
 1367:                         {
 1368:                             if (!sl.ContainsKey(s)) list.Add(s);
 1369:                         }
 1370:                     }
 1371:                     else
 1372:                     {
 1373:                         list = new List<string>();
 1374:                     }
 1375:                 }
 1376:                 else
 1377:                 {
 1378:                     if (srsList != null && srsList.Count > 0) list = sList;
 1379:                     else list = new List<string>();
 1380:                 }
 1381: 
 1382:                 return list;
 1383:             }
 1384:         }
 1385:         */
 1386:  
 1387:         /*
 1388:         ////////////////////////////////////////////////////////////////////////////
 1389: 
 1390:         /// <summary>
 1391:         ///
 1392:         /// </summary>
 1393:         public static List<string> ServiceActiveInServiceRequestServiceButNotInServiceStringNumberList
 1394:         {
 1395:             get
 1396:             {
 1397:                 List<string> list, sList, srsList;
 1398:                 SortedList sl;
 1399: 
 1400:                 sList = Ia.Ftn.Cl.Model.Data.Service2.ServiceSuspensionIsFalseStringNumberList;
 1401:                 srsList = Ia.Ftn.Cl.Model.Data.ServiceRequestService.ServiceSuspensionIsFalseStringNumberList;
 1402: 
 1403:                 if (sList != null && sList.Count > 0)
 1404:                 {
 1405:                     if (srsList != null && srsList.Count > 0)
 1406:                     {
 1407:                         list = new List<string>(sList.Count);
 1408: 
 1409:                         sl = new SortedList(sList.ToDictionary(s => s));
 1410: 
 1411:                         foreach (string s in srsList)
 1412:                         {
 1413:                             if (!sl.ContainsKey(s)) list.Add(s);
 1414:                         }
 1415:                     }
 1416:                     else
 1417:                     {
 1418:                         list = new List<string>();
 1419:                     }
 1420:                 }
 1421:                 else
 1422:                 {
 1423:                     if (srsList != null && srsList.Count > 0) list = sList;
 1424:                     else list = new List<string>();
 1425:                 }
 1426: 
 1427:                 return list;
 1428:             }
 1429:         }
 1430:         */
 1431:  
 1432:         ////////////////////////////////////////////////////////////////////////////
 1433:  
 1434:         /// <summary>
 1435:         ///
 1436:         /// </summary>
 1437:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> EmsOntToBeUpdatedFromH248ToSipList()
 1438:         {
 1439:             List<string> oltSymbolList;
 1440:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList;
 1441:  
 1442:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1443:  
 1444:             oltSymbolList = Ia.Ftn.Cl.Models.Business.Default.H248ToSipUpdateOltSymbolList;
 1445:  
 1446:             var list = Ia.Ftn.Cl.Models.Data.Default.DistinctNddOntWhereVaprofIsNotAluSipBAndIgnoreMduForOltSymbolListList(oltSymbolList);
 1447:  
 1448:             foreach (var l in list)
 1449:             {
 1450:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Ont = l.Ont, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Update });
 1451:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Ont = l.Ont, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read });
 1452:             }
 1453:  
 1454:             return processList;
 1455:         }
 1456:  
 1457:         ////////////////////////////////////////////////////////////////////////////
 1458:  
 1459:         /// <summary>
 1460:         ///
 1461:         /// </summary>
 1462:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> OntSipInfoOrOntVoipPstnUserToBeCreatedForAnOntUpdatedFromH248ToSipList()
 1463:         {
 1464:             int pn;
 1465:             List<string> oltSymbolList;
 1466:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList;
 1467:  
 1468:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1469:  
 1470:             oltSymbolList = Ia.Ftn.Cl.Models.Business.Default.H248ToSipUpdateOltSymbolList;
 1471:  
 1472:             var list = Ia.Ftn.Cl.Models.Data.Default.ServiceAndNddOntAndEmsOntFamilyTypeAndPortWhereAgcfEndpointPortIsNot0AndVaprofIsAluSipBAndSfuEmsOntSipInfoTelDoesNotExistOrMduEmsVagIsSipAndMduEmsVoipPstnUserPnDoesNotExistForOltSymbolListList(oltSymbolList);
 1473:  
 1474:             /*
 1475:              * All Nokia ONTs (SFUs and MDUs) start at port position 1.
 1476:              * Huawei ONTs (SFUs) start at port position 1, while Huawei MDUs start at port position 0.
 1477:              */
 1478:  
 1479:             // issue update then read commands
 1480:             foreach (var l in list)
 1481:             {
 1482:                 if (l.EmsOntFamilyType == Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Sfu)
 1483:                 {
 1484:                     processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, EmsOntFamilyType = Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Sfu, Port = l.Port, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Update });
 1485:                     processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, EmsOntFamilyType = Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Sfu, Port = l.Port, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read });
 1486:                 }
 1487:                 else if (l.EmsOntFamilyType == Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Mdu)
 1488:                 {
 1489:                     pn = Ia.Ftn.Cl.Models.Business.Service.ConvertFlatTermIdPositionToEmsVoipPstnUsersPn(l.Port);
 1490:  
 1491:                     processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, EmsOntFamilyType = Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Mdu, Port = pn, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Update });
 1492:                     processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, EmsOntFamilyType = Ia.Ftn.Cl.Models.Business.Huawei.Ont.FamilyType.Mdu, Port = pn, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read });
 1493:                 }
 1494:                 else
 1495:                 {
 1496:                     throw new Exception("EmsOntFamilyType is not concedered. ");
 1497:                 }
 1498:             }
 1499:  
 1500:             return processList;
 1501:         }
 1502:  
 1503:         ////////////////////////////////////////////////////////////////////////////
 1504:  
 1505:         /// <summary>
 1506:         ///
 1507:         /// </summary>
 1508:         public static List<Ia.Ftn.Cl.Models.Business.Procedure.Process> NokiaImsSubscriberToBeUpdatedFromH248ToSipList()
 1509:         {
 1510:             List<string> oltSymbolList;
 1511:             List<Ia.Ftn.Cl.Models.Business.Procedure.Process> processList;
 1512:  
 1513:             processList = new List<Ia.Ftn.Cl.Models.Business.Procedure.Process>();
 1514:  
 1515:             oltSymbolList = Ia.Ftn.Cl.Models.Business.Default.H248ToSipUpdateOltSymbolList;
 1516:  
 1517:             var list = Ia.Ftn.Cl.Models.Data.Default.ServiceAndNddOntWherePrimaryPuidcpeProfileNumberIsNot10AndEmsOntVaprofIsAluSipBAndSfuEmsOntSipInfoTelExistsOrAndMduEmsOntVagIsSipAndMduEmsVoipPstnUserPnExistsForOltSymbolListList(oltSymbolList);
 1518:  
 1519:             // issue delete then create commands
 1520:             foreach (var l in list)
 1521:             {
 1522:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, Protocol = Ia.Ftn.Cl.Models.Business.Default.Protocol.H248, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.DeleteRead });
 1523:  
 1524:                 processList.Add(new Ia.Ftn.Cl.Models.Business.Procedure.Process { Service = l.Service, Ont = l.Ont, Protocol = Ia.Ftn.Cl.Models.Business.Default.Protocol.Sip, Type = Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.CreateRead });
 1525:             }
 1526:  
 1527:             return processList;
 1528:         }
 1529:  
 1530:         ////////////////////////////////////////////////////////////////////////////    
 1531:         ////////////////////////////////////////////////////////////////////////////    
 1532:  
 1533:         /// <summary>
 1534:         ///
 1535:         /// </summary>
 1536:         public static void ReadService(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms, string input, out Ia.Cl.Models.Result result)
 1537:         {
 1538:             int gatewayId, port;
 1539:             long number;
 1540:             string partyId, r;
 1541:             string accessId, service;
 1542:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1543:             Ia.Ftn.Cl.Models.Service2 service2;
 1544:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor, accessVendor;
 1545:  
 1546:             result = new Ia.Cl.Models.Result();
 1547:  
 1548:             if (!string.IsNullOrEmpty(input))
 1549:             {
 1550:                 input = input.Trim();
 1551:                 //input = input.ToLower();
 1552:  
 1553:                 number = long.Parse(input);
 1554:  
 1555:                 if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
 1556:                 {
 1557:                     service = number.ToString();
 1558:  
 1559:                     result.AddSuccess("Service: " + service + " ");
 1560:  
 1561:                     /*
 1562:                      * Note that in find.aspx (Ia.Ftn.Cl.Model.Ui.Default) I actually hide access name if port is undefined.
 1563:                      * case "service2AccessNameHyperLink":
 1564:                      * {
 1565:                      *   if (service2.AccessName != null && service2.Port != Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
 1566:                      *   {
 1567:                      *     hl.Text = service2.AccessName;
 1568:                      *     hl.NavigateUrl = Ia.Ftn.Cl.Model.Business.Maintenance.Find.Url(service2.AccessName);
 1569:                      *   }
 1570:                      *   break;
 1571:                      * }
 1572: 
 1573:                      */
 1574:  
 1575:                     Ia.Ftn.Cl.Models.Data.Service.AccessIdAndPortByService(service, out accessId, out port);
 1576:  
 1577:                     // below: I should remove the whole section within if(){} below
 1578:                     if (string.IsNullOrEmpty(accessId))
 1579:                     {
 1580:                         var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
 1581:                         var serviceId = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, serviceType);
 1582:  
 1583:                         // attempt a read from Service2
 1584:                         service2 = Ia.Ftn.Cl.Models.Data.Service2.ReadByIdIncludeAccess(serviceId);
 1585:  
 1586:                         if (service2 != null && service2.Access != null) accessId = service2.Access.Id;
 1587:                         else
 1588:                         {
 1589:                             // attempt a read from ServiceRequestService
 1590:                             var serviceRequestService = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ReadIncludeAccess(serviceId);
 1591:  
 1592:                             if (serviceRequestService != null && serviceRequestService.Access != null) accessId = serviceRequestService.Access.Id;
 1593:                             else accessId = string.Empty;
 1594:                         }
 1595:                     }
 1596:  
 1597:                     if (!string.IsNullOrEmpty(accessId))
 1598:                     {
 1599:                         // get service information using accessId
 1600:  
 1601:                         nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(accessId);
 1602:  
 1603:                         if (nddOnt != null)
 1604:                         {
 1605:                             switchVendor = nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor;
 1606:                             accessVendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
 1607:  
 1608:                             try
 1609:                             {
 1610:                                 if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1611:                                 {
 1612:                                     partyId = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PartyId(service);
 1613:                                     gatewayId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromPartyId(partyId);
 1614:  
 1615:                                     if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1616:                                     {
 1617:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
 1618:                                         {
 1619:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gatewayId, out r);
 1620:  
 1621:                                             result.AddSuccess(r);
 1622:                                         }
 1623:                                         else // if IsSip == true
 1624:                                         {
 1625:                                             result.AddSuccess("SIP process is undefined for No/No");
 1626:                                         }
 1627:                                     }
 1628:                                     else if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1629:                                     {
 1630:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
 1631:                                         {
 1632:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gatewayId, out r);
 1633:                                         }
 1634:                                         else // if IsSip == true
 1635:                                         {
 1636:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, nddOnt, out r);
 1637:                                         }
 1638:  
 1639:                                         result.AddSuccess(r);
 1640:                                     }
 1641:                                     else throw new Exception("AccessVendor is undefined");
 1642:                                 }
 1643:                                 else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1644:                                 {
 1645:                                     Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadSbrForService(huaweiIms, service, out string readHuaweiResult);
 1646:  
 1647:                                     result.AddSuccess(readHuaweiResult);
 1648:  
 1649:                                     if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia || accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1650:                                     {
 1651:                                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, accessId, out r);
 1652:  
 1653:                                         result.AddSuccess(r);
 1654:                                     }
 1655:                                     else throw new Exception("accessVendor is undefined");
 1656:                                 }
 1657:                                 else throw new Exception("switchVendor is undefined");
 1658:                             }
 1659:                             catch (Exception ex)
 1660:                             {
 1661:                                 result.AddError("Exception: " + ex.ToString());
 1662:                             }
 1663:                         }
 1664:                         else result.AddError("NDD ONT is null, does not exist for service: " + service);
 1665:                     }
 1666:                     else
 1667:                     {
 1668:                         // get service without knowing accessId
 1669:  
 1670:                         if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
 1671:                         {
 1672:                             /*
 1673:                             partyId = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.PartyId(service);
 1674:                             gatewayId = Ia.Ftn.Cl.Model.Data.Nokia.AgcfGatewayRecord.GwIdFromPartyId(partyId);
 1675: 
 1676:                             Ia.Ftn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gatewayId, out r);
 1677:                             Ia.Ftn.Cl.Model.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, null, out r);
 1678:                             */
 1679:  
 1680:                             result.AddError("(Service2 is null or service.Access is null) and (serviceRequestService is null or serviceRequestService.Access is null) and (number is not within allowed Huawei switch domain list) for service: " + service);
 1681:                         }
 1682:                         else if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service))
 1683:                         {
 1684:                             Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, string.Empty, out r);
 1685:  
 1686:                             result.AddSuccess(r);
 1687:                         }
 1688:                         else
 1689:                         {
 1690:                             throw new Exception("switchVendor is undefined");
 1691:                         }
 1692:                     }
 1693:  
 1694:                     // this is a sensitive issue. later I will allow storing empty accessId
 1695:                     Ia.Ftn.Cl.Models.Data.Service.AccessIdAndPortByService(service, out accessId, out port);
 1696:  
 1697:                     //if (!string.IsNullOrEmpty(accessId))
 1698:                     //{
 1699:                     Ia.Ftn.Cl.Models.Data.Service2.UpdateImsServiceAccessAndPort(service, accessId, port, string.Empty, out Ia.Cl.Models.Result updateServiceAccessResult);
 1700:  
 1701:                     result.AddResult(updateServiceAccessResult);
 1702:                     //}
 1703:                 }
 1704:                 else result.AddError("Number \"" + number + "\" does not belong to the network.");
 1705:             }
 1706:             else result.AddError("No input was entered.");
 1707:         }
 1708:  
 1709:         ////////////////////////////////////////////////////////////////////////////    
 1710:  
 1711:         /// <summary>
 1712:         ///
 1713:         /// </summary>
 1714:         public static void UpdateReadSupplementaryService(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms, string input, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService supplementaryService, bool supplementaryServiceState, out Ia.Cl.Models.Result result)
 1715:         {
 1716:             long number;
 1717:             string r, r0, r2;
 1718:             string accessId, service;
 1719:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1720:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
 1721:  
 1722:             result = new Ia.Cl.Models.Result();
 1723:  
 1724:             if (!string.IsNullOrEmpty(input))
 1725:             {
 1726:                 input = input.Trim();
 1727:                 //input = input.ToLower();
 1728:  
 1729:                 number = long.Parse(input);
 1730:  
 1731:                 if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
 1732:                 {
 1733:                     service = number.ToString();
 1734:  
 1735:                     switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
 1736:  
 1737:                     result.AddSuccess("Service: " + service + " ");
 1738:  
 1739:                     Ia.Ftn.Cl.Models.Data.Service.AccessIdAndPortByService(service, out accessId, out int port);
 1740:  
 1741:                     if (!string.IsNullOrEmpty(accessId))
 1742:                     {
 1743:                         nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(accessId) ? Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary[accessId] : null;
 1744:  
 1745:                         if (nddOnt != null)
 1746:                         {
 1747:                             switchVendor = nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor;
 1748:  
 1749:                             try
 1750:                             {
 1751:                                 if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1752:                                 {
 1753:                                     Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, supplementaryService, supplementaryServiceState, out r);
 1754:  
 1755:                                     result.AddSuccess(r);
 1756:  
 1757:                                     if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
 1758:                                     {
 1759:                                         var gwId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
 1760:  
 1761:                                         if (gwId > 0)
 1762:                                         {
 1763:                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms/*, sNddOnt*/, gwId, out r2);
 1764:                                         }
 1765:                                         else
 1766:                                         {
 1767:                                             r2 = "gwId: zero";
 1768:                                         }
 1769:                                     }
 1770:                                     else // if IsSip == true
 1771:                                     {
 1772:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, nddOnt, out r2);
 1773:                                     }
 1774:  
 1775:                                     result.AddSuccess("updated:" + r + ", read:" + r2);
 1776:                                 }
 1777:                                 else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1778:                                 {
 1779:                                     Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, supplementaryService, supplementaryServiceState, out r);
 1780:  
 1781:                                     Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, string.Empty, out r2);
 1782:  
 1783:                                     result.AddSuccess("updated:" + r + ", read:" + r2);
 1784:                                 }
 1785:                                 else
 1786:                                 {
 1787:                                     throw new Exception("switchVendor is undefined.");
 1788:                                 }
 1789:                             }
 1790:                             catch (Exception ex)
 1791:                             {
 1792:                                 result.AddError("Exception: " + ex.ToString());
 1793:                             }
 1794:                         }
 1795:                         else result.AddError("NDD ONT is null, does not exist for service: " + service);
 1796:                     }
 1797:                     else
 1798:                     {
 1799:                         if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1800:                         {
 1801:                             Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, supplementaryService, supplementaryServiceState, out r);
 1802:  
 1803:                             Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, string.Empty, out r2);
 1804:  
 1805:                             result.AddSuccess("updated:" + r + ", read:" + r2);
 1806:                         }
 1807:                         else
 1808:                         {
 1809:                             result.AddError("AccessId is null and switchVendor is not Huawei for service: " + service);
 1810:                         }
 1811:                     }
 1812:                 }
 1813:                 else result.AddError("Number \"" + number + "\" does not belong to the network");
 1814:             }
 1815:             else result.AddError("No input was entered");
 1816:         }
 1817:  
 1818:         ////////////////////////////////////////////////////////////////////////////
 1819:  
 1820:         /// <summary>
 1821:         ///
 1822:         /// </summary>
 1823:         public static Ia.Cl.Models.Result ManageServiceProvisioning(Ia.Ftn.Cl.Models.Business.Default.Procedure procedure, Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms)
 1824:         {
 1825:             int number;
 1826:             string r0, r1, r2, r3, service;
 1827:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1828:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
 1829:  
 1830:             r0 = r1 = r2 = r3 = string.Empty;
 1831:             var result = new Ia.Cl.Models.Result();
 1832:  
 1833:             var kvp = Ia.Ftn.Cl.Models.Business.Provision.DiscrepancyAndComplementaryServiceMismatchBetweenServiceRequestServiceAndServiceItem(procedure, out int serviceQueueCount, out string progressCounterString);
 1834:  
 1835:             var serviceId = kvp.Key;
 1836:  
 1837:             var serviceRequestAdministrativeIssueType = Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.ServiceRequestAdministrativeIssueTypeByDisconnectionType(Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.DisconnectionType.None);
 1838:  
 1839:             if (!string.IsNullOrEmpty(serviceId))
 1840:             {
 1841:                 var synchronized = false;
 1842:  
 1843:                 r0 = "service: " + serviceId.Replace(":1:965", "") + " " + progressCounterString + ": ";
 1844:  
 1845:                 service = Ia.Ftn.Cl.Models.Business.Service.ServiceIdToService(serviceId);
 1846:  
 1847:                 if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
 1848:                 {
 1849:                     var service2 = Ia.Ftn.Cl.Models.Data.Service2.ReadByIdIncludeAccess(serviceId);
 1850:                     var serviceRequestService = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ReadIncludeAccess(serviceId);
 1851:  
 1852:                     try
 1853:                     {
 1854:                         if (serviceRequestService != null)
 1855:                         {
 1856:                             service = serviceRequestService.Service;
 1857:  
 1858:                             if (serviceRequestService.Provisioned)
 1859:                             {
 1860:                                 if (int.TryParse(service, out number))
 1861:                                 {
 1862:                                     switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
 1863:  
 1864:                                     if (service2 == null)
 1865:                                     {
 1866:                                         // create service
 1867:                                         r0 += "create: ";
 1868:  
 1869:                                         nddOnt = (serviceRequestService.Access != null) ? Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(serviceRequestService.Access.Id) : null;
 1870:  
 1871:                                         if (nddOnt != null)
 1872:                                         {
 1873:                                             if (Ia.Ftn.Cl.Models.Business.Service.OltIsWithinAllowedToBeProvisionedOltList(nddOnt.Pon.PonGroup.Olt))
 1874:                                             {
 1875:                                                 if (switchVendor == nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor)
 1876:                                                 {
 1877:                                                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service))
 1878:                                                     {
 1879:                                                         if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1880:                                                         {
 1881:                                                             r0 += "Nokia: ";
 1882:  
 1883:                                                             // make sure the number is not suspended before creating it
 1884:                                                             Ia.Ftn.Cl.Models.Data.ServiceRequestAdministrativeIssue.Update(service, serviceRequestAdministrativeIssueType, false, out _);
 1885:  
 1886:                                                             Ia.Ftn.Cl.Models.Business.Provision.CreateReadNokiaSwitchSubscriber(nokiaIms, nddOnt.Access.Name, service, Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 1887:  
 1888:                                                             synchronized = true;
 1889:  
 1890:                                                             r0 += r1 + ",";
 1891:                                                         }
 1892:                                                         else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1893:                                                         {
 1894:                                                             r0 += "Huawei: ";
 1895:  
 1896:                                                             // make sure the number is not suspend before creating it
 1897:                                                             Ia.Ftn.Cl.Models.Data.ServiceRequestAdministrativeIssue.Update(service, serviceRequestAdministrativeIssueType, false, out _);
 1898:  
 1899:                                                             // I will completely remove any existing number before installing it again to make sure it installs fresh
 1900:                                                             // maybe I shouldn't
 1901:                                                             // Ia.Ftn.Cl.Model.Business.Provision.DeleteReadHuaweiSwitchSubscriber(huaweiIms, nddOnt.Access.Name, service, Ia.Ftn.Cl.Model.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 1902:  
 1903:                                                             Ia.Ftn.Cl.Models.Business.Provision.CreateReadHuaweiSwitchSubscriber(huaweiIms, nddOnt.Access.Name, service, Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r2);
 1904:  
 1905:                                                             synchronized = true;
 1906:  
 1907:                                                             r0 += r1 + "," + r2 + ",";
 1908:                                                         }
 1909:                                                         else
 1910:                                                         {
 1911:                                                             throw new Exception("switchVendor is undefined.");
 1912:                                                         }
 1913:                                                     }
 1914:                                                     else r0 += "service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
 1915:                                                 }
 1916:                                                 else r0 += "switchVendor of service " + service + " is not equal to switch vendor of access " + nddOnt.Access.Name + ".";
 1917:                                             }
 1918:                                             else r0 += "Access is not in an allowed to be provisioned OLT. ";
 1919:                                         }
 1920:                                         else
 1921:                                         {
 1922:                                             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1923:                                             {
 1924:                                                 // see above
 1925:                                                 r0 += "Huawei: ";
 1926:  
 1927:                                                 // make sure the number is not suspend before creating it
 1928:                                                 Ia.Ftn.Cl.Models.Data.ServiceRequestAdministrativeIssue.Update(service, serviceRequestAdministrativeIssueType, false, out _);
 1929:  
 1930:                                                 // I will completely remove any existing number before installing it again to make sure it installs fresh
 1931:                                                 // maybe I shouldn't
 1932:                                                 //Ia.Ftn.Cl.Model.Business.Provision.DeleteReadHuaweiSwitchSubscriber(huaweiIms, string.Empty, service, Ia.Ftn.Cl.Model.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 1933:  
 1934:                                                 Ia.Ftn.Cl.Models.Business.Provision.CreateReadHuaweiSwitchSubscriber(huaweiIms, string.Empty, service, Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r2);
 1935:  
 1936:                                                 synchronized = true;
 1937:  
 1938:                                                 //r0 += r4.Message + "," + r1 + "," + r2 + ","; too much info
 1939:                                                 r0 += r2 + ",";
 1940:                                             }
 1941:                                             else r0 += "serviceNddOnt is null and switchVendor is not Huawei. ";
 1942:                                         }
 1943:                                     }
 1944:                                     else
 1945:                                     {
 1946:                                         // update service
 1947:                                         r0 += "update: ";
 1948:  
 1949:                                         if (service2.Access != null) nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(service2.Access.Id);
 1950:                                         else if (serviceRequestService.Access != null) nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(serviceRequestService.Access.Id);
 1951:                                         else nddOnt = null;
 1952:  
 1953:                                         if (nddOnt != null)
 1954:                                         {
 1955:                                             if (Ia.Ftn.Cl.Models.Business.Service.OltIsWithinAllowedToBeProvisionedOltList(nddOnt.Pon.PonGroup.Olt))
 1956:                                             {
 1957:                                                 if (switchVendor == nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor)
 1958:                                                 {
 1959:                                                     // To make things easier, I will skip checking for NumberIsWithinAllowedRouterDomainList in updates because it is already checked when the number is installed
 1960:                                                     //if (Ia.Ftn.Cl.Model.Business.Service.NumberIsWithinAllowedRouterDomainList(nddOnt, service))
 1961:                                                     //{
 1962:                                                     r0 += "service: ";
 1963:  
 1964:                                                     if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1965:                                                     {
 1966:                                                         r0 += "Nokia: ";
 1967:  
 1968:                                                         // below: send change command to IMS
 1969:                                                         if (service2.CallerId != serviceRequestService.CallerId) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallerId, serviceRequestService.CallerId, out r2);
 1970:                                                         else if (service2.CallForwarding != serviceRequestService.CallForwarding) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallForwarding, serviceRequestService.CallForwarding, out r2);
 1971:                                                         else if (service2.ConferenceCall != serviceRequestService.ConferenceCall) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.ConferenceCall, serviceRequestService.ConferenceCall, out r2);
 1972:                                                         else if (service2.AlarmCall != serviceRequestService.AlarmCall) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.AlarmCall, out r2); // do not change
 1973:                                                         else if (service2.WakeupCall != serviceRequestService.WakeupCall) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.WakeupCall, out r2);
 1974:                                                         else if (service2.AbbriviatedCalling != serviceRequestService.AbbriviatedCalling) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.AbbriviatedCalling, serviceRequestService.AbbriviatedCalling, out r2);
 1975:                                                         else if (service2.InternationalCalling != serviceRequestService.InternationalCalling) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, serviceRequestService.InternationalCalling, out r2);
 1976:                                                         else if (service2.InternationalCallingUserControlled != serviceRequestService.InternationalCallingUserControlled) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCallingUserControlled, serviceRequestService.InternationalCallingUserControlled, out r2);
 1977:  
 1978:                                                         // below: CallWaiting is not provisioned for PBX keys. It is placed last in the execution logic so that it does not prevention the flow of logic to other services
 1979:                                                         else if (service2.CallWaiting != serviceRequestService.CallWaiting) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallWaiting, serviceRequestService.CallWaiting, out r2);
 1980:  
 1981:                                                         //else if (Ia.Ftn.Cl.Model.Business.Administration.ServiceSuspensionIsEnabled && service2.ServiceSuspension != serviceRequestService.CallBarring) Ia.Ftn.Cl.Model.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.ServiceSuspension, serviceRequestService.CallBarring, out r2);
 1982:                                                         else r2 = "no difference in services. ";
 1983:  
 1984:                                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
 1985:                                                         {
 1986:                                                             var gwId = Ia.Ftn.Cl.Models.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
 1987:  
 1988:                                                             if (gwId > 0)
 1989:                                                             {
 1990:                                                                 Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms/*, sNddOnt*/, gwId, out r3);
 1991:  
 1992:                                                                 r0 += r2 + "," + r3 + ",";
 1993:                                                             }
 1994:                                                             else r0 += "gwId: 0," + r2 + "," + r3 + ",";
 1995:                                                         }
 1996:                                                         else // if IsSip == true
 1997:                                                         {
 1998:                                                             Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, nddOnt, out r3);
 1999:  
 2000:                                                             r0 += r2 + "," + r3 + ",";
 2001:                                                         }
 2002:                                                     }
 2003:                                                     else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2004:                                                     {
 2005:                                                         r0 += "Huawei: ";
 2006:  
 2007:                                                         // See below
 2008:                                                         if (service2.CallerId != serviceRequestService.CallerId) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallerId, serviceRequestService.CallerId, out r2);
 2009:                                                         else if (service2.CallForwarding != serviceRequestService.CallForwarding) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallForwarding, serviceRequestService.CallForwarding, out r2);
 2010:                                                         else if (service2.CallWaiting != serviceRequestService.CallWaiting) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallWaiting, serviceRequestService.CallWaiting, out r2);
 2011:                                                         else if (service2.ConferenceCall != serviceRequestService.ConferenceCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.ConferenceCall, serviceRequestService.ConferenceCall, out r2);
 2012:                                                         else if (service2.AlarmCall != serviceRequestService.AlarmCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.AlarmCall, out r2); // do not change
 2013:                                                         else if (service2.WakeupCall != serviceRequestService.WakeupCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.WakeupCall, out r2);
 2014:                                                         else if (service2.AbbriviatedCalling != serviceRequestService.AbbriviatedCalling) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.AbbriviatedCalling, serviceRequestService.AbbriviatedCalling, out r2);
 2015:                                                         else if (service2.InternationalCalling != serviceRequestService.InternationalCalling) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, serviceRequestService.InternationalCalling, out r2);
 2016:                                                         else if (service2.InternationalCallingUserControlled != serviceRequestService.InternationalCallingUserControlled) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCallingUserControlled, serviceRequestService.InternationalCallingUserControlled, out r2);
 2017:  
 2018:                                                         //else if (Ia.Ftn.Cl.Model.Business.Administration.ServiceSuspensionIsEnabled && service2.ServiceSuspension != serviceRequestService.CallBarring) Ia.Ftn.Cl.Model.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.ServiceSuspension, serviceRequestService.CallBarring, out r2);
 2019:  
 2020:                                                         else r2 = "no difference in services. ";
 2021:  
 2022:                                                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, nddOnt.Access.Id, out r3);
 2023:  
 2024:                                                         r0 += r2 + "," + r3 + ",";
 2025:                                                     }
 2026:                                                     else
 2027:                                                     {
 2028:                                                         throw new Exception("switchVendor is undefined.");
 2029:                                                     }
 2030:                                                     //}
 2031:                                                     //else
 2032:                                                     //{
 2033:                                                     //    r0 += "service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
 2034:                                                     //}
 2035:                                                 }
 2036:                                                 else r0 += "Access is not in an allowed to be provisioned OLT. ";
 2037:                                             }
 2038:                                             else r0 += "switchVendor of service " + service + " is not equal to switch vendor of access " + nddOnt.Access.Name + ".";
 2039:                                         }
 2040:                                         else
 2041:                                         {
 2042:                                             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2043:                                             {
 2044:                                                 r0 += "Huawei: ";
 2045:  
 2046:                                                 // See above
 2047:                                                 if (service2.CallerId != serviceRequestService.CallerId) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallerId, serviceRequestService.CallerId, out r2);
 2048:                                                 else if (service2.CallForwarding != serviceRequestService.CallForwarding) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallForwarding, serviceRequestService.CallForwarding, out r2);
 2049:                                                 else if (service2.CallWaiting != serviceRequestService.CallWaiting) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.CallWaiting, serviceRequestService.CallWaiting, out r2);
 2050:                                                 else if (service2.ConferenceCall != serviceRequestService.ConferenceCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.ConferenceCall, serviceRequestService.ConferenceCall, out r2);
 2051:                                                 else if (service2.AlarmCall != serviceRequestService.AlarmCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.AlarmCall, out r2); // do not change
 2052:                                                 else if (service2.WakeupCall != serviceRequestService.WakeupCall) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.WakeupCall, serviceRequestService.WakeupCall, out r2);
 2053:                                                 else if (service2.AbbriviatedCalling != serviceRequestService.AbbriviatedCalling) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.AbbriviatedCalling, serviceRequestService.AbbriviatedCalling, out r2);
 2054:  
 2055:                                                 else if (service2.InternationalCalling != serviceRequestService.InternationalCalling) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, serviceRequestService.InternationalCalling, out r2);
 2056:                                                 else if (service2.InternationalCallingUserControlled != serviceRequestService.InternationalCallingUserControlled) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCallingUserControlled, serviceRequestService.InternationalCallingUserControlled, out r2);
 2057:  
 2058:                                                 //else if (Ia.Ftn.Cl.Model.Business.Administration.ServiceSuspensionIsEnabled && service2.ServiceSuspension != serviceRequestService.CallBarring) Ia.Ftn.Cl.Model.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.ServiceSuspension, serviceRequestService.CallBarring, out r2);
 2059:  
 2060:                                                 else r2 = "no difference in services. ";
 2061:  
 2062:                                                 Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, string.Empty, out r3);
 2063:  
 2064:                                                 r0 += r2 + "," + r3 + ",";
 2065:                                             }
 2066:                                             else r0 += "serviceNddOnt is null and switchVendor is not Huawei. ";
 2067:                                         }
 2068:                                     }
 2069:                                 }
 2070:                                 else r0 += "service is not a valid number. ";
 2071:                             }
 2072:                             else
 2073:                             {
 2074:                                 if (int.TryParse(service, out number))
 2075:                                 {
 2076:                                     switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
 2077:  
 2078:                                     if (service2 != null)
 2079:                                     {
 2080:                                         // delete service
 2081:                                         r0 += "delete: ";
 2082:  
 2083:                                         nddOnt = (service2.Access != null) ? Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(service2.Access.Id) : null;
 2084:  
 2085:                                         if (nddOnt != null)
 2086:                                         {
 2087:                                             if (Ia.Ftn.Cl.Models.Business.Service.OltIsWithinAllowedToBeProvisionedOltList(nddOnt.Pon.PonGroup.Olt))
 2088:                                             {
 2089:                                                 if (switchVendor == nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor)
 2090:                                                 {
 2091:                                                     if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service))
 2092:                                                     {
 2093:                                                         if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 2094:                                                         {
 2095:                                                             r0 += "Nokia: ";
 2096:  
 2097:                                                             Ia.Ftn.Cl.Models.Business.Provision.DeleteReadNokiaSwitchSubscriber(nokiaIms, nddOnt.Access.Name, service, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 2098:  
 2099:                                                             synchronized = true;
 2100:  
 2101:                                                             r0 += r1;
 2102:                                                         }
 2103:                                                         else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2104:                                                         {
 2105:                                                             r0 += "Huawei: ";
 2106:  
 2107:                                                             Ia.Ftn.Cl.Models.Business.Provision.DeleteReadHuaweiSwitchSubscriber(huaweiIms, nddOnt.Access.Name, service, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 2108:  
 2109:                                                             synchronized = true;
 2110:  
 2111:                                                             r0 += r1;
 2112:                                                         }
 2113:                                                         else
 2114:                                                         {
 2115:                                                             throw new Exception("switchVendor is undefined.");
 2116:                                                         }
 2117:                                                     }
 2118:                                                     else r0 += "service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.";
 2119:                                                 }
 2120:                                                 else r0 += "switchVendor of service " + service + " is not equal to switch vendor of access " + nddOnt.Access.Name + ".";
 2121:                                             }
 2122:                                             else r0 += "Access is not in an allowed to be provisioned OLT. ";
 2123:                                         }
 2124:                                         else
 2125:                                         {
 2126:                                             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 2127:                                             {
 2128:                                                 r0 += "Nokia: ";
 2129:  
 2130:                                                 //Ia.Ftn.Cl.Model.Business.Provision.DeleteReadNokiaSwitchSubscriber(nokiaIms, string.Empty, service, Ia.Ftn.Cl.Model.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 2131:                                                 //r0 += "serviceNddOnt is null and switchVendor is not Huawei. ";
 2132:  
 2133:                                                 Ia.Ftn.Cl.Models.Business.Provision.DeleteReadNokiaSwitchAgcfEndpointAndH248SubscriberFromAnyFsdb(nokiaIms, service, out r1);
 2134:  
 2135:                                                 synchronized = true;
 2136:  
 2137:                                                 r0 += r1;
 2138:                                             }
 2139:                                             else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2140:                                             {
 2141:                                                 // see above
 2142:                                                 r0 += "Huawei: ";
 2143:  
 2144:                                                 Ia.Ftn.Cl.Models.Business.Provision.DeleteReadHuaweiSwitchSubscriber(huaweiIms, string.Empty, service, Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd, false, out r1);
 2145:  
 2146:                                                 synchronized = true;
 2147:  
 2148:                                                 r0 += r1;
 2149:                                             }
 2150:                                             else
 2151:                                             {
 2152:                                                 throw new Exception("switchVendor is undefined.");
 2153:                                             }
 2154:                                         }
 2155:                                     }
 2156:                                     else
 2157:                                     {
 2158:                                         throw new Exception("service2 is null. ");
 2159:                                     }
 2160:                                 }
 2161:                                 else r0 += "service is not a valid number. ";
 2162:                             }
 2163:                         }
 2164:                         else r0 += "serviceRequestService is null. ";
 2165:                     }
 2166:                     catch (Exception ex)
 2167:                     {
 2168:                         r0 += "Exception: " + ex.ToString();
 2169:                     }
 2170:  
 2171:                     if (synchronized) Ia.Ftn.Cl.Models.Data.MessageQueue.SecretaryApplication.Enqueue(Ia.Ftn.Cl.Models.Business.MessageQueue.Application.ProvisionApplication, Ia.Ftn.Cl.Models.Business.MessageQueue.Process.SynchronizeCompleted, serviceRequestService.Service);
 2172:                 }
 2173:                 else r0 += "The service number " + service + " does not have eight digits and/or is not within allowed domain list.";
 2174:             }
 2175:             else r0 = "No numbers in service discrepancy and complementary service mismatch list. ";
 2176:  
 2177:             result.AddSuccess(r0);
 2178:  
 2179:             return result;
 2180:         }
 2181:  
 2182:         ////////////////////////////////////////////////////////////////////////////
 2183:  
 2184:         /// <summary>
 2185:         ///
 2186:         /// </summary>
 2187:         public static Ia.Cl.Models.Result ManageServiceRequestAdministrativeIssue(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms)
 2188:         {
 2189:             string r2, r3;
 2190:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2191:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
 2192:  
 2193:             var result = new Ia.Cl.Models.Result();
 2194:  
 2195:             if (Ia.Ftn.Cl.Models.Business.Administration.ServiceSuspensionIsEnabled)
 2196:             {
 2197:                 var programmedAccountingDisconnectionType = Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.DisconnectionType.ProgrammedAccounting;
 2198:                 var programmedInternationalCallingDisconnectionType = Ia.Ftn.Cl.Models.Business.ServiceRequestAdministrativeIssue.DisconnectionType.ProgrammedInternationalCalling;
 2199:  
 2200:                 //var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 2201:  
 2202:                 var service = Ia.Ftn.Cl.Models.Business.Provision.ImsServiceMismatchBetweenServiceRequestAdministrativeIssueAndServiceServiceListItem(out int serviceRequestAdministrativeIssueQueueCount, out string progressCounterString);
 2203:  
 2204:                 var serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
 2205:                 var serviceId = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, serviceType);
 2206:  
 2207:                 if (!string.IsNullOrEmpty(service))
 2208:                 {
 2209:                     result.AddSuccess("service: " + service + " " + progressCounterString);
 2210:                     r2 = serviceId;
 2211:  
 2212:                     var service2 = Ia.Ftn.Cl.Models.Data.Service2.ReadByIdIncludeAccess(serviceId);
 2213:                     var serviceRequestService = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ReadIncludeAccess(serviceId);
 2214:                     var serviceRequestAdministrativeIssue = Ia.Ftn.Cl.Models.Data.ServiceRequestAdministrativeIssue.Read(service, out _);
 2215:  
 2216:                     if (service2 != null)
 2217:                     {
 2218:                         switchVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SwitchVendorByService(service);
 2219:  
 2220:                         if (service2.Access != null) nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(service2.Access.Id);
 2221:                         else if (serviceRequestService.Access != null) nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByOntAccessId(serviceRequestService.Access.Id);
 2222:                         else nddOnt = null;
 2223:  
 2224:                         if (nddOnt != null)
 2225:                         {
 2226:                             if (Ia.Ftn.Cl.Models.Business.Service.OltIsWithinAllowedToBeProvisionedOltList(nddOnt.Pon.PonGroup.Olt))
 2227:                             {
 2228:                                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedRouterDomainListOrIsWithinSymbolDomainSameSwitchVendorButDifferentSiteExceptionList(nddOnt, service))
 2229:                                 {
 2230:                                     var accessId = nddOnt.Access.Id;
 2231:  
 2232:                                     result.AddSuccess("service: ");
 2233:  
 2234:                                     if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 2235:                                     {
 2236:                                         /*
 2237:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == false) // if H.248
 2238:                                         {
 2239:                                             var gwId = Ia.Ftn.Cl.Model.Data.Nokia.AgcfGatewayRecord.GwIdFromIp(nddOnt.Ip);
 2240: 
 2241:                                             if (gwId > 0)
 2242:                                             {
 2243:                                                 if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedAccountingDisconnectionType && service2.ServiceSuspension == false) Ia.Ftn.Cl.Model.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, true, out r2);
 2244:                                                 else if (serviceRequestAdministrativeIssue == null && service2.ServiceSuspension == true) Ia.Ftn.Cl.Model.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, false, out r2);
 2245:                                                 else if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedInternationalCallingDisconnectionType && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == true) Ia.Ftn.Cl.Model.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.InternationalCalling, false, out r2);
 2246:                                                 else if (serviceRequestAdministrativeIssue == null && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == false) Ia.Ftn.Cl.Model.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.InternationalCalling, true, out r2);
 2247:                                                 else result.AddError("unrecognized serviceRequestAdministrativeIssue");
 2248: 
 2249:                                                 Ia.Ftn.Cl.Model.Data.Nokia.Ims.ReadUpdateAgcfGatewayRecordAndAgcfEndpointListAndSubPartyAndSubscriberAndServiceForGwId(nokiaIms, gwId, out r3);
 2250: 
 2251:                                                 result.AddSuccess(r2 + "," + r3);
 2252:                                             }
 2253:                                             else result.AddError("gwId is 0.");
 2254:                                         }
 2255:                                         else // if IsSip == true
 2256:                                         {
 2257:                                             if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedAccountingDisconnectionType && service2.ServiceSuspension == false) Ia.Ftn.Cl.Model.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, true, out r2);
 2258:                                             else if (serviceRequestAdministrativeIssue == null && service2.ServiceSuspension == true) Ia.Ftn.Cl.Model.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, false, out r2);
 2259:                                             else if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedInternationalCallingDisconnectionType && service2.InternationalCalling == true) Ia.Ftn.Cl.Model.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.InternationalCalling, false, out r2);
 2260:                                             else if (serviceRequestAdministrativeIssue == null && service2.InternationalCalling == true) Ia.Ftn.Cl.Model.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Model.Business.Service.SupplementaryService.InternationalCalling, true, out r2);
 2261:                                             else result.AddError("unrecognized serviceRequestAdministrativeIssue");
 2262: 
 2263:                                             Ia.Ftn.Cl.Model.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, nddOnt, out r3);
 2264: 
 2265:                                             result.AddSuccess(r2 + "," + r3);
 2266:                                         }
 2267:                                         */
 2268:  
 2269:                                         if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedAccountingDisconnectionType && service2.ServiceSuspension == false) Ia.Ftn.Cl.Models.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, true, out r2);
 2270:                                         else if (serviceRequestAdministrativeIssue == null && service2.ServiceSuspension == true) Ia.Ftn.Cl.Models.Data.Nokia.Ims.AssignServiceSuspensionStateToServiceSubscriber(nokiaIms, service, nddOnt, false, out r2);
 2271:                                         else if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedInternationalCallingDisconnectionType && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == true) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, false, out r2);
 2272:                                         else if (serviceRequestAdministrativeIssue == null && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == false) Ia.Ftn.Cl.Models.Data.Nokia.Ims.UpdateSupplementaryService(nokiaIms, service, nddOnt, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, true, out r2);
 2273:                                         else result.AddError("unrecognized serviceRequestAdministrativeIssue");
 2274:  
 2275:                                         Ia.Ftn.Cl.Models.Data.Nokia.Ims.ReadUpdateSubPartyAndSubscriberAndServiceForService(nokiaIms, service, nddOnt, out r3);
 2276:  
 2277:                                         result.AddSuccess(r2 + "," + r3);
 2278:                                     }
 2279:                                     else if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2280:                                     {
 2281:                                         if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedAccountingDisconnectionType && service2.ServiceSuspension == false) Ia.Ftn.Cl.Models.Data.Huawei.Ims.AssignServiceSuspensionStateToServiceSubscriber(huaweiIms, service, true, out r2);
 2282:                                         else if (serviceRequestAdministrativeIssue == null && service2.ServiceSuspension == true) Ia.Ftn.Cl.Models.Data.Huawei.Ims.AssignServiceSuspensionStateToServiceSubscriber(huaweiIms, service, false, out r2);
 2283:                                         else if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedInternationalCallingDisconnectionType && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == true) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, false, out r2);
 2284:                                         else if (serviceRequestAdministrativeIssue == null && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == false) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, true, out r2);
 2285:                                         else result.AddError("unrecognized serviceRequestAdministrativeIssue.");
 2286:  
 2287:                                         Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadSbrForService(huaweiIms, service, out r3);
 2288:  
 2289:                                         result.AddSuccess(r2 + "," + r3);
 2290:                                     }
 2291:                                     else result.AddError("switchVendor is undefined.");
 2292:                                 }
 2293:                                 else result.AddError("service " + service + " is not within allowed router domain list for access " + nddOnt.Access.Name + ". To override restrictions contact department.");
 2294:                             }
 2295:                             else result.AddError("access is not in an allowed to be provisioned OLT.");
 2296:                         }
 2297:                         else
 2298:                         {
 2299:                             if (switchVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 2300:                             {
 2301:                                 if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedAccountingDisconnectionType && service2.ServiceSuspension == false) Ia.Ftn.Cl.Models.Data.Huawei.Ims.AssignServiceSuspensionStateToServiceSubscriber(huaweiIms, service, true, out r2);
 2302:                                 else if (serviceRequestAdministrativeIssue == null && service2.ServiceSuspension == true) Ia.Ftn.Cl.Models.Data.Huawei.Ims.AssignServiceSuspensionStateToServiceSubscriber(huaweiIms, service, false, out r2);
 2303:                                 else if (serviceRequestAdministrativeIssue != null && serviceRequestAdministrativeIssue.Type == (int)programmedInternationalCallingDisconnectionType && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == true) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, false, out r2);
 2304:                                 else if (serviceRequestAdministrativeIssue == null && serviceRequestService.InternationalCalling == true && service2.InternationalCalling == false) Ia.Ftn.Cl.Models.Data.Huawei.Ims.UpdateSupplementaryService(huaweiIms, service, Ia.Ftn.Cl.Models.Business.Service.SupplementaryService.InternationalCalling, true, out r2);
 2305:                                 else result.AddError("unrecognized serviceRequestAdministrativeIssue.");
 2306:  
 2307:                                 Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadSbrForService(huaweiIms, service, out r3);
 2308:  
 2309:                                 result.AddSuccess(r2 + "," + r3);
 2310:                             }
 2311:                             else result.AddError("nddOnt is null and switchVendor is not Huawei.");
 2312:                         }
 2313:                     }
 2314:                     else result.AddError("service2 is null.");
 2315:                 }
 2316:                 else result.AddWarning("No numbers in service request administrative issue mismatch list.");
 2317:             }
 2318:             else result.AddWarning("service request administrative issue is disabled.");
 2319:  
 2320:             return result;
 2321:         }
 2322:  
 2323:         ////////////////////////////////////////////////////////////////////////////
 2324:  
 2325:         /// <summary>
 2326:         ///
 2327:         /// </summary>
 2328:         public static async Task<Ia.Cl.Models.Result> ManageMessageQueue(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms)
 2329:         {
 2330:             string r;
 2331:  
 2332:             var result = new Ia.Cl.Models.Result();
 2333:  
 2334:             var count = await Ia.Ftn.Cl.Models.Data.MessageQueue.ProvisionApplication.CountAsync;
 2335:  
 2336:             if (count > 0)
 2337:             {
 2338:                 var message = await Ia.Ftn.Cl.Models.Data.MessageQueue.ProvisionApplication.DequeueAsync;
 2339:  
 2340:                 if (message != null)
 2341:                 {
 2342:                     if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ServiceRequestAndOrServiceRequestTypeUpdated)
 2343:                     {
 2344:                         if (Ia.Ftn.Cl.Models.Business.Administration.NowIsOfficialWorkingTime)
 2345:                         {
 2346:                             var r2 = Ia.Ftn.Cl.Models.Business.Provision.ManageServiceProvisioning(Ia.Ftn.Cl.Models.Business.Default.Procedure.InitializeOrIterate, nokiaIms, huaweiIms);
 2347:  
 2348:                             result.AddSuccess("Provision service: " + r2.MessageWithoutCaption);
 2349:                         }
 2350:                         else
 2351:                         {
 2352:                         }
 2353:                     }
 2354:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.Synchronize)
 2355:                     {
 2356:                         if (Ia.Ftn.Cl.Models.Business.Administration.NowIsOfficialWorkingTime)
 2357:                         {
 2358:                             var r2 = Ia.Ftn.Cl.Models.Business.Provision.ManageServiceProvisioning(Ia.Ftn.Cl.Models.Business.Default.Procedure.InitializeOrIterate, nokiaIms, huaweiIms);
 2359:  
 2360:                             result.AddSuccess("Provision (from sync) service: " + r2.MessageWithoutCaption);
 2361:                         }
 2362:                         else
 2363:                         {
 2364:                         }
 2365:                     }
 2366:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.CreateReadServiceAccessPort)
 2367:                     {
 2368:                         var service = message.Service;
 2369:                         var accessName = message.AccessName;
 2370:                         var port = (message.Port > 0) ? message.Port : Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
 2371:                         var overrideRouterDomainRestriction = message.OverrideRouterDomainRestriction;
 2372:  
 2373:                         var protocol = Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd;
 2374:  
 2375:                         Ia.Ftn.Cl.Models.Business.Provision.CreateReadService(nokiaIms, huaweiIms, accessName, service, port, protocol, overrideRouterDomainRestriction, out r);
 2376:  
 2377:                         result.AddSuccess("Create/Read: " + service + "|" + accessName + "|" + port + ": " + r);
 2378:                     }
 2379:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.DeleteReadServiceAccess)
 2380:                     {
 2381:                         var service = message.Service;
 2382:                         var accessName = message.AccessName;
 2383:                         var overrideRouterDomainRestriction = message.OverrideRouterDomainRestriction;
 2384:  
 2385:                         var protocol = Ia.Ftn.Cl.Models.Business.Default.Protocol.DefaultAsInNdd;
 2386:  
 2387:                         Ia.Ftn.Cl.Models.Business.Provision.DeleteReadService(nokiaIms, huaweiIms, accessName, service, protocol, overrideRouterDomainRestriction, out r);
 2388:  
 2389:                         result.AddSuccess("Delete/Read: " + service + "|" + accessName + ": " + r);
 2390:                     }
 2391:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.UpdateReadServiceSupplementaryService)
 2392:                     {
 2393:                         var service = message.Service;
 2394:                         var serviceSupplementaryService = message.ServiceSupplementaryService;
 2395:                         var serviceSupplementaryServiceState = message.ServiceSupplementaryServiceState;
 2396:  
 2397:                         Ia.Ftn.Cl.Models.Business.Provision.UpdateReadSupplementaryService(nokiaIms, huaweiIms, service, serviceSupplementaryService, serviceSupplementaryServiceState, out Ia.Cl.Models.Result r2);
 2398:  
 2399:                         result.AddSuccess("Set/Reset/Read Service Supplementary Service: " + service + ": " + r2.Message);
 2400:                     }
 2401:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.AccessCreated)
 2402:                     {
 2403:                         Ia.Ftn.Cl.Models.Data.Huawei.Default.AccessNameToMduDevDictionaryReset();
 2404:  
 2405:                         var result0 = Ia.Ftn.Cl.Models.Business.Nokia.Ims.CreateMissingAgcfGatewayRecordForNokiaSwitchOntInNonSipOlt(nokiaIms);
 2406:  
 2407:                         result.AddSuccess("Access created: AccessNameToMduDevDictionary reset. CreateMissingAgcfGatewayRecordForNokiaSwitchOntInNonSipOlt(): " + result0.Message);
 2408:                     }
 2409:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ServiceInServiceRequestAdministrativeIssuesUpdated)
 2410:                     {
 2411:                         var r1 = Ia.Ftn.Cl.Models.Business.Provision.ManageServiceRequestAdministrativeIssue(nokiaIms, huaweiIms);
 2412:  
 2413:                         result.AddResult("Manage Service Request Administrative Issue: ", r1);
 2414:                     }
 2415:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ActiveApplicationRunningPermissionState)
 2416:                     {
 2417:                         Ia.Ftn.Cl.Models.Business.Default.PermitActiveApplicationsToRun = message.State;
 2418:  
 2419:                         result.AddSuccess("PermitActiveApplicationsToRun: " + message.State);
 2420:                     }
 2421:                     else
 2422:                     {
 2423:                         throw new ArgumentOutOfRangeException("MessageQueue process " + message.Process.ToString() + " is undefined");
 2424:                     }
 2425:                 }
 2426:                 else
 2427:                 {
 2428:                 }
 2429:             }
 2430:  
 2431:             return result;
 2432:         }
 2433:  
 2434:         ////////////////////////////////////////////////////////////////////////////
 2435:  
 2436:         /// <summary>
 2437:         ///
 2438:         /// </summary>
 2439:         public static Ia.Cl.Models.Result ManageAperiodicProcedure(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms)
 2440:         {
 2441:             int aperiodicQueueCount;
 2442:             string service;
 2443:  
 2444:             var result = new Ia.Cl.Models.Result();
 2445:  
 2446:             if (aperiodicQueue.Count == 0)
 2447:             {
 2448:                 List<string> list;
 2449:  
 2450:                 using (var db = new Ia.Ftn.Cl.Db())
 2451:                 {
 2452:                     list = (from s in db.Service2
 2453:                             where s.Service.StartsWith("24825") || s.Service.StartsWith("24826") || s.Service.StartsWith("24827") || s.Service.StartsWith("24828") || s.Service.StartsWith("24829")
 2454:                             select s.Service).ToList();
 2455:                 }
 2456:  
 2457:                 aperiodicQueue = new Queue<string>(list);
 2458:  
 2459:                 aperiodicQueueOriginalCount = aperiodicQueue.Count;
 2460:             }
 2461:  
 2462:             if (aperiodicQueue.Count > 0) service = aperiodicQueue.Dequeue();
 2463:             else service = string.Empty;
 2464:  
 2465:             if (!string.IsNullOrEmpty(service))
 2466:             {
 2467:                 Ia.Ftn.Cl.Models.Data.Huawei.Ims.DeleteSubscriber(huaweiIms, service, out string deleteString);
 2468:                 Ia.Ftn.Cl.Models.Business.Huawei.Ims.ReadUpdateSbrAndServiceForService(huaweiIms, service, string.Empty, out string readString);
 2469:  
 2470:                 result.AddSuccess(service + " (" + aperiodicQueue.Count + "/" + aperiodicQueueOriginalCount + "): delete:" + deleteString + ", read:" + readString);
 2471:             }
 2472:             else
 2473:             {
 2474:                 result.AddSuccess("service is null");
 2475:             }
 2476:  
 2477:             aperiodicQueueCount = aperiodicQueue.Count;
 2478:  
 2479:             return result;
 2480:         }
 2481:  
 2482:         ////////////////////////////////////////////////////////////////////////////
 2483:         ////////////////////////////////////////////////////////////////////////////
 2484:  
 2485:         /// <summary>
 2486:         ///
 2487:         /// </summary>
 2488:         public static void CreateReadService(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms, string accessName, string service, int port, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
 2489:         {
 2490:             if (!string.IsNullOrEmpty(service))
 2491:             {
 2492:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
 2493:                 {
 2494:                     if (!string.IsNullOrEmpty(accessName))
 2495:                     {
 2496:                         Ia.Ftn.Cl.Models.Business.Provision.CreateReadNokiaSwitchSubscriber(nokiaIms, accessName, service, port, protocol, overrideRouterDomainRestriction, out result);
 2497:                     }
 2498:                     else result = "Error: Can't create a Nokia service without an access. AccessName is null or empty. ";
 2499:                 }
 2500:                 else if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service))
 2501:                 {
 2502:                     Ia.Ftn.Cl.Models.Business.Provision.CreateReadHuaweiSwitchSubscriber(huaweiIms, accessName, service, port, protocol, overrideRouterDomainRestriction, out result);
 2503:                 }
 2504:                 else result = "Error: service number does not belong to a valid vendor switch. ";
 2505:             }
 2506:             else result = "Error: service null or empty. ";
 2507:         }
 2508:  
 2509:         ////////////////////////////////////////////////////////////////////////////
 2510:  
 2511:         /// <summary>
 2512:         ///
 2513:         /// </summary>
 2514:         public static void DeleteReadService(Ia.Ftn.Cl.Models.Client.Nokia.Ims nokiaIms, Ia.Ftn.Cl.Models.Client.Huawei.Ims huaweiIms, string accessName, string service, Ia.Ftn.Cl.Models.Business.Default.Protocol protocol, bool overrideRouterDomainRestriction, out string result)
 2515:         {
 2516:             bool b;
 2517:  
 2518:             if (!string.IsNullOrEmpty(service))
 2519:             {
 2520:                 if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedNokiaSwitchDomainList(service))
 2521:                 {
 2522:                     if (!string.IsNullOrEmpty(accessName))
 2523:                     {
 2524:                         b = Ia.Ftn.Cl.Models.Business.Provision.DeleteReadNokiaSwitchSubscriber(nokiaIms, accessName, service, protocol, overrideRouterDomainRestriction, out result);
 2525:                     }
 2526:                     else
 2527:                     {
 2528:                         b = Ia.Ftn.Cl.Models.Business.Provision.DeleteReadNokiaSwitchAgcfEndpointAndH248SubscriberFromAnyFsdb(nokiaIms, service, out result);
 2529:                     }
 2530:                 }
 2531:                 else if (Ia.Ftn.Cl.Models.Business.Service.NumberIsWithinAllowedHuaweiSwitchDomainList(service))
 2532:                 {
 2533:                     b = Ia.Ftn.Cl.Models.Business.Provision.DeleteReadHuaweiSwitchSubscriber(huaweiIms, accessName, service, protocol, overrideRouterDomainRestriction, out result);
 2534:                 }
 2535:                 else result = "Error: service number does not belong to a valid vendor switch. ";
 2536:             }
 2537:             else
 2538:             {
 2539:                 result = "Error: service null or empty. ";
 2540:             }
 2541:         }
 2542:  
 2543:         ////////////////////////////////////////////////////////////////////////////
 2544:         ////////////////////////////////////////////////////////////////////////////    
 2545:     }
 2546:  
 2547:     ////////////////////////////////////////////////////////////////////////////
 2548:     ////////////////////////////////////////////////////////////////////////////   
 2549: }