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