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

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), Integrated Applications - Kuwait. All Rights Reserved.
  19:      ///
  20:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  21:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  22:      ///
  23:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  24:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  25:      /// 
  26:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  27:      /// 
  28:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  29:      /// </remarks> 
  30:      public partial class Ems
  31:      {
  32:          private static Queue<string> emsCommandQueue = new Queue<string>();
  33:          private static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt;
  34:   
  35:          /// <summary/>
  36:          public enum EmsOpcode
  37:          {
  38:              LstDevByDt, LstDevByDev, LstDevByDevIp, LstBoard, LstPort, LstOnt, LstVag, ModOntAlias, ModOntAliasAnnul, ModOntVaprofileAluSipB, LstOntSipInfo, CfgOntVainDiv, CfgOntVainDivVacant, AddVoipPstnUser, LstVoipPstnUser, DelVoipPstnUser, CfgVoipPstnAccount, CfgVoipPstnAccountVacant
  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 (Ia.Ngn.Cl.Model.Business.Access.AccessNameIsInValidFormat(input))
 372:                      {
 373:                          if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 374:                          {
 375:                              list = Ia.Ngn.Cl.Model.Business.Huawei.Ems.EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevAndForItIfThisSingleOntDefinedInNddDocumentList(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);
 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 if (amsOpcode == EmsOpcode.LstVag)
 754:              {
 755:                  if (did > 0)
 756:                  {
 757:                      command = "LST-VAG::DID=" + did + ",VAGID=0:{ctag}::;";
 758:                  }
 759:                  else
 760:                  {
 761:                      command = string.Empty;
 762:                  }
 763:              }
 764:              else
 765:              {
 766:                  command = string.Empty;
 767:              }
 768:   
 769:              return PrepareCtaggedCommand(command);
 770:          }
 771:   
 772:          ////////////////////////////////////////////////////////////////////////////
 773:   
 774:          /// <summary>
 775:          ///
 776:          /// </summary>
 777:          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)
 778:          {
 779:              string command;
 780:   
 781:              if (amsOpcode == EmsOpcode.LstVoipPstnUser)
 782:              {
 783:                  if (ont != null) // && telPort != 0) telPort can be 0
 784:                  {
 785:                      //sn = ont.CardSlot; you can not use ont.CardSlot for SN in Huawei MDUs
 786:   
 787:                      // LST-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::;
 788:                      command = "LST-VOIPPSTNUSER::DEV=" + mduDev.Dev + ",FN=0,SN=" + sn + ",PN=" + telPort + ":{ctag}::;";
 789:                  }
 790:                  else
 791:                  {
 792:                      command = string.Empty;
 793:                  }
 794:              }
 795:              else
 796:              {
 797:                  command = string.Empty;
 798:              }
 799:   
 800:              return PrepareCtaggedCommand(command);
 801:          }
 802:   
 803:          ////////////////////////////////////////////////////////////////////////////
 804:   
 805:          /// <summary>
 806:          ///
 807:          /// </summary>
 808:          private static string FormatEmsDevLstCommand(EmsOpcode amsOpcode, string parameter)
 809:          {
 810:              int devTypeId;
 811:              string command;
 812:   
 813:              if (amsOpcode == EmsOpcode.LstDevByDt)
 814:              {
 815:                  devTypeId = Ia.Ngn.Cl.Model.Data.Huawei.Dev.DevTypeToDevTypeIdDictionary[parameter];
 816:   
 817:                  if (devTypeId != 0)
 818:                  {
 819:                      command = "LST-DEV::DT=" + devTypeId + ":{ctag}::;";
 820:                  }
 821:                  else
 822:                  {
 823:                      command = string.Empty;
 824:                  }
 825:              }
 826:              else if (amsOpcode == EmsOpcode.LstDevByDev)
 827:              {
 828:                  if (!string.IsNullOrEmpty(parameter))
 829:                  {
 830:                      command = "LST-DEV::DEV=" + parameter + ":{ctag}::;";
 831:                  }
 832:                  else
 833:                  {
 834:                      command = string.Empty;
 835:                  }
 836:              }
 837:              else if (amsOpcode == EmsOpcode.LstDevByDevIp)
 838:              {
 839:                  if (!string.IsNullOrEmpty(parameter))
 840:                  {
 841:                      command = "LST-DEV::DEVIP=" + parameter + ":{ctag}::;";
 842:                  }
 843:                  else
 844:                  {
 845:                      command = string.Empty;
 846:                  }
 847:              }
 848:              else
 849:              {
 850:                  command = string.Empty;
 851:              }
 852:   
 853:              return PrepareCtaggedCommand(command);
 854:          }
 855:   
 856:          ////////////////////////////////////////////////////////////////////////////
 857:   
 858:          /// <summary>
 859:          ///
 860:          /// </summary>
 861:          private static string FormatEmsBoardLstCommand(EmsOpcode amsOpcode, string dev)
 862:          {
 863:              int fn;
 864:              string command;
 865:   
 866:              fn = 0;
 867:   
 868:              if (amsOpcode == EmsOpcode.LstBoard)
 869:              {
 870:                  if (!string.IsNullOrWhiteSpace(dev))
 871:                  {
 872:                      command = "LST-BOARD::DEV=" + dev + ",FN=" + fn + ":{ctag}::;";
 873:                  }
 874:                  else
 875:                  {
 876:                      command = string.Empty;
 877:                  }
 878:              }
 879:              else
 880:              {
 881:                  command = string.Empty;
 882:              }
 883:   
 884:              return PrepareCtaggedCommand(command);
 885:          }
 886:   
 887:          ////////////////////////////////////////////////////////////////////////////
 888:   
 889:          /// <summary>
 890:          ///
 891:          /// </summary>
 892:          private static string FormatEmsPortLstCommand(EmsOpcode amsOpcode, string dev, int fn, int sn)
 893:          {
 894:              string command;
 895:   
 896:              if (amsOpcode == EmsOpcode.LstPort)
 897:              {
 898:                  if (!string.IsNullOrWhiteSpace(dev))
 899:                  {
 900:                      command = "LST-PORT::DEV=" + dev + ",FN=" + fn + ",SN=" + sn + ":{ctag}::;";
 901:                  }
 902:                  else
 903:                  {
 904:                      command = string.Empty;
 905:                  }
 906:              }
 907:              else
 908:              {
 909:                  command = string.Empty;
 910:              }
 911:   
 912:              return PrepareCtaggedCommand(command);
 913:          }
 914:   
 915:          ////////////////////////////////////////////////////////////////////////////
 916:   
 917:          /// <summary>
 918:          ///
 919:          /// </summary>
 920:          private static string FormatEmsModCommand(EmsOpcode amsOpcode, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont)
 921:          {
 922:              int sn, pn, ontId;
 923:              string command;
 924:   
 925:              if (ont != null)
 926:              {
 927:                  if (amsOpcode == EmsOpcode.ModOntAlias)
 928:                  {
 929:                      // MOD-ONT::DEV=OLT-JHB-SAA-01,FN=0,SN=1,PN=1,ONTID=20:{ctag}::ALIAS=SAA.502.20;
 930:                      sn = ont.CardSlot;
 931:                      pn = ont.Port;
 932:                      ontId = ont.InternalNumber;
 933:   
 934:                      command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::ALIAS=" + ont.Access.Name + ";";
 935:                  }
 936:                  else if (amsOpcode == EmsOpcode.ModOntAliasAnnul)
 937:                  {
 938:                      // MOD-ONT::DEV=OLT-JHB-SAA-01,FN=0,SN=1,PN=1,ONTID=20:{ctag}::ALIAS=;
 939:                      sn = ont.CardSlot;
 940:                      pn = ont.Port;
 941:                      ontId = ont.InternalNumber;
 942:   
 943:                      command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::ALIAS=;";
 944:                  }
 945:                  else if (amsOpcode == EmsOpcode.ModOntVaprofileAluSipB)
 946:                  {
 947:                      // MOD-ONT::DEV=OLT-ALU,FN=0,SN=1,PN=0,ONTID=2:{ctag}::VAPROFILE=ALU-SIP-B-MS;
 948:                      sn = ont.CardSlot;
 949:                      pn = ont.Port;
 950:                      ontId = ont.InternalNumber;
 951:   
 952:                      command = "MOD-ONT::DEV=" + ont.Pon.PonGroup.Olt.EmsName + ",FN=0,SN=" + sn + ",PN=" + pn + ",ONTID=" + ontId + ":{ctag}::VAPROFILE=ALU-SIP-B-MS;";
 953:                  }
 954:                  else
 955:                  {
 956:                      command = string.Empty;
 957:                  }
 958:              }
 959:              else
 960:              {
 961:                  command = string.Empty;
 962:              }
 963:   
 964:              return PrepareCtaggedCommand(command);
 965:          }
 966:   
 967:          ////////////////////////////////////////////////////////////////////////////
 968:   
 969:          /// <summary>
 970:          ///
 971:          /// </summary>
 972:          private static string FormatEmsCfgOntVainDivCommand(EmsOpcode amsOpcode, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont, string service, int telPort)
 973:          {
 974:              string command, aid, impiOrPrividUser, sipSubscriberRegistrationPassword, emsEmpty;
 975:   
 976:              /*
 977:  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}::;
 978:  
 979:     7340032 2017-12-20 17:26:33
 980:  M  {ctag} COMPLD
 981:     EN=0   ENDESC=Succeeded.
 982:  ;
 983:  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}::;
 984:  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}::;
 985:  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}::;
 986:  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}::;
 987:  
 988:  CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_1=--,SIPUSERPWD_1=--,SIPNAME_1=--:{ctag}::;
 989:  CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_2=--,SIPUSERPWD_2=--,SIPNAME_2=--:{ctag}::;
 990:  CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_3=--,SIPUSERPWD_3=--,SIPNAME_3=--:{ctag}::;
 991:  CFG-ONTVAINDIV::DEV=OLT-JHB-JBA-01,FN=0,SN=1,PN=0,ONTID=2,SIPUSERNAME_4=--,SIPUSERPWD_4=--,SIPNAME_4=--:{ctag}::;
 992:  */
 993:   
 994:              aid = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ImpuAid(service); //"+965" + service
 995:   
 996:              // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
 997:              if (ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 998:              {
 999:                  impiOrPrividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Impi(service);
1000:                  sipSubscriberRegistrationPassword = Ia.Ngn.Cl.Model.Business.Huawei.Ims.SipSubscriberRegistrationPassword;
1001:              }
1002:              else //if(ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
1003:              {
1004:                  impiOrPrividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
1005:                  sipSubscriberRegistrationPassword = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SipSubscriberRegistrationPassword;
1006:              }
1007:   
1008:              if (ont != null)
1009:              {
1010:                  if (amsOpcode == EmsOpcode.CfgOntVainDiv)
1011:                  {
1012:                      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}::;";
1013:                  }
1014:                  else if (amsOpcode == EmsOpcode.CfgOntVainDivVacant)
1015:                  {
1016:                      emsEmpty = "--"; // this means vacant
1017:                      // also SIPUSERPWD_n is "--"
1018:                      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}::;";
1019:                  }
1020:                  else
1021:                  {
1022:                      command = string.Empty;
1023:                  }
1024:              }
1025:              else
1026:              {
1027:                  command = string.Empty;
1028:              }
1029:   
1030:              return PrepareCtaggedCommand(command);
1031:          }
1032:   
1033:          ////////////////////////////////////////////////////////////////////////////
1034:   
1035:          /// <summary>
1036:          ///
1037:          /// </summary>
1038:          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)
1039:          {
1040:              string command, aid, impiOrPrividUser, sipSubscriberRegistrationPassword, emsEmpty;
1041:   
1042:              /*
1043:  CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName=priv_96524602285,Password=1234;
1044:  CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName=--,Password=--;
1045:  */
1046:   
1047:              aid = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ImpuAid(service); //"+965" + service
1048:   
1049:              // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
1050:              if (ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
1051:              {
1052:                  impiOrPrividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Impi(service);
1053:                  sipSubscriberRegistrationPassword = Ia.Ngn.Cl.Model.Business.Huawei.Ims.SipSubscriberRegistrationPassword;
1054:              }
1055:              else //if(ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
1056:              {
1057:                  impiOrPrividUser = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
1058:                  sipSubscriberRegistrationPassword = Ia.Ngn.Cl.Model.Business.Nokia.Ims.SipSubscriberRegistrationPassword;
1059:              }
1060:   
1061:              if (ont != null)
1062:              {
1063:                  if (amsOpcode == EmsOpcode.CfgVoipPstnAccount)
1064:                  {
1065:                      // CFG-VOIPPSTNACCOUNT::DEV= MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::BINDINDEX=0,UserName= priv_96524602285,Password=1234;
1066:                      command = @"CFG-VOIPPSTNACCOUNT::DEV=" + mduDev.Dev + ",FN=" + ont.Rack + ",SN=" + sn + ",PN=" + telPort + ":{ctag}::BINDINDEX=0,UserName=" + impiOrPrividUser + ",Password=" + sipSubscriberRegistrationPassword + ";";
1067:                  }
1068:                  else //if (amsOpcode == EmsOpcode.CfgVoipPstnAccountVacant)
1069:                  {
1070:                      emsEmpty = "--"; // this means vacant
1071:                                       // also UserName is "--"
1072:                      command = @"CFG-VOIPPSTNACCOUNT::DEV=" + mduDev.Dev + ",FN=" + ont.Rack + ",SN=" + sn + ",PN=" + telPort + ":{ctag}::BINDINDEX=0,UserName=" + emsEmpty + ",Password=" + emsEmpty + ";";
1073:                  }
1074:              }
1075:              else
1076:              {
1077:                  command = string.Empty;
1078:              }
1079:   
1080:              return PrepareCtaggedCommand(command);
1081:          }
1082:   
1083:          ////////////////////////////////////////////////////////////////////////////
1084:   
1085:          /// <summary>
1086:          ///
1087:          /// </summary>
1088:          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)
1089:          {
1090:              string command, serviceWithCountryCode;
1091:   
1092:              /*
1093:              Add new SIP number on MDU:
1094:              ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,DN=96524602285;
1095:  
1096:              Delete SIP number from MDU:
1097:              DEL-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:7::;
1098:              */
1099:   
1100:              serviceWithCountryCode = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode(service);
1101:   
1102:              if (ont != null)
1103:              {
1104:                  if (amsOpcode == EmsOpcode.AddVoipPstnUser)
1105:                  {
1106:                      // ADD-VOIPPSTNUSER::DEV=MDU-MA5616-TEST-S,FN=0,SN=4,PN=1:{ctag}::MGID=0,DN=96524674072;
1107:                      // ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,DN=96524602285;
1108:                      // PN IS TELPORT for MDU
1109:                      command = @"ADD-VOIPPSTNUSER::DEV=" + mduDev.Dev + ",FN=" + ont.Rack + ",SN=" + sn + ",PN=" + port + ":{ctag}::MGID=0,DN=" + serviceWithCountryCode + ";";
1110:                  }
1111:                  else if (amsOpcode == EmsOpcode.DelVoipPstnUser)
1112:                  {
1113:                      // DEL-VOIPPSTNUSER::DEV=MDU-MA5616-TEST-S,FN=0,SN=4,PN=1:7::;
1114:                      // PN IS TELPORT for MDU
1115:                      command = @"DEL-VOIPPSTNUSER::DEV=" + mduDev.Dev + ",FN=" + ont.Rack + ",SN=" + sn + ",PN=" + port + ":{ctag}::;";
1116:                  }
1117:                  else
1118:                  {
1119:                      command = string.Empty;
1120:                  }
1121:              }
1122:              else
1123:              {
1124:                  command = string.Empty;
1125:              }
1126:   
1127:              return PrepareCtaggedCommand(command);
1128:          }
1129:   
1130:          ////////////////////////////////////////////////////////////////////////////
1131:   
1132:          /// <summary>
1133:          /// Return a bool indicator as to weather the command is a CFG "slow" command
1134:          /// </summary>
1135:          public static bool IsACfgCommand(string command)
1136:          {
1137:              bool b;
1138:              string s;
1139:   
1140:              if (!string.IsNullOrEmpty(command))
1141:              {
1142:                  s = command.ToLower();
1143:                  b = s.Contains("cfg-ontvaindiv") || s.Contains("cfg-voippstnaccount");
1144:              }
1145:              else b = false;
1146:   
1147:              return b;
1148:          }
1149:   
1150:          ////////////////////////////////////////////////////////////////////////////
1151:   
1152:          /// <summary>
1153:          ///
1154:          /// </summary>
1155:          private static void EmsNameAndCardPortOntSquenceFromOntPosition(string ontPosition, out string amsName, out string pon)
1156:          {
1157:              Match match;
1158:   
1159:              if (!string.IsNullOrEmpty(ontPosition))
1160:              {
1161:                  // SUR-1-1-1-1-1;
1162:                  match = Regex.Match(ontPosition, @"([a-zA-Z]{3}\-\d{1,2}\-\d{1,2})\-(\d{1,2}\-\d{1,2}\-\d{1,2})");
1163:   
1164:                  amsName = match.Groups[1].Value;
1165:                  pon = match.Groups[2].Value;
1166:              }
1167:              else
1168:              {
1169:                  amsName = string.Empty;
1170:                  pon = string.Empty;
1171:              }
1172:          }
1173:   
1174:          ////////////////////////////////////////////////////////////////////////////
1175:   
1176:          /// <summary>
1177:          ///
1178:          /// </summary>
1179:          public static List<string> EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevAndForItIfThisSingleOntDefinedInNddDocumentList(string accessName)
1180:          {
1181:              List<string> l1, l2;
1182:              HashSet<string> list;
1183:   
1184:              l1 = EmsCommandToRetrieveSingleOntDefinedInNddDocumentList(accessName);
1185:   
1186:              l2 = EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevList(accessName);
1187:   
1188:              list = new HashSet<string>();
1189:   
1190:              foreach (var i in l1) list.Add(i);
1191:              foreach (var i in l2) list.Add(i);
1192:   
1193:              return list.ToList();
1194:          }
1195:   
1196:          ////////////////////////////////////////////////////////////////////////////
1197:   
1198:          /// <summary>
1199:          ///
1200:          /// </summary>
1201:          public static List<string> EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyType_EmsCommandsToRetrieveOntForOntsDefinedInNddDocument_EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
1202:          {
1203:              HashSet<string> hashSet1, hashSet2, hashSet3, hashSet;
1204:   
1205:              //hashSet1 = new HashSet<string>(EmsCommandsToRetrieveOntForOntsDefinedInNddDocumentList(olt)); takes too long
1206:              hashSet1 = new HashSet<string>(EmsCommandsToRetrieveOntForOntsWithAccessList(olt));
1207:   
1208:              hashSet2 = new HashSet<string>(EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyTypeList(olt));
1209:   
1210:              hashSet3 = new HashSet<string>(); // EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(olt);
1211:   
1212:              hashSet = new HashSet<string>(hashSet1);
1213:              hashSet.UnionWith(hashSet2);
1214:              hashSet.UnionWith(hashSet3);
1215:   
1216:              return hashSet.Shuffle().ToList();
1217:          }
1218:   
1219:          ////////////////////////////////////////////////////////////////////////////
1220:   
1221:          /// <summary>
1222:          ///
1223:          /// </summary>
1224:          public static List<string> EmsCommandsToUpdateAndRetrieveOntAliasWithItsAccessNameList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
1225:          {
1226:              string accessName, ontId, ontAlias;
1227:              List<string> list;
1228:              Dictionary<string, string> ontAccessIdToOntAccessNameDictionary;
1229:              Hashtable ontIdWithNullAccessHashtable;
1230:              //Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType familyType;
1231:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
1232:              //List<Ia.Ngn.Cl.Model.Ont> ontList;
1233:              Dictionary<string, string> ontIdToAliasForNonNullAccessDictionary;
1234:              Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> ontIdToOntDictionary;
1235:              list = null;
1236:   
1237:              ontAccessIdToOntAccessNameDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
1238:   
1239:              ontIdToAliasForNonNullAccessDictionary = Ia.Ngn.Cl.Model.Data.Huawei.Ont.IdToAliasForNonNullAccessDictionary;
1240:   
1241:              ontIdWithNullAccessHashtable = Ia.Ngn.Cl.Model.Data.Huawei.Ont.IdWithNullAccessHashtable;
1242:   
1243:              ontIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntIdToOntDictionary;
1244:   
1245:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1246:              {
1247:                  list = new List<string>();
1248:   
1249:                  //ontList = (from o in db.Onts where o.Access != null select o).ToList();
1250:   
1251:                  // insert descriptions for missing entries
1252:                  if (ontIdToAliasForNonNullAccessDictionary.Count > 0)
1253:                  {
1254:                      foreach (KeyValuePair<string, string> kvp in ontIdToAliasForNonNullAccessDictionary) //Ia.Ngn.Cl.Model.Ont ont in ontList)
1255:                      {
1256:                          ontId = kvp.Key;
1257:                          ontAlias = kvp.Value;
1258:   
1259:                          if (ontAccessIdToOntAccessNameDictionary.ContainsKey(ontId))
1260:                          {
1261:                              accessName = ontAccessIdToOntAccessNameDictionary[ontId];
1262:   
1263:                              if (ontAlias != accessName)
1264:                              {
1265:                                  // below: too slow needs to be changed
1266:                                  nddOnt = ontIdToOntDictionary[ontId]; // (from nddo in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where nddo.Id == ont.Id select nddo).SingleOrDefault();
1267:   
1268:                                  if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
1269:                                  {
1270:                                      //familyType = (Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType)ont.FamilyTypeId;
1271:   
1272:                                      list.Add(Ia.Ngn.Cl.Model.Business.Huawei.Ems.FormatEmsModCommand(EmsOpcode.ModOntAlias, nddOnt));
1273:                                  }
1274:                              }
1275:                              else
1276:                              {
1277:                              }
1278:                          }
1279:                      }
1280:                  }
1281:   
1282:                  // delete descriptions ONTs with missing access info
1283:                  if (ontIdWithNullAccessHashtable.Count > 0)
1284:                  {
1285:                      foreach (string _ontId in ontIdWithNullAccessHashtable.Keys)
1286:                      {
1287:                          if (ontIdToOntDictionary.ContainsKey(_ontId))
1288:                          {
1289:                              nddOnt = ontIdToOntDictionary[_ontId];
1290:   
1291:                              if (nddOnt.Pon.PonGroup.Olt.Id == olt.Id)
1292:                              {
1293:                                  list.Add(Ia.Ngn.Cl.Model.Business.Huawei.Ems.FormatEmsModCommand(EmsOpcode.ModOntAliasAnnul, nddOnt));
1294:                              }
1295:                          }
1296:                      }
1297:                  }
1298:              }
1299:   
1300:              return list.ToList();
1301:          }
1302:   
1303:          ////////////////////////////////////////////////////////////////////////////
1304:   
1305:          /// <summary>
1306:          ///
1307:          /// </summary>
1308:          private static List<string> EmsCommandToRetrieveSingleOntDefinedInNddDocumentList(string accessName)
1309:          {
1310:              List<string> list;
1311:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
1312:   
1313:              list = new List<string>();
1314:   
1315:              if (!string.IsNullOrEmpty(accessName))
1316:              {
1317:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
1318:   
1319:                  if (nddOnt != null)
1320:                  {
1321:                      list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
1322:                  }
1323:              }
1324:   
1325:              return list;
1326:          }
1327:   
1328:          ////////////////////////////////////////////////////////////////////////////
1329:   
1330:          /// <summary>
1331:          ///
1332:          /// </summary>
1333:          private static List<string> EmsCommandsToRetrieveOntForOntsDefinedInNddDocumentList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
1334:          {
1335:              List<string> list;
1336:   
1337:              list = new List<string>();
1338:   
1339:              if (olt != null)
1340:              {
1341:                  foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.PonGroup ponGroup in olt.PonGroupList)
1342:                  {
1343:                      foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon in ponGroup.PonList)
1344:                      {
1345:                          foreach (Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont in pon.OntList)
1346:                          {
1347:                              list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, ont));
1348:                          }
1349:                      }
1350:                  }
1351:              }
1352:   
1353:              return list;
1354:          }
1355:   
1356:          ////////////////////////////////////////////////////////////////////////////
1357:   
1358:          /// <summary>
1359:          ///
1360:          /// </summary>
1361:          private static List<string> EmsCommandsToRetrieveOntForOntsWithAccessList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
1362:          {
1363:              List<string> list;
1364:              List<Ia.Ngn.Cl.Model.Access> accessList;
1365:   
1366:              list = new List<string>();
1367:   
1368:              if (olt != null)
1369:              {
1370:                  accessList = Ia.Ngn.Cl.Model.Data.Access.List(olt);
1371:   
1372:                  var ontAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary;
1373:   
1374:                  foreach (var access in accessList)
1375:                  {
1376:                      list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, ontAccessIdToOntDictionary[access.Id]));
1377:   
1378:                      list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, ontAccessIdToOntDictionary[access.Id]));
1379:                  }
1380:              }
1381:   
1382:              return list;
1383:          }
1384:   
1385:          ////////////////////////////////////////////////////////////////////////////
1386:   
1387:          /// <summary>
1388:          ///
1389:          /// </summary>
1390:          private static List<string> EmsCommandsToRetrieveSfuOntAndOntSipInfoOrMduOntAndVoipPstnUserAndVagAndBoardForSingleOntsWithDefinedFamilyTypeOrDefinedMduDevList(string accessName)
1391:          {
1392:              Ia.Ngn.Cl.Model.Business.Huawei.Dev.MduDev mduDev;
1393:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
1394:              Ia.Ngn.Cl.Model.Huawei.EmsOnt ont;
1395:              List<string> list, possibleMduNameList;
1396:   
1397:              list = new List<string>();
1398:   
1399:              if (!string.IsNullOrEmpty(accessName))
1400:              {
1401:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
1402:   
1403:                  if (nddOnt != null)
1404:                  {
1405:                      if (Ia.Ngn.Cl.Model.Data.Huawei.Default.AccessNameToMduDevDictionary.ContainsKey(nddOnt.Access.Name))
1406:                      {
1407:                          mduDev = Ia.Ngn.Cl.Model.Data.Huawei.Default.AccessNameToMduDevDictionary[nddOnt.Access.Name];
1408:   
1409:                          list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDev, mduDev.Dev));
1410:   
1411:                          list.Add(FormatEmsBoardLstCommand(EmsOpcode.LstBoard, mduDev.Dev));
1412:   
1413:                          list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
1414:   
1415:                          list.Add(FormatEmsLstCommand(EmsOpcode.LstVag, mduDev.Did));
1416:   
1417:                          foreach (var fsSnPn in mduDev.PossibleFnSnPnList)
1418:                          {
1419:                              list.Add(FormatEmsLstVoipPstnUserCommand(EmsOpcode.LstVoipPstnUser, mduDev, nddOnt, fsSnPn.Sn, fsSnPn.Pn));
1420:                          }
1421:                      }
1422:                      else
1423:                      {
1424:                          ont = Ia.Ngn.Cl.Model.Data.Huawei.Ont.Read(nddOnt.Id);
1425:   
1426:                          if (ont != null)
1427:                          {
1428:                              if (ont.FamilyType == Ont.FamilyType.Mdu)
1429:                              {
1430:                                  possibleMduNameList = Ia.Ngn.Cl.Model.Business.Huawei.Ems.ConstructPossibleMduNameListFromNddOntAccessName(nddOnt);
1431:   
1432:                                  foreach (string s in possibleMduNameList)
1433:                                  {
1434:                                      list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDev, s));
1435:   
1436:                                      //list.Add(FormatEmsLstCommand(EmsOpcode.LstVag, mduDev.Did));
1437:   
1438:                                      list.Add(FormatEmsBoardLstCommand(EmsOpcode.LstBoard, s));
1439:                                  }
1440:   
1441:                                  list.Add(FormatEmsDevLstCommand(EmsOpcode.LstDevByDevIp, ont.IP));
1442:                                  // see EmsOnt with Name = 10.133.57.6, and select * from EmsOnts where EQUIPMENTID = '5878'
1443:                              }
1444:                              else
1445:                              {
1446:                                  list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
1447:   
1448:                                  list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt));
1449:                              }
1450:                          }
1451:                      }
1452:                  }
1453:              }
1454:   
1455:              return list;
1456:          }
1457:   
1458:          ////////////////////////////////////////////////////////////////////////////
1459:   
1460:          /// <summary>
1461:          ///
1462:          /// </summary>
1463:          private static List<string> EmsCommandsToRetrieveOntAndOntSipInfoWithDefinedFamilyTypeList(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt olt)
1464:          {
1465:              int did;
1466:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
1467:              List<string> list;
1468:              List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> nddOntList;
1469:              List<Ia.Ngn.Cl.Model.Huawei.EmsOnt> ontList;
1470:   
1471:              list = new List<string>();
1472:   
1473:              if (olt != null)
1474:              {
1475:                  did = olt.Did;
1476:   
1477:                  if (did != 0)
1478:                  {
1479:                      ontList = Ia.Ngn.Cl.Model.Data.Huawei.Ont.ListByDid(did);
1480:                      nddOntList = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt == olt select o).ToList();
1481:   
1482:                      if (ontList != null && ontList.Count > 0 && nddOntList != null && nddOntList.Count > 0)
1483:                      {
1484:                          list = new List<string>(ontList.Count);
1485:   
1486:                          foreach (Ia.Ngn.Cl.Model.Huawei.EmsOnt ont in ontList)
1487:                          {
1488:                              if (ont.Access != null)
1489:                              {
1490:                                  nddOnt = (from o in nddOntList where o.Id == ont.Id select o).SingleOrDefault();
1491:   
1492:                                  if (nddOnt != null)
1493:                                  {
1494:                                      list.Add(FormatEmsLstCommand(EmsOpcode.LstOnt, nddOnt));
1495:   
1496:                                      list.Add(FormatEmsLstCommand(EmsOpcode.LstOntSipInfo, nddOnt));
1497:                                  }
1498:                                  else
1499:                                  {
1500:   
1501:                                  }
1502:                              }
1503:                          }
1504:                      }
1505:                      else
1506:                      {
1507:   
1508:                      }
1509:                  }
1510:                  else
1511:                  {
1512:   
1513:                  }
1514:              }
1515:              else
1516:              {
1517:   
1518:              }
1519:   
1520:              return list;
1521:          }
1522:   
1523:          ////////////////////////////////////////////////////////////////////////////
1524:   
1525:          /// <summary>
1526:          /// 
1527:          /// </summary>
1528:          public static List<Ia.Ngn.Cl.Model.Business.Huawei.Default.FnSnPn> PossibleFnSnPnForMduDevList(Ia.Ngn.Cl.Model.Business.Huawei.Dev.MduDev mdu)
1529:          {
1530:              int count;
1531:              List<Ia.Ngn.Cl.Model.Business.Huawei.Default.FnSnPn> list;
1532:   
1533:              list = new List<Ia.Ngn.Cl.Model.Business.Huawei.Default.FnSnPn>();
1534:   
1535:              if (mdu != null)
1536:              {
1537:                  foreach (var mduDevBoard in mdu.MduDevBoardList)
1538:                  {
1539:                      count = mduDevBoard.TelPortCount;
1540:   
1541:                      for (int pn = 0; pn < count; pn++)
1542:                      {
1543:                          list.Add(new Ia.Ngn.Cl.Model.Business.Huawei.Default.FnSnPn(mduDevBoard.Fn, mduDevBoard.Sn, pn));
1544:                      }
1545:                  }
1546:              }
1547:   
1548:              return list;
1549:          }
1550:   
1551:          ////////////////////////////////////////////////////////////////////////////
1552:   
1553:          /// <summary>
1554:          /// 
1555:          /// </summary>
1556:          public static Ia.Ngn.Cl.Model.Business.Huawei.Default.FnSnPn FirstFnSnPnForMduDevList(Ia.Ngn.Cl.Model.Business.Huawei.Dev.MduDev mdu)
1557:          {
1558:              return Ia.Ngn.Cl.Model.Business.Huawei.Ems.PossibleFnSnPnForMduDevList(mdu).First();
1559:          }
1560:   
1561:          /*
1562:          ////////////////////////////////////////////////////////////////////////////
1563:  
1564:          /// <summary>
1565:          /// Return the ONT family type from the software version
1566:          /// </summary>
1567:          public static Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType FamilyType(string activeSoftware, string plannedSoftware)
1568:          {
1569:              Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType familyType;
1570:  
1571:              if (activeSoftware != null)
1572:              {
1573:                  if (activeSoftware == plannedSoftware)
1574:                  {
1575:                      if (activeSoftware.Contains("3FE508")) familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Sfu;
1576:                      else if (activeSoftware.Contains("3FE511")) familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Soho;
1577:                      else if (activeSoftware.Contains("3FE514")) familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Mdu;
1578:                      else familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
1579:                  }
1580:                  else familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
1581:              }
1582:              else familyType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType.Undefined;
1583:  
1584:              return familyType;
1585:          }
1586:          */
1587:   
1588:          ////////////////////////////////////////////////////////////////////////////
1589:   
1590:          /// <summary>
1591:          ///
1592:          /// </summary>
1593:          public static bool UpdateDatabaseWithEmsCommandOutput(string rowData, ref Ia.Ngn.Cl.Model.Client.Huawei.Ems ems, out Ia.Cl.Model.Result result)
1594:          {
1595:              bool b;
1596:              Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response;
1597:   
1598:              b = false;
1599:              result = new Ia.Cl.Model.Result();
1600:   
1601:              // below: remove all '\' characters from rowData and reset NULL comments to ""
1602:              rowData = rowData.Replace(@"\", "");
1603:              rowData = rowData.Replace(@"NULL", "");
1604:   
1605:              response = Ia.Ngn.Cl.Model.Business.Huawei.Ems.ParseResponse(rowData);
1606:   
1607:              // don't use if (response.QueryCommand) because if resource did not exist it will set Query command to false
1608:   
1609:              if (response.CompletionCode == "COMPLD")
1610:              {
1611:                  if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-DEV:"))
1612:                  {
1613:                      if (response.QueryDataTable != null)
1614:                      {
1615:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Dev.Update(response, out result);
1616:                      }
1617:                      else result.AddWarning("LST-DEV: QueryDataTable is null, Endesc: " + response.Endesc);
1618:                  }
1619:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-BOARD:"))
1620:                  {
1621:                      if (response.QueryDataTable != null)
1622:                      {
1623:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Board.Update(response, out result);
1624:                      }
1625:                      else result.AddWarning("LST-BOARD: QueryDataTable is null, Endesc: " + response.Endesc);
1626:                  }
1627:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-PORT:"))
1628:                  {
1629:                      if (response.QueryDataTable != null)
1630:                      {
1631:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Port.Update(response, out result);
1632:                      }
1633:                      else result.AddWarning("LST-PORT: QueryDataTable is null, Endesc: " + response.Endesc);
1634:                  }
1635:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-ONT:"))
1636:                  {
1637:                      if (Regex.IsMatch(response.CommandFromCorrelationTagDictionaryByCtag, @"LST-ONT::DEV=(.+?),FN=(\d+),SN=(\d+),PN=(\d+),ONTID=(\d+):"))
1638:                      {
1639:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Ont.Update(response, out result);
1640:                      }
1641:                      else if (Regex.IsMatch(response.CommandFromCorrelationTagDictionaryByCtag, @"LST-ONT::DEV=(.+?),FN=(\d+),SN=(\d+),PN=(\d+):"))
1642:                      {
1643:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Ont.UpdateList(response, out result);
1644:                      }
1645:                      else if (Regex.IsMatch(response.CommandFromCorrelationTagDictionaryByCtag, @"LST-ONT::DID=(\d+):"))
1646:                      {
1647:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Ont.UpdateListWithDid(response, out result);
1648:                      }
1649:                      else
1650:                      {
1651:                          b = false;
1652:                      }
1653:                  }
1654:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-ONTSIPINFO:"))
1655:                  {
1656:                      if (response.QueryDataTable != null)
1657:                      {
1658:                          b = Ia.Ngn.Cl.Model.Data.Huawei.OntSipInfo.Update(response, out result);
1659:                      }
1660:                      else result.AddWarning("LST-ONTSIPINFO: QueryDataTable is null, Endesc: " + response.Endesc);
1661:                  }
1662:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("CFG-ONTVAINDIV:"))
1663:                  {
1664:                      result.AddSuccess("Endesc: " + response.Endesc);
1665:                  }
1666:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-VOIPPSTNUSER:"))
1667:                  {
1668:                      if (response.QueryDataTable != null)
1669:                      {
1670:                          b = Ia.Ngn.Cl.Model.Data.Huawei.VoipPstnUser.Update(response, out result);
1671:                      }
1672:                      else result.AddWarning("LST-VOIPPSTNUSER: QueryDataTable is null, Endesc: " + response.Endesc);
1673:                  }
1674:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("ADD-VOIPPSTNUSER:"))
1675:                  {
1676:                      result.AddSuccess("Endesc: " + response.Endesc);
1677:                  }
1678:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("CFG-VOIPPSTNACCOUNT:"))
1679:                  {
1680:                      result.AddSuccess("Endesc: " + response.Endesc);
1681:                  }
1682:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LST-VAG:"))
1683:                  {
1684:                      if (response.QueryDataTable != null)
1685:                      {
1686:                          b = Ia.Ngn.Cl.Model.Data.Huawei.Vag.Update(response, out result);
1687:                      }
1688:                      else result.AddWarning("LST-VAG: QueryDataTable is null, Endesc: " + response.Endesc);
1689:                  }
1690:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("MOD-ONT:"))
1691:                  {
1692:                      result.AddSuccess("Endesc: " + response.Endesc);
1693:                  }
1694:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("SHAKEHAND:"))
1695:                  {
1696:                      result.AddSuccess("Endesc: " + response.Endesc);
1697:                  }
1698:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LOGIN:"))
1699:                  {
1700:                      ems.IsLoggedIn = true;
1701:   
1702:                      result.AddSuccess("Endesc: " + response.Endesc);
1703:                  }
1704:                  else if (response.CommandFromCorrelationTagDictionaryByCtag.Contains("LOGOUT:"))
1705:                  {
1706:                      ems.IsLoggedIn = false;
1707:   
1708:                      result.AddSuccess("Endesc: " + response.Endesc);
1709:                  }
1710:                  else
1711:                  {
1712:                      result.AddWarning("No designated opcode to process");
1713:   
1714:                      b = false;
1715:                  }
1716:              }
1717:              else
1718:              {
1719:                  result.AddWarning("CompletionCode is DENY, Endesc: " + response.Endesc);
1720:   
1721:                  b = false;
1722:              }
1723:   
1724:              return b;
1725:          }
1726:   
1727:          ////////////////////////////////////////////////////////////////////////////
1728:   
1729:          /// <summary>
1730:          /// Parse the U2000 TL1 NBI response by approximatly following the "10.3 Response Format Description standard" in iManager U2000 Unified Network Management System Guide.
1731:          /// </summary>
1732:          public static Response ParseResponse(string rowData)
1733:          {
1734:              bool attributeFirstGroupFlag;
1735:              int blockTag, currentBlockCount, totalCount;
1736:              string header, responseIdentification, textBlock, endesc, terminator, quotedLine, result, title, attributeValueStringList, ctag, completionCode;
1737:              DataTable dataTable;
1738:              MatchCollection matchCollection;
1739:              Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response;
1740:              List<string> attributeList;
1741:              List<List<string>> valueListList;
1742:              Dictionary<string, string> attributeValueDictionary;
1743:   
1744:              blockTag = currentBlockCount = totalCount = 0;
1745:   
1746:              title = string.Empty;
1747:              endesc = string.Empty;
1748:              ctag = string.Empty;
1749:              completionCode = string.Empty;
1750:   
1751:              response = new Response();
1752:   
1753:              attributeList = new List<string>(100);
1754:              valueListList = new List<List<string>>(100);
1755:              attributeValueDictionary = new Dictionary<string, string>(100);
1756:   
1757:              // 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
1758:              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);
1759:              //                                         header                                     response identification   text block                  terminator
1760:   
1761:              foreach (Match match in matchCollection)
1762:              {
1763:                  header = match.Groups[1].Value;
1764:                  responseIdentification = match.Groups[2].Value;
1765:                  textBlock = match.Groups[3].Value;
1766:                  terminator = match.Groups[4].Value;
1767:   
1768:                  if (!string.IsNullOrEmpty(responseIdentification))
1769:                  {
1770:                      matchCollection = Regex.Matches(responseIdentification, @"^\r\nM  ([\w\d]+?) ([\w\d]+?)$", RegexOptions.Singleline);
1771:   
1772:                      foreach (Match match9 in matchCollection)
1773:                      {
1774:                          ctag = match9.Groups[1].Value;
1775:                          completionCode = match9.Groups[2].Value;
1776:   
1777:                          if (!string.IsNullOrEmpty(textBlock))
1778:                          {
1779:                              matchCollection = Regex.Matches(textBlock, @"^\r\n   EN=.+?   ENDESC=(.+?)\r\n   (.+?\r\n)$", RegexOptions.Singleline); // if you do (.+?)$ you will not match the last \n
1780:   
1781:                              if (matchCollection.Count > 0)
1782:                              {
1783:                                  foreach (Match match2 in matchCollection)
1784:                                  {
1785:                                      endesc = match2.Groups[1].Value;
1786:                                      quotedLine = match2.Groups[2].Value;
1787:   
1788:                                      if (!string.IsNullOrEmpty(quotedLine))
1789:                                      {
1790:                                          response.QueryCommand = true;
1791:   
1792:                                          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
1793:   
1794:                                          foreach (Match match3 in matchCollection)
1795:                                          {
1796:                                              blockTag = int.Parse(match3.Groups[1].Value);
1797:                                              currentBlockCount = int.Parse(match3.Groups[2].Value);
1798:                                              totalCount = int.Parse(match3.Groups[3].Value);
1799:   
1800:                                              result = match3.Groups[4].Value;
1801:   
1802:                                              if (!string.IsNullOrEmpty(result))
1803:                                              {
1804:                                                  matchCollection = Regex.Matches(result, @"^\r\n(.+?)\r\n-*\r\n(.+?\r\n)-*(\r\n)+$", RegexOptions.Singleline);
1805:   
1806:                                                  foreach (Match match4 in matchCollection)
1807:                                                  {
1808:                                                      title = match4.Groups[1].Value;
1809:   
1810:                                                      attributeValueStringList = match4.Groups[2].Value;
1811:   
1812:                                                      if (!string.IsNullOrEmpty(attributeValueStringList))
1813:                                                      {
1814:                                                          matchCollection = Regex.Matches(attributeValueStringList, @"(.+?)\r\n", RegexOptions.Singleline);
1815:   
1816:                                                          attributeFirstGroupFlag = true;
1817:   
1818:                                                          foreach (Match match5 in matchCollection)
1819:                                                          {
1820:                                                              if (attributeFirstGroupFlag)
1821:                                                              {
1822:                                                                  attributeList = new List<string>(Regex.Split(match5.Groups[1].Value, @"\t"));
1823:   
1824:                                                                  attributeFirstGroupFlag = false;
1825:                                                              }
1826:                                                              else valueListList.Add(new List<string>(Regex.Split(match5.Groups[1].Value, @"\t")));
1827:                                                          }
1828:                                                      }
1829:                                                  }
1830:                                              }
1831:                                          }
1832:                                      }
1833:                                      else
1834:                                      {
1835:                                          response.QueryCommand = false;
1836:                                      }
1837:                                  }
1838:                              }
1839:                              else
1840:                              {
1841:                                  matchCollection = Regex.Matches(textBlock, @"^\r\n   EN=.+?   ENDESC=(.+?)$", RegexOptions.Singleline); // if you do (.+?)$ you will not match the last \n
1842:   
1843:                                  foreach (Match match6 in matchCollection)
1844:                                  {
1845:                                      endesc = match6.Groups[1].Value;
1846:                                  }
1847:                              }
1848:                          }
1849:                      }
1850:                  }
1851:              }
1852:   
1853:              // build datatable
1854:   
1855:              dataTable = new DataTable();
1856:              dataTable.Clear();
1857:   
1858:              if (attributeList.Count > 0)
1859:              {
1860:                  foreach (string attribute in attributeList) dataTable.Columns.Add(attribute);
1861:   
1862:                  if (valueListList.Count > 0)
1863:                  {
1864:                      if (attributeList.Count == valueListList[0].Count)
1865:                      {
1866:                          foreach (List<string> valuelist in valueListList)
1867:                          {
1868:                              dataTable.Rows.Add(valuelist.ToArray());
1869:                          }
1870:                      }
1871:                      else
1872:                      {
1873:                          throw new Exception("ParseResponse(): attributeList.Count != valueListList[0].Count");
1874:                      }
1875:                  }
1876:              }
1877:              else dataTable = null;
1878:   
1879:              response.BlockTag = blockTag;
1880:              response.CurrentBlockCount = currentBlockCount;
1881:              response.TotalCount = totalCount;
1882:   
1883:              response.Title = title;
1884:              response.Endesc = endesc;
1885:              response.Ctag = ctag;
1886:              response.CompletionCode = completionCode;
1887:              response.QueryDataTable = dataTable;
1888:   
1889:              return response;
1890:          }
1891:   
1892:          ////////////////////////////////////////////////////////////////////////////    
1893:          ////////////////////////////////////////////////////////////////////////////    
1894:      }
1895:   
1896:      ////////////////////////////////////////////////////////////////////////////
1897:      ////////////////////////////////////////////////////////////////////////////   
1898:  }