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