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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » OntSipInfo

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

Huawei's EMS ONT SIP INFO 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 ONT SIP INFO support class of Next Generation Network'a (NGN's) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2016-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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 OntSipInfo
  30:      {
  31:          /// <summary/>
  32:          public OntSipInfo() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          /// Update a single EmsOntSipInfo item
  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 queryFn, querySn, queryPn, queryOntId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, tableRowIndex, tel;
  43:              string id, ontId, queryCommand, queryDev, sipUserName, sipName;
  44:              DataColumnCollection columns;
  45:              DataRow columnDataRow;
  46:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon pon;
  47:              Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo ontSipInfo, newOntSipInfo;
  48:              Ia.Ngn.Cl.Model.Huawei.EmsOnt emsOnt;
  49:              List<string> itemIdList;
  50:              List<Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo> ontSipInfoList;
  51:   
  52:              isUpdated = false;
  53:              tableRowIndex = 0;
  54:              readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  55:              result = new Ia.Cl.Model.Result();
  56:   
  57:              if (response.QueryDataTable != null)
  58:              {
  59:                  queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
  60:   
  61:                  // ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,TID=1,DN=96524602285;
  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:                  queryOntId = int.Parse(Ia.Cl.Model.Default.Match(queryCommand, @"ONTID=(\d+)"));
  67:   
  68:                  columns = response.QueryDataTable.Columns;
  69:                  readItemCount = response.QueryDataTable.Rows.Count;
  70:   
  71:                  pon = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PonByOltEmsNameAndSnAndPn(queryDev, querySn, queryPn);
  72:   
  73:                  if (pon != null)
  74:                  {
  75:                      ontId = Ia.Ngn.Cl.Model.Business.Huawei.Ont.OntId(pon.Id, queryOntId);
  76:   
  77:                      itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
  78:   
  79:                      using (var db = new Ia.Ngn.Cl.Model.Ngn())
  80:                      {
  81:                          emsOnt = (from eo in db.EmsOnts where eo.Id == ontId select eo).SingleOrDefault();
  82:   
  83:                          if (emsOnt != null)
  84:                          {
  85:                              ontSipInfoList = (from eo in db.EmsOntSipInfos where eo.EmsOnt.Id == emsOnt.Id select eo).ToList();
  86:   
  87:                              existingItemCount = ontSipInfoList.Count;
  88:   
  89:                              if (response.QueryDataTable.Rows.Count >= 1)
  90:                              {
  91:                                  columnDataRow = response.QueryDataTable.Rows[0];
  92:   
  93:                                  foreach (DataRow dataRow in response.QueryDataTable.Rows)
  94:                                  {
  95:                                      tableRowIndex++;
  96:   
  97:                                      sipUserName = columns.Contains("SIPUSERNAME") ? dataRow[columns.IndexOf("SIPUSERNAME")].ToString() : string.Empty;
  98:                                      sipName = columns.Contains("SIPNAME") ? dataRow[columns.IndexOf("SIPNAME")].ToString() : string.Empty;
  99:   
 100:                                      // we will check that the records is for a real number, otherwise we will not send it to the database
 101:                                      if ((Ia.Ngn.Cl.Model.Business.NumberFormatConverter.IsMatchToImpi(sipName) || Ia.Ngn.Cl.Model.Business.NumberFormatConverter.IsMatchToPridUser(sipName)) && Ia.Ngn.Cl.Model.Business.NumberFormatConverter.IsMatchToImpuAid(sipUserName))
 102:                                      {
 103:                                          tel = tableRowIndex;
 104:   
 105:                                          id = Ia.Ngn.Cl.Model.Business.Huawei.OntSipInfo.OntSipInfoId(ontId, tel);
 106:   
 107:                                          ontSipInfo = (from eo in ontSipInfoList where eo.Id == id select eo).SingleOrDefault();
 108:   
 109:                                          newOntSipInfo = new Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo()
 110:                                          {
 111:                                              Id = id,
 112:                                              SIPUSERNAME = sipUserName,
 113:                                              SIPUSERPWD = columns.Contains("SIPUSERPWD") ? dataRow[columns.IndexOf("SIPUSERPWD")].ToString() : string.Empty,
 114:                                              SIPNAME = sipName,
 115:                                              TEL = tel,
 116:                                              EmsOnt = (from eo in db.EmsOnts where eo.Id == ontId select eo).SingleOrDefault()
 117:                                          };
 118:   
 119:                                          if (ontSipInfo == null)
 120:                                          {
 121:                                              newOntSipInfo.Created = newOntSipInfo.Updated = DateTime.UtcNow.AddHours(3);
 122:   
 123:                                              db.EmsOntSipInfos.Add(newOntSipInfo);
 124:   
 125:                                              insertedItemCount++;
 126:                                          }
 127:                                          else // update
 128:                                          {
 129:                                              // below: copy values from newOntSipInfo to ontSipInfo
 130:   
 131:                                              if (ontSipInfo.Update(newOntSipInfo))
 132:                                              {
 133:                                                  db.EmsOntSipInfos.Attach(ontSipInfo);
 134:                                                  db.Entry(ontSipInfo).State = System.Data.Entity.EntityState.Modified;
 135:   
 136:                                                  updatedItemCount++;
 137:                                              }
 138:                                          }
 139:   
 140:                                          itemIdList.Add(id); // keep at the end
 141:                                      }
 142:                                  }
 143:   
 144:                                  // below: this function will remove values that were not present in the reading
 145:                                  if (ontSipInfoList.Count > 0)
 146:                                  {
 147:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo o in ontSipInfoList)
 148:                                      {
 149:                                          if (!itemIdList.Contains(o.Id))
 150:                                          {
 151:                                              ontSipInfo = (from osi in db.EmsOntSipInfos where osi.Id == o.Id select osi).SingleOrDefault();
 152:   
 153:                                              db.EmsOntSipInfos.Remove(ontSipInfo);
 154:   
 155:                                              deletedItemCount++;
 156:                                          }
 157:                                      }
 158:                                  }
 159:                              }
 160:                              else //if (dataTable.Rows.Count == 0)
 161:                              {
 162:                                  // note sometimes the response is ONT IS OFFLINE
 163:                                  // delete all ONT SIP INFO elements for this ONT
 164:   
 165:                                  /*
 166:                                  if (ontSipInfoList.Count > 0)
 167:                                  {
 168:                                      foreach (Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo o in ontSipInfoList)
 169:                                      {
 170:                                          ontSipInfo = (from osi in db.EmsOntSipInfos where osi.Id == o.Id select osi).SingleOrDefault();
 171:  
 172:                                          db.EmsOntSipInfos.Remove(ontSipInfo);
 173:  
 174:                                          deletedItemCount++;
 175:                                      }
 176:                                  }
 177:                                  */
 178:                              }
 179:   
 180:                              db.SaveChanges();
 181:                          }
 182:                          else
 183:                          {
 184:                              result.AddWarning("EmsOnt is null for ontId: " + ontId);
 185:                          }
 186:                      }
 187:   
 188:                      if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
 189:                      else isUpdated = false;
 190:   
 191:                      result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
 192:                  }
 193:                  else
 194:                  {
 195:                      result.AddError("NDD PON is null");
 196:                  }
 197:              }
 198:              else
 199:              {
 200:                  result.AddWarning("response.QueryDataTable is null");
 201:              }
 202:   
 203:              return isUpdated;
 204:          }
 205:   
 206:          ////////////////////////////////////////////////////////////////////////////
 207:   
 208:          /// <summary>
 209:          ///
 210:          /// </summary>
 211:          public static List<Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo> List()
 212:          {
 213:              List<Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo> list;
 214:   
 215:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 216:              {
 217:                  list = (from o in db.EmsOntSipInfos select o).ToList();
 218:              }
 219:   
 220:              return list;
 221:          }
 222:   
 223:          ////////////////////////////////////////////////////////////////////////////
 224:   
 225:          /// <summary>
 226:          /// List of service number ids within EmsOntSipInfos within a SIP designated OLT
 227:          /// </summary>
 228:          public static List<string> ServiceIdWithinSipOltList()
 229:          {
 230:              int serviceType;
 231:              string service, serviceId;
 232:              List<int> sipOltIdList;
 233:              List<string> list, serviceIdList;
 234:   
 235:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService;
 236:              sipOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SipOltIdList;
 237:   
 238:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 239:              {
 240:                  list = (from o in db.EmsOntSipInfos where o.EmsOnt.Access != null && sipOltIdList.Contains(o.EmsOnt.Access.Olt) select o.SIPUSERNAME).ToList();
 241:              }
 242:   
 243:              if (list != null && list.Count > 0)
 244:              {
 245:                  serviceIdList = new List<string>(list.Count);
 246:   
 247:                  foreach (string s in list)
 248:                  {
 249:                      service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(s);
 250:   
 251:                      serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
 252:   
 253:                      serviceIdList.Add(serviceId);
 254:                  }
 255:              }
 256:              else
 257:              {
 258:                  serviceIdList = new List<string>();
 259:              }
 260:   
 261:              return serviceIdList;
 262:          }
 263:   
 264:          ////////////////////////////////////////////////////////////////////////////
 265:   
 266:          /// <summary>
 267:          /// List of service number ids within EmsOntSipInfos within a SIP allowed to be provisioned or migrated OLT
 268:          /// </summary>
 269:          public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
 270:          {
 271:              int serviceType;
 272:              string service, serviceId;
 273:              List<int> sipOltIdList;
 274:              List<string> list, serviceIdList;
 275:   
 276:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.NgnService;
 277:              sipOltIdList = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
 278:   
 279:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 280:              {
 281:                  list = (from o in db.EmsOntSipInfos where o.EmsOnt.Access != null && sipOltIdList.Contains(o.EmsOnt.Access.Olt) select o.SIPUSERNAME).ToList();
 282:              }
 283:   
 284:              if (list != null && list.Count > 0)
 285:              {
 286:                  serviceIdList = new List<string>(list.Count);
 287:   
 288:                  foreach (string s in list)
 289:                  {
 290:                      service = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(s);
 291:   
 292:                      serviceId = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(service, serviceType);
 293:   
 294:                      serviceIdList.Add(serviceId);
 295:                  }
 296:              }
 297:              else
 298:              {
 299:                  serviceIdList = new List<string>();
 300:              }
 301:   
 302:              return serviceIdList;
 303:          }
 304:   
 305:          ////////////////////////////////////////////////////////////////////////////
 306:   
 307:          /// <summary>
 308:          ///
 309:          /// </summary>
 310:          public static Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo Read(string id)
 311:          {
 312:              Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo item;
 313:   
 314:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 315:              {
 316:                  item = (from o in db.EmsOntSipInfos where o.Id == id select o).Include(o => o.EmsOnt).SingleOrDefault();
 317:              }
 318:   
 319:              return item;
 320:          }
 321:   
 322:          ////////////////////////////////////////////////////////////////////////////
 323:   
 324:          /// <summary>
 325:          ///
 326:          /// </summary>
 327:          public static Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo ReadByServiceIncludeEmsOntAndAccess(string service) //, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
 328:          {
 329:              string huaweiSipName, nokiaSipName;
 330:              Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo item;
 331:   
 332:              // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
 333:              //if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 334:              //{
 335:              huaweiSipName = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Impi(service);
 336:              //}
 337:              //else //if(ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 338:              //{
 339:              nokiaSipName = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PrividUser(service);
 340:              //}
 341:   
 342:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 343:              {
 344:                  item = (from o in db.EmsOntSipInfos where o.SIPNAME == huaweiSipName || o.SIPNAME == nokiaSipName select o).Include(o => o.EmsOnt).Include(o => o.EmsOnt.Access).FirstOrDefault(); //.SingleOrDefault();
 345:              }
 346:   
 347:              return item;
 348:          }
 349:   
 350:          ////////////////////////////////////////////////////////////////////////////
 351:   
 352:          /// <summary>
 353:          ///
 354:          /// </summary>
 355:          public static Dictionary<string, string> IdToOntIdDictionary
 356:          {
 357:              get
 358:              {
 359:                  Dictionary<string, string> dictionary;
 360:   
 361:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 362:                  {
 363:                      dictionary = (from s in db.EmsOntSipInfos select new { s.Id, OntId = s.EmsOnt.Id }).ToDictionary(u => u.Id, u => u.OntId);
 364:                  }
 365:   
 366:                  return dictionary.ToDictionary(u => u.Key, u => u.Value);
 367:              }
 368:          }
 369:   
 370:          ////////////////////////////////////////////////////////////////////////////
 371:          ////////////////////////////////////////////////////////////////////////////
 372:   
 373:          /// <summary>
 374:          ///
 375:          /// </summary>
 376:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Huawei.EmsOntSipInfo emsOntSipInfo)
 377:          {
 378:              StringBuilder sb;
 379:   
 380:              sb = new StringBuilder();
 381:   
 382:              //sb.AppendLine("Vendor: " + Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei.Name);
 383:              sb.AppendLine("TEL: " + emsOntSipInfo.TEL);
 384:              sb.AppendLine("SIPUSERNAME: " + emsOntSipInfo.SIPUSERNAME);
 385:              sb.AppendLine("SIPUSERPWD: " + emsOntSipInfo.SIPUSERPWD);
 386:              sb.AppendLine("SIPNAME: " + emsOntSipInfo.SIPNAME);
 387:   
 388:              return sb.ToString();
 389:          }
 390:   
 391:          ////////////////////////////////////////////////////////////////////////////
 392:          ////////////////////////////////////////////////////////////////////////////
 393:      }
 394:   
 395:      ////////////////////////////////////////////////////////////////////////////
 396:      ////////////////////////////////////////////////////////////////////////////
 397:  }