)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » OntSipInfo (Ia.Ftn.Cl.Models.Data.Huawei)

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 Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6: using System.Text;
    7:  
    8: namespace Ia.Ftn.Cl.Models.Data.Huawei
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Huawei's EMS ONT SIP INFO support class of Fixed Telecommunications Network (FTN) data model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2016-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     /// </remarks> 
   19:     public class OntSipInfo
   20:     {
   21:         /// <summary/>
   22:         public OntSipInfo() { }
   23:  
   24:         ////////////////////////////////////////////////////////////////////////////
   25:  
   26:         /// <summary>
   27:         /// Update a single EmsOntSipInfo item
   28:         /// </summary>
   29:         public static bool Update(Ia.Ftn.Cl.Models.Business.Huawei.Ems.Response response, out string updatedService, out Ia.Cl.Models.Result result)
   30:         {
   31:             bool isUpdated;
   32:             int queryFn, querySn, queryPn, queryOntId, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount, tableRowIndex, tel;
   33:             string id, ontId, queryCommand, queryDev, sipUserName, sipName;
   34:             DataColumnCollection columns;
   35:             DataRow columnDataRow;
   36:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon;
   37:             Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo ontSipInfo, newOntSipInfo;
   38:             Ia.Ftn.Cl.Models.Huawei.EmsOnt emsOnt;
   39:             List<string> itemIdList;
   40:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> ontSipInfoList;
   41:  
   42:             isUpdated = false;
   43:             updatedService = string.Empty;
   44:             tableRowIndex = 0;
   45:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
   46:             result = new Ia.Cl.Models.Result();
   47:  
   48:             if (response.CompletionCode == "COMPLD" || response.CompletionCode == "DENY")
   49:             {
   50:                 queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
   51:  
   52:                 // ADD-VOIPPSTNUSER::DEV=MDU-JBA-943-002,FN=0,SN=3,PN=10:{ctag}::MGID=0,TID=1,DN=96524602285;
   53:                 queryDev = Ia.Cl.Models.Default.Match(queryCommand, @"DEV=(.+?),");
   54:                 queryFn = int.Parse(Ia.Cl.Models.Default.Match(queryCommand, @"FN=(\d+)"));
   55:                 querySn = int.Parse(Ia.Cl.Models.Default.Match(queryCommand, @"SN=(\d+)"));
   56:                 queryPn = int.Parse(Ia.Cl.Models.Default.Match(queryCommand, @"PN=(\d+)"));
   57:                 queryOntId = int.Parse(Ia.Cl.Models.Default.Match(queryCommand, @"ONTID=(\d+)"));
   58:  
   59:                 pon = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonByOltEmsNameAndSnAndPnAndOptionallyOntId(queryDev, querySn, queryPn, queryOntId);
   60:  
   61:                 if (pon != null)
   62:                 {
   63:                     ontId = Ia.Ftn.Cl.Models.Business.Huawei.Ont.OntId(pon.Id, queryOntId);
   64:  
   65:                     using (var db = new Ia.Ftn.Cl.Db())
   66:                     {
   67:                         emsOnt = (from eo in db.EmsOnts where eo.Id == ontId select eo).SingleOrDefault();
   68:  
   69:                         if (emsOnt != null)
   70:                         {
   71:                             if (response.CompletionCode == "COMPLD")
   72:                             {
   73:                                 ontSipInfoList = (from eo in db.EmsOntSipInfoes where eo.EmsOnt.Id == emsOnt.Id select eo).ToList();
   74:  
   75:                                 existingItemCount = ontSipInfoList.Count;
   76:  
   77:                                 if (response.QueryDataTable != null)
   78:                                 {
   79:                                     if (response.QueryDataTable.Rows.Count >= 1)
   80:                                     {
   81:                                         itemIdList = new List<string>(response.QueryDataTable.Rows.Count + 1);
   82:  
   83:                                         columns = response.QueryDataTable.Columns;
   84:                                         readItemCount = response.QueryDataTable.Rows.Count;
   85:  
   86:                                         columnDataRow = response.QueryDataTable.Rows[0];
   87:  
   88:                                         foreach (DataRow dataRow in response.QueryDataTable.Rows)
   89:                                         {
   90:                                             tableRowIndex++;
   91:  
   92:                                             sipUserName = columns.Contains("SIPUSERNAME") ? dataRow[columns.IndexOf("SIPUSERNAME")].ToString() : string.Empty;
   93:                                             sipName = columns.Contains("SIPNAME") ? dataRow[columns.IndexOf("SIPNAME")].ToString() : string.Empty;
   94:  
   95:                                             // we will check that the records is for a real number, otherwise we will not send it to the database
   96:                                             if ((Ia.Ftn.Cl.Models.Business.NumberFormatConverter.IsMatchToImpi(sipName) || Ia.Ftn.Cl.Models.Business.NumberFormatConverter.IsMatchToPridUser(sipName)) && Ia.Ftn.Cl.Models.Business.NumberFormatConverter.IsMatchToImpuAid(sipUserName))
   97:                                             {
   98:                                                 tel = tableRowIndex;
   99:  
  100:                                                 id = Ia.Ftn.Cl.Models.Business.Huawei.OntSipInfo.OntSipInfoId(ontId, tel);
  101:  
  102:                                                 ontSipInfo = (from eo in ontSipInfoList where eo.Id == id select eo).SingleOrDefault();
  103:  
  104:                                                 newOntSipInfo = new Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo()
  105:                                                 {
  106:                                                     Id = id,
  107:                                                     SIPUSERNAME = sipUserName,
  108:                                                     SIPUSERPWD = columns.Contains("SIPUSERPWD") ? dataRow[columns.IndexOf("SIPUSERPWD")].ToString() : string.Empty,
  109:                                                     SIPNAME = sipName,
  110:                                                     TEL = tel,
  111:                                                     EmsOnt = (from eo in db.EmsOnts where eo.Id == ontId select eo).SingleOrDefault()
  112:                                                 };
  113:  
  114:                                                 if (ontSipInfo == null)
  115:                                                 {
  116:                                                     newOntSipInfo.Created = newOntSipInfo.Updated = DateTime.UtcNow.AddHours(3);
  117:  
  118:                                                     db.EmsOntSipInfoes.Add(newOntSipInfo);
  119:  
  120:                                                     insertedItemCount++;
  121:                                                 }
  122:                                                 else // update
  123:                                                 {
  124:                                                     // below: copy values from newOntSipInfo to ontSipInfo
  125:  
  126:                                                     if (ontSipInfo.Update(newOntSipInfo))
  127:                                                     {
  128:                                                         db.EmsOntSipInfoes.Attach(ontSipInfo);
  129:                                                         db.Entry(ontSipInfo).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  130:  
  131:                                                         updatedItemCount++;
  132:                                                     }
  133:                                                 }
  134:  
  135:                                                 itemIdList.Add(id); // keep at the end
  136:  
  137:                                                 updatedService = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(sipUserName);
  138:                                             }
  139:                                         }
  140:  
  141:                                         // below: this function will remove values that were not present in the reading
  142:                                         if (ontSipInfoList.Count > 0)
  143:                                         {
  144:                                             foreach (Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo o in ontSipInfoList)
  145:                                             {
  146:                                                 if (!itemIdList.Contains(o.Id))
  147:                                                 {
  148:                                                     ontSipInfo = (from osi in db.EmsOntSipInfoes where osi.Id == o.Id select osi).SingleOrDefault();
  149:  
  150:                                                     db.EmsOntSipInfoes.Remove(ontSipInfo);
  151:  
  152:                                                     deletedItemCount++;
  153:  
  154:                                                     updatedService = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(ontSipInfo.SIPUSERNAME);
  155:                                                 }
  156:                                             }
  157:                                         }
  158:                                     }
  159:                                     else //if (dataTable.Rows.Count == 0)
  160:                                     {
  161:                                         if (ontSipInfoList.Count > 0)
  162:                                         {
  163:                                             foreach (Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo o in ontSipInfoList)
  164:                                             {
  165:                                                 ontSipInfo = (from osi in db.EmsOntSipInfoes where osi.Id == o.Id select osi).SingleOrDefault();
  166:  
  167:                                                 db.EmsOntSipInfoes.Remove(ontSipInfo);
  168:  
  169:                                                 deletedItemCount++;
  170:  
  171:                                                 updatedService = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(ontSipInfo.SIPUSERNAME);
  172:                                             }
  173:                                         }
  174:                                     }
  175:  
  176:                                     db.SaveChanges();
  177:                                 }
  178:                                 else
  179:                                 {
  180:                                     if (response.ResultCode == Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.OntIsOffline || response.ResultCode == Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.SystemIsBusy2)
  181:                                     {
  182:                                         var emsOntResultCodeIsUpdated = Ia.Ftn.Cl.Models.Data.Huawei.Ont.UpdateResultCode(emsOnt, response.ResultCode);
  183:  
  184:                                         result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ") EmsOnt.ResultCode updated?: " + emsOntResultCodeIsUpdated.ToString().ToLower());
  185:                                     }
  186:                                     else
  187:                                     {
  188:                                         result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  189:                                     }
  190:                                 }
  191:                             }
  192:                             else if (response.CompletionCode == "DENY")
  193:                             {
  194:                                 if (response.ResultCode == Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.DeviceOfflineError)
  195:                                 {
  196:                                     var emsOntResultCodeIsUpdated = Ia.Ftn.Cl.Models.Data.Huawei.Ont.UpdateResultCode(emsOnt, response.ResultCode);
  197:  
  198:                                     result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ") EmsOnt.ResultCode updated?: " + emsOntResultCodeIsUpdated.ToString().ToLower());
  199:                                 }
  200:                                 else
  201:                                 {
  202:                                     result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  203:                                 }
  204:                             }
  205:                         }
  206:                         else
  207:                         {
  208:                             result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): EmsOnt is null for ontId: " + ontId);
  209:                         }
  210:                     }
  211:  
  212:                     if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  213:                     else isUpdated = false;
  214:  
  215:                     result.AddSuccess("LST-ONTSIPINFO (" + response.Ctag + "): " + response.CompletionCode + ", " + response.ResultCode.ToString() + " (" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  216:                 }
  217:                 else
  218:                 {
  219:                     result.AddError("LST-ONTSIPINFO (" + response.Ctag + "): NDD PON is null");
  220:                 }
  221:             }
  222:             else
  223:             {
  224:                 result.AddWarning("LST-ONTSIPINFO (" + response.Ctag + "): (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  225:             }
  226:  
  227:             return isUpdated;
  228:         }
  229:  
  230:         ////////////////////////////////////////////////////////////////////////////
  231:  
  232:         /// <summary>
  233:         ///
  234:         /// </summary>
  235:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> List()
  236:         {
  237:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> list;
  238:  
  239:             using (var db = new Ia.Ftn.Cl.Db())
  240:             {
  241:                 list = (from eosi in db.EmsOntSipInfoes select eosi).ToList();
  242:             }
  243:  
  244:             return list;
  245:         }
  246:  
  247:         ////////////////////////////////////////////////////////////////////////////
  248:  
  249:         /// <summary>
  250:         ///
  251:         /// </summary>
  252:         public static List<string> ServiceList()
  253:         {
  254:             List<string> list;
  255:  
  256:             using (var db = new Ia.Ftn.Cl.Db())
  257:             {
  258:                 var list0 = (from eosi in db.EmsOntSipInfoes select eosi.SIPUSERNAME).AsNoTracking().ToList();
  259:  
  260:                 list = (from l in list0 select Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(l)).Distinct().ToList();
  261:             }
  262:  
  263:             return list;
  264:         }
  265:  
  266:         ////////////////////////////////////////////////////////////////////////////
  267:  
  268:         /// <summary>
  269:         ///
  270:         /// </summary>
  271:         public static List<string> DuplicateSipUserNameServiceList()
  272:         {
  273:             List<string> list;
  274:  
  275:             using (var db = new Ia.Ftn.Cl.Db())
  276:             {
  277:                 var list0 = (from eosi1 in db.EmsOntSipInfoes
  278:                              join eosi2 in db.EmsOntSipInfoes on eosi1.SIPUSERNAME equals eosi2.SIPUSERNAME
  279:                              where eosi1.Id != eosi2.Id
  280:                              select new { Service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(eosi1.SIPUSERNAME) }).Distinct().ToList();
  281:  
  282:                 list = (from l in list0 select l.Service).ToList();
  283:             }
  284:  
  285:             return list;
  286:         }
  287:  
  288:         ////////////////////////////////////////////////////////////////////////////
  289:  
  290:         /// <summary>
  291:         ///
  292:         /// </summary>
  293:         public static List<string> ServiceIdWithinSipOltList()
  294:         {
  295:             int serviceType;
  296:             string service, serviceId;
  297:             List<int> sipOltIdList;
  298:             List<string> list, serviceIdList;
  299:  
  300:             serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  301:             sipOltIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SipOltIdList;
  302:  
  303:             using (var db = new Ia.Ftn.Cl.Db())
  304:             {
  305:                 list = (from o in db.EmsOntSipInfoes
  306:                         where o.EmsOnt.Access != null && sipOltIdList.Contains(o.EmsOnt.Access.Olt)
  307:                         select o.SIPUSERNAME).AsNoTracking().ToList();
  308:             }
  309:  
  310:             if (list != null && list.Count > 0)
  311:             {
  312:                 serviceIdList = new List<string>(list.Count);
  313:  
  314:                 foreach (string s in list)
  315:                 {
  316:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(s);
  317:  
  318:                     serviceId = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, serviceType);
  319:  
  320:                     serviceIdList.Add(serviceId);
  321:                 }
  322:             }
  323:             else
  324:             {
  325:                 serviceIdList = new List<string>();
  326:             }
  327:  
  328:             return serviceIdList;
  329:         }
  330:  
  331:         ////////////////////////////////////////////////////////////////////////////
  332:  
  333:         /// <summary>
  334:         ///
  335:         /// </summary>
  336:         public static List<string> ServiceWithinEmsOntSipInfoWhereEmsOntResultCodeOntIsOfflineOrDeviceOfflineErrorList()
  337:         {
  338:             string service;
  339:             List<string> list, serviceList;
  340:  
  341:             using (var db = new Ia.Ftn.Cl.Db())
  342:             {
  343:                 list = (from o in db.EmsOntSipInfoes
  344:                         where o.EmsOnt.Access != null && (o.EmsOnt.ResultCode == (long)Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.OntIsOffline || o.EmsOnt.ResultCode == (long)Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.DeviceOfflineError)
  345:                         select o.SIPUSERNAME).AsNoTracking().ToList();
  346:             }
  347:  
  348:             if (list != null && list.Count > 0)
  349:             {
  350:                 serviceList = new List<string>(list.Count);
  351:  
  352:                 foreach (var s in list)
  353:                 {
  354:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(s);
  355:  
  356:                     serviceList.Add(service);
  357:                 }
  358:             }
  359:             else
  360:             {
  361:                 serviceList = new List<string>();
  362:             }
  363:  
  364:             return serviceList;
  365:         }
  366:  
  367:         ////////////////////////////////////////////////////////////////////////////
  368:  
  369:         /// <summary>
  370:         ///
  371:         /// </summary>
  372:         public static List<string> AccessNameWithinEmsOntSipInfoWhereEmsOntResultCodeOntIsOfflineOrDeviceOfflineErrorList()
  373:         {
  374:             string accessName;
  375:             List<string> list, accessNameList;
  376:  
  377:             using (var db = new Ia.Ftn.Cl.Db())
  378:             {
  379:                 list = (from o in db.EmsOntSipInfoes
  380:                         where o.EmsOnt.Access != null && (o.EmsOnt.ResultCode == (long)Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.OntIsOffline || o.EmsOnt.ResultCode == (long)Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.DeviceOfflineError)
  381:                         select o.EmsOnt.Access.Id).AsNoTracking().ToList();
  382:             }
  383:  
  384:             if (list != null && list.Count > 0)
  385:             {
  386:                 accessNameList = new List<string>(list.Count);
  387:  
  388:                 var ontAccessIdToOntAccessNameDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
  389:  
  390:                 foreach (var accessId in list)
  391:                 {
  392:                     if (ontAccessIdToOntAccessNameDictionary.ContainsKey(accessId))
  393:                     {
  394:                         accessName = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary[accessId];
  395:  
  396:                         if (!accessNameList.Contains(accessName))
  397:                         {
  398:                             accessNameList.Add(accessName);
  399:                         }
  400:                     }
  401:                 }
  402:             }
  403:             else
  404:             {
  405:                 accessNameList = new List<string>();
  406:             }
  407:  
  408:             return accessNameList;
  409:         }
  410:  
  411:         ////////////////////////////////////////////////////////////////////////////
  412:  
  413:         /// <summary>
  414:         /// List of service number ids within EmsOntSipInfos within a SIP allowed to be provisioned or migrated OLT
  415:         /// </summary>
  416:         public static List<string> ServiceIdWithinAllowedSipOltToBeProvisionedOrMigratedList()
  417:         {
  418:             int serviceType;
  419:             string service, serviceId;
  420:             List<int> sipOltIdList;
  421:             List<string> list, serviceIdList;
  422:  
  423:             serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  424:             sipOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
  425:  
  426:             using (var db = new Ia.Ftn.Cl.Db())
  427:             {
  428:                 list = (from o in db.EmsOntSipInfoes where o.EmsOnt.Access != null && sipOltIdList.Contains(o.EmsOnt.Access.Olt) select o.SIPUSERNAME).ToList();
  429:             }
  430:  
  431:             if (list != null && list.Count > 0)
  432:             {
  433:                 serviceIdList = new List<string>(list.Count);
  434:  
  435:                 foreach (string s in list)
  436:                 {
  437:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(s);
  438:  
  439:                     serviceId = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, serviceType);
  440:  
  441:                     serviceIdList.Add(serviceId);
  442:                 }
  443:             }
  444:             else
  445:             {
  446:                 serviceIdList = new List<string>();
  447:             }
  448:  
  449:             return serviceIdList;
  450:         }
  451:  
  452:         ////////////////////////////////////////////////////////////////////////////
  453:  
  454:         /// <summary>
  455:         ///
  456:         /// </summary>
  457:         public static List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> ServiceOntWithinAllowedSipOltToBeProvisionedOrMigratedList()
  458:         {
  459:             int serviceType;
  460:             string service, serviceId;
  461:             List<int> sipOltIdList;
  462:             List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated> tempSipUserNameList, serviceOntList;
  463:  
  464:             serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  465:             sipOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeProvisionedSipOltIdList.Union(Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedSipOltIdList).ToList();
  466:  
  467:             var ontAccessIdToOntForOltIdListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntForOltIdListDictionary(sipOltIdList);
  468:  
  469:             using (var db = new Ia.Ftn.Cl.Db())
  470:             {
  471:                 tempSipUserNameList = (from eosi in db.EmsOntSipInfoes
  472:                                        where eosi.EmsOnt.Access != null && sipOltIdList.Contains(eosi.EmsOnt.Access.Olt)
  473:                                        //                        select o.SIPUSERNAME).ToList();
  474:                                        select new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated { Service = eosi.SIPUSERNAME, AccessId = eosi.EmsOnt.Access.Id, CreatedDateTime = eosi.Created }).AsNoTracking().ToList();
  475:             }
  476:  
  477:             if (tempSipUserNameList != null && tempSipUserNameList.Count > 0)
  478:             {
  479:                 serviceOntList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>(tempSipUserNameList.Count);
  480:  
  481:                 foreach (var tsun in tempSipUserNameList)
  482:                 {
  483:                     service = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Service(tsun.Service); // so.Service here is o.SIPUSERNAME
  484:  
  485:                     serviceId = Ia.Ftn.Cl.Models.Business.Service.ServiceToServiceId(service, serviceType);
  486:  
  487:                     serviceOntList.Add(new Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated
  488:                     {
  489:                         ServiceId = serviceId,
  490:                         Service = service,
  491:                         AccessId = tsun.AccessId,
  492:                         Ont = ontAccessIdToOntForOltIdListDictionary.ContainsKey(tsun.AccessId) ? ontAccessIdToOntForOltIdListDictionary[tsun.AccessId] : null,
  493:                         CreatedDateTime = tsun.CreatedDateTime
  494:                     });
  495:                 }
  496:             }
  497:             else
  498:             {
  499:                 serviceOntList = new List<Ia.Ftn.Cl.Models.Business.ServiceAccessIpOntCreated>();
  500:             }
  501:  
  502:             return serviceOntList;
  503:         }
  504:  
  505:         ////////////////////////////////////////////////////////////////////////////
  506:  
  507:         /// <summary>
  508:         ///
  509:         /// </summary>
  510:         public static Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo Read(string id)
  511:         {
  512:             Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo item;
  513:  
  514:             using (var db = new Ia.Ftn.Cl.Db())
  515:             {
  516:                 item = (from o in db.EmsOntSipInfoes
  517:                         where o.Id == id
  518:                         select o).Include(o => o.EmsOnt).AsNoTracking().SingleOrDefault();
  519:             }
  520:  
  521:             return item;
  522:         }
  523:  
  524:         ////////////////////////////////////////////////////////////////////////////
  525:  
  526:         /// <summary>
  527:         ///
  528:         /// </summary>
  529:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> ReadByService(string service)
  530:         {
  531:             string huaweiSipName, nokiaSipName;
  532:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> list;
  533:  
  534:             huaweiSipName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Impi(service);
  535:             nokiaSipName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PrividUser(service);
  536:  
  537:             using (var db = new Ia.Ftn.Cl.Db())
  538:             {
  539:                 list = (from o in db.EmsOntSipInfoes
  540:                         where o.SIPNAME == huaweiSipName || o.SIPNAME == nokiaSipName
  541:                         select o).AsNoTracking().ToList();
  542:             }
  543:  
  544:             return list;
  545:         }
  546:  
  547:         ////////////////////////////////////////////////////////////////////////////
  548:  
  549:         /// <summary>
  550:         ///
  551:         /// </summary>
  552:         public static List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> ReadByServiceIncludeEmsOntAndAccess(string service) //, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
  553:         {
  554:             string huaweiSipName, nokiaSipName;
  555:             List<Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo> list;
  556:  
  557:             // send priv_96525212254 for Nokia switch and +96524602283@ims.moc.kw for Huawei switch
  558:             //if (nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
  559:             //{
  560:             huaweiSipName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.Impi(service);
  561:             //}
  562:             //else //if(ont.Pon.PonGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
  563:             //{
  564:             nokiaSipName = Ia.Ftn.Cl.Models.Business.NumberFormatConverter.PrividUser(service);
  565:             //}
  566:  
  567:             using (var db = new Ia.Ftn.Cl.Db())
  568:             {
  569:                 list = (from o in db.EmsOntSipInfoes
  570:                         where o.SIPNAME == huaweiSipName || o.SIPNAME == nokiaSipName
  571:                         select o).Include(o => o.EmsOnt).ThenInclude(o => o.Access).ToList(); //.FirstOrDefault(); //.SingleOrDefault();
  572:             }
  573:  
  574:             return list;
  575:         }
  576:  
  577:         ////////////////////////////////////////////////////////////////////////////
  578:  
  579:         /// <summary>
  580:         ///
  581:         /// </summary>
  582:         public static Dictionary<string, string> IdToOntIdDictionary
  583:         {
  584:             get
  585:             {
  586:                 Dictionary<string, string> dictionary;
  587:  
  588:                 using (var db = new Ia.Ftn.Cl.Db())
  589:                 {
  590:                     dictionary = (from s in db.EmsOntSipInfoes select new { s.Id, OntId = s.EmsOnt.Id }).ToDictionary(u => u.Id, u => u.OntId);
  591:                 }
  592:  
  593:                 return dictionary.ToDictionary(u => u.Key, u => u.Value);
  594:             }
  595:         }
  596:  
  597:         ////////////////////////////////////////////////////////////////////////////
  598:         ////////////////////////////////////////////////////////////////////////////
  599:  
  600:         /// <summary>
  601:         ///
  602:         /// </summary>
  603:         public static string ToSimpleTextString(Ia.Ftn.Cl.Models.Huawei.EmsOntSipInfo emsOntSipInfo)
  604:         {
  605:             StringBuilder sb;
  606:  
  607:             sb = new StringBuilder();
  608:  
  609:             //sb.AppendLine("Vendor: " + Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei.Name);
  610:             sb.AppendLine("TEL: " + emsOntSipInfo.TEL);
  611:             sb.AppendLine("SIPUSERNAME: " + emsOntSipInfo.SIPUSERNAME);
  612:             sb.AppendLine("SIPUSERPWD: " + emsOntSipInfo.SIPUSERPWD);
  613:             sb.AppendLine("SIPNAME: " + emsOntSipInfo.SIPNAME);
  614:  
  615:             return sb.ToString();
  616:         }
  617:  
  618:         ////////////////////////////////////////////////////////////////////////////
  619:         ////////////////////////////////////////////////////////////////////////////
  620:     }
  621:  
  622:     ////////////////////////////////////////////////////////////////////////////
  623:     ////////////////////////////////////////////////////////////////////////////
  624: }