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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Ems

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

Access Management System (AMS) support class for Huawei's Next Generation Network (NGN) business model.

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