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

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