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