شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Ems

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

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