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

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

Access Management System (AMS) support class for Nokia's Fixed Telecommunications Network (FTN) business model.

    1: using System;
    2: using System.Collections;
    3: using System.Collections.Generic;
    4: using System.Configuration;
    5: using System.Data;
    6: using System.Linq;
    7: using System.Text.RegularExpressions;
    8:  
    9: namespace Ia.Ftn.Cl.Models.Business.Nokia
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Access Management System (AMS) support class for Nokia's Fixed Telecommunications Network (FTN) business model.
   15:     /// </summary>
   16:     /// 
   17:     /// "AppSettings": {
   18:     /// "AmsServerHost": "********",
   19:     /// "AmsServerPort": "****",
   20:     /// "AmsServerActUser": "ACT-USER:{amsName}:********:{ctag}::********;",
   21:     /// "AmsServerCancUser": "CANC-USER:{amsName}:********:{ctag};"
   22:     /// }
   23:     /// 
   24:     /// <remarks> 
   25:     /// Copyright © 2007-2024 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   26:     ///
   27:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   28:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   29:     ///
   30:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   31:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   32:     /// 
   33:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   34:     /// 
   35:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   36:     /// </remarks> 
   37:     public class Ams
   38:     {
   39:         // below: access data for Nokia AMS
   40:         private const string textToSkipInTelnetEndReceive = "IP 0\r\n<";
   41:         private static string lastSentCommand;
   42:         private static string keepAliveCurrentAmsName = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaOltAmsNameList.PickRandom();
   43:  
   44:         private static readonly Procedure serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserOfServiceFromThePast24HourProcedure = new Ia.Ftn.Cl.Models.Business.Procedure(24, Ia.Ftn.Cl.Models.Business.Provision._ServiceOntToCreateAndToDeleteInEmsOntSipInfoOrVoipPstnUserListFromThePastNHourList);
   45:         private static readonly Procedure serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserProcedure = new Ia.Ftn.Cl.Models.Business.Procedure(0, Ia.Ftn.Cl.Models.Business.Provision._ServiceOntToCreateAndToDeleteInEmsOntSipInfoOrVoipPstnUserListFromThePastNHourList);
   46:  
   47:         private static readonly Dictionary<string, int> associateServiceIdAndPortBetweenCreateAndReadDictionary = new Dictionary<string, int>();
   48:  
   49:         private static Dictionary<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont, bool> eventDictionary = new Dictionary<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont, bool>();
   50:  
   51:         private static readonly Queue<string> priorityAmsCommandQueue = new Queue<string>();
   52:         private static Queue<string> amsCommandQueue = new Queue<string>();
   53:         private static readonly Queue<string> amsCreateOntCommandQueue = new Queue<string>();
   54:  
   55:         private static Ia.Ftn.Cl.Models.Client.Nokia.Ams ams = new Ia.Ftn.Cl.Models.Client.Nokia.Ams();
   56:  
   57:         private static List<string> priorityServiceList = new List<string>();
   58:  
   59:         /// <summary/>
   60:         public enum AmsOpcode
   61:         {
   62:             /// <summary/>
   63:             RtrvHdr,
   64:  
   65:             /// <summary/>
   66:             RtrvOnt,
   67:  
   68:             /// <summary/>
   69:             InitSys,
   70:  
   71:             /// <summary/>
   72:             RtrvServiceVoip,
   73:  
   74:             /// <summary/>
   75:             RtrvOntPots,
   76:  
   77:             /// <summary/>
   78:             RtrvAlmPon,
   79:  
   80:             /// <summary/>
   81:             EdOntDesc1,
   82:  
   83:             /// <summary/>
   84:             EdOntDesc1Annul,
   85:  
   86:             /// <summary/>
   87:             EdOntPotsCustinfo
   88:         }
   89:  
   90:         /// <summary/>
   91:         public enum BellcoreState
   92:         {
   93:             /// <summary/>
   94:             Undefined = 0,
   95:  
   96:             /// <summary/>
   97:             IsNr = 1,
   98:  
   99:             /// <summary/>
  100:             OosAu,
  101:  
  102:             /// <summary/>
  103:             OosMa,
  104:  
  105:             /// <summary/>
  106:             OosAuma
  107:         };
  108:  
  109:         /// <summary/>
  110:         public static string Host { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:AmsServerHost"); } }
  111:  
  112:         /// <summary/>
  113:         public static int Port { get { return int.Parse(Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:AmsServerPort")); } }
  114:  
  115:         /// <summary/>
  116:         public static string ActUser(string amsName)
  117:         {
  118:             return PrepareCtaggedCommand(Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:AmsServerActUser").Replace("{amsName}", amsName));
  119:         }
  120:  
  121:         /// <summary/>
  122:         public static string CancUser(string amsName)
  123:         {
  124:             return PrepareCtaggedCommand(Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:AmsServerCancUser").Replace("{amsName}", amsName));
  125:         }
  126:  
  127:         /// <summary/>
  128:         public static string TextToSkipInTelnetEndReceive { get { return textToSkipInTelnetEndReceive; } }
  129:  
  130:         ////////////////////////////////////////////////////////////////////////////
  131:  
  132:         /// <summary>
  133:         ///
  134:         /// </summary>
  135:         public Ams()
  136:         {
  137:         }
  138:  
  139:         ////////////////////////////////////////////////////////////////////////////
  140:  
  141:         /// <summary>
  142:         ///
  143:         /// </summary>
  144:         public static void Connect(out Ia.Cl.Models.Result result)
  145:         {
  146:             if (ams != null && !ams.IsConnected)
  147:             {
  148:                 result = ams.Connect();
  149:             }
  150:             else
  151:             {
  152:                 result = new Ia.Cl.Models.Result();
  153:  
  154:                 result.AddWarning("Warning: ams is already connected.");
  155:             }
  156:         }
  157:  
  158:         ////////////////////////////////////////////////////////////////////////////
  159:  
  160:         /// <summary>
  161:         ///
  162:         /// </summary>
  163:         public static void Disconnect(out Ia.Cl.Models.Result result)
  164:         {
  165:             if (ams != null && ams.IsConnected)
  166:             {
  167:                 result = ams.Disconnect();
  168:             }
  169:             else
  170:             {
  171:                 result = new Ia.Cl.Models.Result();
  172:  
  173:                 result.AddWarning("Warning: ams is already disconnected.");
  174:             }
  175:         }
  176:  
  177:         ////////////////////////////////////////////////////////////////////////////
  178:  
  179:         /// <summary>
  180:         ///
  181:         /// </summary>
  182:         public static void Login()
  183:         {
  184:             foreach (string amsName in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaOltAmsNameList)
  185:             {
  186:                 ams.SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Nokia.Ams.ActUser(amsName));
  187:             }
  188:         }
  189:  
  190:         ////////////////////////////////////////////////////////////////////////////
  191:  
  192:         /// <summary>
  193:         ///
  194:         /// </summary>
  195:         public static void Logout()
  196:         {
  197:             foreach (string amsName in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaOltAmsNameList)
  198:             {
  199:                 ams.SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Nokia.Ams.CancUser(amsName));
  200:             }
  201:         }
  202:  
  203:         ////////////////////////////////////////////////////////////////////////////
  204:  
  205:         /// <summary>
  206:         ///
  207:         /// </summary>
  208:         public static Queue<string> ReceiveQueue
  209:         {
  210:             get
  211:             {
  212:                 return ams.ReceiveQueue;
  213:             }
  214:         }
  215:  
  216:         ////////////////////////////////////////////////////////////////////////////
  217:  
  218:         /// <summary>
  219:         ///
  220:         /// </summary>
  221:         public static Queue<string> SendQueue
  222:         {
  223:             get
  224:             {
  225:                 return ams.SendQueue;
  226:             }
  227:         }
  228:  
  229:         ////////////////////////////////////////////////////////////////////////////
  230:  
  231:         /// <summary>
  232:         ///
  233:         /// </summary>
  234:         public static bool IsConnected
  235:         {
  236:             get
  237:             {
  238:                 return (ams != null && ams.IsConnected);
  239:             }
  240:         }
  241:  
  242:         ////////////////////////////////////////////////////////////////////////////
  243:  
  244:         /// <summary>
  245:         ///
  246:         /// </summary>
  247:         public static bool IsLoggedIn
  248:         {
  249:             get
  250:             {
  251:                 return ams.IsLoggedIn;
  252:             }
  253:         }
  254:  
  255:         ////////////////////////////////////////////////////////////////////////////
  256:         ////////////////////////////////////////////////////////////////////////////
  257:  
  258:         /// <summary>
  259:         ///
  260:         /// </summary>
  261:         public static Ia.Cl.Models.Result ManageReceiveQueue()
  262:         {
  263:             bool isUpdated;
  264:             string rowString, formattedString;
  265:             Ia.Cl.Models.Result updateDatabaseWithAmsCommandOutputResult;
  266:  
  267:             var result = new Ia.Cl.Models.Result();
  268:  
  269:             try
  270:             {
  271:                 while (ReceiveQueue.Count > 0)
  272:                 {
  273:                     rowString = ReceiveQueue.Dequeue();
  274:  
  275:                     formattedString = Ia.Cl.Models.Telnet.FormatAndCleanData(rowString);
  276:  
  277:                     isUpdated = Ia.Ftn.Cl.Models.Business.Nokia.Ams.UpdateDatabaseWithAmsCommandOutput(formattedString, out updateDatabaseWithAmsCommandOutputResult);
  278:  
  279:                     if (updateDatabaseWithAmsCommandOutputResult.IsSuccessful && !updateDatabaseWithAmsCommandOutputResult.HasWarning)
  280:                     {
  281:                         result.AddSuccess(updateDatabaseWithAmsCommandOutputResult.Message + ": formattedString: [" + formattedString + "]");
  282:                     }
  283:                     else
  284:                     {
  285:                         result.AddError("ManageReceiveQueue(): formattedString: [" + formattedString + "]");
  286:                     }
  287:  
  288:                     if (result.IsSuccessful)
  289:                     {
  290:                         AnalyzeReceivedData(formattedString);
  291:                     }
  292:                     else
  293:                     {
  294:                     }
  295:                 }
  296:             }
  297:             catch (Exception ex)
  298:             {
  299:                 result.AddError("ManageReceiveQueue: Exception: " + ex.Message);
  300:             }
  301:  
  302:             return result;
  303:         }
  304:  
  305:         ////////////////////////////////////////////////////////////////////////////
  306:  
  307:         /// <summary>
  308:         ///
  309:         /// </summary>
  310:         private static void AnalyzeReceivedData(string data)
  311:         {
  312:             string lastSentCommandWithoutSemiColon;
  313:  
  314:             //lastCommandEchoedBack = true;
  315:  
  316:             if (data.Contains("COMPLD"))
  317:             {
  318:                 if (lastSentCommand != null)
  319:                 {
  320:                     lastSentCommandWithoutSemiColon = lastSentCommand.Replace(";", "");
  321:  
  322:                     // below: detect the activation of user
  323:                     // debug
  324:                     //activated = true;
  325:                     //if (lastSentCommand == Ia.Ftn.Cl.Model.Business.Nokia.Ams.ActUser(olt.AmsName)) activated = true;
  326:                     //else if (lastSentCommand == Ia.Ftn.Cl.Model.Business.Nokia.Ams.CancUser(olt.AmsName)) activated = false;
  327:  
  328:                     /*
  329:                     if (data.Contains(lastSentCommandWithoutSemiColon)) lastCommandEchoedBack = true;
  330:                     else
  331:                     {
  332:                         //lastCommandEchoBackCounter = 5;
  333:                         lastCommandEchoedBack = false;
  334:                     }
  335:                     */
  336:                 }
  337:             }
  338:             else if (data.Contains("DENY")) { }
  339:             else if (data.Contains(Ia.Ftn.Cl.Models.Business.Nokia.Ams.TextToSkipInTelnetEndReceive)) { }
  340:             else if (data == "\r\n<") { }
  341:             /*
  342:             else
  343:             {
  344:                 lastCommandEchoBackCounter = 5;
  345:                 lastCommandEchoedBack = false;
  346:             }
  347:              */
  348:         }
  349:  
  350:         ////////////////////////////////////////////////////////////////////////////
  351:  
  352:         /// <summary>
  353:         ///
  354:         /// </summary>
  355:         public static string ManageSendQueue(out Ia.Cl.Models.Result result)
  356:         {
  357:             var command = string.Empty;
  358:             result = new Ia.Cl.Models.Result();
  359:  
  360:             try
  361:             {
  362:                 if (ams.SendQueue.Count > 0)
  363:                 {
  364:                     command = ams.SendQueue.Dequeue();
  365:  
  366:                     result = ams.Send(command);
  367:                 }
  368:             }
  369:             catch (Exception ex)
  370:             {
  371:                 result.AddError("ManageSendQueue(): Exception: " + ex.Message);
  372:             }
  373:  
  374:             return result.IsSuccessful ? command : string.Empty;
  375:         }
  376:  
  377:         ////////////////////////////////////////////////////////////////////////////
  378:  
  379:         /// <summary>
  380:         ///
  381:         /// </summary>
  382:         public static Ia.Cl.Models.Result ManageSynchronizationBetweenAccessAndSwitchPast24Hours()
  383:         {
  384:             // See: ManageSynchronizationBetweenAccessAndSwitchPastHour(), ManageSynchronizationBetweenAccessAndSwitchPast24Hours(), ManageSynchronizationBetweenAccessAndSwitch()
  385:  
  386:             Ia.Ftn.Cl.Models.Business.Procedure.Process process;
  387:  
  388:             var result = new Ia.Cl.Models.Result();
  389:  
  390:             process = serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserOfServiceFromThePast24HourProcedure.NextProcess(priorityServiceList);
  391:  
  392:             if (priorityServiceList.Count > 50) priorityServiceList.Clear();
  393:  
  394:             if (process.Type != Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.None)
  395:             {
  396:                 if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Create)
  397:                 {
  398:                     result.AddSuccess("create: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserOfServiceFromThePast24HourProcedure.ProgressCounterString);
  399:  
  400:                     //CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  401:                 }
  402:                 else if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read)
  403:                 {
  404:                     result.AddSuccess("read: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserOfServiceFromThePast24HourProcedure.ProgressCounterString);
  405:  
  406:                     //ReadOntSipInfoOrVoipPstnUser(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  407:                 }
  408:                 else if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Delete)
  409:                 {
  410:                     result.AddSuccess("delete: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserOfServiceFromThePast24HourProcedure.ProgressCounterString);
  411:  
  412:                     //_ = VacateOntSipInfoOrDeleteVoipPstnUserAndOrVacateVoipPstnAccount(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  413:                 }
  414:                 else result.AddError("sync: undefined procedure");
  415:  
  416:                 // Ia.Ftn.Cl.Model.Data.MessageQueue.SecretaryApplication.Updated() is in Ia.Ftn.Cl.Model.Business.Nokia.Ams.UpdateDatabaseWithEmsCommandOutput();
  417:             }
  418:             else result.AddWarning("sync: undefined"); // nothing to create or delete");
  419:  
  420:             return result;
  421:         }
  422:  
  423:         ////////////////////////////////////////////////////////////////////////////
  424:  
  425:         /// <summary>
  426:         ///
  427:         /// </summary>
  428:         public static Ia.Cl.Models.Result ManageSynchronizationBetweenAccessAndSwitch()
  429:         {
  430:             // See: ManageSynchronizationBetweenAccessAndSwitchPastHour(), ManageSynchronizationBetweenAccessAndSwitchPast24Hours(), ManageSynchronizationBetweenAccessAndSwitch()
  431:  
  432:             Ia.Ftn.Cl.Models.Business.Procedure.Process process;
  433:  
  434:             var result = new Ia.Cl.Models.Result();
  435:  
  436:             // problem: I have put empty new List<string>() here because there is an exception: System.Exception: Undefined function
  437:             process = serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserProcedure.NextProcess(new List<string>());
  438:  
  439:             if (process.Type != Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.None)
  440:             {
  441:                 if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Create)
  442:                 {
  443:                     result.AddSuccess("create: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserProcedure.ProgressCounterString);
  444:  
  445:                     //CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  446:                 }
  447:                 else if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Read)
  448:                 {
  449:                     result.AddSuccess("read: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserProcedure.ProgressCounterString);
  450:  
  451:                     //ReadOntSipInfoOrVoipPstnUser(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  452:                 }
  453:                 else if (process.Type == Ia.Ftn.Cl.Models.Business.Procedure.ProcessType.Delete)
  454:                 {
  455:                     result.AddSuccess("delete: " + process.ServiceId + " " + serviceOntToCreateOrDeleteInEmsOntSipInfoOrVoipPstnUserProcedure.ProgressCounterString);
  456:  
  457:                     //_ = VacateOntSipInfoOrDeleteVoipPstnUserAndOrVacateVoipPstnAccount(process.Service, process.Ont, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, ref result);
  458:                 }
  459:                 else result.AddError("sync: undefined procedure");
  460:  
  461:                 // Ia.Ftn.Cl.Model.Data.MessageQueue.SecretaryApplication.Updated() is in Ia.Ftn.Cl.Model.Business.Nokia.Ams.UpdateDatabaseWithEmsCommandOutput();
  462:             }
  463:             else result.AddWarning("sync: undefined"); // nothing to create or delete");
  464:  
  465:             return result;
  466:         }
  467:  
  468:         ////////////////////////////////////////////////////////////////////////////
  469:         ////////////////////////////////////////////////////////////////////////////
  470:  
  471:         /*
  472:         ////////////////////////////////////////////////////////////////////////////
  473:         ////////////////////////////////////////////////////////////////////////////
  474: 
  475:         /// <summary>
  476:         ///
  477:         /// </summary>
  478:         public static void CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(string service, string accessName, int port, out Ia.Cl.Models.Result result)
  479:         {
  480:             int serviceType;
  481:             string serviceId;
  482:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  483: 
  484:             result = new Ia.Cl.Models.Result();
  485: 
  486:             serviceType = Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService;
  487: 
  488:             try
  489:             {
  490:                 if (!string.IsNullOrEmpty(service))
  491:                 {
  492:                     if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  493:                     {
  494:                         serviceId = Ia.Ftn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
  495: 
  496:                         if (!string.IsNullOrEmpty(accessName))
  497:                         {
  498:                             nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
  499: 
  500:                             if (nddOnt != null)
  501:                             {
  502:                                 Ia.Ftn.Cl.Model.Business.Nokia.Ams.CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, nddOnt, port, ref result);
  503:                             }
  504:                             else result.AddError("NDD ONT is null for access name: " + accessName + ".");
  505:                         }
  506:                         else result.AddError("AccessName null or empty.");
  507:                     }
  508:                     else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
  509:                 }
  510:                 else result.AddError("Service null or empty.");
  511:             }
  512:             catch (Exception ex)
  513:             {
  514:                 result.AddError("Exception: " + ex.ToString() + ".");
  515:             }
  516:         }
  517: 
  518:         ////////////////////////////////////////////////////////////////////////////
  519: 
  520:         /// <summary>
  521:         ///
  522:         /// </summary>
  523:         public static void CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(string service, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, int port, ref Ia.Cl.Models.Result result)
  524:         {
  525:             Ia.Ftn.Cl.Model.Business.Nokia.Default.FnSnPnPort fnSnPnPort;
  526:             Ia.Ftn.Cl.Model.Business.Nokia.Dev.MduDev mduDev;
  527:             Ia.Ftn.Cl.Model.Ont ont;
  528: 
  529:             if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  530:             {
  531:                 if (nddOnt != null)
  532:                 {
  533:                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
  534:                     {
  535:                         ont = Ia.Ftn.Cl.Model.Data.Nokia.Ont.ReadIncludeAccess(nddOnt.Id);
  536: 
  537:                         if (ont != null)
  538:                         {
  539:                             if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
  540:                             {
  541:                                 if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
  542:                                 {
  543:                                     var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Default.AccessNameToMduDevDictionary;
  544: 
  545:                                     if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
  546:                                     {
  547:                                         mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
  548: 
  549:                                         var vacantFnSnPnList = Ia.Ftn.Cl.Model.Data.Nokia.Ams.VacantMduFnSnPnForOntList(mduDev, ont);
  550: 
  551:                                         if (vacantFnSnPnList.Count > 0)
  552:                                         {
  553:                                             if (port != Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  554:                                             {
  555:                                                 fnSnPnPort = vacantFnSnPnList.Where(f => f.Port == port).SingleOrDefault();
  556:                                             }
  557:                                             else fnSnPnPort = Ia.Ftn.Cl.Model.Data.Nokia.Ams.NextVacantMduFnSnPnForOnt(mduDev, ont);
  558: 
  559:                                             if (fnSnPnPort != null)
  560:                                             {
  561:                                                 var emsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByService(service);
  562: 
  563:                                                 if (emsVoipPstnUserList.Count == 0)
  564:                                                 {
  565:                                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendCreateVoipPstnUser(ems, mduDev, nddOnt, service, fnSnPnPort.Sn, fnSnPnPort.Pn);
  566: 
  567:                                                     if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
  568:                                                     {
  569:                                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendCreateVoipPstnAccount(ems, mduDev, nddOnt, service, fnSnPnPort.Sn, fnSnPnPort.Pn);
  570:                                                     }
  571: 
  572:                                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, mduDev);
  573: 
  574:                                                     associateServiceIdAndPortBetweenCreateAndReadDictionary[service] = fnSnPnPort.Port;
  575: 
  576:                                                     result.AddSuccess("command(s) sent...");
  577:                                                 }
  578:                                                 else result.AddError("emsVoipPstnUserList count != 0. Value must be zero before the operation is executed for service: " + service + ", and access: " + nddOnt.Access.Name + ".");
  579:                                             }
  580:                                             else result.AddError("MDU sn and/or tel is invalid or does not exist.");
  581:                                         }
  582:                                         else result.AddError("vacantFnSnPnList.Count is 0. There are no vacant ports in MDU.");
  583:                                     }
  584:                                     else result.AddError("ont.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service: " + service + ", and access: " + nddOnt.Access.Name + ".");
  585:                                 }
  586:                                 else // SFU
  587:                                 {
  588:                                     var vacantList = Ia.Ftn.Cl.Model.Data.Nokia.Ams.VacantTelForOntList(ont);
  589: 
  590:                                     if (port != Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  591:                                     {
  592:                                         port = vacantList.Contains(port) ? port : Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
  593:                                     }
  594:                                     else port = Ia.Ftn.Cl.Model.Data.Nokia.Ams.NextVacantTelForOnt(ont);
  595: 
  596:                                     if (port != Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  597:                                     {
  598:                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendCreateOntSipInfo(ems, nddOnt, service, port);
  599: 
  600:                                         // Don't use SAVE-DEV here
  601:                                         //Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, ont.EmsPort.EmsBoard.EmsDev);
  602: 
  603:                                         associateServiceIdAndPortBetweenCreateAndReadDictionary[service] = port;
  604: 
  605:                                         result.AddSuccess("command(s) sent...");
  606:                                     }
  607:                                     else result.AddError("port is invalid or does not exist.");
  608:                                 }
  609:                             }
  610:                             else result.AddError("OLT is not SIP, its H.248.");
  611:                         }
  612:                         else result.AddError("ont is null, does not exist for access: " + nddOnt.Access.Name + ".");
  613:                     }
  614:                     else result.AddError("access is not in an allowed to be provisioned OLT: " + nddOnt.Access.Name + ".");
  615:                 }
  616:                 else result.AddError("nddOnt is null, does not exist for service: " + service + ".");
  617:             }
  618:             else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
  619:         }
  620: 
  621:         ////////////////////////////////////////////////////////////////////////////
  622: 
  623:         /// <summary>
  624:         ///
  625:         /// </summary>
  626:         public static void ReadOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(string service, out Ia.Cl.Models.Result result)
  627:         {
  628:             ReadOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, string.Empty, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown, out result);
  629:         }
  630: 
  631:         ////////////////////////////////////////////////////////////////////////////
  632: 
  633:         /// <summary>
  634:         ///
  635:         /// </summary>
  636:         public static void ReadOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(string service, string accessName, int port, out Ia.Cl.Models.Result result)
  637:         {
  638:             int serviceType;
  639:             string serviceId;
  640: 
  641:             result = new Ia.Cl.Models.Result();
  642: 
  643:             serviceType = Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService;
  644: 
  645:             try
  646:             {
  647:                 if (!string.IsNullOrEmpty(service))
  648:                 {
  649:                     if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  650:                     {
  651:                         serviceId = Ia.Ftn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
  652: 
  653:                         if (!string.IsNullOrEmpty(accessName))
  654:                         {
  655:                             var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
  656: 
  657:                             if (nddOnt != null)
  658:                             {
  659:                                 Ia.Ftn.Cl.Model.Business.Nokia.Ams.ReadOntSipInfoOrVoipPstnUser(service, nddOnt, port, ref result);
  660:                             }
  661:                             else result.AddError("NDD ONT is null for access name: " + accessName + ".");
  662:                         }
  663:                         else
  664:                         {
  665:                             Ia.Ftn.Cl.Model.Business.Nokia.Ams.ReadOntSipInfoOrVoipPstnUser(service, null, port, ref result);
  666:                         }
  667:                     }
  668:                     else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
  669:                 }
  670:                 else result.AddError("Service null or empty.");
  671:             }
  672:             catch (Exception ex)
  673:             {
  674:                 result.AddError("Exception: " + ex.ToString() + ".");
  675:             }
  676:         }
  677: 
  678:         ////////////////////////////////////////////////////////////////////////////
  679: 
  680:         /// <summary>
  681:         ///
  682:         /// </summary>
  683:         public static void ReadOntSipInfoOrVoipPstnUser(string service, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, int port, ref Ia.Cl.Models.Result result)
  684:         {
  685:             Ia.Ftn.Cl.Model.Business.Nokia.Dev.MduDev mduDev;
  686:             Ia.Ftn.Cl.Model.Ont ont;
  687: 
  688:             if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  689:             {
  690:                 if (nddOnt != null)
  691:                 {
  692:                     ont = Ia.Ftn.Cl.Model.Data.Nokia.Ont.Read(nddOnt.Id);
  693: 
  694:                     if (ont != null)
  695:                     {
  696:                         if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
  697:                         {
  698:                             var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Default.AccessNameToMduDevDictionary;
  699: 
  700:                             if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
  701:                             {
  702:                                 mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
  703: 
  704:                                 if (port != Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  705:                                 {
  706:                                     var fnSnPnPort = mduDev.PossibleFnSnPnPortList.Where(f => f.Port == port).SingleOrDefault();
  707: 
  708:                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, mduDev.Dev, fnSnPnPort.Sn, fnSnPnPort.Pn);
  709:                                 }
  710:                                 else if (associateServiceIdAndPortBetweenCreateAndReadDictionary.ContainsKey(service))
  711:                                 {
  712:                                     port = associateServiceIdAndPortBetweenCreateAndReadDictionary[service];
  713: 
  714:                                     var fnSnPnPort = mduDev.PossibleFnSnPnPortList.Where(f => f.Port == port).SingleOrDefault();
  715: 
  716:                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, mduDev.Dev, fnSnPnPort.Sn, fnSnPnPort.Pn);
  717:                                 }
  718:                                 else
  719:                                 {
  720:                                     foreach (var fnSnPnPort in mduDev.PossibleFnSnPnPortList)
  721:                                     {
  722:                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, mduDev.Dev, fnSnPnPort.Sn, fnSnPnPort.Pn);
  723:                                     }
  724:                                 }
  725: 
  726:                                 result.AddSuccess("command(s) sent...");
  727:                             }
  728:                             else result.AddError("ont.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service: " + service + ", and access: " + nddOnt.Access.Name + ".");
  729:                         }
  730:                         else // SFU
  731:                         {
  732:                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadOntSipInfo(ems, nddOnt);
  733: 
  734:                             result.AddSuccess("command(s) sent...");
  735:                         }
  736:                     }
  737:                     else result.AddError("ont is null, does not exist for access: " + nddOnt.Access.Name + ".");
  738:                 }
  739:                 else
  740:                 {
  741:                     var emsOntSipInfoList = Ia.Ftn.Cl.Model.Data.Nokia.OntSipInfo.ReadByServiceIncludeEmsOntAndAccess(service);
  742: 
  743:                     if (emsOntSipInfoList.Count > 0)
  744:                     {
  745:                         // SFU
  746: 
  747:                         foreach (var emsOntSipInfo in emsOntSipInfoList)
  748:                         {
  749:                             ont = emsOntSipInfo.EmsOnt;
  750: 
  751:                             if (ont.Access != null)
  752:                             {
  753:                                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByOntAccessId(ont.Access.Id);
  754: 
  755:                                 if (nddOnt != null)
  756:                                 {
  757:                                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
  758:                                     {
  759:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
  760:                                         {
  761:                                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadOntSipInfo(ems, nddOnt);
  762: 
  763:                                             result.AddSuccess("command(s) sent...");
  764:                                         }
  765:                                         else result.AddError("OLT is not SIP, its H.248.");
  766:                                     }
  767:                                     else result.AddError("nddOnt.Access.Name " + nddOnt.Access.Name + " is not in an allowed to be provisioned OLT.");
  768:                                 }
  769:                                 else result.AddError("nddOnt is null, does not exist for service " + service + ".");
  770:                             }
  771:                             else result.AddError("ont.Access is null for service " + service + ".");
  772:                         }
  773:                     }
  774: 
  775: 
  776:                     var emsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByService(service);
  777: 
  778:                     if (emsVoipPstnUserList.Count > 0)
  779:                     {
  780:                         // MDU
  781: 
  782:                         foreach (var emsVoipPstnUser in emsVoipPstnUserList)
  783:                         {
  784:                             ont = emsVoipPstnUser.EmsOnt;
  785: 
  786:                             if (ont.Access != null)
  787:                             {
  788:                                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByOntAccessId(ont.Access.Id);
  789: 
  790:                                 if (nddOnt != null)
  791:                                 {
  792:                                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
  793:                                     {
  794:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
  795:                                         {
  796:                                             if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
  797:                                             {
  798:                                                 var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Default.AccessNameToMduDevDictionary;
  799: 
  800:                                                 if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
  801:                                                 {
  802:                                                     mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
  803: 
  804:                                                     foreach (var fnSnPnPort in mduDev.PossibleFnSnPnPortList)
  805:                                                     {
  806:                                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, mduDev.Dev, fnSnPnPort.Sn, fnSnPnPort.Pn);
  807: 
  808:                                                         result.AddSuccess("command(s) sent...");
  809:                                                     }
  810:                                                 }
  811:                                                 else result.AddError("ont.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service: " + service + ", and access: " + nddOnt.Access.Name + ".");
  812:                                             }
  813:                                             else result.AddError("ONT family type is not MDU.");
  814:                                         }
  815:                                         else result.AddError("OLT is not SIP, its H.248.");
  816:                                     }
  817:                                     else result.AddError("nddOnt.Access.Name " + nddOnt.Access.Name + " is not in an allowed to be provisioned OLT.");
  818:                                 }
  819:                                 else result.AddError("nddOnt is null, does not exist for service " + service + ".");
  820:                             }
  821:                             else result.AddError("ont.Access is null for service " + service + ".");
  822:                         }
  823: 
  824: 
  825:                         var msanEmsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByMsanService(service);
  826: 
  827:                         if (msanEmsVoipPstnUserList.Count > 0)
  828:                         {
  829:                             // MSAN
  830: 
  831:                             foreach (var emsVoipPstnUser in msanEmsVoipPstnUserList)
  832:                             {
  833:                                 ReadVoipPstnUser(emsVoipPstnUser.DID, emsVoipPstnUser.FN, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
  834:                             }
  835: 
  836:                             result.AddSuccess("command(s) sent...");
  837:                         }
  838:                     }
  839:                 }
  840:             }
  841:             else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
  842:         }
  843: 
  844:         ////////////////////////////////////////////////////////////////////////////
  845: 
  846:         /// <summary>
  847:         ///
  848:         /// </summary>
  849:         public static string DeleteOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(string service, string accessName, int port, out Ia.Cl.Models.Result result)
  850:         {
  851:             int serviceType;
  852:             string serviceId, vacatedAccessName;
  853:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont vacatedNddOnt;
  854: 
  855:             result = new Ia.Cl.Models.Result();
  856: 
  857:             serviceType = Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService;
  858: 
  859:             vacatedAccessName = string.Empty;
  860: 
  861:             try
  862:             {
  863:                 if (!string.IsNullOrEmpty(service))
  864:                 {
  865:                     if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  866:                     {
  867:                         serviceId = Ia.Ftn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
  868: 
  869:                         if (!string.IsNullOrEmpty(accessName))
  870:                         {
  871:                             var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
  872: 
  873:                             if (nddOnt != null)
  874:                             {
  875:                                 vacatedNddOnt = Ia.Ftn.Cl.Model.Business.Nokia.Ams.VacateOntSipInfoOrDeleteVoipPstnUserAndOrVacateVoipPstnAccount(service, nddOnt, port, ref result);
  876: 
  877:                                 vacatedAccessName = (vacatedNddOnt != null) ? vacatedNddOnt.Access.Name : string.Empty;
  878:                             }
  879:                             else result.AddError("NDD ONT is null for access name: " + accessName + ".");
  880:                         }
  881:                         else if (port == Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  882:                         {
  883:                             vacatedNddOnt = Ia.Ftn.Cl.Model.Business.Nokia.Ams.VacateOntSipInfoOrDeleteVoipPstnUserAndOrVacateVoipPstnAccount(service, null, port, ref result);
  884: 
  885:                             vacatedAccessName = (vacatedNddOnt != null) ? vacatedNddOnt.Access.Name : string.Empty;
  886:                         }
  887:                         else result.AddError("accessName is empty or null and port is not PortUndefinedOrInvalidOrUnknown. NCE does not know how to handle vacation where nddOnt is null and port is defined.");
  888:                     }
  889:                     else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
  890:                 }
  891:                 else result.AddError("Service null or empty.");
  892:             }
  893:             catch (Exception ex)
  894:             {
  895:                 result.AddError("Exception: " + ex.ToString() + ".");
  896:             }
  897: 
  898:             return vacatedAccessName;
  899:         }
  900: 
  901:         ////////////////////////////////////////////////////////////////////////////
  902: 
  903:         /// <summary>
  904:         ///
  905:         /// </summary>
  906:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont VacateOntSipInfoOrDeleteVoipPstnUserAndOrVacateVoipPstnAccount(string service, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, int port, ref Ia.Cl.Models.Result result)
  907:         {
  908:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont vacatedNddOnt;
  909:             Ia.Ftn.Cl.Model.Business.Nokia.Dev.MduDev mduDev;
  910:             Ia.Ftn.Cl.Model.Ont ont;
  911: 
  912:             vacatedNddOnt = nddOnt;
  913: 
  914:             if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  915:             {
  916:                 if (nddOnt != null)
  917:                 {
  918:                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
  919:                     {
  920:                         if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
  921:                         {
  922:                             ont = Ia.Ftn.Cl.Model.Data.Nokia.Ont.ReadIncludeAccess(nddOnt.Id);
  923: 
  924:                             if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
  925:                             {
  926:                                 var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Default.AccessNameToMduDevDictionary;
  927: 
  928:                                 if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
  929:                                 {
  930:                                     mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
  931: 
  932:                                     if (port == Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  933:                                     {
  934:                                         var emsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByService(service);
  935: 
  936:                                         foreach (var emsVoipPstnUser in emsVoipPstnUserList)
  937:                                         {
  938:                                             if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
  939:                                             {
  940:                                                 Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateVoipPstnAccount(ems, mduDev, nddOnt, service, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
  941:                                             }
  942: 
  943:                                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, mduDev, nddOnt, service, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
  944: 
  945:                                             result.AddSuccess("command(s) sent...");
  946:                                         }
  947:                                     }
  948:                                     else
  949:                                     {
  950:                                         var fnSnPnPort = mduDev.PossibleFnSnPnPortList.Where(f => f.Port == port).SingleOrDefault();
  951: 
  952:                                         if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
  953:                                         {
  954:                                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateVoipPstnAccount(ems, mduDev, nddOnt, service, mduDev.FirstFnSnPnPort.Sn, fnSnPnPort.Pn);
  955:                                         }
  956: 
  957:                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, mduDev, nddOnt, service, mduDev.FirstFnSnPnPort.Sn, fnSnPnPort.Pn);
  958: 
  959:                                         result.AddSuccess("command(s) sent...");
  960:                                     }
  961: 
  962:                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, mduDev);
  963:                                 }
  964:                                 else result.AddError("ont.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service " + service + " and access " + nddOnt.Access.Name + ".");
  965:                             }
  966:                             else // SFU
  967:                             {
  968:                                 if (port == Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown)
  969:                                 {
  970:                                     var emsOntSipInfoList = Ia.Ftn.Cl.Model.Data.Nokia.OntSipInfo.ReadByService(service);
  971: 
  972:                                     foreach (var emsOntSipInfo in emsOntSipInfoList)
  973:                                     {
  974:                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateOntSipInfo(ems, nddOnt, service, emsOntSipInfo.TEL);
  975:                                     }
  976: 
  977:                                     result.AddSuccess("command(s) sent...");
  978:                                 }
  979:                                 else
  980:                                 {
  981:                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateOntSipInfo(ems, nddOnt, service, port);
  982: 
  983:                                     result.AddSuccess("command(s) sent...");
  984:                                 }
  985:                             }
  986:                         }
  987:                         else result.AddError("OLT is not SIP, its H.248.");
  988:                     }
  989:                     else result.AddError("nddOnt.Access.Name " + nddOnt.Access.Name + " is not in an allowed to be provisioned OLT.");
  990:                 }
  991:                 else
  992:                 {
  993:                     var emsOntSipInfoList = Ia.Ftn.Cl.Model.Data.Nokia.OntSipInfo.ReadByServiceIncludeEmsOntAndAccess(service);
  994: 
  995:                     if (emsOntSipInfoList.Count > 0)
  996:                     {
  997:                         // SFU
  998: 
  999:                         foreach (var emsOntSipInfo in emsOntSipInfoList)
 1000:                         {
 1001:                             ont = emsOntSipInfo.EmsOnt;
 1002: 
 1003:                             if (ont.Access != null)
 1004:                             {
 1005:                                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByOntAccessId(ont.Access.Id);
 1006: 
 1007:                                 if (nddOnt != null)
 1008:                                 {
 1009:                                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
 1010:                                     {
 1011:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
 1012:                                         {
 1013:                                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateOntSipInfo(ems, nddOnt, service, emsOntSipInfo.TEL);
 1014: 
 1015:                                             result.AddSuccess("command(s) sent...");
 1016:                                         }
 1017:                                         else result.AddError("OLT is not SIP, its H.248.");
 1018:                                     }
 1019:                                     else result.AddError("nddOnt.Access.Name " + nddOnt.Access.Name + " is not in an allowed to be provisioned OLT.");
 1020:                                 }
 1021:                                 else result.AddError("nddOnt is null, does not exist for service " + service + ".");
 1022: 
 1023:                                 vacatedNddOnt = nddOnt;
 1024:                             }
 1025:                             else result.AddError("ont.Access is null for service " + service + ".");
 1026:                         }
 1027:                     }
 1028: 
 1029: 
 1030:                     var emsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByService(service);
 1031: 
 1032:                     if (emsVoipPstnUserList.Count > 0)
 1033:                     {
 1034:                         // MDU
 1035: 
 1036:                         foreach (var emsVoipPstnUser in emsVoipPstnUserList)
 1037:                         {
 1038:                             ont = emsVoipPstnUser.EmsOnt;
 1039: 
 1040:                             if (ont.Access != null)
 1041:                             {
 1042:                                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByOntAccessId(ont.Access.Id);
 1043: 
 1044:                                 if (nddOnt != null)
 1045:                                 {
 1046:                                     if (Ia.Ftn.Cl.Model.Business.Service.OltIsWithinAllowedToBeProvisionedOrMigratedOltList(nddOnt.Pon.PonGroup.Olt))
 1047:                                     {
 1048:                                         if (nddOnt.Pon.PonGroup.Olt.IsSip == true)
 1049:                                         {
 1050:                                             if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
 1051:                                             {
 1052:                                                 var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Nokia.Default.AccessNameToMduDevDictionary;
 1053: 
 1054:                                                 if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
 1055:                                                 {
 1056:                                                     mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
 1057: 
 1058:                                                     if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 1059:                                                     {
 1060:                                                         Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateVoipPstnAccount(ems, mduDev, nddOnt, service, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
 1061:                                                     }
 1062: 
 1063:                                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, mduDev, nddOnt, service, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
 1064: 
 1065:                                                     Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, mduDev);
 1066: 
 1067:                                                     result.AddSuccess("command(s) sent...");
 1068:                                                 }
 1069:                                                 else result.AddError("ont.FamilyType is MDU but AccessNameToMduDevDictionary does not contain key: " + nddOnt.Access.Name + " for service: " + service + ", and access: " + nddOnt.Access.Name + ".");
 1070:                                             }
 1071:                                             else result.AddError("ONT family type is not MDU.");
 1072:                                         }
 1073:                                         else result.AddError("OLT is not SIP, its H.248.");
 1074:                                     }
 1075:                                     else result.AddError("nddOnt.Access.Name " + nddOnt.Access.Name + " is not in an allowed to be provisioned OLT.");
 1076:                                 }
 1077:                                 else result.AddError("nddOnt is null, does not exist for service " + service + ".");
 1078: 
 1079:                                 vacatedNddOnt = nddOnt;
 1080:                             }
 1081:                             else result.AddError("ont.Access is null for service " + service + ".");
 1082:                         }
 1083:                     }
 1084:                     else
 1085:                     {
 1086:                         var msanEmsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByMsanService(service);
 1087: 
 1088:                         if (msanEmsVoipPstnUserList.Count > 0)
 1089:                         {
 1090:                             // MSAN
 1091: 
 1092:                             foreach (var emsVoipPstnUser in msanEmsVoipPstnUserList)
 1093:                             {
 1094:                                 DeleteVoipPstnUserAndOrVacateVoipPstnAccount(emsVoipPstnUser.DID, emsVoipPstnUser.FN, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
 1095:                             }
 1096: 
 1097:                             result.AddSuccess("command(s) sent...");
 1098:                         }
 1099:                         else result.AddWarning("Could not find service " + service + ".");
 1100:                     }
 1101:                 }
 1102:             }
 1103:             else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
 1104: 
 1105:             return vacatedNddOnt;
 1106:         }
 1107: 
 1108:         ////////////////////////////////////////////////////////////////////////////
 1109: 
 1110:         /// <summary>
 1111:         ///
 1112:         /// </summary>
 1113:         public static List<Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic> DeleteMsanVoipPstnUser2(string service, out Ia.Cl.Models.Result result)
 1114:         {
 1115:             Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic lic;
 1116: 
 1117:             result = new Ia.Cl.Models.Result();
 1118: 
 1119:             var licList = new List<Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic>();
 1120: 
 1121:             if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
 1122:             {
 1123:                 var msanEmsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByMsanService(service);
 1124: 
 1125:                 if (msanEmsVoipPstnUserList.Count > 0)
 1126:                 {
 1127:                     // MSAN
 1128: 
 1129:                     foreach (var emsVoipPstnUser in msanEmsVoipPstnUserList)
 1130:                     {
 1131:                         DeleteVoipPstnUserAndOrVacateVoipPstnAccount(emsVoipPstnUser.DID, emsVoipPstnUser.FN, emsVoipPstnUser.SN, emsVoipPstnUser.PN);
 1132: 
 1133:                         lic = Ia.Ftn.Cl.Model.Data.Nokia.Default.MsanDevLicByEmsVoipPstnUserId(emsVoipPstnUser.Id);
 1134: 
 1135:                         licList.Add(lic);
 1136:                     }
 1137: 
 1138:                     result.AddSuccess("command(s) sent...");
 1139:                 }
 1140:                 else result.AddWarning("Could not find service " + service + ".");
 1141:             }
 1142:             else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
 1143: 
 1144:             return licList;
 1145:         }
 1146: 
 1147:         ////////////////////////////////////////////////////////////////////////////
 1148: 
 1149:         /// <summary>
 1150:         ///
 1151:         /// </summary>
 1152:         public static void DeleteVoipPstnUserAndOrVacateVoipPstnAccount(string dev, int fn, int sn, int pn)
 1153:         {
 1154:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateVoipPstnAccount(ems, dev, fn, sn, pn);
 1155: 
 1156:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, dev, fn, sn, pn);
 1157: 
 1158:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, dev);
 1159:         }
 1160: 
 1161:         ////////////////////////////////////////////////////////////////////////////
 1162: 
 1163:         /// <summary>
 1164:         ///
 1165:         /// </summary>
 1166:         private static void DeleteVoipPstnUserAndOrVacateVoipPstnAccount(int did, int fn, int sn, int pn)
 1167:         {
 1168:             var dev = Ia.Ftn.Cl.Model.Data.Nokia.Dev.DidToDevDictionary[did];
 1169: 
 1170:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendVacateVoipPstnAccount(ems, dev, fn, sn, pn);
 1171: 
 1172:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, dev, fn, sn, pn);
 1173: 
 1174:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, dev);
 1175:         }
 1176: 
 1177:         ////////////////////////////////////////////////////////////////////////////
 1178:         ////////////////////////////////////////////////////////////////////////////
 1179: 
 1180:         /// <summary>
 1181:         ///
 1182:         /// </summary>
 1183:         public static Ia.Cl.Models.Result CreateMsanVoipPstnUser(string msanDevId, int fn, int sn, int pn, string service)
 1184:         {
 1185:             Ia.Ftn.Cl.Model.Business.Nokia.Default.FnSnPnPort fnSnPn;
 1186: 
 1187:             var result = new Ia.Cl.Models.Result();
 1188: 
 1189:             if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
 1190:             {
 1191:                 var msanDev = (from m in Ia.Ftn.Cl.Model.Data.Nokia.Default.MsanDevList where m.Id == msanDevId select m).Single();
 1192: 
 1193:                 var vacantFnSnPnList = Ia.Ftn.Cl.Model.Data.Nokia.Ams.VacantMsanFnSnPnListForMsanDev(msanDev);
 1194: 
 1195:                 if (vacantFnSnPnList.Count > 0)
 1196:                 {
 1197:                     fnSnPn = vacantFnSnPnList.Where(f => f.Fn == fn && f.Sn == sn && f.Pn == pn).SingleOrDefault();
 1198: 
 1199:                     if (fnSnPn == null) fnSnPn = Ia.Ftn.Cl.Model.Data.Nokia.Ams.NextVacantMsanFnSnPnForMsanDev(msanDev);
 1200: 
 1201:                     if (fnSnPn != null)
 1202:                     {
 1203:                         var emsVoipPstnUserList = Ia.Ftn.Cl.Model.Data.Nokia.VoipPstnUser.ReadByService(service);
 1204: 
 1205:                         if (emsVoipPstnUserList.Count == 0)
 1206:                         {
 1207:                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendCreateMsanVoipPstnUser(ems, msanDev, fnSnPn.Fn, fnSnPn.Sn, fnSnPn.Pn, service);
 1208: 
 1209:                             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, msanDev);
 1210: 
 1211:                             result.AddSuccess("command(s) sent...");
 1212:                         }
 1213:                         else result.AddError("emsVoipPstnUserList count != 0. Value must be zero before the operation is executed for service: " + service + ".");
 1214:                     }
 1215:                     else result.AddError("MDU sn and/or tel is invalid or does not exist.");
 1216:                 }
 1217:                 else result.AddError("vacantFnSnPnList.Count is 0. There are no vacant ports in MSAN.");
 1218:             }
 1219:             else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
 1220: 
 1221:             return result;
 1222:         }
 1223: 
 1224:         ////////////////////////////////////////////////////////////////////////////
 1225: 
 1226:         /// <summary>
 1227:         ///
 1228:         /// </summary>
 1229:         public static void ReadVoipPstnUser(string dev, int fn, int sn, int pn)
 1230:         {
 1231:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, dev, sn, pn);
 1232:         }
 1233: 
 1234:         ////////////////////////////////////////////////////////////////////////////
 1235: 
 1236:         /// <summary>
 1237:         ///
 1238:         /// </summary>
 1239:         public static void ReadMsanVoipPstnUser(Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic lic)
 1240:         {
 1241:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, lic.MsanDevDev, lic.Sn, lic.Pn);
 1242:         }
 1243: 
 1244:         ////////////////////////////////////////////////////////////////////////////
 1245: 
 1246:         /// <summary>
 1247:         ///
 1248:         /// </summary>
 1249:         public static void ReadVoipPstnUser(string service)
 1250:         {
 1251:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, service);
 1252:         }
 1253: 
 1254:         ////////////////////////////////////////////////////////////////////////////
 1255: 
 1256:         /// <summary>
 1257:         ///
 1258:         /// </summary>
 1259:         private static void ReadVoipPstnUser(int did, int fn, int sn, int pn)
 1260:         {
 1261:             var dev = Ia.Ftn.Cl.Model.Data.Nokia.Dev.DidToDevDictionary[did];
 1262: 
 1263:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendReadVoipPstnUser(ems, dev, sn, pn);
 1264:         }
 1265: 
 1266:         ////////////////////////////////////////////////////////////////////////////
 1267: 
 1268:         /// <summary>
 1269:         ///
 1270:         /// </summary>
 1271:         public static void DeleteVoipPstnUser(string dev, int fn, int sn, int pn)
 1272:         {
 1273:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendDeleteVoipPstnUser(ems, dev, fn, sn, pn);
 1274: 
 1275:             Ia.Ftn.Cl.Model.Data.Nokia.Ams.SendSaveDev(ems, dev);
 1276:         }
 1277: 
 1278:         ////////////////////////////////////////////////////////////////////////////
 1279: 
 1280:         /// <summary>
 1281:         ///
 1282:         /// </summary>
 1283:         public static List<Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic> DeleteMsanVoipPstnUser(string service, out Ia.Cl.Models.Result result)
 1284:         {
 1285:             var licList = new List<Ia.Ftn.Cl.Model.Business.Nokia.Dev.MsanDev.Lic>();
 1286: 
 1287:             result = new Ia.Cl.Models.Result();
 1288: 
 1289:             try
 1290:             {
 1291:                 if (!string.IsNullOrEmpty(service))
 1292:                 {
 1293:                     if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
 1294:                     {
 1295:                         licList = Ia.Ftn.Cl.Model.Business.Nokia.Nce.DeleteMsanVoipPstnUser2(service, out result);
 1296:                     }
 1297:                     else result.AddError("Service number " + service + " does not belong to allowed domain lists.");
 1298:                 }
 1299:                 else result.AddError("Service null or empty.");
 1300:             }
 1301:             catch (Exception ex)
 1302:             {
 1303:                 result.AddError("Exception: " + ex.ToString() + ".");
 1304:             }
 1305: 
 1306:             return licList;
 1307:         }
 1308:         */
 1309:  
 1310:         ////////////////////////////////////////////////////////////////////////////
 1311:         ////////////////////////////////////////////////////////////////////////////
 1312:  
 1313:         /// <summary>
 1314:         ///
 1315:         /// </summary>
 1316:         public static Ia.Cl.Models.Result ResetOntInEventsWithClassOntAndCauseInactAndSeverityNotClInLast24HoursList()
 1317:         {
 1318:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
 1319:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontResetSentList;
 1320:             Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontIdToOntDictionary;
 1321:  
 1322:             var result = new Ia.Cl.Models.Result();
 1323:  
 1324:             ontResetSentList = new List<Cl.Models.Business.NetworkDesignDocument.Ont>();
 1325:  
 1326:             var events = Ia.Ftn.Cl.Models.Data.Event.EventWithClassOntAndCauseInactAndLastRecordSeverityNotClAndOntAccessNotNullInLast24HoursList();
 1327:             ontIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary;
 1328:  
 1329:             if (events.Count > 0)
 1330:             {
 1331:                 foreach (var @event in events)
 1332:                 {
 1333:                     if (ontIdToOntDictionary.ContainsKey(@event.Ont.Id))
 1334:                     {
 1335:                         ont = ontIdToOntDictionary[@event.Ont.Id];
 1336:  
 1337:                         if (!eventDictionary.ContainsKey(ont))
 1338:                         {
 1339:                             eventDictionary[ont] = false;
 1340:                         }
 1341:                     }
 1342:                 }
 1343:             }
 1344:             else
 1345:             {
 1346:  
 1347:             }
 1348:  
 1349:             foreach (KeyValuePair<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont, bool> kvp in eventDictionary)
 1350:             {
 1351:                 if (!kvp.Value)
 1352:                 {
 1353:                     ams.SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Nokia.Ams.ResetOntCommand(kvp.Key));
 1354:  
 1355:                     if (result.IsSuccessful) ontResetSentList.Add(kvp.Key);
 1356:                 }
 1357:             }
 1358:  
 1359:             return result;
 1360:         }
 1361:  
 1362:         ////////////////////////////////////////////////////////////////////////////
 1363:  
 1364:         /// <summary>
 1365:         /// Enqueue all ONTs within the eventDictionary to make sure we read their state after the reset
 1366:         /// </summary>
 1367:         public static void EnqueueOntWithinEventDictionary()
 1368:         {
 1369:             foreach (KeyValuePair<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont, bool> kvp in eventDictionary)
 1370:             {
 1371:                 //if (!kvp.Value)
 1372:                 //{
 1373:                 // this will read all reset ONT all day until eventDictionary is cleared.
 1374:                 // eventDictionary[kvp.Value] = true;
 1375:  
 1376:                 Ia.Ftn.Cl.Models.Data.MessageQueue.SecretaryApplication.Enqueue(Ia.Ftn.Cl.Models.Business.MessageQueue.Application.AmsApplication, Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ReadAccess, kvp.Key.Access.Name);
 1377:                 //}
 1378:             }
 1379:  
 1380:             // reset events dictionary
 1381:             eventDictionary.Clear();
 1382:         }
 1383:  
 1384:         ////////////////////////////////////////////////////////////////////////////
 1385:  
 1386:         /// <summary>
 1387:         ///
 1388:         /// </summary>
 1389:         public static Ia.Cl.Models.Result ManageMessageQueue()
 1390:         {
 1391:             var result = new Ia.Cl.Models.Result();
 1392:  
 1393:             var queueCount = Ia.Ftn.Cl.Models.Data.MessageQueue.AmsApplication.Count;
 1394:  
 1395:             if (queueCount > 0)
 1396:             {
 1397:                 var message = Ia.Ftn.Cl.Models.Data.MessageQueue.AmsApplication.Dequeue;
 1398:  
 1399:                 if (message != null)
 1400:                 {
 1401:                     if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ReadAccess)
 1402:                     {
 1403:                         SendQueueEnqueueReadOnt(message.AccessName, out result);
 1404:                     }
 1405:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ResetAccess)
 1406:                     {
 1407:                         SendQueueEnqueueResetOnt(message.AccessName, out result);
 1408:                     }
 1409:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.CreateReadServiceAccessPort || message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.CreateReadNceOrAmsServiceAccessPort)
 1410:                     {
 1411:                         var service = message.Service;
 1412:                         var accessName = message.AccessName;
 1413:                         var port = (message.Port > 0) ? message.Port : Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
 1414:  
 1415:                         var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
 1416:  
 1417:                         if (nddOnt != null)
 1418:                         {
 1419:                             if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1420:                             {
 1421:                                 //Ia.Ftn.Cl.Model.Business.Nokia.Nce.CreateOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, accessName, port, out Ia.Cl.Models.Result createResult);
 1422:  
 1423:                                 //Ia.Ftn.Cl.Model.Business.Nokia.Nce.ReadOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, accessName, port, out Ia.Cl.Models.Result readResult);
 1424:  
 1425:                                 result.AddSuccess("Create/Read: " + service + "|" + accessName + "|" + port + ": " + " Hu-No SIP undefined"); // createResult.Message + "," + readResult.Message);
 1426:  
 1427:                                 if (!priorityServiceList.Contains(service)) priorityServiceList.Add(service);
 1428:                             }
 1429:                             else result.AddError("Access vendor is not Nokia. Access name: " + accessName + ".");
 1430:                         }
 1431:                         else result.AddError("NDD ONT is null for access name: " + accessName + ".");
 1432:                     }
 1433:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.DeleteReadServiceAccess || message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.DeleteReadNceOrAmsServiceAccessPort)
 1434:                     {
 1435:                         var service = message.Service;
 1436:                         var accessName = message.AccessName;
 1437:                         var port = (message.Port > 0) ? message.Port : Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
 1438:  
 1439:                         var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
 1440:  
 1441:                         if (nddOnt != null)
 1442:                         {
 1443:                             if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1444:                             {
 1445:                                 //var vacatedAccessName = Ia.Ftn.Cl.Model.Business.Nokia.Nce.DeleteOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, accessName, port, out Ia.Cl.Models.Result deleteResult);
 1446:  
 1447:                                 //Ia.Ftn.Cl.Model.Business.Nokia.Nce.ReadOntSipInfoOrVoipPstnUserAndOrVoipPstnAccount(service, vacatedAccessName, port, out Ia.Cl.Models.Result readResult);
 1448:  
 1449:                                 result.AddSuccess("Delete/Read: " + service + "|" + accessName + "|" + port + ": " + " Hu-No SIP undefined"); //  + deleteResult.Message + "," + readResult.Message);
 1450:  
 1451:                                 if (!priorityServiceList.Contains(service)) priorityServiceList.Add(service);
 1452:                             }
 1453:                             else result.AddError("Access vendor is not Nokia. Access name: " + accessName + ".");
 1454:                         }
 1455:                         else result.AddError("NDD ONT is null for access name: " + accessName + ".");
 1456:                     }
 1457:                     else if (message.Process == Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ActiveApplicationRunningPermissionState)
 1458:                     {
 1459:                         Ia.Ftn.Cl.Models.Business.Default.PermitActiveApplicationsToRun = message.State;
 1460:  
 1461:                         result.AddSuccess("PermitActiveApplicationsToRun: " + message.State);
 1462:                     }
 1463:                     else
 1464:                     {
 1465:                         throw new ArgumentOutOfRangeException("MessageQueue process " + message.Process.ToString() + " is undefined");
 1466:                     }
 1467:  
 1468:                     result.AddSuccess(message.AccessName);
 1469:                 }
 1470:                 else
 1471:                 {
 1472:                 }
 1473:             }
 1474:  
 1475:             return result;
 1476:         }
 1477:  
 1478:         ////////////////////////////////////////////////////////////////////////////
 1479:  
 1480:         /// <summary>
 1481:         ///
 1482:         /// </summary>
 1483:         public static string ManageProperly()
 1484:         {
 1485:             var command = Ia.Ftn.Cl.Models.Business.Nokia.Ams.ProperlySelectedSingleAmsCommandToManageOntVoipPotsNetworkElements();
 1486:  
 1487:             ams.SendQueue.Enqueue(command);
 1488:  
 1489:             return command;
 1490:         }
 1491:  
 1492:         ////////////////////////////////////////////////////////////////////////////
 1493:  
 1494:         /// <summary>
 1495:         ///
 1496:         /// </summary>
 1497:         public static void KeepAliveOltAmsNameListItem()
 1498:         {
 1499:             keepAliveCurrentAmsName = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaOltAmsNameList.NextOf(keepAliveCurrentAmsName);
 1500:  
 1501:             ams.SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Nokia.Ams.AmsKeepAliveCommand(keepAliveCurrentAmsName));
 1502:  
 1503:             /*
 1504:             foreach (string amsName in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.IsNrNokiaOltAmsNameList)
 1505:             {
 1506:                 sendQueue.Enqueue(Ia.Ftn.Cl.Model.Business.Nokia.Ams.AmsKeepAliveCommand(amsName));
 1507:             }
 1508:             */
 1509:         }
 1510:  
 1511:         ////////////////////////////////////////////////////////////////////////////
 1512:         ////////////////////////////////////////////////////////////////////////////
 1513:  
 1514:         /// <summary>
 1515:         ///
 1516:         /// </summary>
 1517:         public static void SendQueueEnqueueReadOnt(string input, out Ia.Cl.Models.Result result)
 1518:         {
 1519:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor accessVendor;
 1520:             List<string> amsCommandList;
 1521:  
 1522:             result = new Ia.Cl.Models.Result();
 1523:  
 1524:             if (!string.IsNullOrEmpty(input))
 1525:             {
 1526:                 if (input.Length > 0)
 1527:                 {
 1528:                     input = input.Trim();
 1529:                     input = input.ToUpper();
 1530:  
 1531:                     if (Regex.IsMatch(input, @"^[a-zA-Z]{3}\s+\d{1,3}\s+\d{1,3}$") || Regex.IsMatch(input, @"^[a-zA-Z]{3}\.\d{1,3}\.\d{1,3}$") || Regex.IsMatch(input, @"^[a-zA-Z]{3}\/\d{1,3}\/\d{1,3}$"))
 1532:                     {
 1533:                         if (Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out string accessName))
 1534:                         {
 1535:                             accessVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.AccessVendorByAccessName(accessName);
 1536:  
 1537:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1538:                             {
 1539:                                 amsCommandList = Ia.Ftn.Cl.Models.Business.Nokia.Ams.AmsCommandsToRetrieveOntVoipPotsForASingleOntWithDefinedFamilyTypeAndForItIfThisSingleOntDefinedInNddDocumentList(accessName);
 1540:  
 1541:                                 if (amsCommandList != null && amsCommandList.Count > 0)
 1542:                                 {
 1543:                                     if (Ia.Ftn.Cl.Models.Business.Nokia.Ams.IsConnected /*&& activated && !receivingData*/)
 1544:                                     {
 1545:                                         foreach (string s in amsCommandList)
 1546:                                         {
 1547:                                             //telnet.Send(s);
 1548:                                             ams.SendQueue.Enqueue(s);
 1549:                                         }
 1550:                                     }
 1551:  
 1552:                                     result.AddSuccess(accessName);
 1553:                                 }
 1554:                             }
 1555:                             else
 1556:                             {
 1557:                                 result.AddError("SendQueueEnqueueReadOnt(): Error: access [" + accessName + "] is not a valid Nokia access ONT.");
 1558:                             }
 1559:                         }
 1560:                         else
 1561:                         {
 1562:                             result.AddError("SendQueueEnqueueReadOnt(): Error: input AccessName [" + accessName + "] is not within allowed ONT list.");
 1563:                         }
 1564:                     }
 1565:                     else
 1566:                     {
 1567:                         result.AddError("SendQueueEnqueueReadOnt(): Error: input: [" + input + "] is not a valid OntName or AccessName.");
 1568:                     }
 1569:                 }
 1570:                 else
 1571:                 {
 1572:                     result.AddError("SendQueueEnqueueReadOnt(): Error: input is empty.");
 1573:                 }
 1574:             }
 1575:             else
 1576:             {
 1577:                 result.AddError("SendQueueEnqueueReadOnt(): Error: input is null or empty.");
 1578:             }
 1579:         }
 1580:  
 1581:         ////////////////////////////////////////////////////////////////////////////
 1582:  
 1583:         /// <summary>
 1584:         ///
 1585:         /// </summary>
 1586:         public static void SendQueueEnqueueResetOnt(string input, out Ia.Cl.Models.Result result)
 1587:         {
 1588:             string amsCommand;
 1589:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor accessVendor;
 1590:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1591:             //List<string> amsCommandList;
 1592:  
 1593:             result = new Ia.Cl.Models.Result();
 1594:  
 1595:             if (!string.IsNullOrEmpty(input))
 1596:             {
 1597:                 if (input.Length > 0)
 1598:                 {
 1599:                     input = input.Trim();
 1600:                     input = input.ToUpper();
 1601:  
 1602:                     if (Regex.IsMatch(input, @"^[a-zA-Z]{3}\s+\d{1,3}\s+\d{1,3}$") || Regex.IsMatch(input, @"^[a-zA-Z]{3}\.\d{1,3}\.\d{1,3}$") || Regex.IsMatch(input, @"^[a-zA-Z]{3}\/\d{1,3}\/\d{1,3}$"))
 1603:                     {
 1604:                         if (Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out string accessName))
 1605:                         {
 1606:                             accessVendor = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.AccessVendorByAccessName(accessName);
 1607:  
 1608:                             nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
 1609:  
 1610:                             if (accessVendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1611:                             {
 1612:                                 amsCommand = Ia.Ftn.Cl.Models.Business.Nokia.Ams.ResetOntCommand(nddOnt);
 1613:  
 1614:                                 if (!string.IsNullOrEmpty(amsCommand))
 1615:                                 {
 1616:                                     ams.SendQueue.Enqueue(amsCommand);
 1617:                                     result.AddSuccess(accessName);
 1618:                                 }
 1619:                             }
 1620:                             else
 1621:                             {
 1622:                                 result.AddError("SendQueueEnqueueResetOnt(): Error: access [" + accessName + "] is not a valid Nokia access ONT.");
 1623:                             }
 1624:                         }
 1625:                         else
 1626:                         {
 1627:                             result.AddError("SendQueueEnqueueResetOnt(): Error: input AccessName [" + accessName + "] is not within allowed ONT list.");
 1628:                         }
 1629:                     }
 1630:                     else
 1631:                     {
 1632:                         result.AddError("SendQueueEnqueueResetOnt(): Error: input: [" + input + "] is not a valid OntName or AccessName.");
 1633:                     }
 1634:                 }
 1635:                 else
 1636:                 {
 1637:                     result.AddError("SendQueueEnqueueResetOnt(): Error: input is empty.");
 1638:                 }
 1639:             }
 1640:             else
 1641:             {
 1642:                 result.AddError("SendQueueEnqueueResetOnt(): Error: input is null or empty.");
 1643:             }
 1644:         }
 1645:  
 1646:         ////////////////////////////////////////////////////////////////////////////
 1647:         ////////////////////////////////////////////////////////////////////////////
 1648:  
 1649:         /// <summary>
 1650:         ///
 1651:         /// </summary>
 1652:         private static List<string> PrepareCtaggedCommand(List<string> commandList)
 1653:         {
 1654:             List<string> ctaggedCommandList;
 1655:  
 1656:             if (commandList.Count > 0)
 1657:             {
 1658:                 ctaggedCommandList = new List<string>(commandList.Count);
 1659:  
 1660:                 foreach (string command in commandList)
 1661:                 {
 1662:                     ctaggedCommandList.Add(PrepareCtaggedCommand(command));
 1663:                 }
 1664:             }
 1665:             else ctaggedCommandList = new List<string>();
 1666:  
 1667:             return ctaggedCommandList;
 1668:         }
 1669:  
 1670:         ////////////////////////////////////////////////////////////////////////////
 1671:  
 1672:         /// <summary>
 1673:         ///
 1674:         /// </summary>
 1675:         private static string PrepareCtaggedCommand(string command)
 1676:         {
 1677:             string ctaggedCommand, ctag;
 1678:  
 1679:             if (command.Contains("{ctag}"))
 1680:             {
 1681:                 ctag = Ia.Cl.Models.Default.RandomNumber(6);
 1682:                 // CTAG: The value of the CTAG is a non-zero integer of up to six characters. 
 1683:                 // CTAG comes before ; or ::
 1684:  
 1685:                 Ia.Ftn.Cl.Models.Data.Nokia.Ams.CorrelationTagDictionary[ctag] = command;
 1686:  
 1687:                 ctaggedCommand = command.Replace("{ctag}", ctag);
 1688:             }
 1689:             else
 1690:             {
 1691:                 ctaggedCommand = string.Empty;
 1692:             }
 1693:  
 1694:             return ctaggedCommand;
 1695:         }
 1696:  
 1697:         ////////////////////////////////////////////////////////////////////////////
 1698:         ////////////////////////////////////////////////////////////////////////////
 1699:  
 1700:         /// <summary>
 1701:         ///
 1702:         /// </summary>
 1703:         public static string AmsKeepAliveCommand(string amsName)
 1704:         {
 1705:             return FormatAmsCommand(AmsOpcode.RtrvHdr, amsName);
 1706:         }
 1707:  
 1708:         ////////////////////////////////////////////////////////////////////////////
 1709:  
 1710:         /// <summary>
 1711:         ///
 1712:         /// </summary>
 1713:         public static string ResetOntCommand(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont)
 1714:         {
 1715:             return FormatAmsOntCommand(AmsOpcode.InitSys, ont);
 1716:         }
 1717:  
 1718:         ////////////////////////////////////////////////////////////////////////////
 1719:  
 1720:         /// <summary>
 1721:         ///
 1722:         /// </summary>
 1723:         public static string AmsCommandOfARandomAmsKeepAlive()
 1724:         {
 1725:             var amsName = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 1726:                            where o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 1727:                            select o.AmsName).ToList().PickRandom();
 1728:  
 1729:             var command = FormatAmsCommand(AmsOpcode.RtrvHdr, amsName);
 1730:  
 1731:             return command;
 1732:         }
 1733:  
 1734:         ////////////////////////////////////////////////////////////////////////////
 1735:  
 1736:         /// <summary>
 1737:         ///
 1738:         /// </summary>
 1739:         public static void EnqueuePriorityAmsCommandQueue(string command)
 1740:         {
 1741:             priorityAmsCommandQueue.Enqueue(command);
 1742:         }
 1743:  
 1744:         ////////////////////////////////////////////////////////////////////////////
 1745:  
 1746:         /// <summary>
 1747:         ///
 1748:         /// </summary>
 1749:         public static void EnqueuePriorityAmsCommandQueue(List<string> amsCommandList)
 1750:         {
 1751:             if (amsCommandList != null && amsCommandList.Count > 0)
 1752:             {
 1753:                 foreach (string s in amsCommandList) priorityAmsCommandQueue.Enqueue(s);
 1754:             }
 1755:         }
 1756:  
 1757:         ////////////////////////////////////////////////////////////////////////////
 1758:  
 1759:         /// <summary>
 1760:         ///
 1761:         /// </summary>
 1762:         public static string ProperlySelectedSingleAmsCommandToManageOntVoipPotsNetworkElements()
 1763:         {
 1764:             string command;
 1765:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt;
 1766:             List<string> list;
 1767:  
 1768:             command = null;
 1769:  
 1770:             if (priorityAmsCommandQueue.Count > 0)
 1771:             {
 1772:                 command = priorityAmsCommandQueue.Dequeue();
 1773:             }
 1774:             else
 1775:             {
 1776:                 /*
 1777:                 if (false && command == null && randomPercent < 60)
 1778:                 {
 1779:                     if (amsCreateOntCommandQueue.Count == 0)
 1780:                     {
 1781:                         olt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.NokiaOltList.Where(o => o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr).PickRandom();
 1782: 
 1783:                         list = AmsCommandsToPreprovisionOntThatAreNotProvisionedAsDefinedInNddDocumentWithinAnOltList(olt, true, false, out count);
 1784: 
 1785:                         amsCreateOntCommandQueue = new Queue<string>(list);
 1786:                     }
 1787: 
 1788:                     if (amsCreateOntCommandQueue.Count > 0) command = amsCreateOntCommandQueue.Dequeue();
 1789:                 }
 1790:                 */
 1791:  
 1792:                 if (amsCommandQueue.Count == 0)
 1793:                 {
 1794:                     //olt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.NokiaOltList.Where(o => o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr).PickRandom();
 1795:                     olt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NokiaOltList.PickRandom();
 1796:  
 1797:                     list = Ia.Ftn.Cl.Models.Business.Nokia.Ams.AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyType_AmsCommandsToRetrieveOntsDefinedInNddDocument_AmsCommandsToUpdateAndDisplayOntDescriptionWithItsAccessName_AmsCommandsToUpdateOntOntPotsCustomerWithItsConnectedServiceNumberList(olt);
 1798:  
 1799:                     amsCommandQueue = new Queue<string>(list);
 1800:                 }
 1801:  
 1802:                 if (amsCommandQueue.Count > 0) command = amsCommandQueue.Dequeue();
 1803:  
 1804:                 if (command == null) command = AmsCommandOfARandomAmsKeepAlive();
 1805:             }
 1806:  
 1807:             return command;
 1808:         }
 1809:  
 1810:         ////////////////////////////////////////////////////////////////////////////
 1811:  
 1812:         /// <summary>
 1813:         ///
 1814:         /// </summary>
 1815:         private static List<string> FormatAmsRtrvCommand(AmsOpcode amsOpcode, string position)
 1816:         {
 1817:             return FormatAmsRtrvCommand(amsOpcode, 0, position);
 1818:         }
 1819:  
 1820:         ////////////////////////////////////////////////////////////////////////////
 1821:  
 1822:         /// <summary>
 1823:         ///
 1824:         /// </summary>
 1825:         private static List<string> FormatAmsRtrvCommand(AmsOpcode amsOpcode, Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType, string position)
 1826:         {
 1827:             // Use this command with variable number of parameters
 1828:             string command, amsName;
 1829:             List<string> list;
 1830:  
 1831:             command = null;
 1832:  
 1833:             list = new List<string>(10);
 1834:  
 1835:             if (!string.IsNullOrEmpty(position))
 1836:             {
 1837:                 AmsNameAndCardPortOntSquenceFromOntPosition(position, out amsName, out string pon);
 1838:  
 1839:                 if (amsOpcode == AmsOpcode.RtrvOnt)
 1840:                 {
 1841:                     command = "RTRV-ONT:" + amsName + ":ONT-1-1-" + pon + ";";
 1842:                     list.Add(command);
 1843:                 }
 1844:                 else if (amsOpcode == AmsOpcode.RtrvServiceVoip)
 1845:                 {
 1846:                     command = "RTRV-SERVICE-VOIP:" + amsName + ":VOIP-1-1-" + pon + "-1;";
 1847:                     list.Add(command);
 1848:                 }
 1849:                 else if (amsOpcode == AmsOpcode.RtrvOntPots)
 1850:                 {
 1851:                     foreach (string ontPotsCardPort in Ia.Ftn.Cl.Models.Business.Nokia.Ont.PossiblePotsCardPortConfigurationForOntFamilyTypeList(familyType))
 1852:                     {
 1853:                         command = "RTRV-ONTPOTS:" + amsName + ":ONTPOTS-1-1-" + pon + "-" + ontPotsCardPort + ";";
 1854:                         list.Add(command);
 1855:                     }
 1856:                 }
 1857:             }
 1858:  
 1859:             return list;
 1860:         }
 1861:  
 1862:         ////////////////////////////////////////////////////////////////////////////
 1863:  
 1864:         /// <summary>
 1865:         ///
 1866:         /// </summary>
 1867:         private static string FormatAmsOntCommand(AmsOpcode amsOpcode, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont)
 1868:         {
 1869:             string command;
 1870:  
 1871:             command = string.Empty;
 1872:  
 1873:             if (!string.IsNullOrEmpty(ont.Position))
 1874:             {
 1875:                 AmsNameAndCardPortOntSquenceFromOntPosition(ont.Position, out string amsName, out string pon);
 1876:  
 1877:                 if (amsOpcode == AmsOpcode.EdOntDesc1)
 1878:                 {
 1879:                     command = "ED-ONT:" + amsName + @":ONT-1-1-" + pon + "::::DESC1=" + ont.Access.Name + @":;";
 1880:                     // ED-ONT:ESH-1-1:ONT-1-1-2-2-26::::DESC1=ESH.4.26:;
 1881:                 }
 1882:                 else if (amsOpcode == AmsOpcode.EdOntDesc1Annul)
 1883:                 {
 1884:                     //command = "ED-ONT:" + amsName + @":ONT-1-1-" + pon + "::::DESC1=:;"; // this has no effect on ONT DESC1
 1885:                     // ED-ONT:ESH-1-1:ONT-1-1-2-2-26::::DESC1=:;
 1886:  
 1887:                     command = "ED-ONT:" + amsName + @":ONT-1-1-" + pon + "::::DESC1=NULL:;"; // you must send NULL to change ONT DESC1
 1888:                                                                                              // ED-ONT:ESH-1-1:ONT-1-1-2-2-26::::DESC1=NULL:;
 1889:                 }
 1890:                 else if (amsOpcode == AmsOpcode.InitSys)
 1891:                 {
 1892:                     command = "INIT-SYS:" + amsName + @":ONT-1-1-" + pon + ":::6;";
 1893:                     // INIT-SYS:SHD-SUR-LAG17:ONT-1-1-1-1-1:::6;
 1894:                 }
 1895:             }
 1896:  
 1897:             return command;
 1898:         }
 1899:  
 1900:         ////////////////////////////////////////////////////////////////////////////
 1901:  
 1902:         /// <summary>
 1903:         ///
 1904:         /// </summary>
 1905:         private static List<string> FormatAmsOntOntPotsCommandList(AmsOpcode amsOpcode, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont, Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType, string termination, string customerInformation)
 1906:         {
 1907:             string command;
 1908:             List<string> list;
 1909:  
 1910:             list = new List<string>(10);
 1911:  
 1912:             if (!string.IsNullOrEmpty(ont.Position))
 1913:             {
 1914:                 AmsNameAndCardPortOntSquenceFromOntPosition(ont.Position, out string amsName, out string pon);
 1915:  
 1916:                 termination = termination.Replace("td", "");
 1917:  
 1918:                 if (int.TryParse(termination, out int td))
 1919:                 {
 1920:                     Ia.Ftn.Cl.Models.Business.Nokia.Ont.ReturnOntPotsCardAndPortFromFamilyTypeAndTd(familyType, td, out int card, out int port);
 1921:  
 1922:                     if (amsOpcode == AmsOpcode.EdOntPotsCustinfo)
 1923:                     {
 1924:                         if (!string.IsNullOrEmpty(customerInformation))
 1925:                         {
 1926:                             command = "ED-ONTPOTS:" + amsName + @":ONTPOTS-1-1-" + pon + "-" + card + "-" + port + "::::CUSTINFO=" + customerInformation + @":;";
 1927:                             // ED-ONTPOTS:ESH-1-1:ONTPOTS-1-1-1-1-1-2-1::::CUSTINFO=23632222:;\n";
 1928:                         }
 1929:                         else
 1930:                         {
 1931:                             command = "ED-ONTPOTS:" + amsName + @":ONTPOTS-1-1-" + pon + "-" + card + "-" + port + "::::CUSTINFO=NULL:;";
 1932:                             // ED-ONTPOTS:ESH-1-1:ONTPOTS-1-1-1-1-1-2-1::::CUSTINFO=NULL:;\n";
 1933:                         }
 1934:  
 1935:                         list.Add(command);
 1936:                     }
 1937:                 }
 1938:             }
 1939:  
 1940:             return list;
 1941:         }
 1942:  
 1943:         ////////////////////////////////////////////////////////////////////////////
 1944:  
 1945:         /// <summary>
 1946:         ///
 1947:         /// </summary>
 1948:         private static string FormatAmsCommand(AmsOpcode amsOpcode, string amsName)
 1949:         {
 1950:             string command;
 1951:  
 1952:             if (amsOpcode == AmsOpcode.RtrvAlmPon)
 1953:             {
 1954:                 command = "RTRV-ALM-PON:" + amsName + ":ALL:::MN,,NSA;";
 1955:  
 1956:             }
 1957:             else if (amsOpcode == AmsOpcode.RtrvHdr)
 1958:             {
 1959:                 command = "RTRV-HDR:" + amsName + ":;";
 1960:             }
 1961:             else command = null;
 1962:  
 1963:             return command;
 1964:         }
 1965:  
 1966:         ////////////////////////////////////////////////////////////////////////////
 1967:  
 1968:         /// <summary>
 1969:         ///
 1970:         /// </summary>
 1971:         private static void AmsNameAndCardPortOntSquenceFromOntServiceHsiPosition(string ontPosition, out string amsName, out string cardPortOntCardPortServiceSequence)
 1972:         {
 1973:             Match match;
 1974:  
 1975:             // SUR-1-1-1-1-1-1-1-1;
 1976:             match = Regex.Match(ontPosition, @"([a-zA-Z]{3}\-\d{1,2}\-\d{1,2})\-(\d{1,2}\-\d{1,2}\-\d{1,2}\-\d{1,2}\-\d{1,2}\-\d{1,2})");
 1977:  
 1978:             amsName = match.Groups[1].Value;
 1979:             cardPortOntCardPortServiceSequence = match.Groups[2].Value;
 1980:         }
 1981:  
 1982:         ////////////////////////////////////////////////////////////////////////////
 1983:  
 1984:         /// <summary>
 1985:         ///
 1986:         /// </summary>
 1987:         private static void AmsNameAndCardPortOntSquenceFromOntPosition(string ontPosition, out string amsName, out string pon)
 1988:         {
 1989:             Match match;
 1990:  
 1991:             if (!string.IsNullOrEmpty(ontPosition))
 1992:             {
 1993:                 // SBN-ARD-Lag1-1-1-1;
 1994:                 match = Regex.Match(ontPosition, @"^([\w\d\-]+)\-(\d{1,2}\-\d{1,2}\-\d{1,2})$");
 1995:  
 1996:                 if (match.Success)
 1997:                 {
 1998:                     amsName = match.Groups[1].Value;
 1999:                     pon = match.Groups[2].Value;
 2000:                 }
 2001:                 else
 2002:                 {
 2003:                     amsName = string.Empty;
 2004:                     pon = string.Empty;
 2005:                 }
 2006:             }
 2007:             else
 2008:             {
 2009:                 amsName = string.Empty;
 2010:                 pon = string.Empty;
 2011:             }
 2012:         }
 2013:  
 2014:         ////////////////////////////////////////////////////////////////////////////
 2015:  
 2016:         /// <summary>
 2017:         /// Extract OLT Id, Card, Port, and ONT from ONT Position
 2018:         /// </summary>
 2019:         [Obsolete]
 2020:         public static void OltIdCardPortOntFromOntPosition(string ontPosition, out int oltId, out int card, out int port, out int ont)
 2021:         {
 2022:             string amsName;
 2023:             Match match;
 2024:  
 2025:             if (!string.IsNullOrEmpty(ontPosition))
 2026:             {
 2027:                 // SBN-ARD-Lag1-1-1-1;
 2028:                 match = Regex.Match(ontPosition, @"^([\w\d\-]+)\-(\d{1,2})\-(\d{1,2})\-(\d{1,2})$");
 2029:  
 2030:                 if (match.Success)
 2031:                 {
 2032:                     amsName = match.Groups[1].Value;
 2033:                     card = int.Parse(match.Groups[2].Value);
 2034:                     port = int.Parse(match.Groups[3].Value);
 2035:                     ont = int.Parse(match.Groups[4].Value);
 2036:  
 2037:                     oltId = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2038:                              where o.AmsName == amsName
 2039:                              select o.Id).FirstOrDefault();
 2040:                 }
 2041:                 else
 2042:                 {
 2043:                     amsName = string.Empty;
 2044:                     card = port = ont = 0;
 2045:  
 2046:                     oltId = 0;
 2047:                 }
 2048:             }
 2049:             else
 2050:             {
 2051:                 amsName = string.Empty;
 2052:                 card = port = ont = 0;
 2053:  
 2054:                 oltId = 0;
 2055:             }
 2056:         }
 2057:  
 2058:         ////////////////////////////////////////////////////////////////////////////
 2059:  
 2060:         /// <summary>
 2061:         ///
 2062:         /// </summary>
 2063:         public static string OntPositionFromAmsNameAndCardPortOntSquence(string amsName, string cardPortOnt)
 2064:         {
 2065:             string ontPosition;
 2066:  
 2067:             ontPosition = amsName + "-" + cardPortOnt;
 2068:  
 2069:             return ontPosition;
 2070:         }
 2071:  
 2072:         ////////////////////////////////////////////////////////////////////////////
 2073:  
 2074:         /// <summary>
 2075:         ///
 2076:         /// </summary>
 2077:         public static List<string> AmsCommandsToUpdateOntDescriptionWithItsAccessNameList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2078:         {
 2079:             string accessName, ontId, ontDescription1;
 2080:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2081:             List<string> list;
 2082:  
 2083:             var ontIdToOntAccessNameDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntAccessNameDictionary;
 2084:  
 2085:             var ontIdToDescription1ForNonNullAccessDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Ont.IdToDescription1ForNonNullAccessDictionary;
 2086:  
 2087:             var ontIdToDescription1ForNullAccessDictionary = Ia.Ftn.Cl.Models.Data.Nokia.Ont.IdToDescription1ForNullAccessDictionary;
 2088:  
 2089:             //var ontIdWithNullAccessHashtable = Ia.Ftn.Cl.Model.Data.Nokia.Ont.IdWithNullAccessHashtable;
 2090:  
 2091:             var ontIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary;
 2092:  
 2093:             list = new List<string>();
 2094:  
 2095:             // insert descriptions for missing entries
 2096:             if (ontIdToDescription1ForNonNullAccessDictionary.Count > 0)
 2097:             {
 2098:                 foreach (KeyValuePair<string, string> kvp in ontIdToDescription1ForNonNullAccessDictionary) //Ia.Ftn.Cl.Model.Ont ont in ontList)
 2099:                 {
 2100:                     ontId = kvp.Key;
 2101:                     ontDescription1 = kvp.Value;
 2102:  
 2103:                     if (ontIdToOntAccessNameDictionary.ContainsKey(ontId))
 2104:                     {
 2105:                         accessName = ontIdToOntAccessNameDictionary[ontId];
 2106:  
 2107:                         if (ontDescription1 != accessName)
 2108:                         {
 2109:                             nddOnt = ontIdToOntDictionary[ontId];
 2110:  
 2111:                             if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 2112:                             {
 2113:                                 list.Add(Ia.Ftn.Cl.Models.Business.Nokia.Ams.FormatAmsOntCommand(AmsOpcode.EdOntDesc1, nddOnt));
 2114:                             }
 2115:                         }
 2116:                         else
 2117:                         {
 2118:                         }
 2119:                     }
 2120:                 }
 2121:             }
 2122:  
 2123:             // delete descriptions ONTs with missing access info
 2124:             if (ontIdToDescription1ForNullAccessDictionary.Count > 0)
 2125:             {
 2126:                 foreach (KeyValuePair<string, string> kvp in ontIdToDescription1ForNullAccessDictionary)
 2127:                 {
 2128:                     ontId = kvp.Key;
 2129:                     ontDescription1 = kvp.Value;
 2130:  
 2131:                     if (!string.IsNullOrEmpty(ontDescription1))
 2132:                     {
 2133:                         if (ontIdToOntDictionary.ContainsKey(ontId))
 2134:                         {
 2135:                             nddOnt = ontIdToOntDictionary[ontId];
 2136:  
 2137:                             if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 2138:                             {
 2139:                                 list.Add(Ia.Ftn.Cl.Models.Business.Nokia.Ams.FormatAmsOntCommand(AmsOpcode.EdOntDesc1Annul, nddOnt));
 2140:                             }
 2141:                         }
 2142:                     }
 2143:                 }
 2144:             }
 2145:  
 2146:             return list.ToList();
 2147:         }
 2148:  
 2149:         ////////////////////////////////////////////////////////////////////////////
 2150:  
 2151:         /// <summary>
 2152:         ///
 2153:         /// </summary>
 2154:         public static List<string> AmsCommandsToUpdateCustInfoWithServiceNumberInOntOntPotsList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2155:         {
 2156:             List<string> list;
 2157:             Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType;
 2158:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2159:  
 2160:             var ontIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary;
 2161:  
 2162:             var ontOntPotsCustomerNoEqualToSubPartyDisplayNameServiceList = Ia.Ftn.Cl.Models.Data.Nokia.Ams.OntOntPotsCustomerNoEqualToSubPartyDisplayNameServiceList();
 2163:  
 2164:             list = new List<string>(ontOntPotsCustomerNoEqualToSubPartyDisplayNameServiceList.Count);
 2165:  
 2166:             // insert descriptions for missing entries
 2167:             if (ontOntPotsCustomerNoEqualToSubPartyDisplayNameServiceList.Count > 0)
 2168:             {
 2169:                 foreach (var ontOntPotsService in ontOntPotsCustomerNoEqualToSubPartyDisplayNameServiceList)
 2170:                 {
 2171:                     if (ontIdToOntDictionary.ContainsKey(ontOntPotsService.OntId))
 2172:                     {
 2173:                         nddOnt = ontIdToOntDictionary[ontOntPotsService.OntId];
 2174:  
 2175:                         if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 2176:                         {
 2177:                             familyType = (Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType)ontOntPotsService.OntFamilyTypeId;
 2178:  
 2179:                             list.AddRange(Ia.Ftn.Cl.Models.Business.Nokia.Ams.FormatAmsOntOntPotsCommandList(AmsOpcode.EdOntPotsCustinfo, nddOnt, familyType, ontOntPotsService.Termination, ontOntPotsService.Service));
 2180:                         }
 2181:                     }
 2182:                 }
 2183:             }
 2184:  
 2185:             var ontOntPotsCustomerExistsButSubPartyIsNullServiceList = Ia.Ftn.Cl.Models.Data.Nokia.Ams.OntOntPotsCustomerExistsButSubPartyIsNullServiceList();
 2186:  
 2187:             // delete descriptions of non existant entries
 2188:             if (ontOntPotsCustomerExistsButSubPartyIsNullServiceList.Count > 0)
 2189:             {
 2190:                 foreach (var oops in ontOntPotsCustomerExistsButSubPartyIsNullServiceList)
 2191:                 {
 2192:                     if (ontIdToOntDictionary.ContainsKey(oops.OntId))
 2193:                     {
 2194:                         nddOnt = ontIdToOntDictionary[oops.OntId];
 2195:  
 2196:                         if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 2197:                         {
 2198:                             list.Add(Ia.Ftn.Cl.Models.Business.Nokia.Ams.FormatAmsOntCommand(AmsOpcode.EdOntDesc1Annul, nddOnt));
 2199:                         }
 2200:                     }
 2201:                 }
 2202:             }
 2203:  
 2204:             return list;
 2205:         }
 2206:  
 2207:         ////////////////////////////////////////////////////////////////////////////
 2208:  
 2209:         /// <summary>
 2210:         ///
 2211:         /// </summary>
 2212:         public static List<string> AmsCommandsToPreprovisionAllOntsAsDefinedInNddDocumentWithinOltList(int oltId, bool edServiceVoipIsOos, out int count)
 2213:         {
 2214:             List<string> l, list;
 2215:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> nddOntList;
 2216:  
 2217:             count = 0;
 2218:             list = null;
 2219:  
 2220:             nddOntList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == oltId select o).ToList();
 2221:  
 2222:             if (nddOntList != null && nddOntList.Count > 0)
 2223:             {
 2224:                 list = new List<string>(nddOntList.Count);
 2225:  
 2226:                 foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt in nddOntList)
 2227:                 {
 2228:                     l = Ia.Ftn.Cl.Models.Business.Nokia.Ams.CommandsToPreprovisionOntWithinOlt(nddOnt, edServiceVoipIsOos);
 2229:  
 2230:                     list.AddRange(l);
 2231:                     count++;
 2232:                 }
 2233:             }
 2234:             else
 2235:             {
 2236:             }
 2237:  
 2238:             return list;
 2239:         }
 2240:  
 2241:         ////////////////////////////////////////////////////////////////////////////
 2242:  
 2243:         /// <summary>
 2244:         ///
 2245:         /// </summary>
 2246:         public static List<string> AmsCommandsToPreprovisionOntThatAreNotProvisionedAsDefinedInNddDocumentWithinAnOltList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt, bool includeDisplayCommand, bool edServiceVoipIsOos, out int count)
 2247:         {
 2248:             List<string> l, list;
 2249:             List<string> ontIdList;
 2250:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> nddOntList;
 2251:  
 2252:             count = 0;
 2253:             list = null;
 2254:  
 2255:             using (var db = new Ia.Ftn.Cl.Db())
 2256:             {
 2257:                 nddOntList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == olt.Id select o).ToList();
 2258:  
 2259:                 ontIdList = Ia.Ftn.Cl.Models.Data.Nokia.Ont.IdList(olt.Id); //.ReadListByOltId(olt.Id);
 2260:  
 2261:                 if (nddOntList != null && nddOntList.Count > 0)
 2262:                 {
 2263:                     list = new List<string>(nddOntList.Count);
 2264:  
 2265:                     foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt in nddOntList)
 2266:                     {
 2267:                         if (!ontIdList.Contains(nddOnt.Id))
 2268:                         {
 2269:                             l = Ia.Ftn.Cl.Models.Business.Nokia.Ams.CommandsToPreprovisionOntWithinOlt(nddOnt, edServiceVoipIsOos);
 2270:                             list.AddRange(l);
 2271:  
 2272:                             if (includeDisplayCommand)
 2273:                             {
 2274:                                 l = Ia.Ftn.Cl.Models.Business.Nokia.Ams.AmsCommandsToRetrieveOntVoipPotsForSingleOntsWithDefinedFamilyTypeList(nddOnt.Access.Name);
 2275:                                 list.AddRange(l);
 2276:                             }
 2277:  
 2278:                             count++;
 2279:                         }
 2280:                     }
 2281:                 }
 2282:             }
 2283:  
 2284:             return list;
 2285:         }
 2286:  
 2287:         ////////////////////////////////////////////////////////////////////////////
 2288:  
 2289:         /// <summary>
 2290:         ///
 2291:         /// </summary>
 2292:         public static List<string> AmsCommandsToRetrieveOntVoipPotsForASingleOntWithDefinedFamilyTypeAndForItIfThisSingleOntDefinedInNddDocumentList(string accessName)
 2293:         {
 2294:             //Random r;
 2295:             List<string> l1, l2, list;
 2296:  
 2297:             //r = new Random();
 2298:  
 2299:             l1 = AmsCommandToRetrieveSingleOntDefinedInNddDocumentList(accessName);
 2300:  
 2301:             l2 = AmsCommandsToRetrieveOntVoipPotsForSingleOntsWithDefinedFamilyTypeList(accessName);
 2302:  
 2303:             list = new List<string>(l1.Count + l2.Count);
 2304:  
 2305:             foreach (var item in l1) list.Add(item);
 2306:             foreach (var item in l2) list.Add(item);
 2307:  
 2308:             return list.Distinct().ToList();
 2309:         }
 2310:  
 2311:         ////////////////////////////////////////////////////////////////////////////
 2312:  
 2313:         /// <summary>
 2314:         ///
 2315:         /// </summary>
 2316:         public static List<string> AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyTypeAndForOtherOntsDefinedInNddDocumentList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2317:         {
 2318:             List<string> l1, l2, list;
 2319:  
 2320:             l1 = AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyTypeList(olt);
 2321:  
 2322:             l2 = AmsCommandsToRetrieveOntsDefinedInNddDocumentList(olt);
 2323:  
 2324:             list = new List<string>(l1.Count + l2.Count);
 2325:  
 2326:             foreach (var item in l1) list.Add(item);
 2327:             foreach (var item in l2) list.Add(item);
 2328:  
 2329:             return list.Distinct().Shuffle().ToList();
 2330:         }
 2331:  
 2332:         ////////////////////////////////////////////////////////////////////////////
 2333:  
 2334:         /// <summary>
 2335:         ///
 2336:         /// </summary>
 2337:         public static List<string> AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyType_AmsCommandsToRetrieveOntsDefinedInNddDocument_AmsCommandsToUpdateAndDisplayOntDescriptionWithItsAccessName_AmsCommandsToUpdateOntOntPotsCustomerWithItsConnectedServiceNumberList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2338:         {
 2339:             HashSet<string> hashSet1, hashSet2, hashSet3, hashSet4, hashSet;
 2340:  
 2341:             hashSet1 = new HashSet<string>(AmsCommandsToUpdateOntDescriptionWithItsAccessNameList(olt));
 2342:  
 2343:             hashSet2 = new HashSet<string>(AmsCommandsToUpdateCustInfoWithServiceNumberInOntOntPotsList(olt));
 2344:  
 2345:             hashSet3 = new HashSet<string>(AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyTypeList(olt));
 2346:  
 2347:             hashSet4 = new HashSet<string>(AmsCommandsToRetrieveOntsDefinedInNddDocumentList(olt));
 2348:  
 2349:             hashSet = new HashSet<string>(hashSet1);
 2350:             hashSet.UnionWith(hashSet2);
 2351:             hashSet.UnionWith(hashSet3);
 2352:             hashSet.UnionWith(hashSet4);
 2353:  
 2354:             return hashSet.ToList(); //.Shuffle().ToList();
 2355:         }
 2356:  
 2357:         ////////////////////////////////////////////////////////////////////////////
 2358:  
 2359:         /// <summary>
 2360:         ///
 2361:         /// </summary>
 2362:         private static List<string> AmsCommandToRetrieveSingleOntDefinedInNddDocumentList(string accessName)
 2363:         {
 2364:             List<string> list;
 2365:             Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType;
 2366:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2367:  
 2368:             list = new List<string>(5); // 5 is max number of commands from this function
 2369:  
 2370:             if (!string.IsNullOrEmpty(accessName))
 2371:             {
 2372:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
 2373:  
 2374:                 if (nddOnt != null)
 2375:                 {
 2376:                     familyType = Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Sfu;
 2377:  
 2378:                     list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOnt, familyType, nddOnt.Position));
 2379:                 }
 2380:             }
 2381:  
 2382:             return list;
 2383:         }
 2384:  
 2385:         ////////////////////////////////////////////////////////////////////////////
 2386:  
 2387:         /// <summary>
 2388:         ///
 2389:         /// </summary>
 2390:         private static List<string> AmsCommandsToRetrieveOntsDefinedInNddDocumentList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2391:         {
 2392:             Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType;
 2393:             List<string> list;
 2394:             List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontList;
 2395:  
 2396:             ontList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == olt.Id select o).ToList();
 2397:  
 2398:             familyType = Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Sfu;
 2399:  
 2400:             list = new List<string>(ontList.Count);
 2401:  
 2402:             foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont in ontList)
 2403:             {
 2404:                 list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOnt, familyType, ont.Position));
 2405:             }
 2406:  
 2407:             return list;
 2408:         }
 2409:  
 2410:         ////////////////////////////////////////////////////////////////////////////
 2411:  
 2412:         /// <summary>
 2413:         ///
 2414:         /// </summary>
 2415:         private static List<string> AmsCommandsToRetrieveOntVoipPotsForSingleOntsWithDefinedFamilyTypeList(string accessName)
 2416:         {
 2417:             List<string> list;
 2418:             Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType;
 2419:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2420:             Ia.Ftn.Cl.Models.Ont ont;
 2421:  
 2422:             list = new List<string>(5); // 5 is max number of commands from this function
 2423:  
 2424:             if (!string.IsNullOrEmpty(accessName))
 2425:             {
 2426:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntByAccessName(accessName);
 2427:  
 2428:                 if (nddOnt != null)
 2429:                 {
 2430:                     ont = Ia.Ftn.Cl.Models.Data.Nokia.Ont.Read(nddOnt.Id);
 2431:  
 2432:                     if (ont != null)
 2433:                     {
 2434:                         familyType = (Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType)ont.FamilyTypeId;
 2435:  
 2436:                         list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOnt, familyType, nddOnt.Position));
 2437:                         list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvServiceVoip, familyType, nddOnt.Position));
 2438:                         list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOntPots, familyType, nddOnt.Position));
 2439:                     }
 2440:                 }
 2441:             }
 2442:  
 2443:             return list;
 2444:         }
 2445:  
 2446:         ////////////////////////////////////////////////////////////////////////////
 2447:  
 2448:         /// <summary>
 2449:         ///
 2450:         /// </summary>
 2451:         private static List<string> AmsCommandsToRetrieveOntVoipPotsForOntsWithDefinedFamilyTypeList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt)
 2452:         {
 2453:             Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType familyType;
 2454:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 2455:             List<string> list;
 2456:             Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontIdToOntDictionary;
 2457:             List<Ia.Ftn.Cl.Models.Ont> ontList;
 2458:  
 2459:             ontList = Ia.Ftn.Cl.Models.Data.Nokia.Ont.NonNullAccessList(olt.Id);
 2460:  
 2461:             ontIdToOntDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary;
 2462:  
 2463:             list = new List<string>(ontList.Count);
 2464:  
 2465:             foreach (Ia.Ftn.Cl.Models.Ont ont in ontList)
 2466:             {
 2467:                 familyType = (Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType)ont.FamilyTypeId;
 2468:  
 2469:                 if (ontIdToOntDictionary.ContainsKey(ont.Id))
 2470:                 {
 2471:                     nddOnt = ontIdToOntDictionary[ont.Id];
 2472:  
 2473:                     //if (ont.Access != null) access is already non null
 2474:                     //{
 2475:                     list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOnt, familyType, nddOnt.Position));
 2476:                     list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvServiceVoip, familyType, nddOnt.Position));
 2477:                     list.AddRange(FormatAmsRtrvCommand(AmsOpcode.RtrvOntPots, familyType, nddOnt.Position));
 2478:                     //}
 2479:                 }
 2480:             }
 2481:  
 2482:             return list;
 2483:         }
 2484:  
 2485:         ////////////////////////////////////////////////////////////////////////////
 2486:  
 2487:         /// <summary>
 2488:         ///
 2489:         /// </summary>
 2490:         public static ArrayList AmsCommandsToRetrieveNewOntAlarmsForOltArrayList()
 2491:         {
 2492:             ArrayList amsCommandArrayList;
 2493:  
 2494:             amsCommandArrayList = new ArrayList(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList.Count);
 2495:  
 2496:             foreach (var olt in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList)
 2497:             {
 2498:                 amsCommandArrayList.Add(FormatAmsCommand(AmsOpcode.RtrvAlmPon, olt.AmsName));
 2499:             }
 2500:  
 2501:             return amsCommandArrayList;
 2502:         }
 2503:  
 2504:         ////////////////////////////////////////////////////////////////////////////
 2505:  
 2506:         /// <summary>
 2507:         ///
 2508:         /// </summary>
 2509:         public static ArrayList AmsCommandsToUpdateOntServiceDescriptionWithItsIspNameArrayList()
 2510:         {
 2511:             ArrayList amsCommandArrayList;
 2512:  
 2513:             amsCommandArrayList = new ArrayList(100);
 2514:  
 2515:             return amsCommandArrayList;
 2516:         }
 2517:  
 2518:         /*
 2519:         ////////////////////////////////////////////////////////////////////////////
 2520: 
 2521:         /// <summary>
 2522:         /// 
 2523:         /// </summary>
 2524:         public static int PositionOfHsiServiceForCardAndPortAndOntFamilyType(int card, int port, Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType familyType)
 2525:         {
 2526:             int position;
 2527: 
 2528:             if (familyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Sfu || familyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Gfu || familyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Soho)
 2529:             {
 2530:                 position = port;
 2531:             }
 2532:             else if (familyType == Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType.Mdu)
 2533:             {
 2534:                 position = (card - 1) * 4 + port;
 2535:             }
 2536:             else position = 0;
 2537: 
 2538:             return position;
 2539:         }
 2540:         */
 2541:  
 2542:         ////////////////////////////////////////////////////////////////////////////
 2543:  
 2544:         /// <summary>
 2545:         ///
 2546:         /// </summary>
 2547:         public static bool UpdateDatabaseWithAmsCommandOutput(string rowData, out Ia.Cl.Models.Result result)
 2548:         {
 2549:             bool isUpdated;
 2550:             int readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
 2551:             string accessId, ontId, ontPosition;
 2552:             string line, amsName, cardPortOnt;
 2553:             DateTime eventTime;
 2554:             Match match;
 2555:             MatchCollection matchCollection;
 2556:             Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState state;
 2557:  
 2558:             //ponNameToPonIdHashtable = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PonNameToPonIdHashtable;
 2559:  
 2560:             isUpdated = false;
 2561:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
 2562:             result = new Ia.Cl.Models.Result();
 2563:             //result.Content = rowData;
 2564:  
 2565:             // below: remove all '\' characters from rowData and reset NULL comments to ""
 2566:             rowData = rowData.Replace(@"\", "");
 2567:             rowData = rowData.Replace(@"NULL", "");
 2568:  
 2569:             if (rowData.Contains("RTRV-ONT:"))
 2570:             {
 2571:                 #region RTRV-ONT
 2572:                 Ia.Ftn.Cl.Models.Ont ont, dataOnt;
 2573:  
 2574:                 /*
 2575:        SUR-1-1 08-07-10 09:35:07
 2576:     M  0 COMPLD
 2577:        / * RTRV-ONT:SUR-1-1:ONT-1-1-1-1-1&ONT-1-1-1-1-10&ONT-1-1-1-1-2&ONT-1-1-1 * /
 2578:        / * -1-3&ONT-1-1-1-1-4&ONT-1-1-1-1-5&ONT-1-1-1-1-6&ONT-1-1-1-1-7&ONT-1-1- * /
 2579:        / * 1-1-8&ONT-1-1-1-1-9 * /
 2580:        "ONT-1-1-1-1-1::BTRYBKUP=NO,BERINT=8000,DESC1="SLA.1.1",
 2581:        DESC2="all is well",PROVVERSION="*",SERNUM=ALCLA0A1A5F8,
 2582:        SUBSLOCID="WILDCARD",SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,
 2583:        SCHEDPROFID=1,SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,
 2584:        POWERSHEDPROFNM="NULL",ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,
 2585:        SWVERACT=3FE50853AFMA07,SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,
 2586:        EQUIPID=BVM3G00CRAO420EB    ,NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:
 2587:        IS-NR"
 2588:        "ONT-1-1-1-1-10::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2589:        PROVVERSION="*",SERNUM=ALCLA0A1A479,SUBSLOCID="WILDCARD",
 2590:        SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2591:        SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2592:        ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,SWVERACT=3FE50853AFMA07,
 2593:        SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2594:        NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2595:        "ONT-1-1-1-1-2::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2596:        PROVVERSION="*",SERNUM=ALCLA0A261BB,SUBSLOCID="WILDCARD",
 2597:        SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2598:        SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2599:        ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2600:        SWVERPSV=3FE50853AAAA22,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2601:        NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2602:                  */
 2603:  
 2604:                 // below: information from the definition of "RTRV-ONT" in "AMS TL1 Commands Reference"
 2605:  
 2606:                 /*
 2607:     IP 0
 2608:     <
 2609:  
 2610:     SUR-1-1 08-07-10 09:35:07
 2611:     M  0 COMPLD
 2612:     / * RTRV-ONT:SUR-1-1:ONT-1-1-1-1-1&ONT-1-1-1-1-10&ONT-1-1-1-1-2&ONT-1-1-1 * /
 2613:     / * -1-3&ONT-1-1-1-1-4&ONT-1-1-1-1-5&ONT-1-1-1-1-6&ONT-1-1-1-1-7&ONT-1-1- * /
 2614:     / * 1-1-8&ONT-1-1-1-1-9 * /
 2615:     "ONT-1-1-1-1-1::BTRYBKUP=NO,BERINT=8000,DESC1="SLA.1.1",
 2616:     DESC2="all is well",PROVVERSION="*",SERNUM=ALCLA0A1A5F8,
 2617:     SUBSLOCID="WILDCARD",SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,
 2618:     SCHEDPROFID=1,SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,
 2619:     POWERSHEDPROFNM="NULL",ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,
 2620:     SWVERACT=3FE50853AFMA07,SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,
 2621:     EQUIPID=BVM3G00CRAO420EB    ,NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:
 2622:     IS-NR"
 2623:     "ONT-1-1-1-1-10::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2624:     PROVVERSION="*",SERNUM=ALCLA0A1A479,SUBSLOCID="WILDCARD",
 2625:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2626:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2627:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,SWVERACT=3FE50853AFMA07,
 2628:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2629:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2630:     "ONT-1-1-1-1-2::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2631:     PROVVERSION="*",SERNUM=ALCLA0A261BB,SUBSLOCID="WILDCARD",
 2632:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2633:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2634:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2635:     SWVERPSV=3FE50853AAAA22,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2636:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2637:  
 2638:     / * More Output Follows * /
 2639:     >
 2640:  
 2641:     SUR-1-1 08-07-10 09:35:07
 2642:     M  0 COMPLD
 2643:     / * RTRV-ONT:SUR-1-1:ONT-1-1-1-1-1&ONT-1-1-1-1-10&ONT-1-1-1-1-2&ONT-1-1-1-1-3&ONT-1-1-1-1-4&ONT-1-1-1-1-5&ONT-1-1-1-1-6&ONT-1-1-1-1-7&ONT-1-1-1-1-8&ONT-1-1-1-1-9 * /
 2644:     "ONT-1-1-1-1-3::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2645:     PROVVERSION="*",SERNUM=ALCLA0A1C9BC,SUBSLOCID="WILDCARD",
 2646:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2647:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2648:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2649:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2650:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2651:     "ONT-1-1-1-1-4::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2652:     PROVVERSION="*",SERNUM=ALCLA0A1A47A,SUBSLOCID="WILDCARD",
 2653:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2654:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2655:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,SWVERACT=3FE50853AFMA07,
 2656:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2657:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2658:     "ONT-1-1-1-1-5::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2659:     PROVVERSION="*",SERNUM=ALCLA0A1AE44,SUBSLOCID="WILDCARD",
 2660:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2661:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2662:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2663:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2664:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2665:  
 2666:     / * More Output Follows * /
 2667:     >
 2668:  
 2669:     SUR-1-1 08-07-10 09:35:08
 2670:     M  0 COMPLD
 2671:     / * RTRV-ONT:SUR-1-1:ONT-1-1-1-1-1&ONT-1-1-1-1-10&ONT-1-1-1-1-2&ONT-1-1-1-1-3&ONT-1-1-1-1-4&ONT-1-1-1-1-5&ONT-1-1-1-1-6&ONT-1-1-1-1-7&ONT-1-1-1-1-8&ONT-1-1-1-1-9 * /
 2672:     "ONT-1-1-1-1-6::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2673:     PROVVERSION="*",SERNUM=ALCLA0A1BE26,SUBSLOCID="WILDCARD",
 2674:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2675:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2676:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2677:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2678:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2679:     "ONT-1-1-1-1-7::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2680:     PROVVERSION="*",SERNUM=ALCLA0A1C94B,SUBSLOCID="WILDCARD",
 2681:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2682:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2683:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAB01,SWVERACT=3FE50853AFMA07,
 2684:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2685:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2686:     "ONT-1-1-1-1-8::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2687:     PROVVERSION="*",SERNUM=ALCLA0A1A484,SUBSLOCID="WILDCARD",
 2688:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2689:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2690:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,SWVERACT=3FE50853AFMA07,
 2691:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2692:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2693:  
 2694:     / * More Output Follows * /
 2695:     >
 2696:  
 2697:     SUR-1-1 08-07-10 09:35:08
 2698:     M  0 COMPLD
 2699:     / * RTRV-ONT:SUR-1-1:ONT-1-1-1-1-1&ONT-1-1-1-1-10&ONT-1-1-1-1-2&ONT-1-1-1-1-3&ONT-1-1-1-1-4&ONT-1-1-1-1-5&ONT-1-1-1-1-6&ONT-1-1-1-1-7&ONT-1-1-1-1-8&ONT-1-1-1-1-9 * /
 2700:     "ONT-1-1-1-1-9::BTRYBKUP=NO,BERINT=8000,DESC1="NULL",DESC2="NULL",
 2701:     PROVVERSION="*",SERNUM=ALCLA0A1A43E,SUBSLOCID="WILDCARD",
 2702:     SWVERPLND="3FE50853AFMA07",FECUP=DISABLE,SCHEDPROFID=1,
 2703:     SCHEDPROFNM="defSubSchedProf",POWERSHEDPROFID=0,POWERSHEDPROFNM="NULL",
 2704:     ONTENABLE=AUTO,EQPTVERNUM=3FE50683ADAA01,SWVERACT=3FE50853AFMA07,
 2705:     SWVERPSV=3FE50853AFKA03,VENDORID=ALCL,EQUIPID=BVM3G00CRAO420EB    ,
 2706:     NUMSLOTS=2,NUMTCONT=22,NUMTRFSCH=22,NUMPQ=22:IS-NR"
 2707:     ;
 2708:                 */
 2709:  
 2710:                 // below: read OntPosition
 2711:                 match = Regex.Match(rowData, @"RTRV-ONT:([\w\d\-]+)", RegexOptions.Singleline);
 2712:  
 2713:                 amsName = match.Groups[1].Value;
 2714:  
 2715:                 match = Regex.Match(rowData, @"ONT-1-1-(\d{1,2}-\d{1,2}-\d{1,2})::(.+?):\s*(IS-NR|OOS-AU|OOS-MA|OOS-AUMA)", RegexOptions.Singleline);
 2716:  
 2717:                 if (match.Success)
 2718:                 {
 2719:                     cardPortOnt = match.Groups[1].Value;
 2720:  
 2721:                     line = match.Groups[2].Value;
 2722:  
 2723:                     ontId = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(amsName, cardPortOnt);
 2724:  
 2725:                     if (!string.IsNullOrEmpty(ontId))
 2726:                     {
 2727:                         dataOnt = new Ia.Ftn.Cl.Models.Ont();
 2728:  
 2729:                         dataOnt.Id = ontId;
 2730:                         dataOnt.BatteryBackupAvailable = (Ia.Cl.Models.Default.Match(line, @"BTRYBKUP=(\w+)") == "YES") ? true : false;
 2731:                         dataOnt.Description1 = Ia.Cl.Models.Default.Match(line, @"DESC1=""([^""]{1,64})""");
 2732:                         dataOnt.Description2 = Ia.Cl.Models.Default.Match(line, @"DESC2=""([^""]{1,64})""");
 2733:                         dataOnt.Serial = Ia.Cl.Models.Default.Match(line, @"SERNUM=(\w{12})");
 2734:                         dataOnt.PlannedSoftware = Ia.Cl.Models.Default.Match(line, @"SWVERPLND=""(auto|AUTO|\w{14})""");
 2735:                         dataOnt.ActiveSoftware = Ia.Cl.Models.Default.Match(line, @"SWVERACT=(\w{14})");
 2736:                         dataOnt.PassiveSoftware = Ia.Cl.Models.Default.Match(line, @"SWVERPSV=(\w{14})");
 2737:                         dataOnt.FamilyTypeId = (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyTypeIdFromActiveSoftwareAndPlannedSoftware(dataOnt.ActiveSoftware, dataOnt.PlannedSoftware);
 2738:                         dataOnt.VendorId = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.VendorIdFromName(Ia.Cl.Models.Default.Match(line, @"VENDORID=(\w+)"));
 2739:                         dataOnt.EquipmentId = Ia.Cl.Models.Default.Match(line, @"EQUIPID=(\w{16})");
 2740:  
 2741:                         switch (match.Groups[3].Value)
 2742:                         {
 2743:                             case "IS-NR": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.IsNr; break;
 2744:                             case "OOS-AU": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAu; break;
 2745:                             case "OOS-MA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosMa; break;
 2746:                             case "OOS-AUMA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAuma; break;
 2747:                             default: state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.Undefined; break;
 2748:                         }
 2749:  
 2750:                         dataOnt.StateId = (int)state;
 2751:  
 2752:                         using (var db = new Ia.Ftn.Cl.Db())
 2753:                         {
 2754:                             accessId = Ia.Ftn.Cl.Models.Business.Access.AccessId(ontId);
 2755:  
 2756:                             if (accessId != null) dataOnt.Access = (from a in db.Accesses where a.Id == accessId select a).SingleOrDefault();
 2757:  
 2758:                             ont = (from o in db.Onts where o.Id == dataOnt.Id select o).SingleOrDefault();
 2759:  
 2760:                             if (ont == null)
 2761:                             {
 2762:                                 dataOnt.Created = dataOnt.Updated = DateTime.UtcNow.AddHours(3);
 2763:  
 2764:                                 db.Onts.Add(dataOnt);
 2765:  
 2766:                                 insertedItemCount++;
 2767:                             }
 2768:                             else
 2769:                             {
 2770:                                 existingItemCount++;
 2771:  
 2772:                                 if (ont.Update(dataOnt))
 2773:                                 {
 2774:                                     db.Onts.Attach(ont);
 2775:                                     db.Entry(ont).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2776:  
 2777:                                     updatedItemCount++;
 2778:                                 }
 2779:                             }
 2780:  
 2781:                             db.SaveChanges();
 2782:                         }
 2783:                     }
 2784:                     else
 2785:                     {
 2786:                         result.AddError("Error in UpdateDatabaseWithAmsCommandOutput(): ontId was null or empty for amsName: [" + amsName + "] and pon: [" + cardPortOnt + "].");
 2787:                     }
 2788:                 }
 2789:                 else
 2790:                 {
 2791:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 2792:                 }
 2793:                 #endregion
 2794:             }
 2795:             else if (rowData.Contains("ED-ONT:"))
 2796:             {
 2797:                 #region ED-ONT
 2798:                 Ia.Ftn.Cl.Models.Ont ont, dataOnt;
 2799:  
 2800:                 /*
 2801:     SUR-5-2 14-11-23 05:22:08
 2802:     M  0 COMPLD
 2803:     / * ED-ONT:SUR-5-2:ONT-1-1-1-2-6::::DESC1=ZAH.2.6: * /
 2804:  
 2805:     M  0 COMPLD
 2806:     / * ED-ONT:QRW-SLB-LAG2:ONT-1-1-3-2-10:98499:::DESC1=QRW.33.10: * /
 2807:     ;
 2808:                 */
 2809:  
 2810:                 // below: read OntPosition
 2811:                 match = Regex.Match(rowData, @"ED-ONT:([\w\d\-]+)", RegexOptions.Singleline);
 2812:  
 2813:                 amsName = match.Groups[1].Value;
 2814:  
 2815:                 match = Regex.Match(rowData, @"ONT-1-1-(\d{1,2}-\d{1,2}-\d{1,2}):\d{0,6}:::(.+?):", RegexOptions.Singleline);
 2816:  
 2817:                 if (match.Success)
 2818:                 {
 2819:                     cardPortOnt = match.Groups[1].Value;
 2820:  
 2821:                     line = match.Groups[2].Value;
 2822:  
 2823:                     ontId = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(amsName, cardPortOnt);
 2824:  
 2825:                     if (!string.IsNullOrEmpty(ontId))
 2826:                     {
 2827:                         dataOnt = new Ia.Ftn.Cl.Models.Ont();
 2828:  
 2829:                         dataOnt.Id = ontId;
 2830:                         dataOnt.Description1 = Ia.Cl.Models.Default.Match(line, @"DESC1=(.{1,64})");
 2831:                         dataOnt.Description2 = Ia.Cl.Models.Default.Match(line, @"DESC2=(.{1,64})");
 2832:  
 2833:                         using (var db = new Ia.Ftn.Cl.Db())
 2834:                         {
 2835:                             ont = (from o in db.Onts where o.Id == dataOnt.Id select o).SingleOrDefault();
 2836:  
 2837:                             if (ont == null)
 2838:                             {
 2839:                                 // below: Don't create a new ONT in this ED-ONT function
 2840:                                 //dataOnt.Created = dataOnt.Updated = DateTime.UtcNow.AddHours(3);
 2841:  
 2842:                                 //db.Onts.Add(dataOnt);
 2843:  
 2844:                                 insertedItemCount++;
 2845:                             }
 2846:                             else
 2847:                             {
 2848:                                 existingItemCount++;
 2849:  
 2850:                                 if (ont.Update(dataOnt))
 2851:                                 {
 2852:                                     db.Onts.Attach(ont);
 2853:                                     db.Entry(ont).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2854:  
 2855:                                     updatedItemCount++;
 2856:                                 }
 2857:                             }
 2858:  
 2859:                             db.SaveChanges();
 2860:                         }
 2861:                     }
 2862:                     else
 2863:                     {
 2864:                         result.AddError("Error in UpdateDatabaseWithAmsCommandOutput(): ontId was null or empty for amsName: [" + amsName + "] and pon: [" + cardPortOnt + "].");
 2865:                     }
 2866:                 }
 2867:                 else
 2868:                 {
 2869:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 2870:                 }
 2871:                 #endregion
 2872:             }
 2873:             else if (rowData.Contains("RTRV-SERVICE-VOIP:"))
 2874:             {
 2875:                 #region RTRV-SERVICE-VOIP
 2876:  
 2877:                 string ontServiceVoipId;
 2878:                 int card;
 2879:                 Ia.Ftn.Cl.Models.OntServiceVoip ontServiceVoip, dataOntServiceVoip;
 2880:  
 2881:                 // below: information from the definition of "RTRV-SERVICE-VOIP" in "AMS TL1 Commands Reference"
 2882:  
 2883:                 /*
 2884:  
 2885:     SUR-1-1 08-07-09 09:43:13
 2886:     M  0 COMPLD
 2887:     / * RTRV-SERVICE-VOIP:SUR-1-1:VOIP-1-1-1-1-1-1&VOIP-1-1-1-1-10-1&VOIP-1-1 * /
 2888:     / * -1-1-2-1&VOIP-1-1-1-1-3-1&VOIP-1-1-1-1-4-1&VOIP-1-1-1-1-5-1&VOIP-1-1- * /
 2889:     / * 1-1-6-1&VOIP-1-1-1-1-7-1&VOIP-1-1-1-1-8-1&VOIP-1-1-1-1-9-1 * /
 2890:     "VOIP-1-1-1-1-1-1::BWPROFUPID=1,BWPROFUPNM=VOIP,BWPROFDNID=1,
 2891:     BWPROFDNNM=VOIP,PQPROFID=1,PQPROFNM=VOIPPQ,AESENABLE=DISABLE,SVLAN=10,
 2892:     IPADDRLOC=10.3.144.1,NETMASKLOC=255.255.248.0,DEFROUTER=10.3.151.254,
 2893:     IPADDRMGC=10.255.251.5,IPADDRFTP=0.0.0.0,DHCP=DISABLE,PORTMGC=2944,
 2894:     VOIPDSCP=24,VOIPMODE=SSH248,CONFIGFILE=kuwait.xml,CLIENTID="",
 2895:     CUSTOMERID="",SECRETID=,SECRETK=,IPSECENABLE=DISABLED,CONFMETH=FTPSERVER,
 2896:     SPGPROFID=0,SPGPROFNM="",SPGUNAME="",SPGPWD="",SPGREALM="",
 2897:     SRCVLANID=0:IS-NR"
 2898:     "VOIP-1-1-1-1-10-1::BWPROFUPID=1,BWPROFUPNM=VOIP,BWPROFDNID=1,
 2899:     BWPROFDNNM=VOIP,PQPROFID=1,PQPROFNM=VOIPPQ,AESENABLE=DISABLE,SVLAN=10,
 2900:     IPADDRLOC=10.3.144.10,NETMASKLOC=255.255.248.0,DEFROUTER=10.3.151.254,
 2901:     IPADDRMGC=10.255.251.5,IPADDRFTP=0.0.0.0,DHCP=DISABLE,PORTMGC=2944,
 2902:     VOIPDSCP=24,VOIPMODE=SSH248,CONFIGFILE=kuwait.xml,CLIENTID="",
 2903:     CUSTOMERID="",SECRETID=,SECRETK=,IPSECENABLE=DISABLED,CONFMETH=FTPSERVER,
 2904:     SPGPROFID=0,SPGPROFNM="",SPGUNAME="",SPGPWD="",SPGREALM="",
 2905:     SRCVLANID=0:IS-NR"
 2906:     "VOIP-1-1-1-1-2-1::BWPROFUPID=1,BWPROFUPNM=VOIP,BWPROFDNID=1,
 2907:     BWPROFDNNM=VOIP,PQPROFID=1,PQPROFNM=VOIPPQ,AESENABLE=DISABLE,SVLAN=10,
 2908:     IPADDRLOC=10.3.144.2,NETMASKLOC=255.255.248.0,DEFROUTER=10.3.151.254,
 2909:     IPADDRMGC=10.255.251.5,IPADDRFTP=0.0.0.0,DHCP=DISABLE,PORTMGC=2944,
 2910:     VOIPDSCP=24,VOIPMODE=SSH248,CONFIGFILE=kuwait.xml,CLIENTID="",
 2911:     CUSTOMERID="",SECRETID=,SECRETK=,IPSECENABLE=DISABLED,CONFMETH=FTPSERVER,
 2912:     SPGPROFID=0,SPGPROFNM="",SPGUNAME="",SPGPWD="",SPGREALM="",
 2913:     SRCVLANID=0:IS-NR"
 2914:  
 2915:     / * More Output Follows * /
 2916:     >
 2917:                 */
 2918:  
 2919:                 // below: read OntPosition
 2920:                 match = Regex.Match(rowData, @"RTRV-SERVICE-VOIP:([\w\d\-]+)", RegexOptions.Singleline);
 2921:  
 2922:                 amsName = match.Groups[1].Value;
 2923:  
 2924:                 match = Regex.Match(rowData, @"VOIP-1-1-(\d{1,2}-\d{1,2}-\d{1,2})-(\d{1,2})::(.+?):\s*(IS-NR|OOS-AU|OOS-MA|OOS-AUMA)", RegexOptions.Singleline);
 2925:  
 2926:                 if (match.Success)
 2927:                 {
 2928:                     cardPortOnt = match.Groups[1].Value;
 2929:                     card = int.Parse(match.Groups[2].Value);
 2930:  
 2931:                     line = match.Groups[3].Value;
 2932:  
 2933:                     ontId = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(amsName, cardPortOnt);
 2934:  
 2935:                     if (!string.IsNullOrEmpty(ontId))
 2936:                     {
 2937:                         ontServiceVoipId = Ia.Ftn.Cl.Models.Business.Nokia.OntServiceVoip.OntServiceVoipId(ontId, card);
 2938:  
 2939:                         dataOntServiceVoip = new Ia.Ftn.Cl.Models.OntServiceVoip();
 2940:  
 2941:                         dataOntServiceVoip.Id = ontServiceVoipId;
 2942:  
 2943:                         dataOntServiceVoip.ConfiguratinFile = Ia.Cl.Models.Default.Match(line, @"CONFIGFILE=(\w{1,}\.xml)");
 2944:                         dataOntServiceVoip.Customer = Ia.Cl.Models.Default.Match(line, @"CUSTOMERID=""([^""]{1,62})""");
 2945:                         dataOntServiceVoip.FtpIp = Ia.Cl.Models.Default.Match(line, @"IPADDRFTP=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
 2946:                         dataOntServiceVoip.Ip = Ia.Cl.Models.Default.Match(line, @"IPADDRLOC=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
 2947:                         dataOntServiceVoip.Label = Ia.Cl.Models.Default.Match(line, @"LABEL=""([^""]{1,80})""");
 2948:                         dataOntServiceVoip.MgcIp = Ia.Cl.Models.Default.Match(line, @"IPADDRMGC=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
 2949:                         dataOntServiceVoip.MgcSecondaryIp = Ia.Cl.Models.Default.Match(line, @"IPADDRMGCSEC=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
 2950:  
 2951:                         switch (match.Groups[4].Value)
 2952:                         {
 2953:                             case "IS-NR": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.IsNr; break;
 2954:                             case "OOS-AU": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAu; break;
 2955:                             case "OOS-MA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosMa; break;
 2956:                             case "OOS-AUMA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAuma; break;
 2957:                             default: state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.Undefined; break;
 2958:                         }
 2959:  
 2960:                         dataOntServiceVoip.StateId = (int)state;
 2961:  
 2962:                         dataOntServiceVoip.Svlan = int.Parse(Ia.Cl.Models.Default.Match(line, @"SVLAN=(\d{1,3})"));
 2963:  
 2964:                         using (var db = new Ia.Ftn.Cl.Db())
 2965:                         {
 2966:                             dataOntServiceVoip.Ont = (from o in db.Onts where o.Id == ontId select o).SingleOrDefault();
 2967:  
 2968:                             ontServiceVoip = (from osv in db.OntServiceVoips where osv.Id == dataOntServiceVoip.Id select osv).SingleOrDefault();
 2969:  
 2970:                             if (ontServiceVoip == null)
 2971:                             {
 2972:                                 dataOntServiceVoip.Created = dataOntServiceVoip.Updated = DateTime.UtcNow.AddHours(3);
 2973:  
 2974:                                 db.OntServiceVoips.Add(dataOntServiceVoip);
 2975:  
 2976:                                 insertedItemCount++;
 2977:                             }
 2978:                             else
 2979:                             {
 2980:                                 existingItemCount++;
 2981:  
 2982:                                 if (ontServiceVoip.Update(dataOntServiceVoip))
 2983:                                 {
 2984:                                     db.OntServiceVoips.Attach(ontServiceVoip);
 2985:                                     db.Entry(ontServiceVoip).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 2986:  
 2987:                                     updatedItemCount++;
 2988:                                 }
 2989:                             }
 2990:  
 2991:                             db.SaveChanges();
 2992:                         }
 2993:                     }
 2994:                     else
 2995:                     {
 2996:                         result.AddError("Error in UpdateDatabaseWithAmsCommandOutput(): ontId was null or empty for amsName: [" + amsName + "] and pon: [" + cardPortOnt + "].");
 2997:                     }
 2998:                 }
 2999:                 else
 3000:                 {
 3001:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 3002:                 }
 3003:                 #endregion
 3004:             }
 3005:             else if (rowData.Contains("RTRV-ONTPOTS:"))
 3006:             {
 3007:                 #region RTRV-ONTPOTS
 3008:  
 3009:                 string ontOntPotsId;
 3010:                 int card, port, svlan;
 3011:                 Ia.Ftn.Cl.Models.OntOntPots ontOntPots, dataOntOntPots;
 3012:  
 3013:                 // below: information from the definition of "RTRV-ONTPOTS" in "AMS TL1 Commands Reference"
 3014:  
 3015:                 /*
 3016:                  * ;RTRV-ONTPOTS:SUR-1-1:ONTPOTS-1-1-1-1-1-2-1;
 3017:  
 3018:     SUR-1-1 14-03-13 08:15:46
 3019:     M  0 COMPLD
 3020:     /* RTRV-ONTPOTS:SUR-1-1:ONTPOTS-1-1-1-1-1-2-1 * /
 3021:     "ONTPOTS-1-1-1-1-1-2-1::VOIPSERV=1,TERMID=td1,POTSDSCP=46,POTSPWR=0,
 3022:     CALLHIST=DISABLED,PWROVERRIDE=FALSE,SIPMSGTOTH=0,BRRPKTLOSSTH=0,XJTTRTH=0,
 3023:     RXGAIN=0,TXGAIN=0:IS-NR"
 3024:     ;
 3025:     */
 3026:  
 3027:                 // below: read OntPosition
 3028:                 match = Regex.Match(rowData, @"RTRV-ONTPOTS:([\w\d\-]+)", RegexOptions.Singleline);
 3029:  
 3030:                 amsName = match.Groups[1].Value;
 3031:  
 3032:                 match = Regex.Match(rowData, @"ONTPOTS-1-1-(\d{1,2}-\d{1,2}-\d{1,2})-(\d{1,2})-(\d{1,2})::(.+?):\s*(IS-NR|OOS-AU|OOS-MA|OOS-AUMA)", RegexOptions.Singleline);
 3033:  
 3034:                 if (match.Success)
 3035:                 {
 3036:                     cardPortOnt = match.Groups[1].Value;
 3037:                     card = int.Parse(match.Groups[2].Value);
 3038:                     port = int.Parse(match.Groups[3].Value);
 3039:  
 3040:                     line = match.Groups[4].Value;
 3041:  
 3042:                     ontId = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(amsName, cardPortOnt);
 3043:  
 3044:                     if (!string.IsNullOrEmpty(ontId))
 3045:                     {
 3046:                         if (card >= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MinimumCardValue && card <= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MaximumCardValue && port >= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MinimumPortValue && port <= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MaximumPortValue)
 3047:                         {
 3048:                             ontOntPotsId = Ia.Ftn.Cl.Models.Business.Nokia.OntOntPots.OntOntPotsId(ontId, card, port);
 3049:  
 3050:                             dataOntOntPots = new Ia.Ftn.Cl.Models.OntOntPots();
 3051:  
 3052:                             dataOntOntPots.Id = ontOntPotsId;
 3053:  
 3054:                             dataOntOntPots.Card = card;
 3055:                             dataOntOntPots.Customer = Ia.Cl.Models.Default.Match(line, @"CUSTINFO=(\w{1,80})");
 3056:                             dataOntOntPots.Port = port;
 3057:  
 3058:                             switch (match.Groups[5].Value)
 3059:                             {
 3060:                                 case "IS-NR": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.IsNr; break;
 3061:                                 case "OOS-AU": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAu; break;
 3062:                                 case "OOS-MA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosMa; break;
 3063:                                 case "OOS-AUMA": state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.OosAuma; break;
 3064:                                 default: state = Ia.Ftn.Cl.Models.Business.Nokia.Ams.BellcoreState.Undefined; break;
 3065:                             }
 3066:  
 3067:                             dataOntOntPots.StateId = (int)state;
 3068:  
 3069:                             if (int.TryParse(Ia.Cl.Models.Default.Match(line, @"SVLAN=(\d{1,3})"), out svlan)) dataOntOntPots.Svlan = svlan;
 3070:  
 3071:                             dataOntOntPots.Termination = Ia.Cl.Models.Default.Match(line, @"TERMID=(\w{1,20})");
 3072:                             dataOntOntPots.Tn = Ia.Cl.Models.Default.Match(line, @"TN=(\w{1,16})");
 3073:                             dataOntOntPots.VoipClientIp = Ia.Cl.Models.Default.Match(line, @"VOIPCLIENTADDR=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
 3074:  
 3075:                             using (var db = new Ia.Ftn.Cl.Db())
 3076:                             {
 3077:                                 dataOntOntPots.Ont = (from o in db.Onts where o.Id == ontId select o).SingleOrDefault();
 3078:  
 3079:                                 ontOntPots = (from oop in db.OntOntPots where oop.Id == dataOntOntPots.Id select oop).SingleOrDefault();
 3080:  
 3081:                                 if (ontOntPots == null)
 3082:                                 {
 3083:                                     dataOntOntPots.Created = dataOntOntPots.Updated = DateTime.UtcNow.AddHours(3);
 3084:  
 3085:                                     db.OntOntPots.Add(dataOntOntPots);
 3086:  
 3087:                                     insertedItemCount++;
 3088:                                 }
 3089:                                 else
 3090:                                 {
 3091:                                     existingItemCount++;
 3092:  
 3093:                                     if (ontOntPots.Update(dataOntOntPots))
 3094:                                     {
 3095:                                         db.OntOntPots.Attach(ontOntPots);
 3096:                                         db.Entry(ontOntPots).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 3097:  
 3098:                                         updatedItemCount++;
 3099:                                     }
 3100:                                 }
 3101:  
 3102:                                 db.SaveChanges();
 3103:                             }
 3104:                         }
 3105:                         else
 3106:                         {
 3107:                             result.AddError(@"Card and/or port value is invalid: card:" + card + ", port:" + port);
 3108:                         }
 3109:                     }
 3110:                     else
 3111:                     {
 3112:                         result.AddError("Error in UpdateDatabaseWithAmsCommandOutput(): ontId was null or empty for amsName: [" + amsName + "] and pon: [" + cardPortOnt + "].");
 3113:                     }
 3114:                 }
 3115:                 else
 3116:                 {
 3117:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 3118:                 }
 3119:  
 3120:                 #endregion
 3121:             }
 3122:             else if (rowData.Contains("ED-ONTPOTS:"))
 3123:             {
 3124:                 #region ED-ONTPOTS
 3125:  
 3126:                 string ontOntPotsId;
 3127:                 int card, port;
 3128:                 Ia.Ftn.Cl.Models.OntOntPots ontOntPots, dataOntOntPots;
 3129:  
 3130:                 /* ED-ONTPOTS:SUL-1-1:ONTPOTS-1-1-9-1-1-2-1:14614:::CUSTINFO=24977777: */
 3131:                 /* ED-ONTPOTS:SJA-JHR-LAG14:ONTPOTS-1-1-1-6-4-0-0:2425:::CUSTINFO=24531914: */
 3132:  
 3133:                 // below: read OntPosition
 3134:                 match = Regex.Match(rowData, @"ED-ONTPOTS:([\w\d\-]+)", RegexOptions.Singleline);
 3135:  
 3136:                 amsName = match.Groups[1].Value;
 3137:  
 3138:                 match = Regex.Match(rowData, @"ONTPOTS-1-1-(\d{1,2}-\d{1,2}-\d{1,2})-(\d{1,2})-(\d{1,2}):(.+?):", RegexOptions.Singleline);
 3139:  
 3140:                 if (match.Success)
 3141:                 {
 3142:                     cardPortOnt = match.Groups[1].Value;
 3143:                     card = int.Parse(match.Groups[2].Value);
 3144:                     port = int.Parse(match.Groups[3].Value);
 3145:  
 3146:                     line = match.Groups[4].Value;
 3147:  
 3148:                     ontId = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(amsName, cardPortOnt);
 3149:  
 3150:                     if (!string.IsNullOrEmpty(ontId))
 3151:                     {
 3152:                         if (card >= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MinimumCardValue && card <= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MaximumCardValue && port >= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MinimumPortValue && port <= Ia.Ftn.Cl.Models.Business.Nokia.Ont.MaximumPortValue)
 3153:                         {
 3154:                             ontOntPotsId = Ia.Ftn.Cl.Models.Business.Nokia.OntOntPots.OntOntPotsId(ontId, card, port);
 3155:  
 3156:                             dataOntOntPots = new Ia.Ftn.Cl.Models.OntOntPots();
 3157:  
 3158:                             dataOntOntPots.Id = ontOntPotsId;
 3159:  
 3160:                             dataOntOntPots.Card = card;
 3161:                             dataOntOntPots.Customer = Ia.Cl.Models.Default.Match(line, @"CUSTINFO=(\w{1,80})");
 3162:                             dataOntOntPots.Port = port;
 3163:  
 3164:                             using (var db = new Ia.Ftn.Cl.Db())
 3165:                             {
 3166:                                 dataOntOntPots.Ont = (from o in db.Onts where o.Id == ontId select o).SingleOrDefault();
 3167:  
 3168:                                 ontOntPots = (from oop in db.OntOntPots where oop.Id == dataOntOntPots.Id select oop).SingleOrDefault();
 3169:  
 3170:                                 if (ontOntPots == null)
 3171:                                 {
 3172:                                     dataOntOntPots.Created = dataOntOntPots.Updated = DateTime.UtcNow.AddHours(3);
 3173:  
 3174:                                     db.OntOntPots.Add(dataOntOntPots);
 3175:  
 3176:                                     insertedItemCount++;
 3177:                                 }
 3178:                                 else
 3179:                                 {
 3180:                                     existingItemCount++;
 3181:  
 3182:                                     if (ontOntPots.Update(dataOntOntPots))
 3183:                                     {
 3184:                                         db.OntOntPots.Attach(ontOntPots);
 3185:                                         db.Entry(ontOntPots).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 3186:  
 3187:                                         updatedItemCount++;
 3188:                                     }
 3189:                                 }
 3190:  
 3191:                                 db.SaveChanges();
 3192:                             }
 3193:                         }
 3194:                         else
 3195:                         {
 3196:                             result.AddError(@"Card and/or port value is invalid: card:" + card + ", port:" + port);
 3197:                         }
 3198:                     }
 3199:                     else
 3200:                     {
 3201:                         result.AddError("Error in UpdateDatabaseWithAmsCommandOutput(): ontId was null or empty for amsName: [" + amsName + "] and pon: [" + cardPortOnt + "].");
 3202:                     }
 3203:                 }
 3204:                 else
 3205:                 {
 3206:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 3207:                 }
 3208:  
 3209:                 #endregion
 3210:             }
 3211:             else if (rowData.Contains("RTRV-ALM-PON:"))
 3212:             {
 3213:                 // Note: this RTRV-ALM-PON: commnad is never issued by code actally. New ONTs are detected below (see "REPT ALM") as part of regular events
 3214:                 #region RTRV-ALM-PON
 3215:  
 3216:                 Ia.Ftn.Cl.Models.Event @event;
 3217:  
 3218:                 // below: important, remove all ''' char from string
 3219:                 rowData = rowData.Replace(@"'", "");
 3220:  
 3221:                 // below: read eventTime and amsName
 3222:                 // QRW-1-1 14-03-31 06:15:20
 3223:                 match = Regex.Match(rowData, @"([\w\d\-]+) ((\d{2})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}))", RegexOptions.Singleline);
 3224:  
 3225:                 amsName = match.Groups[1].Value;
 3226:                 eventTime = DateTime.ParseExact(match.Groups[2].Captures[0].Value, "yy-MM-dd HH:mm:ss", null);
 3227:  
 3228:                 // old "PON-1-1-9-2,PON:MN,NEWONT,NSA,,,,: \"SERNUM =ALCLA0A2D17A, SLID =DEFAULT,\""
 3229:                 // old matchCollection = Regex.Matches(rowData, @"""(PON-\d{1,2}-\d{1,2}-\d{1,2}-\d{1,2}),PON:MN,NEWONT,NSA,,,,:\s*\r\n\s*""(SERNUM\s*=\s*(ALCL\w{8}), SLID\s*=\s*DEFAULT,)""""", RegexOptions.Singleline);
 3230:  
 3231:                 /*
 3232:     "PON-1-1-10-3:CL,NEWONT,NSA,5-26,23-8-36,,:,
 3233:     "SERNUM =ALCLA0A22564, SLID =DEFAULT                 ,
 3234:     LOID =                        , USRATE =1.25g""
 3235:                 */
 3236:  
 3237:                 matchCollection = Regex.Matches(rowData, @"""(PON-\d{1,2}-\d{1,2}-\d{1,2}-\d{1,2}):(CL|MN),NEWONT,NSA,\d{1,2}-\d{1,2},\d{1,2}-\d{1,2}-\d{1,2},,:,\s*\r\n\s*""(SERNUM\s*=\s*(ALCL\w{8}),\s*SLID\s*=\s*DEFAULT\s*,)\s*\r\n\s*.+?""""", RegexOptions.Singleline);
 3238:  
 3239:                 if (matchCollection.Count > 0)
 3240:                 {
 3241:                     using (var db = new Ia.Ftn.Cl.Db())
 3242:                     {
 3243:                         foreach (Match m in matchCollection)
 3244:                         {
 3245:                             if (m.Success)
 3246:                             {
 3247:                                 @event = new Ia.Ftn.Cl.Models.Event();
 3248:  
 3249:                                 @event.Aid = m.Groups[1].Value;
 3250:                                 @event.Cause = "NEWONT";
 3251:                                 @event.Class = "ONT";
 3252:                                 @event.Detail = m.Groups[3].Value;
 3253:                                 @event.EventTime = eventTime;
 3254:                                 @event.NodeTime = null;
 3255:                                 @event.Number = 0;
 3256:                                 @event.SeverityEffect = "NSA";
 3257:                                 @event.Severity = m.Groups[2].Value;
 3258:                                 @event.System = amsName;
 3259:                                 @event.TypeId = 0;
 3260:  
 3261:                                 @event.Created = @event.Updated = DateTime.UtcNow.AddHours(3);
 3262:                                 db.Events.Add(@event);
 3263:  
 3264:                                 insertedItemCount++;
 3265:                             }
 3266:                         }
 3267:  
 3268:                         db.SaveChanges();
 3269:                     }
 3270:                 }
 3271:                 else
 3272:                 {
 3273:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: [" + rowData + "] was not matched.");
 3274:                 }
 3275:  
 3276:                 #endregion
 3277:             }
 3278:             else if (rowData.Contains("REPT ALM"))
 3279:             {
 3280:                 #region REPT ALM
 3281:  
 3282:                 string _class, aid;
 3283:                 Ia.Ftn.Cl.Models.Event @event;
 3284:  
 3285:                 // below: important, remove all ''' char from string
 3286:                 rowData = rowData.Replace(@"'", "");
 3287:  
 3288:                 // SUR-1-2 08-07-18 11:24:06 * 491 REPT ALM ONT "ONT-1-1-9-2-5:MN,INACT,SA,7-18,11-24-6:\"ONT is inactive\"" ;
 3289:  
 3290:                 /*
 3291:     SLA-SUR-LAG16 18-06-24 18:21:01
 3292:     A  37211 REPT ALM ONT
 3293:     "ONT-1-1-5-9-20:CL,DG,SA,6-24,18-21-1:
 3294:     "Received Dying Gasp indication from ONT","
 3295:     ;                 */
 3296:                 // old: match = Regex.Match(rowData, @"([\w\d\-]+) ((\d{2})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}))\r\n(.{1,10})\s+(\d{1,6}) REPT (ALM|EVT|ALM ENV|SW) (\w{1,20})\r\n\s+""(\w{1,20})-(\d{1,2})-(\d{1,2})-([^:]+?):(CR|MJ|MN|CL),(\w{1,20}),(SA|NSA|NR|Ind NR),((\d{1,2})-(\d{1,2})),((\d{1,2})-(\d{1,2})-(\d{1,2})).*:[\r\n\s]*""(.+?)""[,]{0,1}""\r\n;", RegexOptions.Singleline);
 3297:                 match = Regex.Match(rowData, @"([\w\d\-]+) ((\d{2})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}))\r\n(.{1,10})\s+(\d{1,6}) REPT (ALM|EVT|ALM ENV|SW) (\w{1,20})\r\n\s+""(\w{1,20})-(\d{1,2})-(\d{1,2})-([^:]+?):(CR|MJ|MN|CL),(\w{1,20}),(SA|NSA|NR|Ind NR),((\d{1,2})-(\d{1,2})),((\d{1,2})-(\d{1,2})-(\d{1,2})).*:.*[\r\n\s]*""(.+?)""[,]{0,1}""\r\n;", RegexOptions.Singleline);
 3298:  
 3299:                 if (match.Success)
 3300:                 {
 3301:                     amsName = match.Groups[1].Value;
 3302:  
 3303:                     _class = match.Groups[12].Captures[0].Value;
 3304:                     aid = match.Groups[13].Captures[0].Value + "-" + match.Groups[14].Captures[0].Value + "-" + match.Groups[15].Captures[0].Value + "-" + match.Groups[16].Captures[0].Value;
 3305:  
 3306:                     ontPosition = CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(amsName, _class, aid);
 3307:                     ontId = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdByPosition(ontPosition);
 3308:  
 3309:                     @event = new Ia.Ftn.Cl.Models.Event();
 3310:  
 3311:                     @event.Aid = aid;
 3312:                     @event.Cause = match.Groups[18].Captures[0].Value;
 3313:                     @event.Class = _class;
 3314:                     @event.Detail = match.Groups[27].Captures[0].Value.Replace(@"""", "");
 3315:                     @event.EventTime = DateTime.ParseExact(match.Groups[2].Captures[0].Value, "yy-MM-dd HH:mm:ss", null);
 3316:                     @event.NodeTime = DateTime.ParseExact(match.Groups[3].Captures[0].Value + "-" + match.Groups[21].Captures[0].Value.PadLeft(2, '0') + "-" + match.Groups[22].Captures[0].Value.PadLeft(2, '0') + " " + match.Groups[24].Captures[0].Value.PadLeft(2, '0') + ":" + match.Groups[25].Captures[0].Value.PadLeft(2, '0') + ":" + match.Groups[26].Captures[0].Value.PadLeft(2, '0'), "yy-MM-dd HH:mm:ss", null);
 3317:                     @event.Number = int.Parse(match.Groups[10].Captures[0].Value);
 3318:                     @event.SeverityEffect = match.Groups[19].Captures[0].Value;
 3319:                     @event.Severity = match.Groups[17].Captures[0].Value;
 3320:                     @event.System = amsName;
 3321:                     @event.TypeId = 0;
 3322:  
 3323:                     using (var db = new Ia.Ftn.Cl.Db())
 3324:                     {
 3325:                         if (ontId != null) @event.Ont = (from o in db.Onts where o.Id == ontId select o).SingleOrDefault();
 3326:  
 3327:                         @event.Created = @event.Updated = DateTime.UtcNow.AddHours(3);
 3328:                         db.Events.Add(@event);
 3329:  
 3330:                         insertedItemCount++;
 3331:  
 3332:                         db.SaveChanges();
 3333:                     }
 3334:                 }
 3335:                 else
 3336:                 {
 3337:                     result.AddWarning("Warning in UpdateDatabaseWithAmsCommandOutput(): Row data: REPT ALM [" + rowData + "] was not matched.");
 3338:                 }
 3339:  
 3340:                 #endregion
 3341:             }
 3342:  
 3343:             if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 3344:             else isUpdated = false;
 3345:  
 3346:             result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 3347:  
 3348:             return isUpdated;
 3349:         }
 3350:  
 3351:         ////////////////////////////////////////////////////////////////////////////
 3352:  
 3353:         /// <summary>
 3354:         /// 
 3355:         /// </summary>
 3356:         private static string CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(string amsName, string _class, string aid)
 3357:         {
 3358:             /*
 3359:     --BRGPORT    BRGPORT-1-1-11-2-6-1-1
 3360:     --PON    PON-1-1-13-1
 3361:     --EQPT    LT-1-1-14
 3362:     --ONTPOTS    ONTPOTS-1-1-8-1-17-2-2
 3363:     --ONTVOIP    VOIP-1-1-13-2-22-1
 3364:     --ONT    ONT-1-1-13-1-10
 3365:     --ONTENET    ONTENET-1-1-2-1-20-1-1
 3366:     --ONTCARD    ONTCARD-1-1-9-2-8-1
 3367:     --ONTHSI    HSI-1-1-2-1-8-1-2-2
 3368:             */
 3369:  
 3370:             string ontPosition;
 3371:             Match match;
 3372:  
 3373:             ontPosition = string.Empty;
 3374:  
 3375:             if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(_class))
 3376:             {
 3377:                 if (_class == "BRGPORT")
 3378:                 {
 3379:                     // BRGPORT    BRGPORT-1-1-11-2-6-1-1
 3380:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3381:  
 3382:                     if (match.Success)
 3383:                     {
 3384:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3385:                     }
 3386:                     else
 3387:                     {
 3388:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3389:                     }
 3390:                 }
 3391:                 else if (_class == "PON")
 3392:                 {
 3393:                     // PON    PON-1-1-13-1
 3394:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3395:  
 3396:                     if (match.Success)
 3397:                     {
 3398:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-1"; // I will assign the first ONT in the PON as indication to the PON
 3399:                     }
 3400:                     else
 3401:                     {
 3402:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3403:                     }
 3404:                 }
 3405:                 else if (_class == "EQPT")
 3406:                 {
 3407:                     // EQPT    LT-1-1-14
 3408:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3409:  
 3410:                     if (match.Success)
 3411:                     {
 3412:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-1"; // I will assign the first PON ONT in the PON as indication to the PON
 3413:                     }
 3414:                     else
 3415:                     {
 3416:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3417:                     }
 3418:                 }
 3419:                 else if (_class == "ONTPOTS")
 3420:                 {
 3421:                     // ONTPOTS    ONTPOTS-1-1-8-1-17-2-2
 3422:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3423:  
 3424:                     if (match.Success)
 3425:                     {
 3426:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3427:                     }
 3428:                     else
 3429:                     {
 3430:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3431:                     }
 3432:                 }
 3433:                 else if (_class == "ONTVOIP")
 3434:                 {
 3435:                     // ONTVOIP    VOIP-1-1-13-2-22-1
 3436:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3437:  
 3438:                     if (match.Success)
 3439:                     {
 3440:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3441:                     }
 3442:                     else
 3443:                     {
 3444:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3445:                     }
 3446:                 }
 3447:                 else if (_class == "ONT")
 3448:                 {
 3449:                     // ONT    ONT-1-1-13-1-10
 3450:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3451:  
 3452:                     if (match.Success)
 3453:                     {
 3454:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3455:                     }
 3456:                     else
 3457:                     {
 3458:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3459:                     }
 3460:                 }
 3461:                 else if (_class == "ONTENET")
 3462:                 {
 3463:                     // ONTENET    ONTENET-1-1-2-1-20-1-1
 3464:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3465:  
 3466:                     if (match.Success)
 3467:                     {
 3468:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3469:                     }
 3470:                     else
 3471:                     {
 3472:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3473:                     }
 3474:                 }
 3475:                 else if (_class == "ONTCARD")
 3476:                 {
 3477:                     // ONTCARD    ONTCARD-1-1-9-2-8-1
 3478:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3479:  
 3480:                     if (match.Success)
 3481:                     {
 3482:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3483:                     }
 3484:                     else
 3485:                     {
 3486:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3487:                     }
 3488:                 }
 3489:                 else if (_class == "ONTHSI")
 3490:                 {
 3491:                     // ONTHSI    HSI-1-1-2-1-8-1-2-2
 3492:                     match = Regex.Match(aid, @"^(\w+)-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})$", RegexOptions.Singleline);
 3493:  
 3494:                     if (match.Success)
 3495:                     {
 3496:                         ontPosition = amsName + "-" + int.Parse(match.Groups[4].Value) + "-" + int.Parse(match.Groups[5].Value) + "-" + int.Parse(match.Groups[6].Value);
 3497:                     }
 3498:                     else
 3499:                     {
 3500:                         throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + " unmatched.") { };
 3501:                     }
 3502:                 }
 3503:                 else
 3504:                 {
 3505:                     throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): class: " + _class + ", aid: " + aid + ". Class is unknown.") { };
 3506:                 }
 3507:             }
 3508:             else
 3509:             {
 3510:                 throw new Exception("CalculateRelaventOntPositionAccordingToAmsNameAndClassAndAid(): aid and/or class are null.") { };
 3511:             }
 3512:  
 3513:             return ontPosition;
 3514:         }
 3515:  
 3516:         ////////////////////////////////////////////////////////////////////////////
 3517:  
 3518:         /// <summary>
 3519:         ///
 3520:         /// </summary>
 3521:         public bool AddPot(string td)
 3522:         {
 3523:             bool b;
 3524:  
 3525:             b = true;
 3526:  
 3527:  
 3528:             return b;
 3529:         }
 3530:  
 3531:         ////////////////////////////////////////////////////////////////////////////
 3532:  
 3533:         /// <summary>
 3534:         ///
 3535:         /// </summary>
 3536:         public static string CommandsToDeleteAndCreateServiceVoipUsingNdd(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt, Ia.Ftn.Cl.Models.Ont ont, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt, bool edServiceVoipIsOos)
 3537:         {
 3538:             string sa, cardPortOnt, voipServiceState;
 3539:  
 3540:             sa = string.Empty;
 3541:  
 3542:             foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup ponGroup in olt.PonGroupList)
 3543:             {
 3544:                 cardPortOnt = nddOnt.CardSlot + "-" + nddOnt.Port + "-" + nddOnt.InternalNumber;
 3545:  
 3546:                 if (edServiceVoipIsOos) voipServiceState = "OOS";
 3547:                 else voipServiceState = "IS";
 3548:  
 3549:                 sa = @"
 3550: # Delete then create VOIP and associated ONTPOTS: " + nddOnt.Access.Name + @" " + nddOnt.Position;
 3551:  
 3552:                 if (ont != null)
 3553:                 {
 3554:                     if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Sfu || ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Gfu || ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Undefined)
 3555:                     {
 3556:                         sa += @"
 3557:  
 3558: # Delete ONTPOTS
 3559: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-4:::::OOS;
 3560: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-4::;
 3561:  
 3562: # Delete VOIP
 3563: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::OOS;
 3564: DLT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1;
 3565:  
 3566: # Create VOIP
 3567: ENT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1::::BWPROFUPID=1,BWPROFDNID=1,PQPROFID=1,LABEL=" + nddOnt.Access.Name + @",SVLAN=" /*+ ponGroup.Olt.Vlan*/ + @",IPADDRLOC=" + nddOnt.Ip + @",NETMASKLOC=" + nddOnt.MgcSubnetMask + @",DEFROUTER=" + ponGroup.GatewayIp + @",IPADDRMGC=" + nddOnt.MgcIp + @",IPADDRMGCSEC=" + nddOnt.MgcSecondaryIp + @",VOIPMODE=SSH248,CONFIGFILE=" + olt.Odf.Router.Oams.FirstOrDefault().ConfigFile + @":IS;
 3568:  
 3569: # Create ONTPOTS
 3570: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;
 3571: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;
 3572: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;
 3573: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;
 3574:  
 3575: # VOIP service state
 3576: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3577:  
 3578:  
 3579: ";
 3580:                     }
 3581:                     else if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Soho)
 3582:                     {
 3583:                         sa += @"
 3584:  
 3585: # Delete ONTPOTS
 3586: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-8:::::OOS;
 3587: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-8::;
 3588:  
 3589: # Delete VOIP
 3590: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::OOS;
 3591: DLT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1;
 3592:  
 3593: # Create VOIP
 3594: ENT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1::::BWPROFUPID=1,BWPROFDNID=1,PQPROFID=1,LABEL=" + nddOnt.Access.Name + @",SVLAN=" /*+ ponGroup.Vlan*/ + @",IPADDRLOC=" + nddOnt.Ip + @",NETMASKLOC=" + nddOnt.MgcSubnetMask + @",DEFROUTER=" + ponGroup.GatewayIp + @",IPADDRMGC=" + nddOnt.MgcIp + @",IPADDRMGCSEC=" + nddOnt.MgcSecondaryIp + @",VOIPMODE=SSH248,CONFIGFILE=" + olt.Odf.Router.Oams.FirstOrDefault().ConfigFile + @":IS;
 3595:  
 3596: # Create ONTPOTS
 3597: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;
 3598: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;
 3599: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;
 3600: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;
 3601: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-5::::VOIPSERV=1,TERMID=td5:IS;
 3602: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-6::::VOIPSERV=1,TERMID=td6:IS;
 3603: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-7::::VOIPSERV=1,TERMID=td7:IS;
 3604: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-8::::VOIPSERV=1,TERMID=td8:IS;
 3605:  
 3606: # VOIP service state
 3607: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3608:  
 3609:  
 3610: ";
 3611:                     }
 3612:                     else if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Mdu || ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Gmdu)
 3613:                     {
 3614:                         sa += @"
 3615:  
 3616: # Delete ONTPOTS
 3617: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-1&&-8:::::OOS;
 3618: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-8:::::OOS;
 3619: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-1&&-8:::::OOS;
 3620: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-1&&-8::;
 3621: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-8::;
 3622: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-1&&-8::;
 3623:  
 3624: # Delete VOIP
 3625: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::OOS;
 3626: DLT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1;
 3627:  
 3628: # Create VOIP
 3629: ENT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1::::BWPROFUPID=8,BWPROFDNID=8,PQPROFID=1,AESENABLE=DISABLE,LABEL=" + nddOnt.Access.Name + @",SVLAN=" /*+ ponGroup.Vlan*/ + @",IPADDRLOC=" + nddOnt.Ip + @",NETMASKLOC=" + nddOnt.MgcSubnetMask + @",DEFROUTER=" + ponGroup.GatewayIp + @",IPADDRMGC=" + nddOnt.MgcIp + @",IPADDRMGCSEC=" + nddOnt.MgcSecondaryIp + @",IPADDRFTP=0.0.0.0,DHCP=DISABLE,PORTMGC=2944,VOIPDSCP=24,VOIPMODE=SSH248,CONFIGFILE=" + olt.Odf.Router.Oams.FirstOrDefault().ConfigFile + @":IS;
 3630:  
 3631: # Create ONTPOTS
 3632: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-1::::VOIPSERV=1,TERMID=td1:IS;
 3633: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-2::::VOIPSERV=1,TERMID=td2:IS;
 3634: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-3::::VOIPSERV=1,TERMID=td3:IS;
 3635: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-4::::VOIPSERV=1,TERMID=td4:IS;
 3636: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-5::::VOIPSERV=1,TERMID=td13:IS;
 3637: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-6::::VOIPSERV=1,TERMID=td14:IS;
 3638: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-7::::VOIPSERV=1,TERMID=td15:IS;
 3639: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-8::::VOIPSERV=1,TERMID=td16:IS;
 3640:  
 3641: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td5:IS;
 3642: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td6:IS;
 3643: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td7:IS;
 3644: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td8:IS;
 3645: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-5::::VOIPSERV=1,TERMID=td17:IS;
 3646: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-6::::VOIPSERV=1,TERMID=td18:IS;
 3647: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-7::::VOIPSERV=1,TERMID=td19:IS;
 3648: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-8::::VOIPSERV=1,TERMID=td20:IS;
 3649:  
 3650: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-1::::VOIPSERV=1,TERMID=td9:IS;
 3651: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-2::::VOIPSERV=1,TERMID=td10:IS;
 3652: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-3::::VOIPSERV=1,TERMID=td11:IS;
 3653: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-4::::VOIPSERV=1,TERMID=td12:IS;
 3654: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-5::::VOIPSERV=1,TERMID=td21:IS;
 3655: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-6::::VOIPSERV=1,TERMID=td22:IS;
 3656: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-7::::VOIPSERV=1,TERMID=td23:IS;
 3657: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-8::::VOIPSERV=1,TERMID=td24:IS;
 3658:  
 3659: # VOIP service state
 3660: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3661:  
 3662:  
 3663: ";
 3664:                     }
 3665:                     else
 3666:                     {
 3667:                         throw new Exception("Unknown familyType") { };
 3668:                     }
 3669:                 }
 3670:                 else
 3671:                 {
 3672:  
 3673:                     sa = @"
 3674: # Delete then create VOIP and associated ONTPOTS: " + nddOnt.Access.Name + @" " + nddOnt.Position;
 3675:  
 3676:                     sa += @"
 3677: # ONT does not have an associated Access to it.";
 3678:  
 3679:                     sa += @"
 3680:  
 3681: # Delete ONTPOTS
 3682: ED-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-4:::::OOS;
 3683: DLT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1&&-4::;
 3684:  
 3685: # Delete VOIP
 3686: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::OOS;
 3687: DLT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1;
 3688:  
 3689: # Create VOIP
 3690: ENT-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1::::BWPROFUPID=1,BWPROFDNID=1,PQPROFID=1,LABEL=" + nddOnt.Access.Name + @",SVLAN=" /*+ ponGroup.Vlan*/ + @",IPADDRLOC=" + nddOnt.Ip + @",NETMASKLOC=" + nddOnt.MgcSubnetMask + @",DEFROUTER=" + ponGroup.GatewayIp + @",IPADDRMGC=" + nddOnt.MgcIp + @",IPADDRMGCSEC=" + nddOnt.MgcSecondaryIp + @",VOIPMODE=SSH248,CONFIGFILE=" + olt.Odf.Router.Oams.FirstOrDefault().ConfigFile + @":IS;
 3691:  
 3692: # Create ONTPOTS
 3693: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;
 3694: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;
 3695: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;
 3696: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;
 3697:  
 3698: # VOIP service state
 3699: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3700:  
 3701:  
 3702: ";
 3703:                 }
 3704:             }
 3705:  
 3706:             return sa;
 3707:         }
 3708:  
 3709:         ////////////////////////////////////////////////////////////////////////////
 3710:  
 3711:         /// <summary>
 3712:         ///
 3713:         /// </summary>
 3714:         public static string CommandsToCreateOntPots(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt, Ia.Ftn.Cl.Models.Ont ont, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt, bool edServiceVoipIsOos)
 3715:         {
 3716:             string sa, cardPortOnt, voipServiceState;
 3717:  
 3718:             cardPortOnt = nddOnt.CardSlot + "-" + nddOnt.Port + "-" + nddOnt.InternalNumber;
 3719:  
 3720:             if (edServiceVoipIsOos) voipServiceState = "OOS";
 3721:             else voipServiceState = "IS";
 3722:  
 3723:             sa = @"
 3724: # Create ONTPOTS: " + ont.Access.Name + @" " + ont.Access.Position;
 3725:  
 3726:             if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Sfu || ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Gfu)
 3727:             {
 3728:                 sa += @"
 3729:  
 3730: # Create ONTPOTS
 3731: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;
 3732: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;
 3733: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;
 3734: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;
 3735:  
 3736: # VOIP service state
 3737: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3738:  
 3739:  
 3740: ";
 3741:             }
 3742:             else if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Soho)
 3743:             {
 3744:                 sa += @"
 3745:  
 3746: # Create ONTPOTS
 3747: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;
 3748: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;
 3749: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;
 3750: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;
 3751: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-5::::VOIPSERV=1,TERMID=td5:IS;
 3752: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-6::::VOIPSERV=1,TERMID=td6:IS;
 3753: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-7::::VOIPSERV=1,TERMID=td7:IS;
 3754: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-8::::VOIPSERV=1,TERMID=td8:IS;
 3755:  
 3756: # VOIP service state
 3757: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3758:  
 3759:  
 3760: ";
 3761:             }
 3762:             else if (ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Mdu || ont.FamilyTypeId == (int)Ia.Ftn.Cl.Models.Business.Nokia.Ont.FamilyType.Gmdu)
 3763:             {
 3764:                 sa += @"
 3765:  
 3766: # Create ONTPOTS
 3767: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-1::::VOIPSERV=1,TERMID=td1:IS;
 3768: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-2::::VOIPSERV=1,TERMID=td2:IS;
 3769: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-3::::VOIPSERV=1,TERMID=td3:IS;
 3770: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-4::::VOIPSERV=1,TERMID=td4:IS;
 3771: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-5::::VOIPSERV=1,TERMID=td13:IS;
 3772: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-6::::VOIPSERV=1,TERMID=td14:IS;
 3773: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-7::::VOIPSERV=1,TERMID=td15:IS;
 3774: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-1-8::::VOIPSERV=1,TERMID=td16:IS;
 3775:  
 3776: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td5:IS;
 3777: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td6:IS;
 3778: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td7:IS;
 3779: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td8:IS;
 3780: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-5::::VOIPSERV=1,TERMID=td17:IS;
 3781: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-6::::VOIPSERV=1,TERMID=td18:IS;
 3782: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-7::::VOIPSERV=1,TERMID=td19:IS;
 3783: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-8::::VOIPSERV=1,TERMID=td20:IS;
 3784:  
 3785: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-1::::VOIPSERV=1,TERMID=td9:IS;
 3786: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-2::::VOIPSERV=1,TERMID=td10:IS;
 3787: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-3::::VOIPSERV=1,TERMID=td11:IS;
 3788: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-4::::VOIPSERV=1,TERMID=td12:IS;
 3789: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-5::::VOIPSERV=1,TERMID=td21:IS;
 3790: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-6::::VOIPSERV=1,TERMID=td22:IS;
 3791: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-7::::VOIPSERV=1,TERMID=td23:IS;
 3792: ENT-ONTPOTS:" + olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-3-8::::VOIPSERV=1,TERMID=td24:IS;
 3793:  
 3794: # VOIP service state
 3795: ED-SERVICE-VOIP:" + olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";
 3796:  
 3797:  
 3798: ";
 3799:             }
 3800:             else
 3801:             {
 3802:                 sa += @"
 3803:  
 3804: # Unknown FamilyType
 3805:  
 3806:  
 3807: ";
 3808:             }
 3809:  
 3810:             return sa;
 3811:         }
 3812:  
 3813:         ////////////////////////////////////////////////////////////////////////////
 3814:  
 3815:         /// <summary>
 3816:         ///
 3817:         /// </summary>
 3818:         public static List<string> CommandsToPreprovisionOntWithinOlt(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt, bool edServiceVoipIsOos)
 3819:         {
 3820:             string cardPortOnt, voipServiceState;
 3821:             List<string> list;
 3822:  
 3823:             list = new List<string>();
 3824:  
 3825:             if (edServiceVoipIsOos) voipServiceState = "OOS";
 3826:             else voipServiceState = "IS";
 3827:  
 3828:             cardPortOnt = nddOnt.CardSlot + "-" + nddOnt.Port + "-" + nddOnt.InternalNumber;
 3829:  
 3830:             //list.Add("# Preprovision an empty ONT on the network: " + nddOnt.Access.Name + @" " + nddOnt.Position + " (" + nddOnt.Ip + @");");
 3831:             list.Add("ENT-ONT:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONT-1-1-" + cardPortOnt + @"::::SWVERPLND=" + Ia.Ftn.Cl.Models.Data.Nokia.Ams.PlannedSoftware + @",DESC1=" + nddOnt.Access.Name + @",DESC2=""NULL"":OOS;");
 3832:  
 3833:             //list.Add("# Provision the VOIP service;");
 3834:             list.Add("ENT-ONTCARD:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTCARD-1-1-" + cardPortOnt + @"-2:::POTS::IS;");
 3835:             list.Add("ENT-ONTCARD:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTCARD-1-1-" + cardPortOnt + @"-1:::10_100BASET::IS;");
 3836:             list.Add("ENT-ONTENET:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTENET-1-1-" + cardPortOnt + @"-1-1::::SESSPROFID=1,MAXMACNUM=4:IS;");
 3837:             list.Add("ENT-ONTENET:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTENET-1-1-" + cardPortOnt + @"-1-2::::SESSPROFID=1,MAXMACNUM=4:IS;");
 3838:             list.Add("ENT-SERVICE-VOIP:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1::::BWPROFUPID=1,BWPROFDNID=1,PQPROFID=1,SVLAN=" /*+ nddOnt.Pon.PonGroup.Olt.Vlan*/ + @",IPADDRLOC=" + nddOnt.Ip + @",NETMASKLOC=" + nddOnt.MgcSubnetMask + @",DEFROUTER=" + nddOnt.Pon.PonGroup.GatewayIp + @",IPADDRMGC=" + nddOnt.MgcIp + @",IPADDRMGCSEC=" + nddOnt.MgcSecondaryIp + @",VOIPMODE=SSH248,CONFIGFILE=kuwait.xml:IS;");
 3839:             list.Add("ENT-ONTPOTS:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-1::::VOIPSERV=1,TERMID=td1:IS;");
 3840:             list.Add("ENT-ONTPOTS:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-2::::VOIPSERV=1,TERMID=td2:IS;");
 3841:             list.Add("ENT-ONTPOTS:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-3::::VOIPSERV=1,TERMID=td3:IS;");
 3842:             list.Add("ENT-ONTPOTS:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":ONTPOTS-1-1-" + cardPortOnt + @"-2-4::::VOIPSERV=1,TERMID=td4:IS;");
 3843:  
 3844:             //list.Add("# VOIP service state");
 3845:             list.Add("ED-SERVICE-VOIP:" + nddOnt.Pon.PonGroup.Olt.AmsName + @":VOIP-1-1-" + cardPortOnt + @"-1:::::" + voipServiceState + @";");
 3846:  
 3847:             return list;
 3848:         }
 3849:  
 3850:         ////////////////////////////////////////////////////////////////////////////
 3851:  
 3852:         /// <summary>
 3853:         ///
 3854:         /// </summary>
 3855:         public static string CommandsToPreprovisionOntWithinOltUsingConfigureCommand(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt, bool edServiceVoipIsOos)
 3856:         {
 3857:             string sa, rackSubCardPortOnt;//, voipServiceState;
 3858:  
 3859:             //if (edServiceVoipIsOos) voipServiceState = "OOS";
 3860:             //else voipServiceState = "IS";
 3861:  
 3862:             rackSubCardPortOnt = nddOnt.Rack + "/" + nddOnt.Sub + "/" + nddOnt.CardSlot + "/" + nddOnt.Port + "/" + nddOnt.InternalNumber;
 3863:  
 3864:             sa = @"
 3865: configure equipment ont slot " + rackSubCardPortOnt + @"/1 planned-card-type 10_100base plndnumdataports 2 plndnumvoiceports 0
 3866: configure equipment ont slot " + rackSubCardPortOnt + @"/2 planned-card-type pots plndnumdataports 0 plndnumvoiceports 4
 3867: configure qos interface ont:" + rackSubCardPortOnt + @" us-num-queue 8
 3868: configure qos interface " + rackSubCardPortOnt + @"/voip upstream-queue 5 bandwidth-profile name:VOICE bandwidth-sharing ont-sharing 
 3869: configure bridge port " + rackSubCardPortOnt + @"/voip max-unicast-mac 8    
 3870: configure bridge port " + rackSubCardPortOnt + @"/voip vlan-id " /*+ nddOnt.Pon.PonGroup.Olt.Vlan*/ + @"
 3871: configure bridge port " + rackSubCardPortOnt + @"/voip pvid " /*+ nddOnt.Pon.PonGroup.Olt.Vlan*/ + @"
 3872: configure voice ont service " + rackSubCardPortOnt + @"/1 voip-mode softswitch-h248 mgc-ip-addr " + nddOnt.MgcIp + @" sec-mgc-ip-addr " + nddOnt.MgcSecondaryIp + @" conf-file-name " + nddOnt.Pon.PonGroup.Olt.Odf.Router.Oams.First().ConfigFile + @" ip-address " + nddOnt.Ip + @" net-mask 255.255.248.0 default-router " + nddOnt.Pon.PonGroup.GatewayIp + @" vlan " /*+ nddOnt.Pon.PonGroup.Olt.Vlan*/ + @"
 3873:  
 3874: ";
 3875:  
 3876:             return sa;
 3877:         }
 3878:  
 3879:         ////////////////////////////////////////////////////////////////////////////    
 3880:         ////////////////////////////////////////////////////////////////////////////    
 3881:     }
 3882:  
 3883:     ////////////////////////////////////////////////////////////////////////////
 3884:     ////////////////////////////////////////////////////////////////////////////   
 3885: }