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