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

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

Huawei's Dev 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.Model.Data.Huawei
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     /// Huawei's Dev support class of Fixed Telecommunications Network (FTN) data model.
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2016-2022 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 Dev
   30:     {
   31:         private static Dictionary<int, long> didToResultCodeDictionary;
   32:         private static Dictionary<string, int> devTypeToDevTypeIdDictionary;
   33:         private static Dictionary<int, string> devTypeIdToDevTypeDictionary;
   34:  
   35:         private static Dictionary<string, int> devToDidDictionary;
   36:         private static Dictionary<int, string> didToDevDictionary;
   37:  
   38:         private static Dictionary<string, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type> devToTypeDictionary;
   39:  
   40:         private static Dictionary<int, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type> didToTypeDictionary;
   41:  
   42:         private static DateTime didToResultCodeDictionaryFutureRefreshDateTime;
   43:  
   44:         private static readonly object objectLock = new object();
   45:  
   46:         public static Dictionary<string, int> DevTypeToDevTypeIdDictionary
   47:         {
   48:             get
   49:             {
   50:                 if (devTypeToDevTypeIdDictionary == null || devTypeToDevTypeIdDictionary.Count == 0)
   51:                 {
   52:                     devTypeToDevTypeIdDictionary = new Dictionary<string, int>();
   53:  
   54:                     devTypeToDevTypeIdDictionary["UA5000(PVMV1)"] = 219;
   55:                     devTypeToDevTypeIdDictionary["MA5662"] = 37;
   56:                     devTypeToDevTypeIdDictionary["MA5600V3"] = 44;
   57:                     devTypeToDevTypeIdDictionary["MA5105(BSL)"] = 71;
   58:                     devTypeToDevTypeIdDictionary["MA5100V2"] = 72;
   59:                     devTypeToDevTypeIdDictionary["MA5300V1"] = 74;
   60:                     devTypeToDevTypeIdDictionary["MD5500V1"] = 75;
   61:                     devTypeToDevTypeIdDictionary["UA5000"] = 82;
   62:                     devTypeToDevTypeIdDictionary["MA5100V1"] = 86;
   63:                     devTypeToDevTypeIdDictionary["UA5000(IPMB)"] = 253;
   64:                     devTypeToDevTypeIdDictionary["MA5605"] = 30;
   65:                     devTypeToDevTypeIdDictionary["MA5680T"] = 34;
   66:                     devTypeToDevTypeIdDictionary["MA5606T"] = 57;
   67:                     devTypeToDevTypeIdDictionary["UA5000(PVU)"] = 232;
   68:                     devTypeToDevTypeIdDictionary["MA5600T"] = 249;
   69:                     devTypeToDevTypeIdDictionary["MA5615"] = 60;
   70:                     devTypeToDevTypeIdDictionary["MA5626E"] = 61;
   71:                     devTypeToDevTypeIdDictionary["MA5620E"] = 62;
   72:                     devTypeToDevTypeIdDictionary["MA5651"] = 64;
   73:                     devTypeToDevTypeIdDictionary["MA5620G"] = 65;
   74:                     devTypeToDevTypeIdDictionary["MA5626G"] = 66;
   75:                     devTypeToDevTypeIdDictionary["MA5651G"] = 67;
   76:                     devTypeToDevTypeIdDictionary["MA5610"] = 70;
   77:                     devTypeToDevTypeIdDictionary["MA5652G"] = 92;
   78:                     devTypeToDevTypeIdDictionary["MA5603U"] = 94;
   79:                     devTypeToDevTypeIdDictionary["MA5603T"] = 95;
   80:                     devTypeToDevTypeIdDictionary["MA5620"] = 96;
   81:                     devTypeToDevTypeIdDictionary["MA5626"] = 97;
   82:                     devTypeToDevTypeIdDictionary["MA5616"] = 100;
   83:                     devTypeToDevTypeIdDictionary["MA5635"] = 103;
   84:                     devTypeToDevTypeIdDictionary["MA5612"] = 104;
   85:                     devTypeToDevTypeIdDictionary["MA5621"] = 2319;
   86:                     devTypeToDevTypeIdDictionary["MA5628"] = 2312;
   87:                     devTypeToDevTypeIdDictionary["MA5652"] = 2313;
   88:                     devTypeToDevTypeIdDictionary["MA5631"] = 2317;
   89:                     devTypeToDevTypeIdDictionary["MA5612A"] = 2320;
   90:                     devTypeToDevTypeIdDictionary["MA5669"] = 2321;
   91:                     devTypeToDevTypeIdDictionary["MA5621A"] = 2322;
   92:                     devTypeToDevTypeIdDictionary["MA5622A"] = 2323;
   93:                     devTypeToDevTypeIdDictionary["MA5623"] = 2324;
   94:                     devTypeToDevTypeIdDictionary["MA5623A"] = 2326;
   95:                     devTypeToDevTypeIdDictionary["MA5632"] = 2318;
   96:                     devTypeToDevTypeIdDictionary["MA5608T"] = 2331;
   97:                     devTypeToDevTypeIdDictionary["MA5698"] = 2333;
   98:                     devTypeToDevTypeIdDictionary["MA5694"] = 2335;
   99:                     devTypeToDevTypeIdDictionary["MA5821"] = 2336;
  100:                     devTypeToDevTypeIdDictionary["MA5822"] = 2337;
  101:                     devTypeToDevTypeIdDictionary["MA5898"] = 2338;
  102:                     devTypeToDevTypeIdDictionary["MA5818"] = 2339;
  103:                     devTypeToDevTypeIdDictionary["MA5611S"] = 2340;
  104:                     devTypeToDevTypeIdDictionary["MA5694S"] = 2343;
  105:                     devTypeToDevTypeIdDictionary["RPS"] = 2344;
  106:                 }
  107:  
  108:                 return devTypeToDevTypeIdDictionary;
  109:             }
  110:         }
  111:  
  112:         /// <summary/>
  113:         public Dev() { }
  114:  
  115:         ////////////////////////////////////////////////////////////////////////////
  116:  
  117:         /// <summary>
  118:         ///
  119:         /// </summary>
  120:         public static Dictionary<int, string> DevTypeIdToDevTypeDictionary
  121:         {
  122:             get
  123:             {
  124:                 if (devTypeIdToDevTypeDictionary == null || devTypeIdToDevTypeDictionary.Count == 0)
  125:                 {
  126:                     devTypeIdToDevTypeDictionary = new Dictionary<int, string>();
  127:  
  128:                     foreach (KeyValuePair<string, int> kvp in DevTypeToDevTypeIdDictionary) devTypeIdToDevTypeDictionary[kvp.Value] = kvp.Key;
  129:                 }
  130:  
  131:                 return devTypeIdToDevTypeDictionary;
  132:             }
  133:         }
  134:  
  135:         ////////////////////////////////////////////////////////////////////////////
  136:  
  137:         /// <summary>
  138:         ///
  139:         /// </summary>
  140:         public static Dictionary<string, int> DevToDidDictionary
  141:         {
  142:             get
  143:             {
  144:                 if (devToDidDictionary == null || devToDidDictionary.Count == 0)
  145:                 {
  146:                     devToDidDictionary = new Dictionary<string, int>();
  147:  
  148:                     List<Ia.Ftn.Cl.Model.Huawei.EmsDev> list;
  149:  
  150:                     using (var db = new Ia.Ftn.Cl.Model.Db())
  151:                     {
  152:                         // this will list the Disconnecting devs first so that if there is an override it will allow the Connecting to be in dictionary
  153:                         list = (from ed in db.EmsDevs select ed).OrderBy(u => u.DSTAT == "Connecting").ToList();
  154:                     }
  155:  
  156:                     foreach (var d in list) devToDidDictionary[d.DEV] = d.DID;
  157:                 }
  158:  
  159:                 return devToDidDictionary;
  160:             }
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:  
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         public static Dictionary<int, long> DidToResultCodeDictionary
  169:         {
  170:             get
  171:             {
  172:                 var now = DateTime.UtcNow.AddHours(3);
  173:  
  174:                 if (didToResultCodeDictionary == null || didToResultCodeDictionary.Count == 0 || now > didToResultCodeDictionaryFutureRefreshDateTime)
  175:                 {
  176:                     lock (objectLock)
  177:                     {
  178:                         didToResultCodeDictionary = Ia.Ftn.Cl.Model.Data.Huawei.Dev._DidToResultCodeDictionary(60); // one hour
  179:                     }
  180:                 }
  181:  
  182:                 return didToResultCodeDictionary;
  183:             }
  184:         }
  185:  
  186:         ////////////////////////////////////////////////////////////////////////////
  187:  
  188:         /// <summary>
  189:         ///
  190:         /// </summary>
  191:         private static Dictionary<int, long> _DidToResultCodeDictionary(int minutesToKeepDataValid)
  192:         {
  193:             var now = DateTime.UtcNow.AddHours(3);
  194:  
  195:             didToResultCodeDictionaryFutureRefreshDateTime = now.AddMinutes(minutesToKeepDataValid);
  196:  
  197:             using (var db = new Ia.Ftn.Cl.Model.Db())
  198:             {
  199:                 didToResultCodeDictionary = (from ed in db.EmsDevs
  200:                                              select new { ed.DID, ed.ResultCode }).AsNoTracking().ToDictionary(u => u.DID, u => u.ResultCode);
  201:             }
  202:  
  203:             return didToResultCodeDictionary;
  204:         }
  205:  
  206:         ////////////////////////////////////////////////////////////////////////////
  207:  
  208:         /// <summary>
  209:         ///
  210:         /// </summary>
  211:         public static Dictionary<string, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type> DevToTypeDictionary
  212:         {
  213:             get
  214:             {
  215:                 if (devToTypeDictionary == null || devToTypeDictionary.Count == 0)
  216:                 {
  217:                     devToTypeDictionary = new Dictionary<string, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type>();
  218:  
  219:                     foreach (var dev in Ia.Ftn.Cl.Model.Data.Huawei.Dev.List()) devToTypeDictionary[dev.DEV] = dev.Type;
  220:                 }
  221:  
  222:                 return devToTypeDictionary;
  223:             }
  224:         }
  225:  
  226:         ////////////////////////////////////////////////////////////////////////////
  227:  
  228:         /// <summary>
  229:         ///
  230:         /// </summary>
  231:         public static Dictionary<int, string> DidToDevDictionary
  232:         {
  233:             get
  234:             {
  235:                 if (didToDevDictionary == null || didToDevDictionary.Count == 0)
  236:                 {
  237:                     didToDevDictionary = new Dictionary<int, string>();
  238:  
  239:                     foreach (KeyValuePair<string, int> kvp in DevToDidDictionary) didToDevDictionary[kvp.Value] = kvp.Key;
  240:                 }
  241:  
  242:                 return didToDevDictionary;
  243:             }
  244:         }
  245:  
  246:         ////////////////////////////////////////////////////////////////////////////
  247:  
  248:         /// <summary>
  249:         ///
  250:         /// </summary>
  251:         public static Dictionary<int, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type> DidToTypeDictionary
  252:         {
  253:             get
  254:             {
  255:                 if (didToTypeDictionary == null || didToTypeDictionary.Count == 0)
  256:                 {
  257:                     didToTypeDictionary = new Dictionary<int, Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type>();
  258:  
  259:                     foreach (KeyValuePair<int, string> kvp in DidToDevDictionary)
  260:                     {
  261:                         didToTypeDictionary[kvp.Key] = DevToTypeDictionary.ContainsKey(kvp.Value) ? DevToTypeDictionary[kvp.Value] : Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type.Unknown;
  262:                     }
  263:                 }
  264:  
  265:                 return didToTypeDictionary;
  266:             }
  267:         }
  268:  
  269:         ////////////////////////////////////////////////////////////////////////////
  270:  
  271:         /// <summary>
  272:         ///
  273:         /// </summary>
  274:         public static bool Update(Ia.Ftn.Cl.Model.Business.Huawei.Ems.Response response, out Ia.Cl.Models.Result result)
  275:         {
  276:             bool isUpdated;
  277:             int id, queryDtTypeId, did, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
  278:             string queryCommand, queryDev, devDev, dtType;
  279:             DataColumnCollection columns;
  280:             DataRow columnDataRow;
  281:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  282:             Ia.Ftn.Cl.Model.Huawei.EmsDev dev, devByDev, newDev;
  283:             List<int> itemIdList;
  284:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> devList;
  285:  
  286:             isUpdated = false;
  287:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  288:             result = new Ia.Cl.Models.Result();
  289:  
  290:             if (response.CompletionCode == "COMPLD")
  291:             {
  292:                 if (response.QueryDataTable != null)
  293:                 {
  294:                     queryCommand = response.CommandFromCorrelationTagDictionaryByCtag;
  295:  
  296:                     columns = response.QueryDataTable.Columns;
  297:                     readItemCount = response.QueryDataTable.Rows.Count;
  298:  
  299:                     itemIdList = new List<int>(response.QueryDataTable.Rows.Count + 1);
  300:  
  301:                     using (var db = new Ia.Ftn.Cl.Model.Db())
  302:                     {
  303:                         if (queryCommand.Contains("LST-DEV::DT") || queryCommand.Contains("LST-DEV::DEV"))
  304:                         {
  305:                             if (queryCommand.Contains("LST-DEV::DT"))
  306:                             {
  307:                                 // LST-DEV::DT=100:{ctag}::;
  308:                                 queryDtTypeId = int.Parse(Ia.Cl.Models.Default.Match(queryCommand, @"DT=(\d+)"));
  309:  
  310:                                 //if (Ia.Ftn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary.ContainsKey(queryDtTypeId))
  311:                                 //{
  312:                                 dtType = Ia.Ftn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary[queryDtTypeId];
  313:  
  314:                                 devList = (from ed in db.EmsDevs where ed.DT == dtType select ed).ToList();
  315:                                 //}
  316:                                 //else
  317:                                 //{
  318:                                 //    result.AddWarning("Ia.Ftn.Cl.Model.Data.Huawei.Dev.DevTypeIdToDevTypeDictionary does not contain key queryDtTypeId: " + queryDtTypeId);
  319:                                 //}
  320:                             }
  321:                             else //if (queryCommand.Contains("LST-DEV::DEV"))
  322:                             {
  323:                                 // LST-DEV::DEV=MDU-SAB-1443-001:{ctag}::;
  324:  
  325:                                 queryDev = Ia.Cl.Models.Default.Match(queryCommand, @"DEV=(.+?):");
  326:  
  327:                                 devList = (from ed in db.EmsDevs where ed.DEV == queryDev select ed).ToList();
  328:                             }
  329:  
  330:                             existingItemCount = devList.Count;
  331:  
  332:                             if (response.QueryDataTable.Rows.Count >= 1)
  333:                             {
  334:                                 columnDataRow = response.QueryDataTable.Rows[0];
  335:  
  336:                                 foreach (DataRow dataRow in response.QueryDataTable.Rows)
  337:                                 {
  338:                                     did = int.Parse(dataRow[columns.IndexOf("DID")].ToString());
  339:  
  340:                                     id = Ia.Ftn.Cl.Model.Business.Huawei.Dev.DevId(did);
  341:  
  342:                                     dev = (from d in devList where d.Id == id select d).SingleOrDefault();
  343:  
  344:                                     devDev = columns.Contains("DEV") ? dataRow[columns.IndexOf("DEV")].ToString() : string.Empty;
  345:  
  346:                                     newDev = new Ia.Ftn.Cl.Model.Huawei.EmsDev()
  347:                                     {
  348:                                         Id = id,
  349:                                         DID = did,
  350:                                         ResultCode = (long)response.ResultCode,
  351:                                         DEV = devDev,
  352:                                         DEVIP = columns.Contains("DEVIP") ? dataRow[columns.IndexOf("DEVIP")].ToString() : string.Empty,
  353:                                         DT = columns.Contains("DT") ? dataRow[columns.IndexOf("DT")].ToString() : string.Empty,
  354:                                         DVER = columns.Contains("DVER") ? dataRow[columns.IndexOf("DVER")].ToString() : string.Empty,
  355:                                         DSTAT = columns.Contains("DSTAT") ? dataRow[columns.IndexOf("DSTAT")].ToString() : string.Empty,
  356:                                         DLOC = columns.Contains("DLOC") ? dataRow[columns.IndexOf("DLOC")].ToString() : string.Empty,
  357:                                         AdminStat = columns.Contains("AdminStat") ? dataRow[columns.IndexOf("AdminStat")].ToString() : string.Empty,
  358:                                         WorkMode = columns.Contains("WorkMode") ? dataRow[columns.IndexOf("WorkMode")].ToString() : string.Empty,
  359:                                         ADDITIONALINFO = columns.Contains("ADDITIONALINFO") ? dataRow[columns.IndexOf("ADDITIONALINFO")].ToString() : string.Empty,
  360:                                         CRTID = columns.Contains("CRTID") ? dataRow[columns.IndexOf("CRTID")].ToString() : string.Empty,
  361:                                         CRTADDR = columns.Contains("CRTADDR") ? dataRow[columns.IndexOf("CRTADDR")].ToString() : string.Empty,
  362:                                         CRTTEL = columns.Contains("CRTTEL") ? dataRow[columns.IndexOf("CRTTEL")].ToString() : string.Empty,
  363:                                         CRTDATE = columns.Contains("CRTDATE") ? dataRow[columns.IndexOf("CRTDATE")].ToString() : string.Empty,
  364:                                         REMARK = columns.Contains("REMARK") ? dataRow[columns.IndexOf("REMARK")].ToString() : string.Empty,
  365:                                         TYPE = columns.Contains("TYPE") ? dataRow[columns.IndexOf("TYPE")].ToString() : string.Empty,
  366:                                         NERATELIST = columns.Contains("NERATELIST") ? dataRow[columns.IndexOf("NERATELIST")].ToString() : string.Empty,
  367:                                         NEPROV = columns.Contains("NEPROV") ? dataRow[columns.IndexOf("NEPROV")].ToString() : string.Empty,
  368:                                         TOPXY = columns.Contains("TOPXY") ? dataRow[columns.IndexOf("TOPXY")].ToString() : string.Empty,
  369:                                         EMSID = columns.Contains("EMSID") ? dataRow[columns.IndexOf("EMSID")].ToString() : string.Empty,
  370:                                         ALIAS = columns.Contains("ALIAS") ? dataRow[columns.IndexOf("ALIAS")].ToString() : string.Empty,
  371:                                         PCBVER = columns.Contains("PCBVER") ? dataRow[columns.IndexOf("PCBVER")].ToString() : string.Empty,
  372:                                         MAINTAINID = columns.Contains("MAINTAINID") ? dataRow[columns.IndexOf("MAINTAINID")].ToString() : string.Empty,
  373:                                         MAINTAINADDR = columns.Contains("MAINTAINADDR") ? dataRow[columns.IndexOf("MAINTAINADDR")].ToString() : string.Empty,
  374:                                         MAINTAINTEL = columns.Contains("MAINTAINTEL") ? dataRow[columns.IndexOf("MAINTAINTEL")].ToString() : string.Empty,
  375:                                         REGISTERSTAT = columns.Contains("REGISTERSTAT") ? dataRow[columns.IndexOf("REGISTERSTAT")].ToString() : string.Empty,
  376:                                     };
  377:  
  378:                                     nddOnt = Ia.Ftn.Cl.Model.Business.Default.NddOntFromHuaweiEmsAccessNameFormat(devDev);
  379:                                     if (nddOnt != null) newDev.Access = (from a in db.Accesses where a.Id == nddOnt.Access.Id select a).SingleOrDefault();
  380:  
  381:                                     if (dev == null)
  382:                                     {
  383:                                         devByDev = (from d in devList where d.DEV == devDev select d).SingleOrDefault();
  384:  
  385:                                         if (devByDev == null)
  386:                                         {
  387:                                             newDev.Created = newDev.Updated = DateTime.UtcNow.AddHours(3);
  388:  
  389:                                             db.EmsDevs.Add(newDev);
  390:  
  391:                                             insertedItemCount++;
  392:                                         }
  393:                                         else
  394:                                         {
  395:                                             throw new Exception("Ia.Ftn.Cl.Model.Data.Huawei.Dev.Update(): There is alreay a Dev with the same name: " + devDev + " but different Id. You should check the database and maybe delete the current, old dev entry. ");
  396:                                         }
  397:                                     }
  398:                                     else // update
  399:                                     {
  400:                                         // below: copy values from newDev to dev
  401:  
  402:                                         if (dev.Update(newDev))
  403:                                         {
  404:                                             db.EmsDevs.Attach(dev);
  405:                                             db.Entry(dev).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  406:  
  407:                                             updatedItemCount++;
  408:                                         }
  409:                                     }
  410:  
  411:                                     itemIdList.Add(id); // keep at the end
  412:                                 }
  413:  
  414:                                 // below: this function will remove values that were not present in the reading
  415:                                 if (devList.Count > 0)
  416:                                 {
  417:                                     foreach (Ia.Ftn.Cl.Model.Huawei.EmsDev de in devList)
  418:                                     {
  419:                                         if (!itemIdList.Contains(de.Id))
  420:                                         {
  421:                                             dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
  422:  
  423:                                             db.EmsDevs.Remove(dev);
  424:  
  425:                                             deletedItemCount++;
  426:                                         }
  427:                                     }
  428:                                 }
  429:                             }
  430:                             else
  431:                             {
  432:                                 // below: remove all values since reading was empty
  433:  
  434:                                 if (devList.Count > 0)
  435:                                 {
  436:                                     foreach (Ia.Ftn.Cl.Model.Huawei.EmsDev de in devList)
  437:                                     {
  438:                                         dev = (from ed in db.EmsDevs where ed.Id == de.Id select ed).SingleOrDefault();
  439:  
  440:                                         db.EmsDevs.Remove(dev);
  441:  
  442:                                         deletedItemCount++;
  443:                                     }
  444:                                 }
  445:                             }
  446:                         }
  447:                         else
  448:                         {
  449:                             result.AddWarning("LST-DEV (" + response.Ctag + "): Ia.Ftn.Cl.Model.Data.Huawei.Dev.Update() Unknown parameters in command: " + queryCommand);
  450:                         }
  451:  
  452:                         try
  453:                         {
  454:                             db.SaveChanges();
  455:                         }
  456:                         catch (Exception ex)
  457:                         {
  458:  
  459:                         }
  460:                     }
  461:  
  462:                     if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  463:                     else isUpdated = false;
  464:  
  465:                     result.AddSuccess("LST-DEV (" + response.Ctag + "): (" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ")");
  466:                 }
  467:                 else
  468:                 {
  469:                     result.AddWarning("LST-DEV (" + response.Ctag + "): QueryDataTable is null, (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  470:                 }
  471:             }
  472:             else
  473:             {
  474:                 result.AddWarning("LST-DEV (" + response.Ctag + "): (" + response.CompletionCode + ", " + response.ResultCode.ToString() + ")");
  475:             }
  476:  
  477:             return isUpdated;
  478:         }
  479:  
  480:         ////////////////////////////////////////////////////////////////////////////
  481:  
  482:         /// <summary>
  483:         ///
  484:         /// </summary>
  485:         public static bool UpdateResultCode(int emsDevDid, Ia.Ftn.Cl.Model.Client.Huawei.Ems.ResultCode resultCode)
  486:         {
  487:             // similar to Ia.Ftn.Cl.Model.Data.Huawei.Ont.UpdateResultCode();
  488:             bool isUpdated;
  489:  
  490:             using (var db = new Ia.Ftn.Cl.Model.Db())
  491:             {
  492:                 if (emsDevDid > 0)
  493:                 {
  494:                     var updatedDev = (from o in db.EmsDevs where o.DID == emsDevDid select o).SingleOrDefault();
  495:  
  496:                     if (updatedDev != null)
  497:                     {
  498:                         if (updatedDev.ResultCode != (long)resultCode)
  499:                         {
  500:                             updatedDev.ResultCode = (long)resultCode;
  501:                             updatedDev.Updated = DateTime.UtcNow.AddHours(3);
  502:  
  503:                             db.EmsDevs.Attach(updatedDev);
  504:                             db.Entry(updatedDev).Property(u => u.ResultCode).IsModified = true;
  505:                             db.Entry(updatedDev).Property(u => u.Updated).IsModified = true;
  506:  
  507:                             db.SaveChanges();
  508:  
  509:                             isUpdated = true;
  510:                             //result.AddSuccess("EmsDevs.ResultCode updated. ");
  511:                         }
  512:                         else
  513:                         {
  514:                             isUpdated = false;
  515:                             // result.AddWarning("Warning: EmsDevs.ResultCode value was not updated because its the same. ");
  516:                         }
  517:                     }
  518:                     else
  519:                     {
  520:                         isUpdated = false;
  521:                         // result.AddError("Error: updatedDev is null. ");
  522:                     }
  523:                 }
  524:                 else
  525:                 {
  526:                     isUpdated = false;
  527:                 }
  528:             }
  529:  
  530:             return isUpdated;
  531:         }
  532:  
  533:         ////////////////////////////////////////////////////////////////////////////
  534:  
  535:         /// <summary>
  536:         ///
  537:         /// </summary>
  538:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> List()
  539:         {
  540:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> list;
  541:  
  542:             using (var db = new Ia.Ftn.Cl.Model.Db())
  543:             {
  544:                 list = (from ed in db.EmsDevs select ed).AsNoTracking().ToList();
  545:             }
  546:  
  547:             return list;
  548:         }
  549:  
  550:         ////////////////////////////////////////////////////////////////////////////
  551:  
  552:         /// <summary>
  553:         ///
  554:         /// </summary>
  555:         public static List<string> DevList()
  556:         {
  557:             List<string> list;
  558:  
  559:             using (var db = new Ia.Ftn.Cl.Model.Db())
  560:             {
  561:                 list = (from ed in db.EmsDevs select ed.DEV).ToList();
  562:             }
  563:  
  564:             return list;
  565:         }
  566:  
  567:         ////////////////////////////////////////////////////////////////////////////
  568:  
  569:         /// <summary>
  570:         ///
  571:         /// </summary>
  572:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> ListByMA5616DevType()
  573:         {
  574:             return ListByDevType("MA5616");
  575:         }
  576:  
  577:         ////////////////////////////////////////////////////////////////////////////
  578:  
  579:         /// <summary>
  580:         ///
  581:         /// </summary>
  582:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> ListByDevType(string devType)
  583:         {
  584:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> list;
  585:  
  586:             using (var db = new Ia.Ftn.Cl.Model.Db())
  587:             {
  588:                 list = (from ed in db.EmsDevs where ed.DT == devType select ed).ToList();
  589:             }
  590:  
  591:             return list;
  592:         }
  593:  
  594:         ////////////////////////////////////////////////////////////////////////////
  595:  
  596:         /// <summary>
  597:         ///
  598:         /// </summary>
  599:         public static Ia.Ftn.Cl.Model.Huawei.EmsDev Read(int id)
  600:         {
  601:             Ia.Ftn.Cl.Model.Huawei.EmsDev item;
  602:  
  603:             using (var db = new Ia.Ftn.Cl.Model.Db())
  604:             {
  605:                 item = (from ed in db.EmsDevs where ed.Id == id select ed).SingleOrDefault();
  606:             }
  607:  
  608:             return item;
  609:         }
  610:  
  611:         ////////////////////////////////////////////////////////////////////////////
  612:  
  613:         /// <summary>
  614:         ///
  615:         /// </summary>
  616:         public static Ia.Ftn.Cl.Model.Huawei.EmsDev ReadByEmsName(string emsName)
  617:         {
  618:             Ia.Ftn.Cl.Model.Huawei.EmsDev item;
  619:  
  620:             using (var db = new Ia.Ftn.Cl.Model.Db())
  621:             {
  622:                 item = (from ed in db.EmsDevs where ed.DEV == emsName select ed).SingleOrDefault();
  623:             }
  624:  
  625:             return item;
  626:         }
  627:  
  628:         ////////////////////////////////////////////////////////////////////////////
  629:  
  630:         /// <summary>
  631:         ///
  632:         /// </summary>
  633:         public static Ia.Ftn.Cl.Model.Huawei.EmsDev ReadByDev(string dev)
  634:         {
  635:             Ia.Ftn.Cl.Model.Huawei.EmsDev item;
  636:  
  637:             using (var db = new Ia.Ftn.Cl.Model.Db())
  638:             {
  639:                 item = (from ed in db.EmsDevs where ed.DEV == dev select ed).SingleOrDefault();
  640:             }
  641:  
  642:             return item;
  643:         }
  644:  
  645:         ////////////////////////////////////////////////////////////////////////////
  646:  
  647:         /// <summary>
  648:         ///
  649:         /// </summary>
  650:         public static Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type ReadTypeByDev(string dev)
  651:         {
  652:             Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type type;
  653:  
  654:             if (Ia.Ftn.Cl.Model.Data.Huawei.Dev.DevToTypeDictionary.ContainsKey(dev))
  655:             {
  656:                 type = devToTypeDictionary[dev];
  657:             }
  658:             else type = Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type.Unknown;
  659:  
  660:             return type;
  661:         }
  662:  
  663:         ////////////////////////////////////////////////////////////////////////////
  664:  
  665:         /// <summary>
  666:         ///
  667:         /// </summary>
  668:         public static Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type ReadTypeByDid(int did)
  669:         {
  670:             Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type type;
  671:  
  672:             var d = DidToTypeDictionary;
  673:  
  674:             type = (d.ContainsKey(did)) ? d[did] : Ia.Ftn.Cl.Model.Business.Huawei.Dev.Type.Unknown;
  675:  
  676:             return type;
  677:         }
  678:  
  679:         ////////////////////////////////////////////////////////////////////////////
  680:  
  681:         /// <summary>
  682:         ///
  683:         /// </summary>
  684:         public static Ia.Ftn.Cl.Model.Huawei.EmsDev ReadByDid(int did)
  685:         {
  686:             Ia.Ftn.Cl.Model.Huawei.EmsDev item;
  687:  
  688:             using (var db = new Ia.Ftn.Cl.Model.Db())
  689:             {
  690:                 item = (from ed in db.EmsDevs where ed.DID == did select ed).SingleOrDefault();
  691:             }
  692:  
  693:             return item;
  694:         }
  695:  
  696:         ////////////////////////////////////////////////////////////////////////////
  697:  
  698:         /// <summary>
  699:         ///
  700:         /// </summary>
  701:         public static Ia.Ftn.Cl.Model.Huawei.EmsDev ReadByAccessId(string accessId)
  702:         {
  703:             Ia.Ftn.Cl.Model.Huawei.EmsDev item;
  704:  
  705:             using (var db = new Ia.Ftn.Cl.Model.Db())
  706:             {
  707:                 item = (from ed in db.EmsDevs where ed.Access != null && ed.Access.Id == accessId select ed).SingleOrDefault();
  708:             }
  709:  
  710:             return item;
  711:         }
  712:  
  713:         ////////////////////////////////////////////////////////////////////////////
  714:  
  715:         /// <summary>
  716:         /// Return Devs with similar names
  717:         /// </summary>
  718:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> RedundantDevList()
  719:         {
  720:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> devs;
  721:  
  722:             using (var db = new Ia.Ftn.Cl.Model.Db())
  723:             {
  724:                 // select * from EmsDevs ed1 left outer join EmsDevs ed2 on ed1.DEV = ed2.DEV where ed1.Id <> ed2.Id
  725:  
  726:                 devs = (from ed1 in db.EmsDevs
  727:                         join ed2 in db.EmsDevs on ed1.DEV equals ed2.DEV
  728:                         where ed2.DID != ed2.DID
  729:                         select ed1).AsNoTracking().ToList();
  730:             }
  731:  
  732:             return devs;
  733:         }
  734:  
  735:         ////////////////////////////////////////////////////////////////////////////
  736:  
  737:         /// <summary>
  738:         ///
  739:         /// </summary>
  740:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> OltDevList()
  741:         {
  742:             var oltDtType = new List<string>() { "MA5600T", "MA5603T" };
  743:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> list;
  744:  
  745:             list = new List<Ia.Ftn.Cl.Model.Huawei.EmsDev>();
  746:  
  747:             using (var db = new Ia.Ftn.Cl.Model.Db())
  748:             {
  749:                 list = (from ed in db.EmsDevs
  750:                         where oltDtType.Contains(ed.DT) && ed.DEV.Contains("OLT")
  751:                         select ed).ToList();
  752:             }
  753:  
  754:             return list;
  755:         }
  756:  
  757:         ////////////////////////////////////////////////////////////////////////////
  758:  
  759:         /// <summary>
  760:         ///
  761:         /// </summary>
  762:         public static List<string> OltDevDevList()
  763:         {
  764:             var list = new List<string>();
  765:  
  766:             var oltDevList = Ia.Ftn.Cl.Model.Data.Huawei.Dev.OltDevList();
  767:  
  768:             foreach (var dev in oltDevList)
  769:             {
  770:                 list.Add(dev.DEV);
  771:             }
  772:  
  773:             return list;
  774:         }
  775:  
  776:         ////////////////////////////////////////////////////////////////////////////
  777:  
  778:         /// <summary>
  779:         ///
  780:         /// </summary>
  781:         public static List<Ia.Ftn.Cl.Model.Huawei.EmsDev> MsanDevList()
  782:         {
  783:             List<Ia.Ftn.Cl.Model.Huawei.EmsDev> list;
  784:  
  785:             using (var db = new Ia.Ftn.Cl.Model.Db())
  786:             {
  787:                 list = (from ed in db.EmsDevs where ed.DEV.Contains("_MSAN_") select ed).AsNoTracking().ToList();
  788:             }
  789:  
  790:             return list;
  791:         }
  792:  
  793:         ////////////////////////////////////////////////////////////////////////////
  794:  
  795:         /// <summary>
  796:         ///
  797:         /// </summary>
  798:         public static List<string> MsanDevDevList()
  799:         {
  800:             List<string> list;
  801:  
  802:             using (var db = new Ia.Ftn.Cl.Model.Db())
  803:             {
  804:                 list = (from ed in db.EmsDevs where ed.DEV.Contains("_MSAN_") select ed.DEV).AsNoTracking().ToList();
  805:             }
  806:  
  807:             return list;
  808:         }
  809:  
  810:         ////////////////////////////////////////////////////////////////////////////
  811:  
  812:         /// <summary>
  813:         ///
  814:         /// </summary>
  815:         public static List<int> MsanDevDidList()
  816:         {
  817:             List<int> list;
  818:  
  819:             using (var db = new Ia.Ftn.Cl.Model.Db())
  820:             {
  821:                 list = (from ed in db.EmsDevs where ed.DEV.Contains("_MSAN_") select ed.DID).ToList();
  822:             }
  823:  
  824:             return list;
  825:         }
  826:  
  827:         ////////////////////////////////////////////////////////////////////////////
  828:  
  829:         /// <summary>
  830:         ///
  831:         /// </summary>
  832:         public static Dictionary<int, int> MsanDidToSiteIdDictionary()
  833:         {
  834:             Dictionary<int, int> dictionary;
  835:  
  836:             var msanDevList = Ia.Ftn.Cl.Model.Data.Huawei.Default.MsanDevList;
  837:  
  838:             dictionary = new Dictionary<int, int>();
  839:  
  840:             foreach (var msanDev in msanDevList)
  841:             {
  842:                 dictionary[msanDev.Did] = msanDev.Msan.Site.Id;
  843:             }
  844:  
  845:             return dictionary;
  846:         }
  847:  
  848:         ////////////////////////////////////////////////////////////////////////////
  849:  
  850:         /// <summary>
  851:         ///
  852:         /// </summary>
  853:         public static Dictionary<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site, List<int>> MsanSiteToDidListDictionary()
  854:         {
  855:             var msanDevList = Ia.Ftn.Cl.Model.Data.Huawei.Default.MsanDevList;
  856:  
  857:             var dictionary = new Dictionary<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site, List<int>>();
  858:  
  859:             foreach (var msanDev in msanDevList)
  860:             {
  861:                 var site = msanDev.Msan.Site;
  862:  
  863:                 if (!dictionary.ContainsKey(site)) dictionary[site] = new List<int>();
  864:  
  865:                 dictionary[site].Add(msanDev.Did);
  866:             }
  867:  
  868:             return dictionary;
  869:         }
  870:  
  871:         ////////////////////////////////////////////////////////////////////////////
  872:  
  873:         /// <summary>
  874:         ///
  875:         /// </summary>
  876:         public static Dictionary<int, List<int>> MsanSiteIdToDidListDictionary()
  877:         {
  878:             Dictionary<int, List<int>> dictionary;
  879:  
  880:             var msanDevList = Ia.Ftn.Cl.Model.Data.Huawei.Default.MsanDevList;
  881:  
  882:             dictionary = new Dictionary<int, List<int>>();
  883:  
  884:             foreach (var msanDev in msanDevList)
  885:             {
  886:                 var id = msanDev.Msan.Site.Id;
  887:  
  888:                 if (!dictionary.ContainsKey(id)) dictionary[id] = new List<int>();
  889:  
  890:                 dictionary[id].Add(msanDev.Did);
  891:             }
  892:  
  893:             return dictionary;
  894:         }
  895:  
  896:         ////////////////////////////////////////////////////////////////////////////
  897:  
  898:         /// <summary>
  899:         ///
  900:         /// </summary>
  901:         public static Dictionary<int, int> MsanSiteIdToCapacityDictionary()
  902:         {
  903:             Dictionary<int, int> dictionary;
  904:  
  905:             var msanDevList = Ia.Ftn.Cl.Model.Data.Huawei.Default.MsanDevList;
  906:  
  907:             dictionary = new Dictionary<int, int>();
  908:  
  909:             foreach (var msanDev in msanDevList)
  910:             {
  911:                 var id = msanDev.Msan.Site.Id;
  912:  
  913:                 if (!dictionary.ContainsKey(id)) dictionary[id] = 0;
  914:  
  915:                 dictionary[id] += msanDev.Capacity;
  916:             }
  917:  
  918:             return dictionary;
  919:         }
  920:  
  921:         ////////////////////////////////////////////////////////////////////////////
  922:  
  923:         /// <summary>
  924:         ///
  925:         /// </summary>
  926:         public static bool NullifyAccessIdByAccessId(string accessId, out string result)
  927:         {
  928:             bool b;
  929:             int numberOfRecordsWhereAccessIsNullified;
  930:             Ia.Ftn.Cl.Model.Huawei.EmsDev dev;
  931:  
  932:             b = false;
  933:             numberOfRecordsWhereAccessIsNullified = 0;
  934:  
  935:             using (var db = new Ia.Ftn.Cl.Model.Db())
  936:             {
  937:                 // --update EmsOnts set Access_Id = null where Access_Id = '1040101010040004'
  938:                 //var query = (from eo in db.EmsOnts where eo.Access.Id == accessId select eo).ToList();
  939:  
  940:                 //foreach (var v in query)
  941:                 //{
  942:                 dev = (from o in db.EmsDevs where o.Access.Id == accessId select o).Include(u => u.Access).FirstOrDefault(); //.SingleOrDefault();
  943:  
  944:                 if (dev != null)
  945:                 {
  946:                     dev.Access = null;
  947:                     dev.Updated = DateTime.UtcNow.AddHours(3);
  948:  
  949:                     db.EmsDevs.Attach(dev);
  950:                     db.Entry(dev).Property(u => u.Updated).IsModified = true;
  951:  
  952:                     db.SaveChanges();
  953:  
  954:                     numberOfRecordsWhereAccessIsNullified++;
  955:                 }
  956:                 //}
  957:  
  958:                 b = true;
  959:             }
  960:  
  961:             result = "Number of records where access is nullified: " + numberOfRecordsWhereAccessIsNullified;
  962:  
  963:             return b;
  964:         }
  965:  
  966:         ////////////////////////////////////////////////////////////////////////////
  967:  
  968:         /// <summary>
  969:         ///
  970:         /// </summary>
  971:         public static string EmsDevDevByEmsDevDid(int did)
  972:         {
  973:             string s;
  974:             var didToDevDictionary = Ia.Ftn.Cl.Model.Data.Huawei.Dev.DidToDevDictionary;
  975:  
  976:             if (didToDevDictionary.ContainsKey(did)) s = didToDevDictionary[did];
  977:             else s = string.Empty;
  978:  
  979:             return s;
  980:         }
  981:  
  982:         ////////////////////////////////////////////////////////////////////////////
  983:         ////////////////////////////////////////////////////////////////////////////
  984:  
  985:         /// <summary>
  986:         ///
  987:         /// </summary>
  988:         public static string ToSimpleTextString(Ia.Ftn.Cl.Model.Huawei.EmsDev emsDev)
  989:         {
  990:             StringBuilder sb;
  991:  
  992:             sb = new StringBuilder();
  993:  
  994:             sb.AppendLine("DID: " + emsDev.DID);
  995:             sb.AppendLine("DEV: " + emsDev.DEV);
  996:             sb.AppendLine("DEVIP: " + emsDev.DEVIP);
  997:             sb.AppendLine("DT: " + emsDev.DT);
  998:             sb.AppendLine("DVER: " + emsDev.DVER);
  999:             sb.AppendLine("DSTAT: " + emsDev.DSTAT);
 1000:  
 1001:             return sb.ToString();
 1002:         }
 1003:  
 1004:         ////////////////////////////////////////////////////////////////////////////
 1005:         ////////////////////////////////////////////////////////////////////////////
 1006:     }
 1007:  
 1008:     ////////////////////////////////////////////////////////////////////////////
 1009:     ////////////////////////////////////////////////////////////////////////////
 1010: }