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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » VoipPstnUser

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

Huawei's EMS VOIP PSTN User support class of Next Generation Network'a (NGN's) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Data.Entity;
   5:  using System.Linq;
   6:  using System.Text;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data.Huawei
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Huawei's EMS VOIP PSTN User support class of Next Generation Network'a (NGN's) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2017-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class VoipPstnUser
  30:      {
  31:          /// <summary/>
  32:          public VoipPstnUser() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static bool Update(Ia.Ngn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Model.Result result)
  40:          {
  41:              bool isUpdated;
  42:              int did, queryFn, querySn, queryPn, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, fn, sn, pn;
  43:              string id, queryCommand, queryDev, dn;
  44:              DataColumnCollection columns;
  45:              DataRow columnDataRow;
  46:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  47:              Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser voipPstnUser, newVoipPstnUser;
  48:              Ia.Ngn.Cl.Model.Huawei.EmsOnt emsOnt;
  49:              List<string> itemIdList;
  50:              List<Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser> voipPstnUserList;
  51:   
  52:              isUpdated = false;
  53:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  54:   
  55:              result = new Ia.Cl.Model.Result(); // remove initially then add to test all return paths
  56:   
  57:              queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
  58:   
  59:              //queryCommand = "LST-VOIPPSTNUSER::DEV=MDU-SAB-1615-002,FN=0,SN=3,PN=1:647947868992::;";
  60:   
  61:              // LST-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:1111::;
  62:              queryDev = Ia.Cl.Model.Default.Match(queryCommand, @"DEV=(.+?),");
  63:              queryFn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"FN=(\d+)"));
  64:              querySn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"SN=(\d+)"));
  65:              queryPn = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"PN=(\d+)"));
  66:   
  67:              nddOnt = Ia.Ngn.Cl.Model.Business.Default.NddOntFromHuaweiEmsAccessNameFormat(queryDev);
  68:   
  69:              if (nddOnt != null)
  70:              {
  71:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  72:                  {
  73:                      emsOnt = (from eo in db.EmsOnts where eo.Id == nddOnt.Id select eo).SingleOrDefault();
  74:   
  75:                      if (emsOnt != null)
  76:                      {
  77:                          // this should always give a single value or none
  78:                          voipPstnUserList = (from eo in db.EmsVoipPstnUsers where eo.EmsOnt.Id == emsOnt.Id && eo.SN == querySn && eo.PN == queryPn select eo).ToList();
  79:   
  80:                          existingItemCount = voipPstnUserList.Count;
  81:   
  82:                          if (response.CompletionCode == "COMPLD")
  83:                          {
  84:                              if (response.QueryDataTable != null)
  85:                              {
  86:                                  if (response.QueryDataTable.Rows.Count >= 1)
  87:                                  {
  88:                                      itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
  89:   
  90:                                      columns = response.QueryDataTable.Columns;
  91:                                      readItemCount = response.QueryDataTable.Rows.Count;
  92:   
  93:                                      columnDataRow = response.QueryDataTable.Rows[0];
  94:   
  95:                                      foreach (DataRow dataRow in response.QueryDataTable.Rows)
  96:                                      {
  97:                                          did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
  98:                                          fn = int.Parse(dataRow[columns.IndexOf("FN")].ToString());
  99:                                          sn = int.Parse(dataRow[columns.IndexOf("SN")].ToString());
 100:                                          pn = int.Parse(dataRow[columns.IndexOf("PN")].ToString());
 101:   
 102:                                          dn = columns.Contains("DN") ? dataRow[columns.IndexOf("DN")].ToString() : string.Empty;
 103:   
 104:                                          if (pn == queryPn && sn == querySn)
 105:                                          {
 106:                                              // we will check that the records is for a real 11 digit number, otherwise we will not send it to the database
 107:                                              if (Ia.Ngn.Cl.Model.Business.NumberFormatConverter.IsMatchToServiceWithCountryCode(dn))
 108:                                              {
 109:                                                  id = Ia.Ngn.Cl.Model.Business.Huawei.VoipPstnUser.VoipPstnUserId(nddOnt.Id, sn, pn);
 110:   
 111:                                                  voipPstnUser = (from eo in voipPstnUserList where eo.Id == id select eo).SingleOrDefault();
 112:   
 113:                                                  newVoipPstnUser = new Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser()
 114:                                                  {
 115:                                                      Id = id,
 116:                                                      DID = did,
 117:                                                      FN = fn,
 118:                                                      SN = sn,
 119:                                                      PN = pn,
 120:                                                      DN = dn.ToString(),
 121:                                                      MGID = columns.Contains("MGID") ? int.Parse(dataRow[columns.IndexOf("MGID")].ToString()) : 0,
 122:                                                      MGNAME = columns.Contains("MGNAME") ? dataRow[columns.IndexOf("MGNAME")].ToString() : string.Empty,
 123:                                                      TID = columns.Contains("TID") ? Ia.Ngn.Cl.Model.Business.Huawei.VoipPstnUser.SpecialIntegerParameterHandling("TID", dataRow[columns.IndexOf("TID")].ToString()) : 0,
 124:                                                      LayeredConf = columns.Contains("LayeredConf") ? dataRow[columns.IndexOf("LayeredConf")].ToString() : string.Empty,
 125:                                                      HighLevelWidth = columns.Contains("HighLevelWidth") ? int.Parse(dataRow[columns.IndexOf("HighLevelWidth")].ToString()) : 0,
 126:                                                      LowerLevelWidth = columns.Contains("LowerLevelWidth") ? int.Parse(dataRow[columns.IndexOf("LowerLevelWidth")].ToString()) : 0,
 127:                                                      Voltage = columns.Contains("Voltage") ? dataRow[columns.IndexOf("Voltage")].ToString() : string.Empty,
 128:                                                      KCType = columns.Contains("KCType") ? dataRow[columns.IndexOf("KCType")].ToString() : string.Empty,
 129:                                                      VoiceGain = columns.Contains("VoiceGain") ? dataRow[columns.IndexOf("VoiceGain")].ToString() : string.Empty,
 130:                                                      LimitPulseDial = columns.Contains("LimitPulseDial") ? dataRow[columns.IndexOf("LimitPulseDial")].ToString() : string.Empty,
 131:                                                      RevPolarity = columns.Contains("RevPolarity") ? dataRow[columns.IndexOf("RevPolarity")].ToString() : string.Empty,
 132:                                                      RevPoleLevel = columns.Contains("RevPoleLevel") ? int.Parse(dataRow[columns.IndexOf("RevPoleLevel")].ToString()) : 0,
 133:                                                      RevPolePulse = columns.Contains("RevPolePulse") ? dataRow[columns.IndexOf("RevPolePulse")].ToString() : string.Empty,
 134:                                                      PSTAT = columns.Contains("PSTAT") ? dataRow[columns.IndexOf("PSTAT")].ToString() : string.Empty,
 135:                                                      ConfigStatus = columns.Contains("ConfigStatus") ? dataRow[columns.IndexOf("ConfigStatus")].ToString() : string.Empty,
 136:                                                      ServiceStatus = columns.Contains("ServiceStatus") ? dataRow[columns.IndexOf("ServiceStatus")].ToString() : string.Empty,
 137:                                                      ServiceType = columns.Contains("ServiceType") ? dataRow[columns.IndexOf("ServiceType")].ToString() : string.Empty,
 138:                                                      ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
 139:                                                      UserType = columns.Contains("UserType") ? dataRow[columns.IndexOf("UserType")].ToString() : string.Empty,
 140:                                                      Impedance = columns.Contains("Impedance") ? dataRow[columns.IndexOf("Impedance")].ToString() : string.Empty,
 141:                                                      Current = columns.Contains("Current") ? dataRow[columns.IndexOf("Current")].ToString() : string.Empty,
 142:                                                      DCTime = columns.Contains("DCTime") ? int.Parse(dataRow[columns.IndexOf("DCTime")].ToString()) : 0,
 143:                                                      PITime = columns.Contains("PITime") ? Ia.Ngn.Cl.Model.Business.Huawei.VoipPstnUser.SpecialIntegerParameterHandling("PITime", dataRow[columns.IndexOf("PITime")].ToString()) : 0,
 144:                                                      FSKDelayInterval = columns.Contains("FSKDelayInterval") ? int.Parse(dataRow[columns.IndexOf("FSKDelayInterval")].ToString()) : 0,
 145:                                                      ActualVoiceGain = columns.Contains("ActualVoiceGain") ? dataRow[columns.IndexOf("ActualVoiceGain")].ToString() : string.Empty,
 146:                                                      CidTransWhen = columns.Contains("CidTransWhen") ? dataRow[columns.IndexOf("CidTransWhen")].ToString() : string.Empty,
 147:                                                      CidFormat = columns.Contains("CidFormat") ? dataRow[columns.IndexOf("CidFormat")].ToString() : string.Empty,
 148:                                                      OverloadPRI = columns.Contains("OverloadPRI") ? dataRow[columns.IndexOf("OverloadPRI")].ToString() : string.Empty,
 149:                                                      ImpedanceProfile = columns.Contains("ImpedanceProfile") ? dataRow[columns.IndexOf("ImpedanceProfile")].ToString() : string.Empty,
 150:                                                      SendVoiceGain = columns.Contains("SendVoiceGain") ? dataRow[columns.IndexOf("SendVoiceGain")].ToString() : string.Empty,
 151:                                                      RecvVoiceGain = columns.Contains("RecvVoiceGain") ? dataRow[columns.IndexOf("RecvVoiceGain")].ToString() : string.Empty,
 152:                                                      RevPolarityMode = columns.Contains("RevPolarityMode") ? dataRow[columns.IndexOf("RevPolarityMode")].ToString() : string.Empty,
 153:                                                      PortRunState = columns.Contains("PortRunState") ? dataRow[columns.IndexOf("PortRunState")].ToString() : string.Empty,
 154:                                                      PortTestState = columns.Contains("PortTestState") ? dataRow[columns.IndexOf("PortTestState")].ToString() : string.Empty,
 155:                                                      PortLineState = columns.Contains("PortLineState") ? dataRow[columns.IndexOf("PortLineState")].ToString() : string.Empty,
 156:                                                      PortLoopState = columns.Contains("PortLoopState") ? dataRow[columns.IndexOf("PortLoopState")].ToString() : string.Empty,
 157:                                                      ServiceRunState = columns.Contains("ServiceRunState") ? dataRow[columns.IndexOf("ServiceRunState")].ToString() : string.Empty,
 158:                                                      ServiceAdminState = columns.Contains("ServiceAdminState") ? dataRow[columns.IndexOf("ServiceAdminState")].ToString() : string.Empty,
 159:                                                      ActualSendVoiceGain = columns.Contains("ActualSendVoiceGain") ? dataRow[columns.IndexOf("ActualSendVoiceGain")].ToString() : string.Empty,
 160:                                                      ActualRecvVo = columns.Contains("ActualRecvVo") ? dataRow[columns.IndexOf("ActualRecvVo")].ToString() : string.Empty,
 161:                                                      AGCEnable = columns.Contains("AGCEnable") ? dataRow[columns.IndexOf("AGCEnable")].ToString() : string.Empty,
 162:                                                      AGCEnableLevel = columns.Contains("AGCEnableLevel") ? int.Parse(dataRow[columns.IndexOf("AGCEnableLevel")].ToString()) : 0,
 163:                                                      SNSEnable = columns.Contains("SNSEnable") ? dataRow[columns.IndexOf("SNSEnable")].ToString() : string.Empty,
 164:                                                      SNSEnableLevel = columns.Contains("SNSEnableLevel") ? int.Parse(dataRow[columns.IndexOf("SNSEnableLevel")].ToString()) : 0,
 165:                                                      NlpMode = columns.Contains("NlpMode") ? dataRow[columns.IndexOf("NlpMode")].ToString() : string.Empty,
 166:                                                      LineLockEnable = columns.Contains("LineLockEnable") ? dataRow[columns.IndexOf("LineLockEnable")].ToString() : string.Empty,
 167:                                                      DspInputGain = columns.Contains("DspInputGain") ? dataRow[columns.IndexOf("DspInputGain")].ToString() : string.Empty,
 168:                                                      DspOutputGain = columns.Contains("DspOutputGain") ? dataRow[columns.IndexOf("DspOutputGain")].ToString() : string.Empty,
 169:                                                      ClipReversePole = columns.Contains("ClipReversePole") ? dataRow[columns.IndexOf("ClipReversePole")].ToString() : string.Empty,
 170:                                                      DEFAULTCLI = columns.Contains("DEFAULTCLI") ? dataRow[columns.IndexOf("DEFAULTCLI")].ToString() : string.Empty,
 171:                                                      USERGROUPID = columns.Contains("USERGROUPID") ? int.Parse(dataRow[columns.IndexOf("USERGROUPID")].ToString()) : 0,
 172:                                                      ADJUSTFACTOR = columns.Contains("ADJUSTFACTOR") ? int.Parse(dataRow[columns.IndexOf("ADJUSTFACTOR")].ToString()) : 0,
 173:                                                      DSPPROFILE = columns.Contains("DSPPROFILE") ? dataRow[columns.IndexOf("DSPPROFILE")].ToString() : string.Empty,
 174:   
 175:                                                      EmsOnt = (from eo in db.EmsOnts where eo.Id == nddOnt.Id select eo).SingleOrDefault()
 176:                                                  };
 177:   
 178:                                                  if (voipPstnUser == null)
 179:                                                  {
 180:                                                      newVoipPstnUser.Created = newVoipPstnUser.Updated = DateTime.UtcNow.AddHours(3);
 181:   
 182:                                                      db.EmsVoipPstnUsers.Add(newVoipPstnUser);
 183:   
 184:                                                      insertedItemCount++;
 185:                                                  }
 186:                                                  else // update
 187:                                                  {
 188:                                                      // below: copy values from newVoipPstnUser to ontSipInfo
 189:   
 190:                                                      if (voipPstnUser.Update(newVoipPstnUser))
 191:                                                      {
 192:                                                          db.EmsVoipPstnUsers.Attach(voipPstnUser);
 193:                                                          db.Entry(voipPstnUser).State = System.Data.Entity.EntityState.Modified;
 194:   
 195:                                                          updatedItemCount++;
 196:                                                      }
 197:                                                  }
 198:   
 199:                                                  itemIdList.Add(id); // keep at the end
 200:                                              }
 201:                                              else
 202:                                              {
 203:   
 204:                                              }
 205:                                          }
 206:                                          else
 207:                                          {
 208:                                              result.AddError("pn != queryPn and/or sn != querySn for ont.Access.Name: " + nddOnt.Access.Name);
 209:                                          }
 210:                                      }
 211:   
 212:                                      // below: this function will remove values that were not present in the reading
 213:                                      if (voipPstnUserList.Count > 0)
 214:                                      {
 215:                                          foreach (Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser o in voipPstnUserList)
 216:                                          {
 217:                                              if (!itemIdList.Contains(o.Id))
 218:                                              {
 219:                                                  voipPstnUser = (from osi in db.EmsVoipPstnUsers where osi.Id == o.Id select osi).SingleOrDefault();
 220:   
 221:                                                  db.EmsVoipPstnUsers.Remove(voipPstnUser);
 222:   
 223:                                                  deletedItemCount++;
 224:                                              }
 225:                                          }
 226:                                      }
 227:                                  }
 228:                                  else //if (response.QueryDataTable.Rows.Count == 0)
 229:                                  {
 230:                                      if (voipPstnUserList.Count > 0)
 231:                                      {
 232:                                          foreach (Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser v in voipPstnUserList)
 233:                                          {
 234:                                              voipPstnUser = (from vpu in db.EmsVoipPstnUsers where vpu.Id == v.Id select vpu).SingleOrDefault();
 235:   
 236:                                              db.EmsVoipPstnUsers.Remove(voipPstnUser);
 237:   
 238:                                              deletedItemCount++;
 239:                                          }
 240:                                      }
 241:                                  }
 242:   
 243:                                  db.SaveChanges();
 244:   
 245:                                  if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 246:                                  else isUpdated = false;
 247:   
 248:                                  result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 249:                              }
 250:                              else
 251:                              {
 252:                                  result.AddWarning("LST-VOIPPSTNUSER: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 253:                              }
 254:                          }
 255:                          else
 256:                          {
 257:                              result.AddWarning("LST-VOIPPSTNUSER: (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
 258:                          }
 259:                      }
 260:                      else
 261:                      {
 262:                          result.AddWarning("EmsOnt is null for ont.Access.Name: " + nddOnt.Access.Name);
 263:                      }
 264:                  }
 265:              }
 266:              else
 267:              {
 268:                  result.AddError("nddOnt is null");
 269:              }
 270:   
 271:              return isUpdated;
 272:          }
 273:   
 274:          ////////////////////////////////////////////////////////////////////////////
 275:   
 276:          /// <summary>
 277:          ///
 278:          /// </summary>
 279:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser> List()
 280:          {
 281:              List<Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser> list;
 282:   
 283:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 284:              {
 285:                  list = (from vpu in db.EmsVoipPstnUsers select vpu).ToList();
 286:              }
 287:   
 288:              return list;
 289:          }
 290:   
 291:          ////////////////////////////////////////////////////////////////////////////
 292:   
 293:          /// <summary>
 294:          /// List of service number ids within EmsVoipPstnUsers within a SIP designated OLT
 295:          /// </summary>
 296:          public static List<string> ServiceIdWithinSipOltList()
 297:          {
 298:              int serviceType;
 299:              string service, serviceId;
 300:              List<int> sipOltIdList;
 301:              List<string> list, serviceIdList;
 302:   
 303:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
 304:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 305:   
 306:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 307:              {
 308:                  list = (from vpu in db.EmsVoipPstnUsers where vpu.EmsOnt.Access != null && sipOltIdList.Contains(vpu.EmsOnt.Access.Olt) select vpu.DN).ToList();
 309:              }
 310:   
 311:              if (list != null && list.Count > 0)
 312:              {
 313:                  serviceIdList = new List<string>(list.Count);
 314:   
 315:                  foreach (string s in list)
 316:                  {
 317:                      service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(s);
 318:   
 319:                      serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
 320:   
 321:                      serviceIdList.Add(serviceId);
 322:                  }
 323:              }
 324:              else
 325:              {
 326:                  serviceIdList = new List<string>();
 327:              }
 328:   
 329:              return serviceIdList;
 330:          }
 331:   
 332:          ////////////////////////////////////////////////////////////////////////////
 333:   
 334:          /// <summary>
 335:          /// List of service number ids within EmsVoipPstnUsers within a SIP allowed to be provisioned or migrated OLT
 336:          /// </summary>
 337:          public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
 338:          {
 339:              int serviceType;
 340:              string service, serviceId;
 341:              List<int> sipOltIdList;
 342:              List<string> list, serviceIdList;
 343:   
 344:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
 345:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 346:   
 347:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 348:              {
 349:                  list = (from vpu in db.EmsVoipPstnUsers where vpu.EmsOnt.Access != null && sipOltIdList.Contains(vpu.EmsOnt.Access.Olt) select vpu.DN).ToList();
 350:              }
 351:   
 352:              if (list != null && list.Count > 0)
 353:              {
 354:                  serviceIdList = new List<string>(list.Count);
 355:   
 356:                  foreach (string s in list)
 357:                  {
 358:                      service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(s);
 359:   
 360:                      serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
 361:   
 362:                      serviceIdList.Add(serviceId);
 363:                  }
 364:              }
 365:              else
 366:              {
 367:                  serviceIdList = new List<string>();
 368:              }
 369:   
 370:              return serviceIdList;
 371:          }
 372:   
 373:          ////////////////////////////////////////////////////////////////////////////
 374:   
 375:          /// <summary>
 376:          /// List of ServiceOnts within EmsVoipPstnUsers within a SIP allowed to be provisioned or migrated OLT
 377:          /// </summary>
 378:          public static List<Ia.Ngn.Cl.Model.Business.ServiceOnt> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList()
 379:          {
 380:              int serviceType;
 381:              string service, serviceId;
 382:              List<int> sipOltIdList;
 383:              List<Ia.Ngn.Cl.Model.Business.ServiceOnt> tempSipUserNamelist, serviceOntList;
 384:   
 385:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
 386:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 387:   
 388:              var ontAccessIdToOntForOltIdListDictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(sipOltIdList);
 389:   
 390:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 391:              {
 392:                  tempSipUserNamelist = (from vpu in db.EmsVoipPstnUsers
 393:                                         where vpu.EmsOnt.Access != null && sipOltIdList.Contains(vpu.EmsOnt.Access.Olt)
 394:                                         // select vpu.DN).ToList();
 395:                                         select new Ia.Ngn.Cl.Model.Business.ServiceOnt { Service = vpu.DN, AccessId = vpu.EmsOnt.Access.Id, CreatedDateTime = vpu.Created }).ToList();
 396:              }
 397:   
 398:              if (tempSipUserNamelist != null && tempSipUserNamelist.Count > 0)
 399:              {
 400:                  serviceOntList = new List<Ia.Ngn.Cl.Model.Business.ServiceOnt>(tempSipUserNamelist.Count);
 401:   
 402:                  foreach (var so in tempSipUserNamelist)
 403:                  {
 404:                      service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(so.Service); // so.Service here is vpu.DN
 405:   
 406:                      serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
 407:   
 408:                      serviceOntList.Add(new Ia.Ngn.Cl.Model.Business.ServiceOnt
 409:                      {
 410:                          ServiceId = serviceId,
 411:                          Service = service,
 412:                          AccessId = so.AccessId,
 413:                          Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(so.AccessId) ? ontAccessIdToOntForOltIdListDictionary[so.AccessId] : null,
 414:                          CreatedDateTime = so.CreatedDateTime
 415:                      });
 416:                  }
 417:              }
 418:              else
 419:              {
 420:                  serviceOntList = new List<Ia.Ngn.Cl.Model.Business.ServiceOnt>();
 421:              }
 422:   
 423:              return serviceOntList;
 424:          }
 425:   
 426:          ////////////////////////////////////////////////////////////////////////////
 427:   
 428:          /// <summary>
 429:          ///
 430:          /// </summary>
 431:          public static Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser Read(string id)
 432:          {
 433:              Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser item;
 434:   
 435:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 436:              {
 437:                  item = (from vpu in db.EmsVoipPstnUsers where vpu.Id == id select vpu).Include(o => o.EmsOnt).SingleOrDefault();
 438:              }
 439:   
 440:              return item;
 441:          }
 442:   
 443:          ////////////////////////////////////////////////////////////////////////////
 444:   
 445:          /// <summary>
 446:          ///
 447:          /// </summary>
 448:          public static Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser ReadByService(string service) //, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
 449:          {
 450:              string dn;
 451:              Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser item;
 452:   
 453:              dn = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode(service);
 454:   
 455:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 456:              {
 457:                  item = (from vpu in db.EmsVoipPstnUsers where vpu.DN == dn select vpu).Include(o => o.EmsOnt).Include(o => o.EmsOnt.Access).SingleOrDefault();
 458:              }
 459:   
 460:              return item;
 461:          }
 462:   
 463:          ////////////////////////////////////////////////////////////////////////////
 464:   
 465:          /// <summary>
 466:          ///
 467:          /// </summary>
 468:          public static Dictionary<string, string> IdToOntIdDictionary
 469:          {
 470:              get
 471:              {
 472:                  Dictionary<string, string> dictionary;
 473:   
 474:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 475:                  {
 476:                      dictionary = (from s in db.EmsVoipPstnUsers select new { s.Id, OntId = s.EmsOnt.Id }).ToDictionary(u => u.Id, u => u.OntId);
 477:                  }
 478:   
 479:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 480:              }
 481:          }
 482:   
 483:          ////////////////////////////////////////////////////////////////////////////
 484:          ////////////////////////////////////////////////////////////////////////////
 485:   
 486:          /// <summary>
 487:          ///
 488:          /// </summary>
 489:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Huawei.EmsVoipPstnUser emsVoipPstnUser)
 490:          {
 491:              StringBuilder sb;
 492:   
 493:              sb = new StringBuilder();
 494:   
 495:              //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei.Name);
 496:              sb.AppendLine("DID: " + emsVoipPstnUser.DID);
 497:              sb.AppendLine("FN: " + emsVoipPstnUser.FN);
 498:              sb.AppendLine("SN: " + emsVoipPstnUser.SN);
 499:              sb.AppendLine("PN: " + emsVoipPstnUser.PN);
 500:              sb.AppendLine("MGID: " + emsVoipPstnUser.MGID);
 501:              sb.AppendLine("MGNAME: " + emsVoipPstnUser.MGNAME);
 502:              sb.AppendLine("TID: " + emsVoipPstnUser.TID);
 503:              sb.AppendLine("DN: " + emsVoipPstnUser.DN);
 504:              sb.AppendLine("LayeredConf: " + emsVoipPstnUser.LayeredConf);
 505:              sb.AppendLine("HighLevelWidth: " + emsVoipPstnUser.HighLevelWidth);
 506:              sb.AppendLine("LowerLevelWidth: " + emsVoipPstnUser.LowerLevelWidth);
 507:              sb.AppendLine("Voltage: " + emsVoipPstnUser.Voltage);
 508:              sb.AppendLine("KCType: " + emsVoipPstnUser.KCType);
 509:              sb.AppendLine("VoiceGain: " + emsVoipPstnUser.VoiceGain);
 510:              sb.AppendLine("LimitPulseDial: " + emsVoipPstnUser.LimitPulseDial);
 511:              sb.AppendLine("RevPolarity: " + emsVoipPstnUser.RevPolarity);
 512:              sb.AppendLine("RevPoleLevel: " + emsVoipPstnUser.RevPoleLevel);
 513:              sb.AppendLine("RevPolePulse: " + emsVoipPstnUser.RevPolePulse);
 514:              sb.AppendLine("PSTAT: " + emsVoipPstnUser.PSTAT);
 515:              sb.AppendLine("ConfigStatus: " + emsVoipPstnUser.ConfigStatus);
 516:              sb.AppendLine("ServiceStatus: " + emsVoipPstnUser.ServiceStatus);
 517:              sb.AppendLine("ServiceType: " + emsVoipPstnUser.ServiceType);
 518:              sb.AppendLine("ALIAS: " + emsVoipPstnUser.ALIAS);
 519:              sb.AppendLine("UserType: " + emsVoipPstnUser.UserType);
 520:              sb.AppendLine("Impedance: " + emsVoipPstnUser.Impedance);
 521:              sb.AppendLine("Current: " + emsVoipPstnUser.Current);
 522:              sb.AppendLine("DCTime: " + emsVoipPstnUser.DCTime);
 523:              sb.AppendLine("PITime: " + emsVoipPstnUser.PITime);
 524:              sb.AppendLine("FSKDelayInterval: " + emsVoipPstnUser.FSKDelayInterval);
 525:              sb.AppendLine("ActualVoiceGain: " + emsVoipPstnUser.ActualVoiceGain);
 526:              sb.AppendLine("CidTransWhen: " + emsVoipPstnUser.CidTransWhen);
 527:              sb.AppendLine("CidFormat: " + emsVoipPstnUser.CidFormat);
 528:              sb.AppendLine("OverloadPRI: " + emsVoipPstnUser.OverloadPRI);
 529:              sb.AppendLine("ImpedanceProfile: " + emsVoipPstnUser.ImpedanceProfile);
 530:              sb.AppendLine("SendVoiceGain: " + emsVoipPstnUser.SendVoiceGain);
 531:              sb.AppendLine("RecvVoiceGain: " + emsVoipPstnUser.RecvVoiceGain);
 532:              sb.AppendLine("RevPolarityMode: " + emsVoipPstnUser.RevPolarityMode);
 533:              sb.AppendLine("PortRunState: " + emsVoipPstnUser.PortRunState);
 534:              sb.AppendLine("PortTestState: " + emsVoipPstnUser.PortTestState);
 535:              sb.AppendLine("PortLineState: " + emsVoipPstnUser.PortLineState);
 536:              sb.AppendLine("PortLoopState: " + emsVoipPstnUser.PortLoopState);
 537:              sb.AppendLine("ServiceRunState: " + emsVoipPstnUser.ServiceRunState);
 538:              sb.AppendLine("ServiceAdminState: " + emsVoipPstnUser.ServiceAdminState);
 539:              sb.AppendLine("ActualSendVoiceGain: " + emsVoipPstnUser.ActualSendVoiceGain);
 540:              sb.AppendLine("ActualRecvVo: " + emsVoipPstnUser.ActualRecvVo);
 541:              sb.AppendLine("AGCEnable: " + emsVoipPstnUser.AGCEnable);
 542:              sb.AppendLine("AGCEnableLevel: " + emsVoipPstnUser.AGCEnableLevel);
 543:              sb.AppendLine("SNSEnable: " + emsVoipPstnUser.SNSEnable);
 544:              sb.AppendLine("SNSEnableLevel: " + emsVoipPstnUser.SNSEnableLevel);
 545:              sb.AppendLine("NlpMode: " + emsVoipPstnUser.NlpMode);
 546:              sb.AppendLine("LineLockEnable: " + emsVoipPstnUser.LineLockEnable);
 547:              sb.AppendLine("DspInputGain: " + emsVoipPstnUser.DspInputGain);
 548:              sb.AppendLine("DspOutputGain: " + emsVoipPstnUser.DspOutputGain);
 549:              sb.AppendLine("ClipReversePole: " + emsVoipPstnUser.ClipReversePole);
 550:              sb.AppendLine("DEFAULTCLI: " + emsVoipPstnUser.DEFAULTCLI);
 551:              sb.AppendLine("USERGROUPID: " + emsVoipPstnUser.USERGROUPID);
 552:              sb.AppendLine("ADJUSTFACTOR: " + emsVoipPstnUser.ADJUSTFACTOR);
 553:              sb.AppendLine("DSPPROFILE: " + emsVoipPstnUser.DSPPROFILE);
 554:   
 555:              return sb.ToString();
 556:          }
 557:   
 558:          ////////////////////////////////////////////////////////////////////////////
 559:          ////////////////////////////////////////////////////////////////////////////
 560:      }
 561:   
 562:      ////////////////////////////////////////////////////////////////////////////
 563:      ////////////////////////////////////////////////////////////////////////////
 564:  }