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

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