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

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