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