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

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

Element Management System (EMS) support class for Huawei'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.Huawei
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Element Management System (EMS) support class for Huawei's Fixed Telecommunications Network (FTN) business model.
   15:     /// </summary>
   16:  
   17:     /// <remarks> 
   18:     /// Copyright © 2016-2022 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     ///
   20:     /// 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
   21:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   22:     ///
   23:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   24:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   25:     /// 
   26:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   27:     /// 
   28:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   29:     /// </remarks> 
   30:     public class Ems
   31:     {
   32:         private static Queue<string> emsCommandQueue = new Queue<string>();
   33:         private static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltList.PickRandom();
   34:  
   35:         /// <summary/>
   36:         public enum EmsOpcode
   37:         {
   38:             LstDevByDt, LstDevByDev, LstDevByDevIp, LstBoard, LstPort, LstOnt, LstVag, ModOntAlias, ModOntAliasAnnul, ModOntVaprofileAluSipB, LstOntSipInfo, CfgOntVainDiv, CfgOntVainDivVacant, AddVoipPstnUser, AddMsanVoipPstnUser, LstVoipPstnUser, DelVoipPstnUser, CfgVoipPstnAccount, CfgVoipPstnAccountVacant, SaveDev, ResetOnt
   39:         }
   40:  
   41:         /// <summary/>
   42:         public enum BellcoreState { Unknown = 0, IsNr = 1, OosAu, OosMa, OosAuma };
   43:  
   44:         /// <summary/>
   45:         public static string Host { get { return ConfigurationManager.AppSettings["nceServerHost"].ToString(); } }
   46:  
   47:         /// <summary/>
   48:         public static int Port { get { return int.Parse(ConfigurationManager.AppSettings["nceServerPort"].ToString()); } }
   49:  
   50:         /// <summary/>
   51:         public static string LoginUser { get { return PrepareCtaggedCommand(ConfigurationManager.AppSettings["nceServerLoginUser"].ToString()); } }
   52:  
   53:         /// <summary/>
   54:         public static string LogoutUser { get { return PrepareCtaggedCommand(ConfigurationManager.AppSettings["nceServerLogoutUser"].ToString()); } }
   55:  
   56:         ////////////////////////////////////////////////////////////////////////////
   57:  
   58:         /// <summary>
   59:         /// Response class of NCE TL1 NBI following the "10.3 Response Format Description standard" in iManager NCE Unified Network Management System Guide.
   60:         /// </summary>
   61:         public class Response
   62:         {
   63:             /// <summary/>
   64:             public enum CompletionCodeType { DENY, COMPLD };
   65:  
   66:             /// <summary/>
   67:             public enum CommandType { Operation, Query };
   68:  
   69:             /// <summary/>
   70:             public bool OperationCommand { get { return !QueryCommand; } }
   71:  
   72:             /// <summary/>
   73:             public bool QueryCommand { get; set; }
   74:  
   75:             /// <summary/>
   76:             public int BlockTag { get; set; }
   77:  
   78:             /// <summary/>
   79:             public int CurrentBlockCount { get; set; }
   80:  
   81:             /// <summary/>
   82:             public int TotalCount { get; set; }
   83:  
   84:             /// <summary/>
   85:  
   86:             public string Ctag { get; set; }
   87:  
   88:             /// <summary/>
   89:             public string CompletionCode { get; set; }
   90:  
   91:             /// <summary/>
   92:             public string Title { get; set; }
   93:  
   94:             /// <summary/>
   95:             public long En { get; set; }
   96:  
   97:             /// <summary/>
   98:             public string Endesc { get; set; }
   99:  
  100:             /// <summary/>
  101:             public Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode ResultCode { get; set; }
  102:  
  103:             /// <summary/>
  104:             public string CommandFromCorrelationTagDictionaryByCtag
  105:             {
  106:                 get
  107:                 {
  108:                     string opcode;
  109:  
  110:                     if (Ia.Ftn.Cl.Model.Data.Huawei.Ems.CorrelationTagDictionary.ContainsKey(Ctag)) opcode = Ia.Ftn.Cl.Model.Data.Huawei.Ems.CorrelationTagDictionary[Ctag];
  111:                     else opcode = string.Empty;
  112:  
  113:                     return opcode;
  114:                 }
  115:             }
  116:  
  117:             /// <summary/>
  118:             public DataTable QueryDataTable { get; set; }
  119:  
  120:             /// <summary/>
  121:             public Response() { }
  122:         }
  123:  
  124:         ////////////////////////////////////////////////////////////////////////////
  125:  
  126:         /// <summary>
  127:         ///
  128:         /// </summary>
  129:         public Ems() { }
  130:  
  131:         ////////////////////////////////////////////////////////////////////////////
  132:         ////////////////////////////////////////////////////////////////////////////
  133:  
  134:         /// <summary>
  135:         ///
  136:         /// </summary>
  137:         private static List<string> PrepareCtaggedCommand(List<string> commandList)
  138:         {
  139:             List<string> ctaggedCommandList;
  140:  
  141:             if (commandList.Count > 0)
  142:             {
  143:                 ctaggedCommandList = new List<string>(commandList.Count);
  144:  
  145:                 foreach (string command in commandList)
  146:                 {
  147:                     ctaggedCommandList.Add(PrepareCtaggedCommand(command));
  148:                 }
  149:             }
  150:             else ctaggedCommandList = new List<string>();
  151:  
  152:             return ctaggedCommandList;
  153:         }
  154:  
  155:         ////////////////////////////////////////////////////////////////////////////
  156:  
  157:         /// <summary>
  158:         ///
  159:         /// </summary>
  160:         public static string PrepareCtaggedCommand(string command)
  161:         {
  162:             string ctaggedCommand, ctag;
  163:  
  164:             if (command.Contains("{ctag}"))
  165:             {
  166:                 ctag = Ia.Cl.Models.Default.RandomNumber(12);
  167:  
  168:                 Ia.Ftn.Cl.Model.Data.Huawei.Ems.CorrelationTagDictionary[ctag] = command;
  169:  
  170:                 ctaggedCommand = command.Replace("{ctag}", ctag);
  171:             }
  172:             else
  173:             {
  174:                 ctaggedCommand = string.Empty;
  175:             }
  176:  
  177:             return ctaggedCommand;
  178:         }
  179:  
  180:         ////////////////////////////////////////////////////////////////////////////
  181:  
  182:         /// <summary>
  183:         ///
  184:         /// </summary>
  185:         public static string PrepareCtaggedCommand(string command, string ctag)
  186:         {
  187:             string ctaggedCommand;
  188:  
  189:             if (command.Contains("{ctag}"))
  190:             {
  191:                 Ia.Ftn.Cl.Model.Data.Huawei.Ems.CorrelationTagDictionary[ctag] = command;
  192:  
  193:                 ctaggedCommand = command.Replace("{ctag}", ctag);
  194:             }
  195:             else
  196:             {
  197:                 ctaggedCommand = string.Empty;
  198:             }
  199:  
  200:             return ctaggedCommand;
  201:         }
  202:  
  203:         ////////////////////////////////////////////////////////////////////////////
  204:         ////////////////////////////////////////////////////////////////////////////
  205:  
  206:         /// <summary>
  207:         ///
  208:         /// </summary>
  209:         public static string HuaweiAccessNameFormatFromInaccurateHuaweiFileAndEmsNameFormat(string line)
  210:         {
  211:             // see: ConstructMduNameFromNddOntAccessName(string accessName)
  212:  
  213:             if (!Regex.IsMatch(line, @"^(\w{3})-(\d{3})-(\d{3})$") && !Regex.IsMatch(line, @"^(\w{3})-([1-9]\d{3})-(\d{3})$"))
  214:             {
  215:                 /*
  216:                 replace:
  217:                 and DEV not like 'MDU-___-01-____-___' 
  218:                 and DEV not like 'MDU-___-B4-___-___' 
  219:                 and DEV not like 'MDU-___-B4-____-___' 
  220:                 and DEV not like '___-B4-___-___' 
  221:                 and DEV not like '___-B4-____-___' 
  222:                 and DEV not like 'ONT-___-___-___' 
  223:                 and DEV not like 'MDU--___-____-___' 
  224:                 and DEV not like 'ONT-___-____-___' 
  225:                 and DEV not like '___-___-___V8R016C10S200'
  226:                 and DEV not like '___-____-___sHERIFARD'
  227:                 and DEV not like 'QSR1319-002'
  228:                  */
  229:  
  230:                 line = line.Replace("MDU--", ""); // must be before line.Replace("MDU-", "");
  231:                 line = line.Replace("MDU-", "");
  232:                 line = line.Replace("MDI-", "");
  233:                 line = line.Replace("B4-", "");
  234:                 line = line.Replace("-01-", "-");
  235:                 line = line.Replace("-4-", "-");
  236:                 line = line.Replace("ONT-", "");
  237:                 line = line.Replace("V8R016C10S200", "");
  238:                 line = line.Replace("sHERIFARD", "");
  239:                 line = line.Replace("QSR1319-002", "QSR-1319-002");
  240:  
  241:                 /*
  242:                 regex:
  243:                 and DEV not like '___.___._'
  244:                 and DEV not like 'MDU-___-0___-___' 
  245:                 and DEV not like 'MDU-___-___-___' 
  246:                 and DEV not like 'MDU-___-____-___' 
  247:                 and DEV not like '___-____-__'
  248:                 and DEV not like '___-__-___'
  249:                 and DEV not like '___-_-___'
  250:                 and DEV not like '___[_]___-___'
  251:                 and DEV not like '___ ____-___'
  252:                 and DEV not like '___0____-___'
  253:                  */
  254:  
  255:                 // below must be after line.Replace("MDU-", "");
  256:                 line = Regex.Replace(line, @"^(\w{3})\.(\d{3})\.(\d)$", "$1-$2-00$3");
  257:                 line = Regex.Replace(line, @"^(\w{3})-0(\d{3})-(\d{3})$", "$1-$2-$3");
  258:                 line = Regex.Replace(line, @"^(\w{3})-(\d{3})-(\d{3})$", "$1-$2-$3");
  259:                 line = Regex.Replace(line, @"^(\w{3})-(\d{4})-(\d{3})$", "$1-$2-$3");
  260:                 line = Regex.Replace(line, @"^(\w{3})-(\d{4})-(\d{2})$", "$1-$2-$3");
  261:                 line = Regex.Replace(line, @"^(\w{3})-(\d{2})-(\d{3})$", "$1-$2-$3");
  262:                 line = Regex.Replace(line, @"^(\w{3})_(\d{3})-(\d{3})$", "$1-$2-$3");
  263:                 line = Regex.Replace(line, @"^(\w{3})_(\d{3})-(\d{3})$", "$1-$2-$3");
  264:                 line = Regex.Replace(line, @"^(\w{3}) (\d{4})-(\d{3})$", "$1-$2-$3");
  265:                 line = Regex.Replace(line, @"^(\w{3})0(\d{4})-(\d{3})$", "$1-$2-$3");
  266:             }
  267:  
  268:             /*
  269:             no change
  270:             and DEV not like '___-___-___'
  271:             and DEV not like '___-____-___'
  272:              */
  273:  
  274:             return line;
  275:  
  276:             /*
  277:             // below do to all dev and alias in EMS
  278:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  279:             {
  280:                 var list = (from eo in db.EmsOnts select eo.ALIAS).ToList();
  281: 
  282:                 sb = new StringBuilder(list.Count * 50);
  283: 
  284:                 foreach (string l in list)
  285:                 {
  286:                     var v = Ia.Ftn.Cl.Model.Business.Huawei.Ems.HuaweiAccessNameFormatFromInaccurateHuaweiFileAndEmsNameFormat(l);
  287: 
  288:                     if(l != v) sb.AppendLine("[" + l + "]: [" + v + "]");
  289:                 }
  290: 
  291:                 filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\HuaweiAccessNameFormatFromInaccurateHuaweiFileAndEmsNameFormat.txt";
  292:                 File.WriteAllText(filePath, sb.ToString());
  293:             }
  294:              */
  295:         }
  296:  
  297:         ////////////////////////////////////////////////////////////////////////////
  298:  
  299:         /// <summary>
  300:         ///
  301:         /// </summary>
  302:         public static List<string> ConstructPossibleMduNameListFromNddOntAccessName(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
  303:         {
  304:             // see RemoveMduNameInHuaweiOntActivationReportSpecificNameFormat(string line)
  305:             List<string> possibleMduNameList;
  306:  
  307:             possibleMduNameList = new List<string>();
  308:  
  309:             // SAB-1443-001
  310:             possibleMduNameList.Add(nddOnt.Access.Symbol + "-" + nddOnt.Access.Pon.ToString().PadLeft(3, '0') + "-" + nddOnt.Access.Ont.ToString().PadLeft(3, '0'));
  311:  
  312:             // MDU-SAB-1443-001
  313:             possibleMduNameList.Add("MDU-" + nddOnt.Access.Symbol + "-" + nddOnt.Access.Pon.ToString().PadLeft(3, '0') + "-" + nddOnt.Access.Ont.ToString().PadLeft(3, '0'));
  314:  
  315:             if (nddOnt.Access.Name == "MGF.1306.1")
  316:             {
  317:                 // MDU-MGF-B4-1306-001
  318:                 possibleMduNameList.Add("MDU-MGF-B4-1306-001");
  319:             }
  320:             else if (nddOnt.Access.Name == "MGF.1522.4")
  321:             {
  322:                 // MGF-B4-1522-004
  323:                 possibleMduNameList.Add("MGF-B4-1522-004");
  324:             }
  325:             else if (nddOnt.Access.Name == "SAA.547.3")
  326:             {
  327:                 // ONT-SAA-547-003
  328:                 possibleMduNameList.Add("ONT-SAA-547-003");
  329:             }
  330:  
  331:             return possibleMduNameList;
  332:         }
  333:  
  334:         ////////////////////////////////////////////////////////////////////////////
  335:  
  336:         /// <summary>
  337:         ///
  338:         /// </summary>
  339:         public static string Semicolon
  340:         {
  341:             get
  342:             {
  343:                 return ";";
  344:             }
  345:         }
  346:  
  347:         ////////////////////////////////////////////////////////////////////////////
  348:  
  349:         /// <summary>
  350:         ///
  351:         /// </summary>
  352:         public static string EmsKeepAliveCommand
  353:         {
  354:             get
  355:             {
  356:                 return PrepareCtaggedCommand("SHAKEHAND:::{ctag}::;");
  357:             }
  358:         }
  359:  
  360:         ////////////////////////////////////////////////////////////////////////////
  361:  
  362:         /// <summary>
  363:         ///
  364:         /// </summary>
  365:         public static string ProperlySelectedSingleEmsCommandToManageOntNetworkElements
  366:         {
  367:             get
  368:             {
  369:                 string command;
  370:                 List<string> list;
  371:  
  372:                 command = EmsKeepAliveCommand;
  373:  
  374:                 if (emsCommandQueue.Count == 0)
  375:                 {
  376:                     olt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltList.NextOf(olt);
  377:  
  378:                     list = Ia.Ftn.Cl.Model.Business.Huawei.Ems.EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyType_EmsCommandsToRetrieveOntForOntsDefinedInNddDocument_EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(olt);
  379:  
  380:                     emsCommandQueue = new Queue<string>(list);
  381:                 }
  382:  
  383:                 if (emsCommandQueue.Count > 0) command = emsCommandQueue.Dequeue();
  384:  
  385:                 return command;
  386:             }
  387:         }
  388:  
  389:         ////////////////////////////////////////////////////////////////////////////
  390:  
  391:         /// <summary>
  392:         ///
  393:         /// </summary>
  394:         public static List<string> EmsCommandsToRetriveOntNetworkElementDataByAccessName(string input)
  395:         {
  396:             Ia.Cl.Models.Result result;
  397:             List<string> list;
  398:  
  399:             result = new Ia.Cl.Models.Result();
  400:             list = new List<string>(5);
  401:  
  402:             if (!string.IsNullOrEmpty(input))
  403:             {
  404:                 if (input.Length > 0)
  405:                 {
  406:                     input = input.Trim();
  407:                     input = input.ToUpper();
  408:  
  409:                     if (Ia.Ftn.Cl.Model.Business.Access.AccessNameIsInAValidFormat(input))
  410:                     {
  411:                         if (Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out string accessName))
  412:                         {
  413:                             list = Ia.Ftn.Cl.Model.Business.Huawei.Ems.EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevAndForItIfThisSingleOntDefinedInNddDocumentList(accessName);
  414:                         }
  415:                         else
  416:                         {
  417:                             result.AddError("EmsCommandsToRetriveOntNetworkElementDataByAccessName(): Error: accessName is not within allowed ONT list. ");
  418:                         }
  419:                     }
  420:                     else
  421:                     {
  422:                         result.AddError("EmsCommandsToRetriveOntNetworkElementDataByAccessName(): Error: accessName is not valid. ");
  423:                     }
  424:                 }
  425:                 else
  426:                 {
  427:                     result.AddError("EmsCommandsToRetriveOntNetworkElementDataByAccessName(): Error: accessName is empty. ");
  428:                 }
  429:             }
  430:             else
  431:             {
  432:                 result.AddError("EmsCommandsToRetriveOntNetworkElementDataByAccessName(): Error: accessName is null or empty. ");
  433:             }
  434:  
  435:             if (list.Count == 0) list.Add(EmsKeepAliveCommand);
  436:  
  437:             return list;
  438:         }
  439:  
  440:         ////////////////////////////////////////////////////////////////////////////
  441:  
  442:         /// <summary>
  443:         ///
  444:         /// </summary>
  445:         public static List<string> EmsCommandsToRetriveOntNetworkElementDataByService(string service)
  446:         {
  447:             Ia.Cl.Models.Result result;
  448:             List<string> list;
  449:  
  450:             result = new Ia.Cl.Models.Result();
  451:             list = new List<string>(5);
  452:  
  453:             if (!string.IsNullOrEmpty(service))
  454:             {
  455:                 service = service.Trim();
  456:                 service = service.ToUpper();
  457:  
  458:                 if (Ia.Ftn.Cl.Model.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  459:                 {
  460:                     list = Ia.Ftn.Cl.Model.Business.Huawei.Ems.EmsCommandsToRetrieveVoipPstnUser(service);
  461:                 }
  462:                 else
  463:                 {
  464:                     result.AddError("EmsCommandsToRetriveOntNetworkElementDataByService(): Error: Service number \"" + service + "\" does not belong to the network.");
  465:                 }
  466:             }
  467:             else
  468:             {
  469:                 result.AddError("EmsCommandsToRetriveOntNetworkElementDataByService(): Error: service is null or empty.");
  470:             }
  471:  
  472:             if (list.Count == 0) list.Add(EmsKeepAliveCommand);
  473:  
  474:             return list;
  475:         }
  476:  
  477:         ////////////////////////////////////////////////////////////////////////////
  478:         ////////////////////////////////////////////////////////////////////////////
  479:  
  480:         /// <summary>
  481:         ///
  482:         /// </summary>
  483:         public static string ReadDevListByDtCommand(string devType)
  484:         {
  485:             string command;
  486:  
  487:             command = FormatEmsDevLstCommand(EmsOpcode.LstDevByDt, devType);
  488:  
  489:             return command;
  490:         }
  491:  
  492:         ////////////////////////////////////////////////////////////////////////////
  493:  
  494:         /// <summary>
  495:         ///
  496:         /// </summary>
  497:         public static string ReadDevListByDevCommand(string dev)
  498:         {
  499:             string command;
  500:  
  501:             command = FormatEmsDevLstCommand(EmsOpcode.LstDevByDev, dev);
  502:  
  503:             return command;
  504:         }
  505:  
  506:         ////////////////////////////////////////////////////////////////////////////
  507:  
  508:         /// <summary>
  509:         ///
  510:         /// </summary>
  511:         public static string SaveDevCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev)
  512:         {
  513:             return FormatEmsDevLstCommand(EmsOpcode.SaveDev, mduDev.Dev);
  514:         }
  515:  
  516:         ////////////////////////////////////////////////////////////////////////////
  517:  
  518:         /// <summary>
  519:         ///
  520:         /// </summary>
  521:         public static string SaveDevCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MsanDev msanDev)
  522:         {
  523:             return FormatEmsDevLstCommand(EmsOpcode.SaveDev, msanDev.Dev);
  524:         }
  525:  
  526:         ////////////////////////////////////////////////////////////////////////////
  527:  
  528:         /// <summary>
  529:         ///
  530:         /// </summary>
  531:         public static string SaveDevCommand(string dev)
  532:         {
  533:             return FormatEmsDevLstCommand(EmsOpcode.SaveDev, dev);
  534:         }
  535:  
  536:         ////////////////////////////////////////////////////////////////////////////
  537:  
  538:         /// <summary>
  539:         ///
  540:         /// </summary>
  541:         public static string ReadBoardListCommand(string dev)
  542:         {
  543:             string command;
  544:  
  545:             command = FormatEmsBoardLstCommand(EmsOpcode.LstBoard, dev);
  546:  
  547:             return command;
  548:         }
  549:  
  550:         ////////////////////////////////////////////////////////////////////////////
  551:  
  552:         /// <summary>
  553:         ///
  554:         /// </summary>
  555:         public static string ReadOntListCommand(int did)
  556:         {
  557:             string command;
  558:  
  559:             command = FormatEmsLstCommand(EmsOpcode.LstOnt, did);
  560:  
  561:             return command;
  562:         }
  563:  
  564:         ////////////////////////////////////////////////////////////////////////////
  565:  
  566:         /// <summary>
  567:         ///
  568:         /// </summary>
  569:         public static string ReadOntCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
  570:         {
  571:             string command;
  572:  
  573:             command = FormatEmsLstCommand(EmsOpcode.LstOnt, ont);
  574:  
  575:             return command;
  576:         }
  577:  
  578:         ////////////////////////////////////////////////////////////////////////////
  579:  
  580:         /// <summary>
  581:         ///
  582:         /// </summary>
  583:         public static string UpdateOntFromH248ToSipCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
  584:         {
  585:             string command;
  586:  
  587:             command = FormatEmsModCommand(EmsOpcode.ModOntVaprofileAluSipB, ont);
  588:  
  589:             return command;
  590:         }
  591:  
  592:         ////////////////////////////////////////////////////////////////////////////
  593:  
  594:         /// <summary>
  595:         ///
  596:         /// </summary>
  597:         public static string ReadPortListCommand(string dev, int fn, int sn)
  598:         {
  599:             string command;
  600:  
  601:             command = FormatEmsPortLstCommand(EmsOpcode.LstPort, dev, fn, sn);
  602:  
  603:             return command;
  604:         }
  605:  
  606:         ////////////////////////////////////////////////////////////////////////////
  607:         ////////////////////////////////////////////////////////////////////////////
  608:  
  609:         /// <summary>
  610:         ///
  611:         /// </summary>
  612:         public static string CreateOrModifyOntSipInfoCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int telPort)
  613:         {
  614:             string command;
  615:  
  616:             command = FormatEmsCfgOntVainDivCommand(EmsOpcode.CfgOntVainDiv, nddOnt, service, telPort);
  617:  
  618:             return command;
  619:         }
  620:  
  621:         ////////////////////////////////////////////////////////////////////////////
  622:  
  623:         /// <summary>
  624:         ///
  625:         /// </summary>
  626:         public static string ReadOntSipInfoCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
  627:         {
  628:             string command;
  629:  
  630:             command = FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt);
  631:  
  632:             return command;
  633:         }
  634:  
  635:         ////////////////////////////////////////////////////////////////////////////
  636:  
  637:         /// <summary>
  638:         ///
  639:         /// </summary>
  640:         public static string ReadOntSipInfoCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string ctag)
  641:         {
  642:             string command;
  643:  
  644:             command = FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt, ctag);
  645:  
  646:             return command;
  647:         }
  648:  
  649:         ////////////////////////////////////////////////////////////////////////////
  650:  
  651:         /// <summary>
  652:         ///
  653:         /// </summary>
  654:         public static string VacateOntSipInfoCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int telPort)
  655:         {
  656:             string command;
  657:  
  658:             command = FormatEmsCfgOntVainDivCommand(EmsOpcode.CfgOntVainDivVacant, nddOnt, service, telPort);
  659:  
  660:             return command;
  661:         }
  662:  
  663:         ////////////////////////////////////////////////////////////////////////////
  664:  
  665:         /// <summary>
  666:         ///
  667:         /// </summary>
  668:         public static string ResetOntCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
  669:         {
  670:             var command = FormatEmsResetCommand(EmsOpcode.ResetOnt, nddOnt);
  671:  
  672:             return command;
  673:         }
  674:  
  675:         ////////////////////////////////////////////////////////////////////////////
  676:  
  677:         /// <summary>
  678:         ///
  679:         /// </summary>
  680:         public static string CreateOrModifyVoipPstnUserCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int sn, int port)
  681:         {
  682:             string command;
  683:  
  684:             if (nddOnt != null)
  685:             {
  686:                 command = FormatEmsVoipPstnUserCommand(EmsOpcode.AddVoipPstnUser, mduDev.Dev, nddOnt.Rack, sn, port, service);
  687:             }
  688:             else command = string.Empty;
  689:  
  690:             return command;
  691:         }
  692:  
  693:         ////////////////////////////////////////////////////////////////////////////
  694:  
  695:         /// <summary>
  696:         ///
  697:         /// </summary>
  698:         public static string CreateOrModifyMsanVoipPstnUserCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MsanDev msanDev, int fn, int sn, int pn, string service)
  699:         {
  700:             string command;
  701:  
  702:             if (msanDev != null)
  703:             {
  704:                 command = FormatEmsVoipPstnUserCommand(EmsOpcode.AddMsanVoipPstnUser, msanDev.Dev, fn, sn, pn, service);
  705:             }
  706:             else command = string.Empty;
  707:  
  708:             return command;
  709:         }
  710:  
  711:         ////////////////////////////////////////////////////////////////////////////
  712:  
  713:         /// <summary>
  714:         ///
  715:         /// </summary>
  716:         public static string ReadVoipPstnUserCommand(string dev, int sn, int pn)
  717:         {
  718:             var command = FormatEmsLstVoipPstnUserCommand(EmsOpcode.LstVoipPstnUser, dev, sn, pn);
  719:  
  720:             return command;
  721:         }
  722:  
  723:         ////////////////////////////////////////////////////////////////////////////
  724:  
  725:         /// <summary>
  726:         ///
  727:         /// </summary>
  728:         public static string DeleteVoipPstnUserCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int sn, int telPort)
  729:         {
  730:             string command;
  731:  
  732:             if (nddOnt != null)
  733:             {
  734:                 command = FormatEmsVoipPstnUserCommand(EmsOpcode.DelVoipPstnUser, mduDev.Dev, nddOnt.Rack, sn, telPort, service);
  735:             }
  736:             else command = string.Empty;
  737:  
  738:             return command;
  739:         }
  740:  
  741:         ////////////////////////////////////////////////////////////////////////////
  742:  
  743:         /// <summary>
  744:         ///
  745:         /// </summary>
  746:         public static string DeleteVoipPstnUserCommand(string dev, int fn, int sn, int pn)
  747:         {
  748:             return FormatEmsVoipPstnUserCommand(EmsOpcode.DelVoipPstnUser, dev, fn, sn, pn, string.Empty);
  749:         }
  750:  
  751:         ////////////////////////////////////////////////////////////////////////////
  752:  
  753:         /// <summary>
  754:         ///
  755:         /// </summary>
  756:         public static string CreateOrModifyVoipPstnAccountCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int sn, int telPort)
  757:         {
  758:             var command = FormatEmsCfgVoipPstnAccountCommand(EmsOpcode.CfgVoipPstnAccount, mduDev.Dev, nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor, nddOnt.Rack, service, sn, telPort);
  759:  
  760:             return command;
  761:         }
  762:  
  763:         ////////////////////////////////////////////////////////////////////////////
  764:  
  765:         /// <summary>
  766:         ///
  767:         /// </summary>
  768:         public static string ReadVoipPstnAccountCommand(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
  769:         {
  770:             string command;
  771:  
  772:             command = null; // FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt);
  773:  
  774:             return command;
  775:         }
  776:  
  777:         ////////////////////////////////////////////////////////////////////////////
  778:  
  779:         /// <summary>
  780:         ///
  781:         /// </summary>
  782:         public static string VacateVoipPstnAccountCommand(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, string service, int sn, int telPort)
  783:         {
  784:             var command = FormatEmsCfgVoipPstnAccountCommand(EmsOpcode.CfgVoipPstnAccountVacant, mduDev.Dev, nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor, nddOnt.Rack, service, sn, telPort);
  785:  
  786:             return command;
  787:         }
  788:  
  789:         ////////////////////////////////////////////////////////////////////////////
  790:  
  791:         /// <summary>
  792:         ///
  793:         /// </summary>
  794:         public static string VacateVoipPstnAccountCommand(string dev, int fn, int sn, int pn)
  795:         {
  796:             var command = FormatEmsCfgVoipPstnAccountCommand(EmsOpcode.CfgVoipPstnAccountVacant, dev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined, fn, string.Empty, sn, pn);
  797:  
  798:             return command;
  799:         }
  800:  
  801:         ////////////////////////////////////////////////////////////////////////////
  802:         ////////////////////////////////////////////////////////////////////////////
  803:  
  804:         /// <summary>
  805:         ///
  806:         /// </summary>
  807:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, int did)
  808:         {
  809:             return FormatEmsLstCommand(amsOpcode, 0, did, null, string.Empty);
  810:         }
  811:  
  812:         /*
  813:         ////////////////////////////////////////////////////////////////////////////
  814: 
  815:         /// <summary>
  816:         ///
  817:         /// </summary>
  818:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon pon)
  819:         {
  820:             return FormatEmsLstCommand(amsOpcode, 0, 0, pon, null, string.Empty);
  821:         }
  822:         */
  823:  
  824:         ////////////////////////////////////////////////////////////////////////////
  825:  
  826:         /// <summary>
  827:         ///
  828:         /// </summary>
  829:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
  830:         {
  831:             return FormatEmsLstCommand(amsOpcode, 0, 0, ont, string.Empty);
  832:         }
  833:  
  834:         ////////////////////////////////////////////////////////////////////////////
  835:  
  836:         /// <summary>
  837:         ///
  838:         /// </summary>
  839:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont, string ctag)
  840:         {
  841:             return FormatEmsLstCommand(amsOpcode, 0, 0, ont, ctag);
  842:         }
  843:  
  844:         ////////////////////////////////////////////////////////////////////////////
  845:  
  846:         /// <summary>
  847:         ///
  848:         /// </summary>
  849:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont, int telPort)
  850:         {
  851:             return FormatEmsLstCommand(amsOpcode, telPort, 0, ont, string.Empty);
  852:         }
  853:  
  854:         ////////////////////////////////////////////////////////////////////////////
  855:  
  856:         /// <summary>
  857:         ///
  858:         /// </summary>
  859:         private static string FormatEmsLstCommand(EmsOpcode amsOpcode, int telPort, int did, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont, string ctag)
  860:         {
  861:             int sn, pn, ontId;
  862:             string command;
  863:  
  864:             if (amsOpcode == EmsOpcode.LstOnt)
  865:             {
  866:                 if (ont != null)
  867:                 {
  868:                     sn = ont.CardSlot;
  869:                     pn = ont.Port;
  870:                     ontId = ont.InternalNumber;
  871:  
  872:                     //command = "LST-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::;";
  873:                     command = "LST-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::SHOWOPTION=SERIALNUM VAPROF;";
  874:                     //command = "LST-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::SHOWOPTION=SERIALNUM PWD LOID CHECKCODE ALMPROF DEV VLAN PRI IP MASK GATE ROUTEIP ROUTEMASK NEXTHOP SNMPPROF OPTALMPROF VAPROF MACLEARN SRVLEVELPROF HARDWAREVERSION LSTUPTIME LSTDOWNTIME DEVCURRENTTIME VASPROFILESET;";
  875:                 }
  876:                 /*
  877:                 else if (pon != null)
  878:                 {
  879:                     sn = pon.CardSlot;
  880:                     pn = pon.Port;
  881: 
  882:                     command = "LST-ONT::DEV=" + pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ":{ctag}::;";
  883:                 }
  884:                 */
  885:                 else if (did > 0)
  886:                 {
  887:                     command = "LST-ONT::DID=" + did + ":{ctag}::;";
  888:                 }
  889:                 else
  890:                 {
  891:                     command = string.Empty;
  892:                 }
  893:             }
  894:             else if (amsOpcode == EmsOpcode.LstOntSipInfo)
  895:             {
  896:                 if (ont != null)
  897:                 {
  898:                     sn = ont.CardSlot;
  899:                     pn = ont.Port;
  900:                     ontId = ont.InternalNumber;
  901:  
  902:                     command = "LST-ONTSIPINFO::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::;";
  903:                 }
  904:                 /*
  905:                 else if (pon != null)
  906:                 {
  907:                     sn = pon.CardSlot;
  908:                     pn = pon.Port;
  909: 
  910:                     command = "LST-ONTSIPINFO::DEV=" + pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ":{ctag}::;";
  911:                 }
  912:                 */
  913:                 else
  914:                 {
  915:                     command = string.Empty;
  916:                 }
  917:             }
  918:             else if (amsOpcode == EmsOpcode.LstVag)
  919:             {
  920:                 if (did > 0)
  921:                 {
  922:                     command = "LST-VAG::DID=" + did + ",VAGID=0:{ctag}::;";
  923:                 }
  924:                 else
  925:                 {
  926:                     command = string.Empty;
  927:                 }
  928:             }
  929:             else
  930:             {
  931:                 command = string.Empty;
  932:             }
  933:  
  934:             var preparedCtaggedCommand = (string.IsNullOrEmpty(ctag)) ? PrepareCtaggedCommand(command) : PrepareCtaggedCommand(command, ctag);
  935:  
  936:             return preparedCtaggedCommand;
  937:         }
  938:  
  939:         ////////////////////////////////////////////////////////////////////////////
  940:  
  941:         /// <summary>
  942:         ///
  943:         /// </summary>
  944:         private static string FormatEmsLstVoipPstnUserCommand(EmsOpcode amsOpcode, string dev, int sn, int pn)
  945:         {
  946:             return FormatEmsLstVoipPstnUserCommand(amsOpcode, dev, sn, pn, string.Empty);
  947:         }
  948:  
  949:         ////////////////////////////////////////////////////////////////////////////
  950:  
  951:         /// <summary>
  952:         ///
  953:         /// </summary>
  954:         private static string FormatEmsLstVoipPstnUserCommand(EmsOpcode amsOpcode, string service)
  955:         {
  956:             return FormatEmsLstVoipPstnUserCommand(amsOpcode, string.Empty, -1, -1, service);
  957:         }
  958:  
  959:         ////////////////////////////////////////////////////////////////////////////
  960:  
  961:         /// <summary>
  962:         ///
  963:         /// </summary>
  964:         private static string FormatEmsLstVoipPstnUserCommand(EmsOpcode amsOpcode, string dev, int sn, int pn, string service)
  965:         {
  966:             string command;
  967:  
  968:             if (amsOpcode == EmsOpcode.LstVoipPstnUser)
  969:             {
  970:                 if (!string.IsNullOrEmpty(service) && string.IsNullOrEmpty(dev))
  971:                 {
  972:                     // LST-VOIPPSTNUSER::DN=+96524805054:{ctag}::;  // OK MSAN
  973:                     // LST-VOIPPSTNUSER::DN=+96525650644:{ctag}::;  // OK MDU No matching port
  974:                     // LST-VOIPPSTNUSER::DN=96525650644:{ctag}::;  // OK MDU (no + prefix)
  975:                     // LST-VOIPPSTNUSER::DN=+96525442262:{ctag}::;  // OK, NO matching port
  976:  
  977:                     command = "LST-VOIPPSTNUSER::DN=" + service + ":{ctag}::;";
  978:                 }
  979:                 else
  980:                 {
  981:                     // sn = ont.CardSlot; you can not use ont.CardSlot for SN in Huawei MDUs
  982:                     // LST-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::;
  983:                     // LST-VOIPPSTNUSER::DEV=ARD_MSAN_Cabinet 1_Frame 0,FN=0,SN=2,PN=0:{ctag}::;
  984:  
  985:                     command = "LST-VOIPPSTNUSER::DEV=" + dev + ",FN=0,SN=" + sn + ",PN=" + pn + ":{ctag}::;";
  986:                 }
  987:             }
  988:             else
  989:             {
  990:                 command = string.Empty;
  991:             }
  992:  
  993:             return PrepareCtaggedCommand(command);
  994:         }
  995:  
  996:         ////////////////////////////////////////////////////////////////////////////
  997:  
  998:         /// <summary>
  999:         ///
 1000:         /// </summary>
 1001:         private static string FormatEmsDevLstCommand(EmsOpcode amsOpcode, string parameter)
 1002:         {
 1003:             int devTypeId;
 1004:             string command;
 1005:  
 1006:             if (amsOpcode == EmsOpcode.LstDevByDt)
 1007:             {
 1008:                 devTypeId = Ia.Ftn.Cl.Model.Data.Huawei.Dev.DevTypeToDevTypeIdDictionary[parameter];
 1009:  
 1010:                 if (devTypeId != 0)
 1011:                 {
 1012:                     command = "LST-DEV::DT=" + devTypeId + ":{ctag}::;";
 1013:                 }
 1014:                 else
 1015:                 {
 1016:                     command = string.Empty;
 1017:                 }
 1018:             }
 1019:             else if (amsOpcode == EmsOpcode.LstDevByDev)
 1020:             {
 1021:                 if (!string.IsNullOrEmpty(parameter))
 1022:                 {
 1023:                     command = "LST-DEV::DEV=" + parameter + ":{ctag}::;";
 1024:                 }
 1025:                 else
 1026:                 {
 1027:                     command = string.Empty;
 1028:                 }
 1029:             }
 1030:             else if (amsOpcode == EmsOpcode.LstDevByDevIp)
 1031:             {
 1032:                 if (!string.IsNullOrEmpty(parameter))
 1033:                 {
 1034:                     command = "LST-DEV::DEVIP=" + parameter + ":{ctag}::;";
 1035:                 }
 1036:                 else
 1037:                 {
 1038:                     command = string.Empty;
 1039:                 }
 1040:             }
 1041:             else if (amsOpcode == EmsOpcode.SaveDev)
 1042:             {
 1043:                 // after creating, modifing, or deleted a number in MDU we should save the configuration of device
 1044:                 if (!string.IsNullOrEmpty(parameter))
 1045:                 {
 1046:                     command = "SAVE-DEV::DEV=" + parameter + ":{ctag}::;";
 1047:                 }
 1048:                 else
 1049:                 {
 1050:                     command = string.Empty;
 1051:                 }
 1052:             }
 1053:             else
 1054:             {
 1055:                 command = string.Empty;
 1056:             }
 1057:  
 1058:             return PrepareCtaggedCommand(command);
 1059:         }
 1060:  
 1061:         ////////////////////////////////////////////////////////////////////////////
 1062:  
 1063:         /// <summary>
 1064:         ///
 1065:         /// </summary>
 1066:         public static bool IsASaveDevCommand(string command)
 1067:         {
 1068:             bool b;
 1069:  
 1070:             if (!string.IsNullOrEmpty(command))
 1071:             {
 1072:                 b = command.StartsWith("SAVE-DEV:");
 1073:             }
 1074:             else b = false;
 1075:  
 1076:             return b;
 1077:         }
 1078:  
 1079:         ////////////////////////////////////////////////////////////////////////////
 1080:  
 1081:         /// <summary>
 1082:         ///
 1083:         /// </summary>
 1084:         private static string FormatEmsBoardLstCommand(EmsOpcode amsOpcode, string dev)
 1085:         {
 1086:             int fn;
 1087:             string command;
 1088:  
 1089:             fn = 0;
 1090:  
 1091:             if (amsOpcode == EmsOpcode.LstBoard)
 1092:             {
 1093:                 if (!string.IsNullOrWhiteSpace(dev))
 1094:                 {
 1095:                     command = "LST-BOARD::DEV=" + dev + ",FN=" + fn + ":{ctag}::SHOWOPTION=BNAME;";
 1096:                 }
 1097:                 else
 1098:                 {
 1099:                     command = string.Empty;
 1100:                 }
 1101:             }
 1102:             else
 1103:             {
 1104:                 command = string.Empty;
 1105:             }
 1106:  
 1107:             return PrepareCtaggedCommand(command);
 1108:         }
 1109:  
 1110:         ////////////////////////////////////////////////////////////////////////////
 1111:  
 1112:         /// <summary>
 1113:         ///
 1114:         /// </summary>
 1115:         private static string FormatEmsPortLstCommand(EmsOpcode amsOpcode, string dev, int fn, int sn)
 1116:         {
 1117:             string command;
 1118:  
 1119:             if (amsOpcode == EmsOpcode.LstPort)
 1120:             {
 1121:                 if (!string.IsNullOrWhiteSpace(dev))
 1122:                 {
 1123:                     command = "LST-PORT::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ":{ctag}::;";
 1124:                 }
 1125:                 else
 1126:                 {
 1127:                     command = string.Empty;
 1128:                 }
 1129:             }
 1130:             else
 1131:             {
 1132:                 command = string.Empty;
 1133:             }
 1134:  
 1135:             return PrepareCtaggedCommand(command);
 1136:         }
 1137:  
 1138:         ////////////////////////////////////////////////////////////////////////////
 1139:  
 1140:         /// <summary>
 1141:         ///
 1142:         /// </summary>
 1143:         private static string FormatEmsModCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
 1144:         {
 1145:             int sn, pn, ontId;
 1146:             string command;
 1147:  
 1148:             if (ont != null)
 1149:             {
 1150:                 if (amsOpcode == EmsOpcode.ModOntAlias)
 1151:                 {
 1152:                     // MOD-ONT::DEV=OLT-JHB-SAA-01,FN=0,SN=1,PN=1,ONTID=20:{ctag}::ALIAS=SAA.502.20;
 1153:                     sn = ont.CardSlot;
 1154:                     pn = ont.Port;
 1155:                     ontId = ont.InternalNumber;
 1156:  
 1157:                     command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::ALIAS=" + ont.Access.Name + ";";
 1158:                 }
 1159:                 else if (amsOpcode == EmsOpcode.ModOntAliasAnnul)
 1160:                 {
 1161:                     // MOD-ONT::DEV=OLT-JHB-SAA-01,FN=0,SN=1,PN=1,ONTID=20:{ctag}::ALIAS=;
 1162:                     sn = ont.CardSlot;
 1163:                     pn = ont.Port;
 1164:                     ontId = ont.InternalNumber;
 1165:  
 1166:                     command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::ALIAS=;";
 1167:                 }
 1168:                 else if (amsOpcode == EmsOpcode.ModOntVaprofileAluSipB)
 1169:                 {
 1170:                     // MOD-ONT::DEV=OLT-ALU,FN=0,SN=1,PN=0,ONTID=2:{ctag}::VAPROFILE=ALU-SIP-B-MS;
 1171:                     sn = ont.CardSlot;
 1172:                     pn = ont.Port;
 1173:                     ontId = ont.InternalNumber;
 1174:  
 1175:                     command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::VAPROFILE=ALU-SIP-B-MS;";
 1176:                 }
 1177:                 else
 1178:                 {
 1179:                     command = string.Empty;
 1180:                 }
 1181:             }
 1182:             else
 1183:             {
 1184:                 command = string.Empty;
 1185:             }
 1186:  
 1187:             return PrepareCtaggedCommand(command);
 1188:         }
 1189:  
 1190:         ////////////////////////////////////////////////////////////////////////////
 1191:  
 1192:         /// <summary>
 1193:         ///
 1194:         /// </summary>
 1195:         private static string FormatEmsCfgOntVainDivCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont, string service, int telPort)
 1196:         {
 1197:             string command, aid, impiOrPrividUser, sipSubscriberRegistrationPassword, emsEmpty;
 1198:  
 1199:             /*
 1200: CFG-ONTVAINDIV::DEV=OLT_01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_2=+96524674071,SIPUSERPWD_2=admin,SIPNAME_2=+96524674071@ims.moc.kw:{ctag}::;
 1201: 
 1202:    7340032 2017-12-20 17:26:33
 1203: M  {ctag} COMPLD
 1204:    EN=0   ENDESC=Succeeded.
 1205: ;
 1206: CFG-ONTVAINDIV::DEV=OLT-QRN-FUN-01,FN=0,SN=1,PN=1,ONTID=20,SIPUSERNAME_2=+96524674071,SIPUSERPWD_2=admin,SIPNAME_2=+96524674071@ims.moc.kw:{ctag}::;
 1207: CFG-ONTVAINDIV::DEV=OLT-QRN-FUN-01,FN=0,SN=1,PN=1,ONTID=20,SIPUSERNAME_2=a2,SIPUSERPWD_2=admin,SIPNAME_2=a2@ims.moc.kw:{ctag}::;
 1208: CFG-ONTVAINDIV::DEV=OLT-QRN-FUN-01,FN=0,SN=1,PN=1,ONTID=20,SIPUSERNAME_3=a3,SIPUSERPWD_3=admin,SIPNAME_3=a2@ims.moc.kw:{ctag}::;
 1209: CFG-ONTVAINDIV::DEV=OLT-QRN-FUN-01,FN=0,SN=1,PN=1,ONTID=20,SIPUSERNAME_4=a4,SIPUSERPWD_4=admin,SIPNAME_4=a2@ims.moc.kw:{ctag}::;
 1210: 
 1211: CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_1=--,SIPUSERPWD_1=--,SIPNAME_1=--:{ctag}::;
 1212: CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_2=--,SIPUSERPWD_2=--,SIPNAME_2=--:{ctag}::;
 1213: CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_3=--,SIPUSERPWD_3=--,SIPNAME_3=--:{ctag}::;
 1214: CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_4=--,SIPUSERPWD_4=--,SIPNAME_4=--:{ctag}::;
 1215: */
 1216:  
 1217:             aid = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.ImpuAid(service); //"+965" + service
 1218:  
 1219:             // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
 1220:             if (ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 1221:             {
 1222:                 impiOrPrividUser = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Impi(service);
 1223:                 sipSubscriberRegistrationPassword = Ia.Ftn.Cl.Model.Business.Huawei.Ims.SipSubscriberRegistrationPassword;
 1224:             }
 1225:             else //if(ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 1226:             {
 1227:                 impiOrPrividUser = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
 1228:                 sipSubscriberRegistrationPassword = Ia.Ftn.Cl.Model.Business.Nokia.Ims.SipSubscriberRegistrationPassword;
 1229:             }
 1230:  
 1231:             if (ont != null)
 1232:             {
 1233:                 if (amsOpcode == EmsOpcode.CfgOntVainDiv)
 1234:                 {
 1235:                     command = @"CFG-ONTVAINDIV::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=" + ont.Rack + ",SN=" + ont.CardSlot + ",PN=" + ont.Port + ",ONTID=" + ont.InternalNumber + ",SIPUSERNAME_" + telPort + "=" + aid + ",SIPUSERPWD_" + telPort + "=" + sipSubscriberRegistrationPassword + ",SIPNAME_" + telPort + "=" + impiOrPrividUser + ":{ctag}::;";
 1236:                 }
 1237:                 else if (amsOpcode == EmsOpcode.CfgOntVainDivVacant)
 1238:                 {
 1239:                     emsEmpty = "--"; // this means vacant
 1240:                     // also SIPUSERPWD_n is "--"
 1241:                     command = @"CFG-ONTVAINDIV::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=" + ont.Rack + ",SN=" + ont.CardSlot + ",PN=" + ont.Port + ",ONTID=" + ont.InternalNumber + ",SIPUSERNAME_" + telPort + "=" + emsEmpty + ",SIPUSERPWD_" + telPort + "=" + emsEmpty + ",SIPNAME_" + telPort + "=" + emsEmpty + ":{ctag}::;";
 1242:                 }
 1243:                 else
 1244:                 {
 1245:                     command = string.Empty;
 1246:                 }
 1247:             }
 1248:             else
 1249:             {
 1250:                 command = string.Empty;
 1251:             }
 1252:  
 1253:             return PrepareCtaggedCommand(command);
 1254:         }
 1255:  
 1256:         ////////////////////////////////////////////////////////////////////////////
 1257:  
 1258:         /// <summary>
 1259:         ///
 1260:         /// </summary>
 1261:         private static string FormatEmsCfgVoipPstnAccountCommand(EmsOpcode amsOpcode, string dev, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor, int fn, string service, int sn, int pn)
 1262:         {
 1263:             string command, aid, impiOrPrividUser, sipSubscriberRegistrationPassword, emsEmpty;
 1264:  
 1265:             /*
 1266: CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName=priv_96524602285,Password=1234;
 1267: CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName=--,Password=--;
 1268: */
 1269:  
 1270:             if (amsOpcode == EmsOpcode.CfgVoipPstnAccount)
 1271:             {
 1272:                 aid = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.ImpuAid(service); //"+965" + service for reference only
 1273:  
 1274:                 // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
 1275:                 if (vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 1276:                 {
 1277:                     impiOrPrividUser = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Impi(service);
 1278:                     sipSubscriberRegistrationPassword = Ia.Ftn.Cl.Model.Business.Huawei.Ims.SipSubscriberRegistrationPassword;
 1279:                 }
 1280:                 else if (vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 1281:                 {
 1282:                     impiOrPrividUser = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
 1283:                     sipSubscriberRegistrationPassword = Ia.Ftn.Cl.Model.Business.Nokia.Ims.SipSubscriberRegistrationPassword;
 1284:                 }
 1285:                 else
 1286:                 {
 1287:                     throw new ArgumentOutOfRangeException("amsOpcode undefined");
 1288:                 }
 1289:  
 1290:                 // CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName= priv_96524602285,Password=1234;
 1291:                 command = @"CFG-VOIPPSTNACCOUNT::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ",PN=" + pn + ":{ctag}::BINDINDEX=0,UserName=" + impiOrPrividUser + ",Password=" + sipSubscriberRegistrationPassword + ";";
 1292:             }
 1293:             else if (amsOpcode == EmsOpcode.CfgVoipPstnAccountVacant)
 1294:             {
 1295:                 emsEmpty = "--"; // this means vacant
 1296:                                  // also UserName is "--"
 1297:                 command = @"CFG-VOIPPSTNACCOUNT::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ",PN=" + pn + ":{ctag}::BINDINDEX=0,UserName=" + emsEmpty + ",Password=" + emsEmpty + ";";
 1298:             }
 1299:             else command = string.Empty;
 1300:  
 1301:             return PrepareCtaggedCommand(command);
 1302:         }
 1303:  
 1304:         ////////////////////////////////////////////////////////////////////////////
 1305:  
 1306:         /// <summary>
 1307:         ///
 1308:         /// </summary>
 1309:         private static string FormatEmsVoipPstnUserCommand(EmsOpcode amsOpcode, string dev, int fn, int sn, int pn, string service)
 1310:         {
 1311:             string command;
 1312:  
 1313:             /*
 1314:             Add new SIP number on MDU:
 1315:             ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,DN=96524602285;
 1316: 
 1317:             Delete SIP number from MDU:
 1318:             DEL-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:7::;
 1319:             */
 1320:  
 1321:             if (amsOpcode == EmsOpcode.AddVoipPstnUser)
 1322:             {
 1323:                 var serviceWithCountryCode = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 1324:  
 1325:                 // ADD-VOIPPSTNUSER::DEV=MDU-MA5616-TEST-S,FN=0,SN=4,PN=1:{ctag}::MGID=0,DN=96524674072;
 1326:                 // ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,DN=96524602285;
 1327:                 command = @"ADD-VOIPPSTNUSER::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ",PN=" + pn + ":{ctag}::MGID=0,DN=" + serviceWithCountryCode + ";";
 1328:             }
 1329:             else if (amsOpcode == EmsOpcode.AddMsanVoipPstnUser)
 1330:             {
 1331:                 var dn = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.Aid(service);
 1332:  
 1333:                 // ADD-VOIPPSTNUSER::DEV=JHR_MSAN_Cabinet 0_Frame 0,FN=0,SN=3,PN=10:{ctag}::MGID=0,DN=+96524602285;
 1334:                 command = @"ADD-VOIPPSTNUSER::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ",PN=" + pn + ":{ctag}::MGID=0,DN=" + dn + ";";
 1335:             }
 1336:             else if (amsOpcode == EmsOpcode.DelVoipPstnUser)
 1337:             {
 1338:                 // DEL-VOIPPSTNUSER::DEV=MDU-MA5616-TEST-S,FN=0,SN=4,PN=1:7::;
 1339:                 // PN IS TELPORT for MDU
 1340:                 command = @"DEL-VOIPPSTNUSER::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ",PN=" + pn + ":{ctag}::;";
 1341:             }
 1342:             else
 1343:             {
 1344:                 command = string.Empty;
 1345:             }
 1346:  
 1347:             return PrepareCtaggedCommand(command);
 1348:         }
 1349:  
 1350:         ////////////////////////////////////////////////////////////////////////////
 1351:  
 1352:         /// <summary>
 1353:         ///
 1354:         /// </summary>
 1355:         private static string FormatEmsResetCommand(EmsOpcode amsOpcode, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
 1356:         {
 1357:             string command;
 1358:  
 1359:             /*
 1360:              * Reset ONT
 1361:              * RESET-ONT::DEV=OLT-KHP-KHP-A3-01,FN=0,SN=4,PN=1,ONTID=14:{ctag}::;
 1362:             */
 1363:  
 1364:             if (ont != null)
 1365:             {
 1366:                 if (amsOpcode == EmsOpcode.ResetOnt)
 1367:                 {
 1368:                     var sn = ont.CardSlot;
 1369:                     var pn = ont.Port;
 1370:                     var ontId = ont.InternalNumber;
 1371:  
 1372:                     command = "RESET-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::;";
 1373:                 }
 1374:                 else
 1375:                 {
 1376:                     command = string.Empty;
 1377:                 }
 1378:             }
 1379:             else
 1380:             {
 1381:                 command = string.Empty;
 1382:             }
 1383:  
 1384:             return PrepareCtaggedCommand(command);
 1385:         }
 1386:  
 1387:         ////////////////////////////////////////////////////////////////////////////
 1388:  
 1389:         /// <summary>
 1390:         /// Return a bool indicator as to weather the command is a CFG "slow" command
 1391:         /// </summary>
 1392:         public static bool IsACfgCommand(string command)
 1393:         {
 1394:             bool b;
 1395:             string s;
 1396:  
 1397:             if (!string.IsNullOrEmpty(command))
 1398:             {
 1399:                 s = command.ToLower();
 1400:                 b = s.Contains("cfg-ontvaindiv") || s.Contains("cfg-voippstnaccount");
 1401:             }
 1402:             else b = false;
 1403:  
 1404:             return b;
 1405:         }
 1406:  
 1407:         ////////////////////////////////////////////////////////////////////////////
 1408:  
 1409:         /// <summary>
 1410:         ///
 1411:         /// </summary>
 1412:         private static void EmsNameAndCardPortOntSquenceFromOntPosition(string ontPosition, out string amsName, out string pon)
 1413:         {
 1414:             Match match;
 1415:  
 1416:             if (!string.IsNullOrEmpty(ontPosition))
 1417:             {
 1418:                 // SUR-1-1-1-1-1;
 1419:                 match = Regex.Match(ontPosition, @"([a-zA-Z]{3}\-\d{1,2}\-\d{1,2})\-(\d{1,2}\-\d{1,2}\-\d{1,2})");
 1420:  
 1421:                 amsName = match.Groups[1].Value;
 1422:                 pon = match.Groups[2].Value;
 1423:             }
 1424:             else
 1425:             {
 1426:                 amsName = string.Empty;
 1427:                 pon = string.Empty;
 1428:             }
 1429:         }
 1430:  
 1431:         ////////////////////////////////////////////////////////////////////////////
 1432:  
 1433:         /// <summary>
 1434:         ///
 1435:         /// </summary>
 1436:         public static List<string> EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevAndForItIfThisSingleOntDefinedInNddDocumentList(string accessName)
 1437:         {
 1438:             List<string> list;
 1439:  
 1440:             list = EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevList(accessName);
 1441:  
 1442:             if (list.Count == 0) list = EmsCommandToRetrieveSingleOntDefinedInNddDocumentList(accessName);
 1443:  
 1444:             return list;
 1445:         }
 1446:  
 1447:         ////////////////////////////////////////////////////////////////////////////
 1448:  
 1449:         /// <summary>
 1450:         ///
 1451:         /// </summary>
 1452:         public static List<string> EmsCommandsToRetrieveVoipPstnUser(string service)
 1453:         {
 1454:             var list = EmsCommandsToRetrieveVoipPstnUserForMduAndMsan(service);
 1455:  
 1456:             return list;
 1457:         }
 1458:  
 1459:         ////////////////////////////////////////////////////////////////////////////
 1460:  
 1461:         /// <summary>
 1462:         ///
 1463:         /// </summary>
 1464:         private static List<string> EmsCommandsToRetrieveVoipPstnUserForMduAndMsan(string service)
 1465:         {
 1466:             List<string> list;
 1467:  
 1468:             list = new List<string>();
 1469:  
 1470:             if (!string.IsNullOrEmpty(service))
 1471:             {
 1472:                 // for MDUs numbers will look like 96524805054
 1473:                 // for MSAN numbers will look like +96524805054
 1474:  
 1475:                 var serviceWithCountryCode = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 1476:                 var impuAid = Ia.Ftn.Cl.Model.Business.NumberFormatConverter.ImpuAid(service);
 1477:  
 1478:                 list.Add(FormatEmsLstVoipPstnUserCommand(EmsOpcode.LstVoipPstnUser, serviceWithCountryCode));
 1479:                 list.Add(FormatEmsLstVoipPstnUserCommand(EmsOpcode.LstVoipPstnUser, impuAid));
 1480:             }
 1481:  
 1482:             return list;
 1483:         }
 1484:  
 1485:         ////////////////////////////////////////////////////////////////////////////
 1486:  
 1487:         /// <summary>
 1488:         ///
 1489:         /// </summary>
 1490:         public static List<string> EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyType_EmsCommandsToRetrieveOntForOntsDefinedInNddDocument_EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1491:         {
 1492:             HashSet<string> hashSet1, hashSet2, hashSet3, hashSet;
 1493:  
 1494:             //hashSet1 = new HashSet<string>(EmsCommandsToRetrieveOntForOntsDefinedInNddDocumentList(olt)); takes too long
 1495:             hashSet1 = new HashSet<string>(EmsCommandsToRetrieveOntForOntsWithAccessList(olt));
 1496:  
 1497:             hashSet2 = new HashSet<string>(EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyTypeList(olt));
 1498:  
 1499:             hashSet3 = new HashSet<string>(); // EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(olt);
 1500:  
 1501:             hashSet = new HashSet<string>(hashSet1);
 1502:             hashSet.UnionWith(hashSet2);
 1503:             hashSet.UnionWith(hashSet3);
 1504:  
 1505:             return hashSet.Shuffle().ToList();
 1506:         }
 1507:  
 1508:         ////////////////////////////////////////////////////////////////////////////
 1509:  
 1510:         /// <summary>
 1511:         ///
 1512:         /// </summary>
 1513:         public static List<string> EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1514:         {
 1515:             string accessName, ontId, ontAlias;
 1516:             List<string> list;
 1517:             Dictionary<string, string> ontAccessIdToOntAccessNameDictionary;
 1518:             Hashtable ontIdWithNullAccessHashtable;
 1519:             //Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType familyType;
 1520:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1521:             //List<Ia.Ftn.Cl.Model.Ont> ontList;
 1522:             Dictionary<string, string> ontIdToAliasForNonNullAccessDictionary;
 1523:             Dictionary<string, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont> ontIdToOntDictionary;
 1524:             list = null;
 1525:  
 1526:             ontAccessIdToOntAccessNameDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 1527:  
 1528:             ontIdToAliasForNonNullAccessDictionary = Ia.Ftn.Cl.Model.Data.Huawei.Ont.IdToAliasForNonNullAccessDictionary;
 1529:  
 1530:             ontIdWithNullAccessHashtable = Ia.Ftn.Cl.Model.Data.Huawei.Ont.IdWithNullAccessHashtable;
 1531:  
 1532:             ontIdToOntDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntIdToOntDictionary;
 1533:  
 1534:             using (var db = new Ia.Ftn.Cl.Model.Db())
 1535:             {
 1536:                 list = new List<string>();
 1537:  
 1538:                 //ontList = (from o in db.Onts where o.Access != null select o).ToList();
 1539:  
 1540:                 // insert descriptions for missing entries
 1541:                 if (ontIdToAliasForNonNullAccessDictionary.Count > 0)
 1542:                 {
 1543:                     foreach (KeyValuePair<string, string> kvp in ontIdToAliasForNonNullAccessDictionary) //Ia.Ftn.Cl.Model.Ont ont in ontList)
 1544:                     {
 1545:                         ontId = kvp.Key;
 1546:                         ontAlias = kvp.Value;
 1547:  
 1548:                         if (ontAccessIdToOntAccessNameDictionary.ContainsKey(ontId))
 1549:                         {
 1550:                             accessName = ontAccessIdToOntAccessNameDictionary[ontId];
 1551:  
 1552:                             if (ontAlias != accessName)
 1553:                             {
 1554:                                 // below: too slow needs to be changed
 1555:                                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntById(ontId);
 1556:  
 1557:                                 if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 1558:                                 {
 1559:                                     //familyType = (Ia.Ftn.Cl.Model.Business.Nokia.Ont.FamilyType)ont.FamilyTypeId;
 1560:  
 1561:                                     list.Add(Ia.Ftn.Cl.Model.Business.Huawei.Ems.FormatEmsModCommand(EmsOpcode.ModOntAlias, nddOnt));
 1562:                                 }
 1563:                             }
 1564:                             else
 1565:                             {
 1566:                             }
 1567:                         }
 1568:                     }
 1569:                 }
 1570:  
 1571:                 // delete descriptions ONTs with missing access info
 1572:                 if (ontIdWithNullAccessHashtable.Count > 0)
 1573:                 {
 1574:                     foreach (string _ontId in ontIdWithNullAccessHashtable.Keys)
 1575:                     {
 1576:                         if (ontIdToOntDictionary.ContainsKey(_ontId))
 1577:                         {
 1578:                             nddOnt = ontIdToOntDictionary[_ontId];
 1579:  
 1580:                             if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
 1581:                             {
 1582:                                 list.Add(Ia.Ftn.Cl.Model.Business.Huawei.Ems.FormatEmsModCommand(EmsOpcode.ModOntAliasAnnul, nddOnt));
 1583:                             }
 1584:                         }
 1585:                     }
 1586:                 }
 1587:             }
 1588:  
 1589:             return list.ToList();
 1590:         }
 1591:  
 1592:         ////////////////////////////////////////////////////////////////////////////
 1593:  
 1594:         /// <summary>
 1595:         ///
 1596:         /// </summary>
 1597:         private static List<string> EmsCommandToRetrieveSingleOntDefinedInNddDocumentList(string accessName)
 1598:         {
 1599:             List<string> list;
 1600:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1601:  
 1602:             list = new List<string>();
 1603:  
 1604:             if (!string.IsNullOrEmpty(accessName))
 1605:             {
 1606:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
 1607:  
 1608:                 if (nddOnt != null)
 1609:                 {
 1610:                     list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
 1611:                 }
 1612:             }
 1613:  
 1614:             return list;
 1615:         }
 1616:  
 1617:         ////////////////////////////////////////////////////////////////////////////
 1618:  
 1619:         /// <summary>
 1620:         ///
 1621:         /// </summary>
 1622:         private static List<string> EmsCommandsToRetrieveOntForOntsDefinedInNddDocumentList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1623:         {
 1624:             List<string> list;
 1625:  
 1626:             list = new List<string>();
 1627:  
 1628:             if (olt != null)
 1629:             {
 1630:                 foreach (Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PonGroup ponGroup in olt.PonGroupList)
 1631:                 {
 1632:                     foreach (Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon pon in ponGroup.PonList)
 1633:                     {
 1634:                         foreach (Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont in pon.OntList)
 1635:                         {
 1636:                             list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, ont));
 1637:                         }
 1638:                     }
 1639:                 }
 1640:             }
 1641:  
 1642:             return list;
 1643:         }
 1644:  
 1645:         ////////////////////////////////////////////////////////////////////////////
 1646:  
 1647:         /// <summary>
 1648:         ///
 1649:         /// </summary>
 1650:         private static List<string> EmsCommandsToRetrieveOntForOntsWithAccessList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1651:         {
 1652:             List<string> list;
 1653:             List<Ia.Ftn.Cl.Model.Access> accessList;
 1654:  
 1655:             list = new List<string>();
 1656:  
 1657:             if (olt != null)
 1658:             {
 1659:                 accessList = Ia.Ftn.Cl.Model.Data.Access.List(olt);
 1660:  
 1661:                 var ontAccessIdToOntDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
 1662:  
 1663:                 foreach (var access in accessList)
 1664:                 {
 1665:                     list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, ontAccessIdToOntDictionary[access.Id]));
 1666:  
 1667:                     list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, ontAccessIdToOntDictionary[access.Id]));
 1668:                 }
 1669:             }
 1670:  
 1671:             return list;
 1672:         }
 1673:  
 1674:         ////////////////////////////////////////////////////////////////////////////
 1675:  
 1676:         /// <summary>
 1677:         ///
 1678:         /// </summary>
 1679:         private static List<string> EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevList(string accessName)
 1680:         {
 1681:             Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mduDev;
 1682:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1683:             Ia.Ftn.Cl.Model.Huawei.EmsOnt ont;
 1684:             List<string> list, possibleMduNameList;
 1685:  
 1686:             list = new List<string>();
 1687:  
 1688:             if (!string.IsNullOrEmpty(accessName))
 1689:             {
 1690:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
 1691:  
 1692:                 if (nddOnt != null)
 1693:                 {
 1694:                     var accessNameToMduDevDictionary = Ia.Ftn.Cl.Model.Data.Huawei.Default.AccessNameToMduDevDictionary;
 1695:  
 1696:                     if (accessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
 1697:                     {
 1698:                         mduDev = accessNameToMduDevDictionary[nddOnt.Access.Name];
 1699:  
 1700:                         list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDev, mduDev.Dev));
 1701:  
 1702:                         list.Add(FormatEmsBoardLstCommand(EmsOpcode.LstBoard, mduDev.Dev));
 1703:  
 1704:                         list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
 1705:  
 1706:                         list.Add(FormatEmsLstCommand(EmsOpcode.LstVag, mduDev.Did));
 1707:  
 1708:                         foreach (var fsSnPn in mduDev.PossibleFnSnPnPortList)
 1709:                         {
 1710:                             list.Add(FormatEmsLstVoipPstnUserCommand(EmsOpcode.LstVoipPstnUser, mduDev.Dev, fsSnPn.Sn, fsSnPn.Pn));
 1711:                         }
 1712:                     }
 1713:                     else
 1714:                     {
 1715:                         ont = Ia.Ftn.Cl.Model.Data.Huawei.Ont.Read(nddOnt.Id);
 1716:  
 1717:                         if (ont != null)
 1718:                         {
 1719:                             if (ont.FamilyType == Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Mdu)
 1720:                             {
 1721:                                 possibleMduNameList = Ia.Ftn.Cl.Model.Business.Huawei.Ems.ConstructPossibleMduNameListFromNddOntAccessName(nddOnt);
 1722:  
 1723:                                 foreach (string s in possibleMduNameList)
 1724:                                 {
 1725:                                     list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDev, s));
 1726:  
 1727:                                     //list.Add(FormatEmsLstCommand(EmsOpcode.LstVag, mduDev.Did));
 1728:  
 1729:                                     list.Add(FormatEmsBoardLstCommand(EmsOpcode.LstBoard, s));
 1730:                                 }
 1731:  
 1732:                                 list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDevIp, ont.IP));
 1733:                                 // see EmsOnt with Name = 10.133.57.6, and select * from EmsOnts where EQUIPMENTID = '5878'
 1734:                             }
 1735:                             else
 1736:                             {
 1737:                                 list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
 1738:  
 1739:                                 list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt));
 1740:                             }
 1741:                         }
 1742:                     }
 1743:                 }
 1744:             }
 1745:  
 1746:             return list;
 1747:         }
 1748:  
 1749:         ////////////////////////////////////////////////////////////////////////////
 1750:  
 1751:         /// <summary>
 1752:         ///
 1753:         /// </summary>
 1754:         private static List<string> EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyTypeList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
 1755:         {
 1756:             int did;
 1757:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1758:             List<string> list;
 1759:             List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont> nddOntList;
 1760:             List<Ia.Ftn.Cl.Model.Huawei.EmsOnt> ontList;
 1761:  
 1762:             list = new List<string>();
 1763:  
 1764:             if (olt != null)
 1765:             {
 1766:                 did = olt.Did;
 1767:  
 1768:                 if (did != 0)
 1769:                 {
 1770:                     ontList = Ia.Ftn.Cl.Model.Data.Huawei.Ont.ListByDid(did);
 1771:                     nddOntList = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt == olt select o).ToList();
 1772:  
 1773:                     if (ontList != null && ontList.Count > 0 && nddOntList != null && nddOntList.Count > 0)
 1774:                     {
 1775:                         list = new List<string>(ontList.Count);
 1776:  
 1777:                         foreach (var ont in ontList)
 1778:                         {
 1779:                             if (ont.Access != null)
 1780:                             {
 1781:                                 nddOnt = (from o in nddOntList where o.Id == ont.Id select o).SingleOrDefault();
 1782:  
 1783:                                 if (nddOnt != null)
 1784:                                 {
 1785:                                     list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
 1786:  
 1787:                                     list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt));
 1788:                                 }
 1789:                                 else
 1790:                                 {
 1791:  
 1792:                                 }
 1793:                             }
 1794:                         }
 1795:                     }
 1796:                     else
 1797:                     {
 1798:  
 1799:                     }
 1800:                 }
 1801:                 else
 1802:                 {
 1803:  
 1804:                 }
 1805:             }
 1806:             else
 1807:             {
 1808:  
 1809:             }
 1810:  
 1811:             return list;
 1812:         }
 1813:  
 1814:         ////////////////////////////////////////////////////////////////////////////
 1815:  
 1816:         /// <summary>
 1817:         /// 
 1818:         /// </summary>
 1819:         public static List<Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort> PossibleFnSnPnForMduDevList(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mdu)
 1820:         {
 1821:             int count, port;
 1822:             List<Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort> list;
 1823:  
 1824:             list = new List<Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort>();
 1825:  
 1826:             if (mdu != null)
 1827:             {
 1828:                 port = 1;
 1829:  
 1830:                 /* 1 is the port starting point according to service request service position
 1831:                  * 
 1832:                  * All Nokia ONTs (SFUs and MDUs) start at port position 1
 1833:                  * Huawei ONTs (SFUs) start at port position 1, while Huawei MDUs start at port position 0
 1834:                  * All positions in the Customer Department database will start at position 1 (e.g. port 3 in a Huawei MDU is 4 in the Customer Department database)
 1835:                  */
 1836:  
 1837:                 foreach (var mduDevBoard in mdu.MduDevBoardList)
 1838:                 {
 1839:                     count = mduDevBoard.TelPortCount;
 1840:  
 1841:                     for (int pn = 0; pn < count; pn++)
 1842:                     {
 1843:                         list.Add(new Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort(mduDevBoard.Fn, mduDevBoard.Sn, pn, port++));
 1844:                     }
 1845:                 }
 1846:             }
 1847:  
 1848:             return list;
 1849:         }
 1850:  
 1851:         ////////////////////////////////////////////////////////////////////////////
 1852:  
 1853:         /// <summary>
 1854:         /// 
 1855:         /// </summary>
 1856:         public static Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort FirstFnSnPnForMduDevList(Ia.Ftn.Cl.Model.Business.Huawei.Dev.MduDev mdu)
 1857:         {
 1858:             return Ia.Ftn.Cl.Model.Business.Huawei.Ems.PossibleFnSnPnForMduDevList(mdu).First();
 1859:         }
 1860:  
 1861:         ////////////////////////////////////////////////////////////////////////////
 1862:         ////////////////////////////////////////////////////////////////////////////
 1863:  
 1864:         /// <summary>
 1865:         /// 
 1866:         /// </summary>
 1867:         public static List<Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort> PossibleFnSnPnForMsanDevList()
 1868:         {
 1869:             var list = new List<Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort>();
 1870:  
 1871:             foreach (var fn in Ia.Ftn.Cl.Model.Business.Huawei.Ems.PossibleFnForMsanDevList)
 1872:             {
 1873:                 foreach (var sn in Ia.Ftn.Cl.Model.Business.Huawei.Ems.PossibleSnForMsanDevList)
 1874:                 {
 1875:                     foreach (var pn in Ia.Ftn.Cl.Model.Business.Huawei.Ems.PossiblePnForMsanDevList)
 1876:                     {
 1877:                         list.Add(new Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort(fn, sn, pn, Ia.Ftn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown));
 1878:                     }
 1879:                 }
 1880:             }
 1881:  
 1882:             return list;
 1883:         }
 1884:  
 1885:         ////////////////////////////////////////////////////////////////////////////
 1886:  
 1887:         /// <summary>
 1888:         /// 
 1889:         /// </summary>
 1890:         public static Ia.Ftn.Cl.Model.Business.Huawei.Default.FnSnPnPort FirstFnSnPnForMsanDevList()
 1891:         {
 1892:             return Ia.Ftn.Cl.Model.Business.Huawei.Ems.PossibleFnSnPnForMsanDevList().First();
 1893:         }
 1894:  
 1895:         ////////////////////////////////////////////////////////////////////////////
 1896:  
 1897:         /// <summary>
 1898:         /// 
 1899:         /// </summary>
 1900:         public static List<int> PossibleFnForMsanDevList
 1901:         {
 1902:             get
 1903:             {
 1904:                 return new List<int>() { 0 };
 1905:             }
 1906:         }
 1907:  
 1908:         ////////////////////////////////////////////////////////////////////////////
 1909:  
 1910:         /// <summary>
 1911:         /// 
 1912:         /// </summary>
 1913:         public static List<int> PossibleSnForMsanDevList
 1914:         {
 1915:             get
 1916:             {
 1917:                 // these are there EmsDev.BT is PSTN
 1918:                 return new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18 };
 1919:             }
 1920:         }
 1921:  
 1922:         ////////////////////////////////////////////////////////////////////////////
 1923:  
 1924:         /// <summary>
 1925:         /// 
 1926:         /// </summary>
 1927:         public static List<int> PossiblePnForMsanDevList
 1928:         {
 1929:             get
 1930:             {
 1931:                 var list = new List<int>();
 1932:  
 1933:                 for (int pn = 0; pn <= 63; pn++) list.Add(pn);
 1934:  
 1935:                 return list;
 1936:             }
 1937:         }
 1938:  
 1939:         ////////////////////////////////////////////////////////////////////////////
 1940:         ////////////////////////////////////////////////////////////////////////////
 1941:  
 1942:         /*
 1943:         ////////////////////////////////////////////////////////////////////////////
 1944: 
 1945:         /// <summary>
 1946:         /// Return the ONT family type from the software version
 1947:         /// </summary>
 1948:         public static Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType FamilyType(string activeSoftware, string plannedSoftware)
 1949:         {
 1950:             Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType familyType;
 1951: 
 1952:             if (activeSoftware != null)
 1953:             {
 1954:                 if (activeSoftware == plannedSoftware)
 1955:                 {
 1956:                     if (activeSoftware.Contains("3FE508")) familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Sfu;
 1957:                     else if (activeSoftware.Contains("3FE511")) familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Soho;
 1958:                     else if (activeSoftware.Contains("3FE514")) familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Mdu;
 1959:                     else familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
 1960:                 }
 1961:                 else familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
 1962:             }
 1963:             else familyType = Ia.Ftn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
 1964: 
 1965:             return familyType;
 1966:         }
 1967:         */
 1968:  
 1969:         ////////////////////////////////////////////////////////////////////////////
 1970:  
 1971:         /// <summary>
 1972:         ///
 1973:         /// </summary>
 1974:         public static Ia.Cl.Models.Result UpdateDatabaseWithEmsCommandOutput(string rowData, ref Ia.Ftn.Cl.Model.Client.Huawei.Ems ems, out string systemIsBusyResponseCommand, out string ontLoadingCommandIsBeingExecutedNowResponseCommand)
 1975:         {
 1976:             string updatedService;
 1977:  
 1978:             var isProvisionEffectingUpdated = false;
 1979:             var isUpdated = false;
 1980:             var result = new Ia.Cl.Models.Result();
 1981:  
 1982:             updatedService = string.Empty;
 1983:  
 1984:             // below: remove all '\' characters from rowData and reset NULL comments to ""
 1985:             rowData = rowData.Replace(@"\", "");
 1986:             rowData = rowData.Replace(@"NULL", "");
 1987:  
 1988:             var response = Ia.Ftn.Cl.Model.Business.Huawei.Ems.ParseResponse(rowData);
 1989:  
 1990:             // don't use if (response.QueryCommand) because if resource did not exist it will set Query command to false
 1991:  
 1992:             if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LST-DEV:"))
 1993:             {
 1994:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Dev.Update(response, out result);
 1995:             }
 1996:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("SAVE-DEV:"))
 1997:             {
 1998:                 result.AddSuccess("SAVE-DEV (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 1999:             }
 2000:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LST-BOARD:"))
 2001:             {
 2002:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Board.Update(response, out result);
 2003:             }
 2004:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LST-PORT:"))
 2005:             {
 2006:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Port.Update(response, out result);
 2007:             }
 2008:  
 2009:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith(@"LST-ONT::DEV="))
 2010:             {
 2011:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Ont.Update(response, out result);
 2012:             }
 2013:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith(@"LST-ONT::DID="))
 2014:             {
 2015:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Ont.UpdateListWithDid(response, out result);
 2016:             }
 2017:  
 2018:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LST-ONTSIPINFO:"))
 2019:             {
 2020:                 isProvisionEffectingUpdated = Ia.Ftn.Cl.Model.Data.Huawei.OntSipInfo.Update(response, out updatedService, out result);
 2021:             }
 2022:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("CFG-ONTVAINDIV:"))
 2023:             {
 2024:                 result.AddSuccess("CFG-ONTVAINDIV (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2025:             }
 2026:  
 2027:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith(@"LST-VOIPPSTNUSER::DEV"))
 2028:             {
 2029:                 isProvisionEffectingUpdated = Ia.Ftn.Cl.Model.Data.Huawei.VoipPstnUser.Update(response, out result);
 2030:             }
 2031:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith(@"LST-VOIPPSTNUSER::DN"))
 2032:             {
 2033:                 isProvisionEffectingUpdated = Ia.Ftn.Cl.Model.Data.Huawei.VoipPstnUser.UpdateByDn(response, out updatedService, out result);
 2034:             }
 2035:  
 2036:  
 2037:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("ADD-VOIPPSTNUSER:"))
 2038:             {
 2039:                 result.AddSuccess("ADD-VOIPPSTNUSER (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2040:             }
 2041:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("DEL-VOIPPSTNUSER:"))
 2042:             {
 2043:                 result.AddSuccess("DEL-VOIPPSTNUSER (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2044:             }
 2045:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("CFG-VOIPPSTNACCOUNT:"))
 2046:             {
 2047:                 result.AddSuccess("CFG-VOIPPSTNACCOUNT (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2048:             }
 2049:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LST-VAG:"))
 2050:             {
 2051:                 isUpdated = Ia.Ftn.Cl.Model.Data.Huawei.Vag.Update(response, out result);
 2052:             }
 2053:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("MOD-ONT:"))
 2054:             {
 2055:                 result.AddSuccess("MOD-ONT (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2056:             }
 2057:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("RESET-ONT:"))
 2058:             {
 2059:                 result.AddSuccess("RESET-ONT (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2060:             }
 2061:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("SHAKEHAND:"))
 2062:             {
 2063:                 result.AddSuccess("SHAKEHAND (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2064:             }
 2065:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LOGIN:"))
 2066:             {
 2067:                 ems.IsLoggedIn = true;
 2068:  
 2069:                 result.AddSuccess("LOGIN (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2070:             }
 2071:             else if (response.CommandFromCorrelationTagDictionaryByCtag.StartsWith("LOGOUT:"))
 2072:             {
 2073:                 ems.IsLoggedIn = false;
 2074:  
 2075:                 result.AddSuccess("LOGOUT (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2076:             }
 2077:             else
 2078:             {
 2079:                 result.AddError("UpdateDatabaseWithEmsCommandOutput(): No designated opcode to process: (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString());
 2080:             }
 2081:  
 2082:             if (response.ResultCode == Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode.SystemIsBusy1 || response.ResultCode == Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode.SystemIsBusy2) systemIsBusyResponseCommand = Ia.Ftn.Cl.Model.Business.Huawei.Ems.PrepareCtaggedCommand(response.CommandFromCorrelationTagDictionaryByCtag);
 2083:             else systemIsBusyResponseCommand = string.Empty;
 2084:  
 2085:             if (response.ResultCode == Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode.OntLoadingCommandIsBeingExecutedNow) ontLoadingCommandIsBeingExecutedNowResponseCommand = Ia.Ftn.Cl.Model.Business.Huawei.Ems.PrepareCtaggedCommand(response.CommandFromCorrelationTagDictionaryByCtag);
 2086:             else ontLoadingCommandIsBeingExecutedNowResponseCommand = string.Empty;
 2087:  
 2088:             if (isProvisionEffectingUpdated)
 2089:             {
 2090:                 Ia.Ftn.Cl.Model.Data.Msmq.SecretaryApplication.Enqueue(Ia.Ftn.Cl.Model.Business.Msmq.Application.NceApplication, Ia.Ftn.Cl.Model.Business.Msmq.Process.Updated, updatedService);
 2091:             }
 2092:  
 2093:             return result;
 2094:         }
 2095:  
 2096:         ////////////////////////////////////////////////////////////////////////////
 2097:  
 2098:         /// <summary>
 2099:         /// Parse the NCE TL1 NBI response by approximatly following the "10.3 Response Format Description standard" in iManager NCE Unified Network Management System Guide.
 2100:         /// </summary>
 2101:         public static Response ParseResponse(string rowData)
 2102:         {
 2103:             bool attributeFirstGroupFlag;
 2104:             int blockTag, currentBlockCount, totalCount;
 2105:             long en;
 2106:             string header, responseIdentification, textBlock, endesc, terminator, quotedLine, result, title, attributeValueStringList, ctag, completionCode;
 2107:             DataTable dataTable;
 2108:             MatchCollection matchCollection;
 2109:             Ia.Ftn.Cl.Model.Business.Huawei.Ems.Response response;
 2110:             List<string> attributeList;
 2111:             List<List<string>> valueListList;
 2112:             Dictionary<string, string> attributeValueDictionary;
 2113:  
 2114:             blockTag = currentBlockCount = totalCount = 0;
 2115:  
 2116:             title = string.Empty;
 2117:             en = 0;
 2118:             endesc = string.Empty;
 2119:             ctag = string.Empty;
 2120:             completionCode = string.Empty;
 2121:  
 2122:             response = new Response();
 2123:  
 2124:             attributeList = new List<string>(100);
 2125:             valueListList = new List<List<string>>(100);
 2126:             attributeValueDictionary = new Dictionary<string, string>(100);
 2127:  
 2128:             // iManager_NCE_V200R014C60_TL1_NBI_User_Guide_13 document has header start with \r\n\n but there are issues with this I removed it
 2129:             matchCollection = Regex.Matches(rowData, @"(   \d+? \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)(\r\nM  [\S]+? [\w\d]+?)(\r\n   EN=.+?   ENDESC=.+?)(\r\n[;>])", RegexOptions.Singleline);
 2130:             //                                         header                                     response identification   text block                  terminator
 2131:  
 2132:             foreach (Match match in matchCollection)
 2133:             {
 2134:                 header = match.Groups[1].Value;
 2135:                 responseIdentification = match.Groups[2].Value;
 2136:                 textBlock = match.Groups[3].Value;
 2137:                 terminator = match.Groups[4].Value;
 2138:  
 2139:                 if (!string.IsNullOrEmpty(responseIdentification))
 2140:                 {
 2141:                     matchCollection = Regex.Matches(responseIdentification, @"^\r\nM  ([\S]+?) ([\w\d]+?)$", RegexOptions.Singleline);
 2142:  
 2143:                     foreach (Match match9 in matchCollection)
 2144:                     {
 2145:                         ctag = match9.Groups[1].Value;
 2146:                         completionCode = match9.Groups[2].Value;
 2147:  
 2148:                         if (!string.IsNullOrEmpty(textBlock))
 2149:                         {
 2150:                             matchCollection = Regex.Matches(textBlock, @"^\r\n   EN=(.+?)   ENDESC=(.+?)\r\n   (.+?\r\n)$", RegexOptions.Singleline); // if you do (.+?)$ you will not match the last \n
 2151:  
 2152:                             if (matchCollection.Count > 0)
 2153:                             {
 2154:                                 foreach (Match match2 in matchCollection)
 2155:                                 {
 2156:                                     en = long.Parse(match2.Groups[1].Value);
 2157:                                     endesc = match2.Groups[2].Value;
 2158:                                     quotedLine = match2.Groups[3].Value;
 2159:  
 2160:                                     if (!string.IsNullOrEmpty(quotedLine))
 2161:                                     {
 2162:                                         response.QueryCommand = true;
 2163:  
 2164:                                         matchCollection = Regex.Matches(quotedLine, @"^blktag=(.+?)\r\n   blkcount=(.+?)\r\n   blktotal=(.+?)\r\n(.+?\r\n)$", RegexOptions.Singleline); // if you do (.+?)$ you will not match the last \n
 2165:  
 2166:                                         foreach (Match match3 in matchCollection)
 2167:                                         {
 2168:                                             blockTag = int.Parse(match3.Groups[1].Value);
 2169:                                             currentBlockCount = int.Parse(match3.Groups[2].Value);
 2170:                                             totalCount = int.Parse(match3.Groups[3].Value);
 2171:  
 2172:                                             result = match3.Groups[4].Value;
 2173:  
 2174:                                             if (!string.IsNullOrEmpty(result))
 2175:                                             {
 2176:                                                 matchCollection = Regex.Matches(result, @"^\r\n(.+?)\r\n-*\r\n(.+?\r\n)-*(\r\n)+$", RegexOptions.Singleline);
 2177:  
 2178:                                                 foreach (Match match4 in matchCollection)
 2179:                                                 {
 2180:                                                     title = match4.Groups[1].Value;
 2181:  
 2182:                                                     attributeValueStringList = match4.Groups[2].Value;
 2183:  
 2184:                                                     if (!string.IsNullOrEmpty(attributeValueStringList))
 2185:                                                     {
 2186:                                                         matchCollection = Regex.Matches(attributeValueStringList, @"(.+?)\r\n", RegexOptions.Singleline);
 2187:  
 2188:                                                         attributeFirstGroupFlag = true;
 2189:  
 2190:                                                         foreach (Match match5 in matchCollection)
 2191:                                                         {
 2192:                                                             if (attributeFirstGroupFlag)
 2193:                                                             {
 2194:                                                                 attributeList = new List<string>(Regex.Split(match5.Groups[1].Value, @"\t"));
 2195:  
 2196:                                                                 attributeFirstGroupFlag = false;
 2197:                                                             }
 2198:                                                             else valueListList.Add(new List<string>(Regex.Split(match5.Groups[1].Value, @"\t")));
 2199:                                                         }
 2200:                                                     }
 2201:                                                 }
 2202:                                             }
 2203:                                         }
 2204:                                     }
 2205:                                     else
 2206:                                     {
 2207:                                         response.QueryCommand = false;
 2208:                                     }
 2209:                                 }
 2210:                             }
 2211:                             else
 2212:                             {
 2213:                                 matchCollection = Regex.Matches(textBlock, @"^\r\n   EN=(.+?)   ENDESC=(.+?)$", RegexOptions.Singleline); // if you do (.+?)$ you will not match the last \n
 2214:  
 2215:                                 foreach (Match match6 in matchCollection)
 2216:                                 {
 2217:                                     en = long.Parse(match6.Groups[1].Value);
 2218:                                     endesc = match6.Groups[2].Value;
 2219:                                 }
 2220:                             }
 2221:                         }
 2222:                     }
 2223:                 }
 2224:             }
 2225:  
 2226:             // build datatable
 2227:  
 2228:             dataTable = new DataTable();
 2229:             dataTable.Clear();
 2230:  
 2231:             if (attributeList.Count > 0)
 2232:             {
 2233:                 foreach (string attribute in attributeList) dataTable.Columns.Add(attribute);
 2234:  
 2235:                 if (valueListList.Count > 0)
 2236:                 {
 2237:                     if (attributeList.Count == valueListList[0].Count)
 2238:                     {
 2239:                         foreach (List<string> valuelist in valueListList)
 2240:                         {
 2241:                             dataTable.Rows.Add(valuelist.ToArray());
 2242:                         }
 2243:                     }
 2244:                     else
 2245:                     {
 2246:                         throw new Exception("ParseResponse(): attributeList.Count != valueListList[0].Count. attributeList: " + string.Join(",", attributeList) + "; valueListList: " + string.Join(",", valueListList));
 2247:                     }
 2248:                 }
 2249:             }
 2250:             else dataTable = null;
 2251:  
 2252:             response.BlockTag = blockTag;
 2253:             response.CurrentBlockCount = currentBlockCount;
 2254:             response.TotalCount = totalCount;
 2255:  
 2256:             if (System.Enum.IsDefined(typeof(Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode), en))
 2257:             {
 2258:                 response.ResultCode = (Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode)en;
 2259:             }
 2260:             else response.ResultCode = Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode.Unknown;
 2261:  
 2262:             response.Title = title;
 2263:             response.En = en;
 2264:             response.Endesc = endesc;
 2265:             response.Ctag = ctag;
 2266:             response.CompletionCode = completionCode;
 2267:             response.QueryDataTable = dataTable;
 2268:  
 2269:             return response;
 2270:         }
 2271:  
 2272:         ////////////////////////////////////////////////////////////////////////////    
 2273:         ////////////////////////////////////////////////////////////////////////////    
 2274:     }
 2275:  
 2276:     ////////////////////////////////////////////////////////////////////////////
 2277:     ////////////////////////////////////////////////////////////////////////////   
 2278: }