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

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

Network Design Document support class for Fixed Telecommunications Network (FTN) data model.

    1: using System;
    2: using System.Collections;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.IO;
    6: using System.Linq;
    7: using System.Reflection;
    8: using System.Text;
    9: using System.Text.RegularExpressions;
   10: using System.Xml;
   11: using System.Xml.Linq;
   12: using System.Xml.Schema;
   13:  
   14: namespace Ia.Ftn.Cl.Models.Data
   15: {
   16:     ////////////////////////////////////////////////////////////////////////////
   17:  
   18:     /// <summary publish="true">
   19:     /// Network Design Document support class for Fixed Telecommunications Network (FTN) data model.
   20:     /// </summary>
   21:     /// 
   22:     /// <remarks> 
   23:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   24:     /// </remarks> 
   25:     public static class NetworkDesignDocument
   26:     {
   27:         private static XDocument xDocument;
   28:  
   29:         private static List<string> ontIdList, ontAccessIdList;
   30:  
   31:         private static Dictionary<int, int> didToOltIdDictionary;
   32:         private static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> routerDomainToSiteDictionary, msanDomainToSiteDictionary, pstnDomainToSiteDictionary;
   33:         private static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType> pstnFiveDigitDomainToPstnExchangeTypeDictionary;
   34:         private static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> domainToRouterVendorDictionary;
   35:         private static Dictionary<string, string> ontAccessIdToOntIdDictionary, ontIdToOntAccessNameDictionary, ontAccessNameToOntAccessIdDictionary, ontAccessNameToOntIdDictionary, ontAccessIdToOntAccessNameDictionary, ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary, ontIpToOntAccessIdDictionary, ontAccessNameToOntIpDictionary, ontIdDictionary, ontIpDictionary, ponNameToPonIdDictionary, ontIpToPrimarySwitchImsFsdbDictionary, nokiaOntIpToPrimarySwitchImsFsdbDictionary;
   36:         private static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontAccessIdToOntDictionary, ontIdToOntDictionary, ontIpToOntDictionary, ontAccessNameToOntDictionary, ontPositionToOntDictionary;
   37:         private static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> ponIdToPonDictionary, ponNameToPonDictionary;
   38:         private static Dictionary<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn, List<int>> pstnToFiveDigitDomainListDictionary;
   39:  
   40:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Network> networkList;
   41:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> vendorList;
   42:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> siteList, legacySiteList;
   43:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> pstnList, legacyPstnList;
   44:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan> msanList;
   45:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX> softXList;
   46:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router> routerList;
   47:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam> oamList;
   48:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf> odfList;
   49:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> oltList;
   50:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup> ponGroupList;
   51:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> ponList;
   52:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> ontList, greenFieldOntList, brownFieldOntList;
   53:  
   54:         private static readonly object objectLock = new object();
   55:  
   56:         /// <summary/>
   57:         public enum BellcoreState { Undefined = 0, IsNr = 1, OosAu, OosMa, OosAuma };
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         ///
   63:         /// </summary>
   64:         //public NetworkDesignDocument() { }
   65:  
   66:         ////////////////////////////////////////////////////////////////////////////
   67:  
   68:         /// <summary>
   69:         ///
   70:         /// </summary>
   71:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntList
   72:         {
   73:             get
   74:             {
   75:                 if (ontList == null || ontList.Count == 0)
   76:                 {
   77:                     lock (objectLock)
   78:                     {
   79:                         ontList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._OntList;
   80:                     }
   81:                 }
   82:  
   83:                 return ontList;
   84:             }
   85:         }
   86:  
   87:         ////////////////////////////////////////////////////////////////////////////
   88:  
   89:         /// <summary>
   90:         ///
   91:         /// </summary>
   92:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> _OntList
   93:         {
   94:             get
   95:             {
   96:                 bool nokiaRouter, huaweiRouter, nokiaOdf, huaweiOdf;
   97:                 long networkNumberIpLong, ipLong, diff, l;
   98:                 string oltSymbol;
   99:  
  100: #if DEBUG
  101:                 Dictionary<string, string> ontDictionary, /*proposedOntDictionary,*/ ipDictionary;
  102: #endif
  103:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
  104:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Access access;
  105:                 Ia.Ftn.Cl.Models.Business.Ims.ImsBasicService imsBasicService;
  106:  
  107:                 var ontList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont>(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList.Count * 32);
  108: #if DEBUG
  109:                 ontDictionary = new Dictionary<string, string>(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList.Count * 32);
  110:                 //proposedOntDictionary = new Dictionary<string, string>(Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PonList.Count * 32);
  111:                 ipDictionary = new Dictionary<string, string>(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList.Count * 32);
  112: #endif
  113:  
  114:                 var nokiaAccessNameWithPbxList = new List<string>(); // Ia.Ftn.Cl.Model.Data.Ims.NokiaAccessNameWithPbxList;
  115:  
  116:                 foreach (var ponGroup in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonGroupList)
  117:                 {
  118:                     nokiaRouter = (ponGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
  119:                     huaweiRouter = !nokiaRouter;
  120:  
  121:                     nokiaOdf = (ponGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
  122:                     huaweiOdf = !nokiaOdf;
  123:  
  124:                     oltSymbol = ponGroup.Olt.Symbol;
  125:  
  126:                     networkNumberIpLong = Ia.Cl.Models.Default.IpToDec(ponGroup.NetworkNumber);
  127:  
  128:                     // standard imsBasicService
  129:                     if (nokiaRouter)
  130:                     {
  131:                         if (nokiaOdf) imsBasicService = Ia.Ftn.Cl.Models.Business.Ims.NokiaImsBasicServiceItem(ponGroup);
  132:                         else imsBasicService = Ia.Ftn.Cl.Models.Business.Ims.SpecialHuaweiIpHandlingForNokiaImsBasicServiceItem(ponGroup);
  133:                     }
  134:                     else imsBasicService = Ia.Ftn.Cl.Models.Business.Ims.HuaweiImsBasicServiceItem(ponGroup);
  135:  
  136:                     foreach (var pon in ponGroup.PonList)
  137:                     {
  138: #if DEBUG
  139:                         if (pon.Name == "ABW.144")
  140:                         {
  141:  
  142:                         }
  143: #endif
  144:  
  145:                         for (int ontNumber = 1; ontNumber <= ponGroup.Olt.NumberOfOntsInPon; ontNumber++)
  146:                         {
  147:                             ont = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont();
  148:                             access = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Access();
  149:  
  150:                             ont.Pon = pon;
  151:  
  152:                             ont.Rack = ponGroup.Olt.Rack;
  153:                             ont.Sub = ponGroup.Olt.Sub;
  154:                             ont.CardSlot = pon.CardSlot;  // CardSlot might change for MDUs below
  155:                             ont.Port = pon.Port;
  156:  
  157:                             ont.Number = ontNumber;
  158:  
  159:                             ont.InternalNumber = (pon.Index * ponGroup.Olt.NumberOfOntsInPon) % 32 + ont.Number;
  160:  
  161:                             ont.Position = ponGroup.Olt.AmsName + "-" + ont.CardSlot + "-" + ont.Port + "-" + ont.InternalNumber;
  162:  
  163:                             access.Id = access.AccessId(ponGroup.Olt.Id, pon.Number, ont.Number);
  164:                             access.Pon = pon.Number;
  165:                             //access.ProposedPon = pon.ProposedNumber;
  166:                             access.Ont = ont.Number;
  167:  
  168:                             access.Symbol = ponGroup.Symbol;
  169:                             access.Name = ponGroup.Symbol + "." + pon.Number + "." + ont.Number;
  170:                             //access.ProposedName = ponGroup.Symbol + "." + pon.ProposedNumber + "." + ont.Number;
  171:  
  172: #if DEBUG
  173:                             if (access.Name == "SSB.44.27")
  174:                             {
  175:  
  176:                             }
  177: #endif
  178:  
  179:                             ont.Access = access;
  180:  
  181:                             ipLong = networkNumberIpLong + pon.PonGroupPonIndex * ponGroup.Olt.NumberOfOntsInPon + ont.Number; // or ont.InternalNumber
  182:                             diff = ipLong - networkNumberIpLong;
  183:  
  184:                             if (nokiaOdf)
  185:                             {
  186:                                 // below: skip *.*.*.0 only for Nokia ONTs
  187:                                 l = (diff - 1) / 255;
  188:  
  189:                                 ipLong += l;
  190:                             }
  191:                             else //if(huaweiOdf)
  192:                             {
  193:                                 if (nokiaRouter)
  194:                                 {
  195:                                 }
  196:                                 else //if (huaweiRouter)
  197:                                 {
  198:                                     // Huawei router and ODF. Here we will skip *.*.*.0 and *.*.*.1. Go figure!
  199:                                     ipLong += 1;
  200:                                 }
  201:                             }
  202:  
  203:                             ont.Ip = Ia.Cl.Models.Default.DecToIp((int)ipLong);
  204:  
  205:                             // ont.Id is used in functions below
  206:                             ont.Id = Ia.Ftn.Cl.Models.Business.Nokia.Ont.OntId(pon.Id, ont.InternalNumber);
  207:  
  208:                             // special imsBasicService
  209:                             if (nokiaRouter)
  210:                             {
  211:                                 if (huaweiOdf)
  212:                                 {
  213:                                     if (nokiaAccessNameWithPbxList.Contains(ont.Access.Name))
  214:                                     {
  215:                                         ont.ImsBasicService = Ia.Ftn.Cl.Models.Business.Ims.NokiaImsBasicServiceItemForAccessWithPbx(ont);
  216:                                     }
  217:                                     else ont.ImsBasicService = Ia.Ftn.Cl.Models.Business.Ims.SpecialHuaweiIpHandlingForNokiaImsBasicServiceItem(ont) ?? imsBasicService;
  218:                                 }
  219:                                 else
  220:                                 {
  221:                                     if (nokiaAccessNameWithPbxList.Contains(ont.Access.Name))
  222:                                     {
  223:                                         ont.ImsBasicService = Ia.Ftn.Cl.Models.Business.Ims.NokiaImsBasicServiceItemForAccessWithPbx(ont);
  224:                                     }
  225:                                     else ont.ImsBasicService = imsBasicService;
  226:                                 }
  227:                             }
  228:                             else ont.ImsBasicService = imsBasicService;
  229:  
  230:  
  231: #if DEBUG
  232:                             // this will throw an exception if there is a duplicate ont.Access.Name
  233:                             if (ontDictionary.ContainsKey(ont.Access.Name))
  234:                             {
  235:                                 throw new ArgumentOutOfRangeException(@"ontDictionary.ContainsKey(ont.Access.Name)");
  236:                             }
  237:                             else ontDictionary[ont.Access.Name] = ont.Id;
  238:  
  239:                             /*
  240:                             // this will throw an exception if there is a duplicate ont.Access.ProposedName
  241:                             if (proposedOntDictionary.ContainsKey(ont.Access.ProposedName))
  242:                             {
  243:                                 throw new ArgumentOutOfRangeException(@"proposedOntDictionary.ContainsKey(ont.Access.ProposedName)");
  244:                             }
  245:                             else proposedOntDictionary[ont.Access.ProposedName] = ont.Id;
  246:                             */
  247:  
  248:                             /*
  249:                             // this will throw an exception if an IP has *.*.*.0
  250:                             // over 400 Huawei ONTs with *.*.*.0 IPs
  251:                             if (Regex.IsMatch(ont.Ip, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.0"))
  252:                             {
  253:                                 list.Add(ont.Access.Name);
  254:                             }
  255:                             */
  256:  
  257:                             // this will throw an exception if there is a duplicate ont.Ip
  258:                             if (ipDictionary.ContainsKey(ont.Ip))
  259:                             {
  260:                                 throw new ArgumentOutOfRangeException(@"ipDictionary.ContainsKey(ont.Ip)");
  261:                             }
  262:                             else ipDictionary[ont.Ip] = ont.Id;
  263: #endif
  264:                             ontList.Add(ont);
  265:                         }
  266:                     }
  267:                 }
  268:  
  269:                 // as a precaution, this will throw an exception if there are not n number of records
  270:                 if (ontList.Count != Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PrecautionaryHardCodedNumberOfOntRecords)
  271:                 {
  272:                     throw new ArgumentOutOfRangeException(@"(ontList.Count != " + Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PrecautionaryHardCodedNumberOfOntRecords);
  273:                 }
  274:  
  275:                 return ontList;
  276:             }
  277:         }
  278:  
  279:         ////////////////////////////////////////////////////////////////////////////
  280:  
  281:         /// <summary>
  282:         /// 
  283:         /// </summary>
  284:         public static List<string> OntIdList
  285:         {
  286:             get
  287:             {
  288:                 if (ontIdList == null || ontIdList.Count == 0)
  289:                 {
  290:                     lock (objectLock)
  291:                     {
  292:                         ontIdList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  293:                                      orderby o.Id
  294:                                      select o.Id).ToList();
  295:                     }
  296:                 }
  297:  
  298:                 return ontIdList;
  299:             }
  300:         }
  301:  
  302:         ////////////////////////////////////////////////////////////////////////////
  303:  
  304:         /// <summary>
  305:         /// 
  306:         /// </summary>
  307:         public static List<string> OntAccessIdList
  308:         {
  309:             get
  310:             {
  311:                 if (ontAccessIdList == null || ontAccessIdList.Count == 0)
  312:                 {
  313:                     lock (objectLock)
  314:                     {
  315:                         ontAccessIdList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  316:                                            orderby o.Access.Id
  317:                                            select o.Access.Id).ToList();
  318:                     }
  319:                 }
  320:  
  321:                 return ontAccessIdList;
  322:             }
  323:         }
  324:  
  325:         ////////////////////////////////////////////////////////////////////////////
  326:  
  327:         /// <summary>
  328:         ///
  329:         /// </summary>
  330:         public static Dictionary<string, string> OntAccessIdToOntIdDictionary
  331:         {
  332:             get
  333:             {
  334:                 if (ontAccessIdToOntIdDictionary == null || ontAccessIdToOntIdDictionary.Count == 0)
  335:                 {
  336:                     lock (objectLock)
  337:                     {
  338:                         ontAccessIdToOntIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  339:                                                         select new { AccessId = o.Access.Id, OntId = o.Id }).ToDictionary(n => n.AccessId, n => n.OntId);
  340:                     }
  341:                 }
  342:  
  343:                 return ontAccessIdToOntIdDictionary;
  344:             }
  345:         }
  346:  
  347:         ////////////////////////////////////////////////////////////////////////////
  348:  
  349:         /// <summary>
  350:         ///
  351:         /// </summary>
  352:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntAccessIdToOntDictionary
  353:         {
  354:             get
  355:             {
  356:                 if (ontAccessIdToOntDictionary == null || ontAccessIdToOntDictionary.Count == 0)
  357:                 {
  358:                     lock (objectLock)
  359:                     {
  360:                         ontAccessIdToOntDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  361:                                                       select new { AccessId = o.Access.Id, Ont = o }).ToDictionary(n => n.AccessId, n => n.Ont);
  362:                     }
  363:                 }
  364:  
  365:                 return ontAccessIdToOntDictionary;
  366:             }
  367:         }
  368:  
  369:         ////////////////////////////////////////////////////////////////////////////
  370:  
  371:         /// <summary>
  372:         ///
  373:         /// </summary>
  374:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntIpToOntDictionary
  375:         {
  376:             get
  377:             {
  378:                 if (ontIpToOntDictionary == null || ontIpToOntDictionary.Count == 0)
  379:                 {
  380:                     lock (objectLock)
  381:                     {
  382:                         ontIpToOntDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  383:                                                 select new { Ip = o.Ip, Ont = o }).ToDictionary(n => n.Ip, n => n.Ont);
  384:                     }
  385:                 }
  386:  
  387:                 return ontIpToOntDictionary;
  388:             }
  389:         }
  390:  
  391:         ////////////////////////////////////////////////////////////////////////////
  392:  
  393:         /// <summary>
  394:         ///
  395:         /// </summary>
  396:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntAccessIdToOntForOltIdListDictionary(List<int> oltIdList)
  397:         {
  398:             lock (objectLock)
  399:             {
  400:                 var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  401:                             where oltIdList.Contains(o.Pon.PonGroup.Olt.Id)
  402:                             select new { AccessId = o.Access.Id, Ont = o }).ToDictionary(n => n.AccessId, n => n.Ont);
  403:  
  404:                 return list;
  405:             }
  406:         }
  407:  
  408:         ////////////////////////////////////////////////////////////////////////////
  409:  
  410:         /// <summary>
  411:         ///
  412:         /// </summary>
  413:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntIpToOntForOltIdListDictionary(List<int> oltIdList)
  414:         {
  415:             lock (objectLock)
  416:             {
  417:                 var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  418:                             where oltIdList.Contains(o.Pon.PonGroup.Olt.Id)
  419:                             select new { OntIp = o.Ip, Ont = o }).ToDictionary(n => n.OntIp, n => n.Ont);
  420:  
  421:                 return list;
  422:             }
  423:         }
  424:  
  425:         ////////////////////////////////////////////////////////////////////////////
  426:  
  427:         /// <summary>
  428:         ///
  429:         /// </summary>
  430:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntAccessIdToOntForOltSymbolListDictionary(List<string> oltSymbolList)
  431:         {
  432:             lock (objectLock)
  433:             {
  434:                 var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  435:                             where oltSymbolList.Contains(o.Pon.PonGroup.Olt.Symbol)
  436:                             select new { AccessId = o.Access.Id, Ont = o }).ToDictionary(n => n.AccessId, n => n.Ont);
  437:  
  438:                 return list;
  439:             }
  440:         }
  441:  
  442:         ////////////////////////////////////////////////////////////////////////////
  443:  
  444:         /// <summary>
  445:         ///
  446:         /// </summary>
  447:         public static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> RouterDomainToSiteDictionary
  448:         {
  449:             get
  450:             {
  451:                 if (routerDomainToSiteDictionary == null || routerDomainToSiteDictionary.Count == 0)
  452:                 {
  453:                     lock (objectLock)
  454:                     {
  455:                         routerDomainToSiteDictionary = new Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>();
  456:  
  457:                         var routerList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList;
  458:  
  459:                         foreach (int domain in routerList.SelectMany(u => u.DomainList))
  460:                         {
  461:                             routerDomainToSiteDictionary[domain] = (from r in routerList where r.DomainList.Contains(domain) select r.Site).FirstOrDefault(); //.SingleOrDefault(); see NDD XML with domain 2390, has two sites
  462:                         }
  463:                     }
  464:                 }
  465:  
  466:                 return routerDomainToSiteDictionary;
  467:             }
  468:         }
  469:  
  470:         ////////////////////////////////////////////////////////////////////////////
  471:  
  472:         /// <summary>
  473:         ///
  474:         /// </summary>
  475:         public static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> MsanDomainToSiteDictionary
  476:         {
  477:             get
  478:             {
  479:                 if (msanDomainToSiteDictionary == null || msanDomainToSiteDictionary.Count == 0)
  480:                 {
  481:                     lock (objectLock)
  482:                     {
  483:                         msanDomainToSiteDictionary = new Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>();
  484:  
  485:                         var msanList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.MsanList;
  486:  
  487:                         foreach (int domain in msanList.SelectMany(u => u.DomainList))
  488:                         {
  489:                             msanDomainToSiteDictionary[domain] = (from m in msanList where m.DomainList.Contains(domain) select m.Site).FirstOrDefault(); //.SingleOrDefault();
  490:                         }
  491:                     }
  492:                 }
  493:  
  494:                 return msanDomainToSiteDictionary;
  495:             }
  496:         }
  497:  
  498:         ////////////////////////////////////////////////////////////////////////////
  499:  
  500:         /// <summary>
  501:         ///
  502:         /// </summary>
  503:         public static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> PstnDomainToSiteDictionary
  504:         {
  505:             get
  506:             {
  507:                 if (pstnDomainToSiteDictionary == null || pstnDomainToSiteDictionary.Count == 0)
  508:                 {
  509:                     lock (objectLock)
  510:                     {
  511:                         pstnDomainToSiteDictionary = new Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>();
  512:  
  513:                         var pstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList;
  514:  
  515:                         foreach (int domain in pstnList.SelectMany(u => u.DomainList))
  516:                         {
  517:                             pstnDomainToSiteDictionary[domain] = (from p in pstnList where p.DomainList.Contains(domain) select p.Site).SingleOrDefault();
  518:                         }
  519:                     }
  520:                 }
  521:  
  522:                 return pstnDomainToSiteDictionary;
  523:             }
  524:         }
  525:  
  526:         ////////////////////////////////////////////////////////////////////////////
  527:  
  528:         /// <summary>
  529:         ///
  530:         /// </summary>
  531:         public static Dictionary<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn, List<int>> PstnToFiveDigitDomainListDictionary()
  532:         {
  533:             if (pstnToFiveDigitDomainListDictionary == null || pstnToFiveDigitDomainListDictionary.Count == 0)
  534:             {
  535:                 lock (objectLock)
  536:                 {
  537:                     pstnToFiveDigitDomainListDictionary = new Dictionary<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn, List<int>>();
  538:  
  539:                     var pstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList;
  540:  
  541:                     foreach (var pstn in pstnList)
  542:                     {
  543:                         var list = new List<int>();
  544:  
  545:                         foreach (int domain in pstn.DomainList)
  546:                         {
  547:                             // already five digit domain
  548:                             if (domain > 9999) list.Add(domain);
  549:                             else
  550:                             {
  551:                                 // four digit domain, we will need to create five digit domains related to it
  552:                                 for (int i = 0; i <= 9; i++)
  553:                                 {
  554:                                     list.Add(domain * 10 + i);
  555:                                 }
  556:                             }
  557:  
  558:                             pstnToFiveDigitDomainListDictionary[pstn] = list;
  559:                         }
  560:                     }
  561:                 }
  562:             }
  563:  
  564:             return pstnToFiveDigitDomainListDictionary;
  565:         }
  566:  
  567:         ////////////////////////////////////////////////////////////////////////////
  568:  
  569:         /// <summary>
  570:         ///
  571:         /// </summary>
  572:         public static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType> PstnFiveDigitDomainToVendorDictionary()
  573:         {
  574:             if (pstnFiveDigitDomainToPstnExchangeTypeDictionary == null || pstnFiveDigitDomainToPstnExchangeTypeDictionary.Count == 0)
  575:             {
  576:                 lock (objectLock)
  577:                 {
  578:                     pstnFiveDigitDomainToPstnExchangeTypeDictionary = new Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType>();
  579:  
  580:                     var pstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList;
  581:  
  582:                     foreach (var pstn in pstnList)
  583:                     {
  584:                         foreach (int domain in pstn.DomainList)
  585:                         {
  586:                             // already five digit domain
  587:                             if (domain > 9999) pstnFiveDigitDomainToPstnExchangeTypeDictionary[domain] = pstn.PstnExchangeType;
  588:                             else
  589:                             {
  590:                                 // four digit domain, we will need to create five digit domains related to it
  591:                                 for (int i = 0; i <= 9; i++)
  592:                                 {
  593:                                     pstnFiveDigitDomainToPstnExchangeTypeDictionary[domain * 10 + i] = pstn.PstnExchangeType;
  594:                                 }
  595:                             }
  596:                         }
  597:                     }
  598:                 }
  599:             }
  600:  
  601:             return pstnFiveDigitDomainToPstnExchangeTypeDictionary;
  602:         }
  603:  
  604:         ////////////////////////////////////////////////////////////////////////////
  605:  
  606:         /// <summary>
  607:         ///
  608:         /// </summary>
  609:         public static Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> DomainToRouterVendorDictionary
  610:         {
  611:             get
  612:             {
  613:                 if (domainToRouterVendorDictionary == null || domainToRouterVendorDictionary.Count == 0)
  614:                 {
  615:                     lock (objectLock)
  616:                     {
  617:                         domainToRouterVendorDictionary = new Dictionary<int, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>();
  618:  
  619:                         var routerList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList;
  620:  
  621:                         foreach (int domain in routerList.SelectMany(u => u.DomainList))
  622:                         {
  623:                             domainToRouterVendorDictionary[domain] = (from r in routerList
  624:                                                                       where r.DomainList.Contains(domain)
  625:                                                                       select r.Vendor).FirstOrDefault(); //.SingleOrDefault(); see NDD XML with domain 2390, has two sites
  626:                         }
  627:                     }
  628:                 }
  629:  
  630:                 return domainToRouterVendorDictionary;
  631:             }
  632:         }
  633:  
  634:         ////////////////////////////////////////////////////////////////////////////
  635:  
  636:         /// <summary>
  637:         ///
  638:         /// </summary>
  639:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntIdToOntDictionary
  640:         {
  641:             get
  642:             {
  643:                 if (ontIdToOntDictionary == null || ontIdToOntDictionary.Count == 0)
  644:                 {
  645:                     lock (objectLock)
  646:                     {
  647:                         ontIdToOntDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  648:                                                 select new { OntId = o.Id, Ont = o }).ToDictionary(n => n.OntId, n => n.Ont);
  649:                     }
  650:                 }
  651:                 return ontIdToOntDictionary;
  652:             }
  653:         }
  654:  
  655:         ////////////////////////////////////////////////////////////////////////////
  656:  
  657:         /// <summary>
  658:         ///
  659:         /// </summary>
  660:         public static Dictionary<string, string> OntIdToOntAccessNameDictionary
  661:         {
  662:             get
  663:             {
  664:                 if (ontIdToOntAccessNameDictionary == null || ontIdToOntAccessNameDictionary.Count == 0)
  665:                 {
  666:                     lock (objectLock)
  667:                     {
  668:                         ontIdToOntAccessNameDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  669:                                                           select new { OntId = o.Id, OntAccessName = o.Access.Name }).ToDictionary(n => n.OntId, n => n.OntAccessName);
  670:                     }
  671:                 }
  672:  
  673:                 return ontIdToOntAccessNameDictionary;
  674:             }
  675:         }
  676:  
  677:         ////////////////////////////////////////////////////////////////////////////
  678:  
  679:         /// <summary>
  680:         ///
  681:         /// </summary>
  682:         public static Dictionary<string, string> OntAccessNameToOntIdDictionary
  683:         {
  684:             get
  685:             {
  686:                 if (ontAccessNameToOntIdDictionary == null || ontAccessNameToOntIdDictionary.Count == 0)
  687:                 {
  688:                     lock (objectLock)
  689:                     {
  690:                         ontAccessNameToOntIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  691:                                                           select new { OntAccessName = o.Access.Name, OntId = o.Id }).ToDictionary(n => n.OntAccessName, n => n.OntId);
  692:                     }
  693:                 }
  694:  
  695:                 return ontAccessNameToOntIdDictionary;
  696:             }
  697:         }
  698:  
  699:         ////////////////////////////////////////////////////////////////////////////
  700:  
  701:         /// <summary>
  702:         ///
  703:         /// </summary>
  704:         public static Dictionary<string, string> OntAccessNameToOntAccessIdDictionary
  705:         {
  706:             get
  707:             {
  708:                 if (ontAccessNameToOntAccessIdDictionary == null || ontAccessNameToOntAccessIdDictionary.Count == 0)
  709:                 {
  710:                     lock (objectLock)
  711:                     {
  712:                         ontAccessNameToOntAccessIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  713:                                                                 select new { OntAccessName = o.Access.Name, OntAccessId = o.Access.Id }).ToDictionary(n => n.OntAccessName, n => n.OntAccessId);
  714:                     }
  715:                 }
  716:  
  717:                 return ontAccessNameToOntAccessIdDictionary;
  718:             }
  719:         }
  720:  
  721:         ////////////////////////////////////////////////////////////////////////////
  722:  
  723:         /// <summary>
  724:         ///
  725:         /// </summary>
  726:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntAccessNameToOntDictionary
  727:         {
  728:             get
  729:             {
  730:                 if (ontAccessNameToOntDictionary == null || ontAccessNameToOntDictionary.Count == 0)
  731:                 {
  732:                     lock (objectLock)
  733:                     {
  734:                         ontAccessNameToOntDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  735:                                                         select new { OntAccessName = o.Access.Name, Ont = o }).ToDictionary(n => n.OntAccessName, n => n.Ont);
  736:                     }
  737:                 }
  738:  
  739:                 return ontAccessNameToOntDictionary;
  740:             }
  741:         }
  742:  
  743:         ////////////////////////////////////////////////////////////////////////////
  744:  
  745:         /// <summary>
  746:         ///
  747:         /// </summary>
  748:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> OntPositionToOntDictionary
  749:         {
  750:             get
  751:             {
  752:                 if (ontPositionToOntDictionary == null || ontPositionToOntDictionary.Count == 0)
  753:                 {
  754:                     lock (objectLock)
  755:                     {
  756:                         ontPositionToOntDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  757:                                                       select new { OntPosition = o.Position, Ont = o }).ToDictionary(n => n.OntPosition, n => n.Ont);
  758:                     }
  759:                 }
  760:  
  761:                 return ontPositionToOntDictionary;
  762:             }
  763:         }
  764:  
  765:         ////////////////////////////////////////////////////////////////////////////
  766:  
  767:         /// <summary>
  768:         ///
  769:         /// </summary>
  770:         public static Dictionary<string, string> OntAccessIdToOntAccessNameDictionary
  771:         {
  772:             get
  773:             {
  774:                 if (ontAccessIdToOntAccessNameDictionary == null || ontAccessIdToOntAccessNameDictionary.Count == 0)
  775:                 {
  776:                     lock (objectLock)
  777:                     {
  778:                         ontAccessIdToOntAccessNameDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  779:                                                                 select new { OntAccessId = o.Access.Id, OntAccessName = o.Access.Name }).ToDictionary(n => n.OntAccessId, n => n.OntAccessName);
  780:                     }
  781:                 }
  782:  
  783:                 return ontAccessIdToOntAccessNameDictionary;
  784:             }
  785:         }
  786:  
  787:         ////////////////////////////////////////////////////////////////////////////
  788:  
  789:         /// <summary>
  790:         ///
  791:         /// </summary>
  792:         public static Dictionary<string, string> OntAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary
  793:         {
  794:             get
  795:             {
  796:                 if (ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary == null || ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary.Count == 0)
  797:                 {
  798:                     lock (objectLock)
  799:                     {
  800:                         var allowedToBeMigratedOltIdList = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
  801:  
  802:                         ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  803:                                                                                             where allowedToBeMigratedOltIdList.Contains(o.Pon.PonGroup.Olt.Id)
  804:                                                                                             select new { OntAccessId = o.Access.Id, OntAccessName = o.Access.Name }).ToDictionary(n => n.OntAccessId, n => n.OntAccessName);
  805:                     }
  806:                 }
  807:  
  808:                 return ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary;
  809:             }
  810:         }
  811:  
  812:         ////////////////////////////////////////////////////////////////////////////
  813:  
  814:         /// <summary>
  815:         ///
  816:         /// </summary>
  817:         public static Dictionary<string, string> OntIpToOntAccessIdDictionary
  818:         {
  819:             get
  820:             {
  821:                 if (ontIpToOntAccessIdDictionary == null || ontIpToOntAccessIdDictionary.Count == 0)
  822:                 {
  823:                     lock (objectLock)
  824:                     {
  825:                         ontIpToOntAccessIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  826:                                                         select new { OntIp = o.Ip, OntAccessId = o.Access.Id }).ToDictionary(n => n.OntIp, n => n.OntAccessId);
  827:                     }
  828:                 }
  829:  
  830:                 return ontIpToOntAccessIdDictionary;
  831:             }
  832:         }
  833:  
  834:         ////////////////////////////////////////////////////////////////////////////
  835:  
  836:         /// <summary>
  837:         ///
  838:         /// </summary>
  839:         public static Dictionary<string, string> OntAccessNameToOntIpDictionary
  840:         {
  841:             get
  842:             {
  843:                 if (ontAccessNameToOntIpDictionary == null || ontAccessNameToOntIpDictionary.Count == 0)
  844:                 {
  845:                     lock (objectLock)
  846:                     {
  847:                         ontAccessNameToOntIpDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  848:                                                           select new { OntAccessName = o.Access.Name, OntIp = o.Ip }).ToDictionary(n => n.OntAccessName, n => n.OntIp);
  849:                     }
  850:                 }
  851:  
  852:                 return ontAccessNameToOntIpDictionary;
  853:             }
  854:         }
  855:  
  856:         ////////////////////////////////////////////////////////////////////////////
  857:  
  858:         /// <summary>
  859:         ///
  860:         /// </summary>
  861:         public static Dictionary<string, string> OntIdDictionary
  862:         {
  863:             get
  864:             {
  865:                 if (ontIdDictionary == null || ontIdDictionary.Count == 0)
  866:                 {
  867:                     lock (objectLock)
  868:                     {
  869:                         ontIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  870:                                            select o.Id).ToDictionary(n => n, n => n);
  871:                     }
  872:                 }
  873:  
  874:                 return ontIdDictionary;
  875:             }
  876:         }
  877:  
  878:         ////////////////////////////////////////////////////////////////////////////
  879:  
  880:         /// <summary>
  881:         ///
  882:         /// </summary>
  883:         public static Dictionary<string, string> OntIpDictionary
  884:         {
  885:             get
  886:             {
  887:                 if (ontIpDictionary == null || ontIpDictionary.Count == 0)
  888:                 {
  889:                     lock (objectLock)
  890:                     {
  891:                         ontIpDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  892:                                            select o.Ip).ToDictionary(n => n, n => n);
  893:                     }
  894:                 }
  895:                 return ontIpDictionary;
  896:             }
  897:         }
  898:  
  899:         ////////////////////////////////////////////////////////////////////////////
  900:  
  901:         /// <summary>
  902:         ///
  903:         /// </summary>
  904:         public static Dictionary<string, string> OntIpToPrimarySwitchImsFsdbDictionary
  905:         {
  906:             get
  907:             {
  908:                 if (ontIpToPrimarySwitchImsFsdbDictionary == null || ontIpToPrimarySwitchImsFsdbDictionary.Count == 0)
  909:                 {
  910:                     lock (objectLock)
  911:                     {
  912:                         ontIpToPrimarySwitchImsFsdbDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  913:                                                                  select o).Distinct().ToDictionary(n => n.Ip, n => n.PrimarySwitch + " (" + n.ImsFsdb + ")");
  914:                     }
  915:                 }
  916:  
  917:                 return ontIpToPrimarySwitchImsFsdbDictionary;
  918:             }
  919:         }
  920:  
  921:         ////////////////////////////////////////////////////////////////////////////
  922:  
  923:         /// <summary>
  924:         ///
  925:         /// </summary>
  926:         public static Dictionary<string, string> NokiaOntIpToPrimarySwitchImsFsdbDictionary
  927:         {
  928:             get
  929:             {
  930:                 if (nokiaOntIpToPrimarySwitchImsFsdbDictionary == null || nokiaOntIpToPrimarySwitchImsFsdbDictionary.Count == 0)
  931:                 {
  932:                     lock (objectLock)
  933:                     {
  934:                         nokiaOntIpToPrimarySwitchImsFsdbDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  935:                                                                       where o.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
  936:                                                                       select o).Distinct().ToDictionary(n => n.Ip, n => n.PrimarySwitch + " (" + n.ImsFsdb + ")");
  937:                     }
  938:                 }
  939:  
  940:                 return nokiaOntIpToPrimarySwitchImsFsdbDictionary;
  941:             }
  942:         }
  943:  
  944:         ////////////////////////////////////////////////////////////////////////////
  945:  
  946:         /// <summary>
  947:         ///
  948:         /// </summary>
  949:         public static bool AccessNameIsWithinAllowedOntList(string inputAccessName, out string accessName)
  950:         {
  951:             // below: this checks that this accessName is within the standard possible values in network
  952:             bool isWithinAllowedOnts;
  953:  
  954:             var nddOnt = Ia.Ftn.Cl.Models.Business.Default.NddOntUsingExtractedAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(inputAccessName);
  955:  
  956:             if (nddOnt != null)
  957:             {
  958:                 isWithinAllowedOnts = true;
  959:                 accessName = nddOnt.Access.Name;
  960:             }
  961:             else
  962:             {
  963:                 isWithinAllowedOnts = false;
  964:                 accessName = string.Empty;
  965:             }
  966:  
  967:             return isWithinAllowedOnts;
  968:         }
  969:  
  970:         ////////////////////////////////////////////////////////////////////////////
  971:  
  972:         /// <summary>
  973:         ///
  974:         /// </summary>
  975:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont OntById(string ontId)
  976:         {
  977:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont ont;
  978:  
  979:             if (!string.IsNullOrEmpty(ontId))
  980:             {
  981:                 var d = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary;
  982:  
  983:                 if (d.ContainsKey(ontId)) ont = d[ontId];
  984:                 else ont = null;
  985:             }
  986:             else ont = null;
  987:  
  988:             return ont;
  989:         }
  990:  
  991:         ////////////////////////////////////////////////////////////////////////////
  992:  
  993:         /// <summary>
  994:         ///
  995:         /// </summary>
  996:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont OntByAccessName(string accessName)
  997:         {
  998:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
  999:  
 1000:             if (!string.IsNullOrEmpty(accessName))
 1001:             {
 1002:                 accessName = accessName.ToUpper();
 1003:  
 1004:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1005:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary[accessName] : null;
 1006:             }
 1007:             else nddOnt = null;
 1008:  
 1009:             return nddOnt;
 1010:         }
 1011:  
 1012:         ////////////////////////////////////////////////////////////////////////////
 1013:  
 1014:         /// <summary>
 1015:         ///
 1016:         /// </summary>
 1017:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont OntByOntAccessId(string accessId)
 1018:         {
 1019:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1020:  
 1021:             if (!string.IsNullOrEmpty(accessId))
 1022:             {
 1023:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(accessId) ?
 1024:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary[accessId] : null;
 1025:             }
 1026:             else nddOnt = null;
 1027:  
 1028:             return nddOnt;
 1029:         }
 1030:  
 1031:         ////////////////////////////////////////////////////////////////////////////
 1032:  
 1033:         /// <summary>
 1034:         ///
 1035:         /// </summary>
 1036:         public static string AccessNameByOntId(string ontId)
 1037:         {
 1038:             string accessName;
 1039:  
 1040:             if (!string.IsNullOrEmpty(ontId))
 1041:             {
 1042:                 var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary.ContainsKey(ontId) ?
 1043:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIdToOntDictionary[ontId] : null;
 1044:  
 1045:                 if (nddOnt != null)
 1046:                 {
 1047:                     accessName = nddOnt.Access.Name;
 1048:                 }
 1049:                 else accessName = string.Empty;
 1050:             }
 1051:             else accessName = string.Empty;
 1052:  
 1053:             return accessName;
 1054:         }
 1055:  
 1056:         ////////////////////////////////////////////////////////////////////////////
 1057:  
 1058:         /// <summary>
 1059:         ///
 1060:         /// </summary>
 1061:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont OntByIp(string ip)
 1062:         {
 1063:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1064:  
 1065:             if (!string.IsNullOrEmpty(ip))
 1066:             {
 1067:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIpToOntDictionary.ContainsKey(ip) ?
 1068:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntIpToOntDictionary[ip] : null;
 1069:             }
 1070:             else nddOnt = null;
 1071:  
 1072:             return nddOnt;
 1073:         }
 1074:  
 1075:         ////////////////////////////////////////////////////////////////////////////
 1076:  
 1077:         /// <summary>
 1078:         ///
 1079:         /// </summary>
 1080:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> AccessVendorListByOntIdList(List<string> ontIdList)
 1081:         {
 1082:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
 1083:             var vendorList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>();
 1084:  
 1085:             foreach (var ontId in ontIdList)
 1086:             {
 1087:                 if (!string.IsNullOrEmpty(ontId))
 1088:                 {
 1089:                     var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntById(ontId);
 1090:  
 1091:                     vendor = (nddOnt != null) ? nddOnt.Pon.PonGroup.Olt.Odf.Vendor : Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1092:                 }
 1093:                 else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1094:  
 1095:                 vendorList.Add(vendor);
 1096:             }
 1097:  
 1098:             return vendorList;
 1099:         }
 1100:  
 1101:         ////////////////////////////////////////////////////////////////////////////
 1102:  
 1103:         /// <summary>
 1104:         ///
 1105:         /// </summary>
 1106:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> SwitchVendorListByOntIdList(List<string> ontIdList)
 1107:         {
 1108:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
 1109:             var vendorList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>();
 1110:  
 1111:             foreach (var ontId in ontIdList)
 1112:             {
 1113:                 if (!string.IsNullOrEmpty(ontId))
 1114:                 {
 1115:                     var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntById(ontId);
 1116:  
 1117:                     vendor = (nddOnt != null) ? nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor : Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1118:                 }
 1119:                 else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1120:  
 1121:                 vendorList.Add(vendor);
 1122:             }
 1123:  
 1124:             return vendorList;
 1125:         }
 1126:  
 1127:         ////////////////////////////////////////////////////////////////////////////
 1128:  
 1129:         /// <summary>
 1130:         ///
 1131:         /// </summary>
 1132:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor AccessVendorByOntAccessId(string ontAccessId)
 1133:         {
 1134:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
 1135:  
 1136:             if (!string.IsNullOrEmpty(ontAccessId))
 1137:             {
 1138:                 var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(ontAccessId) ?
 1139:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary[ontAccessId] : null;
 1140:  
 1141:                 if (nddOnt != null)
 1142:                 {
 1143:                     vendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
 1144:                 }
 1145:                 else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1146:             }
 1147:             else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1148:  
 1149:             return vendor;
 1150:         }
 1151:  
 1152:         ////////////////////////////////////////////////////////////////////////////
 1153:  
 1154:         /// <summary>
 1155:         ///
 1156:         /// </summary>
 1157:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor AccessVendorByAccessName(string accessName)
 1158:         {
 1159:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
 1160:  
 1161:             if (!string.IsNullOrEmpty(accessName))
 1162:             {
 1163:                 accessName = accessName.ToUpper();
 1164:  
 1165:                 var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1166:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary[accessName] : null;
 1167:  
 1168:                 if (nddOnt != null)
 1169:                 {
 1170:                     vendor = nddOnt.Pon.PonGroup.Olt.Odf.Vendor;
 1171:                 }
 1172:                 else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1173:             }
 1174:             else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1175:  
 1176:             return vendor;
 1177:         }
 1178:  
 1179:         ////////////////////////////////////////////////////////////////////////////
 1180:  
 1181:         /// <summary>
 1182:         ///
 1183:         /// </summary>
 1184:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor SwitchVendorByAccessName(string accessName)
 1185:         {
 1186:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
 1187:  
 1188:             if (!string.IsNullOrEmpty(accessName))
 1189:             {
 1190:                 accessName = accessName.ToUpper();
 1191:  
 1192:                 var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1193:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessNameToOntDictionary[accessName] : null;
 1194:  
 1195:                 if (nddOnt != null)
 1196:                 {
 1197:                     vendor = nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor;
 1198:                 }
 1199:                 else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1200:             }
 1201:             else vendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 1202:  
 1203:             return vendor;
 1204:         }
 1205:  
 1206:         ////////////////////////////////////////////////////////////////////////////
 1207:  
 1208:         /// <summary>
 1209:         ///
 1210:         /// </summary>
 1211:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router RouterFromService(string service)
 1212:         {
 1213:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router router;
 1214:  
 1215:             if (!string.IsNullOrEmpty(service))
 1216:             {
 1217:                 if (int.TryParse(service, out int i))
 1218:                 {
 1219:                     router = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
 1220:                               where r.DomainList.Any(u => service.StartsWith(u.ToString()))
 1221:                               select r).FirstOrDefault(); //.SingleOrDefault(); // 2390 is defined in two different huawei routers
 1222:                 }
 1223:                 else router = null;
 1224:             }
 1225:             else router = null;
 1226:  
 1227:             return router;
 1228:         }
 1229:  
 1230:         ////////////////////////////////////////////////////////////////////////////
 1231:  
 1232:         /// <summary>
 1233:         ///
 1234:         /// </summary>
 1235:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont OntByPosition(string position)
 1236:         {
 1237:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt;
 1238:  
 1239:             if (!string.IsNullOrEmpty(position))
 1240:             {
 1241:                 nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntPositionToOntDictionary.ContainsKey(position) ?
 1242:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntPositionToOntDictionary[position] : null;
 1243:             }
 1244:             else nddOnt = null;
 1245:  
 1246:             return nddOnt;
 1247:         }
 1248:  
 1249:         ////////////////////////////////////////////////////////////////////////////
 1250:  
 1251:         /// <summary>
 1252:         ///
 1253:         /// </summary>
 1254:         public static string OntIdByPosition(string position)
 1255:         {
 1256:             string ontId;
 1257:  
 1258:             if (!string.IsNullOrEmpty(position))
 1259:             {
 1260:                 var ont = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntPositionToOntDictionary.ContainsKey(position) ?
 1261:                     Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntPositionToOntDictionary[position] : null;
 1262:  
 1263:                 if (ont != null) ontId = ont.Id;
 1264:                 else ontId = string.Empty;
 1265:             }
 1266:             else ontId = string.Empty;
 1267:  
 1268:             return ontId;
 1269:         }
 1270:  
 1271:         ////////////////////////////////////////////////////////////////////////////
 1272:         ////////////////////////////////////////////////////////////////////////////
 1273:  
 1274:  
 1275:  
 1276:  
 1277:  
 1278:  
 1279:  
 1280:         ////////////////////////////////////////////////////////////////////////////
 1281:         ////////////////////////////////////////////////////////////////////////////
 1282:  
 1283:         /// <summary>
 1284:         ///
 1285:         /// </summary>
 1286:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> PonList
 1287:         {
 1288:             get
 1289:             {
 1290:                 if (ponList == null || ponList.Count == 0)
 1291:                 {
 1292:                     lock (objectLock)
 1293:                     {
 1294:                         ponList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._PonList;
 1295:                     }
 1296:                 }
 1297:  
 1298:                 return ponList;
 1299:             }
 1300:         }
 1301:  
 1302:         ////////////////////////////////////////////////////////////////////////////
 1303:  
 1304:         /// <summary>
 1305:         ///
 1306:         /// </summary>
 1307:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> _PonList
 1308:         {
 1309:             get
 1310:             {
 1311:                 bool nokiaRouter, huaweiRouter, nokiaOdf, huaweiOdf;
 1312:                 int ponNumber, slot, oltPonIndex, oltPonCount;
 1313:                 //int proposedPonNumber, oltProposedPonCount;
 1314:                 string odfName;
 1315: #if DEBUG
 1316:                 Dictionary<string, string> ponIdDictionary;
 1317: #endif
 1318:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon;
 1319:  
 1320:                 var ponList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon>(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonGroupList.Count * 32); // 32 is the max number of PONs in an PonGroup (16 max per LT)
 1321: #if DEBUG
 1322:                 ponIdDictionary = new Dictionary<string, string>(Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonGroupList.Count * 32);
 1323: #endif
 1324:                 foreach (var olt in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList)
 1325:                 {
 1326:                     oltPonIndex = 0;
 1327:  
 1328:                     nokiaRouter = (olt.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
 1329:                     huaweiRouter = !nokiaRouter;
 1330:  
 1331:                     nokiaOdf = (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
 1332:                     huaweiOdf = !nokiaOdf;
 1333:  
 1334:                     odfName = olt.Odf.Name;
 1335:  
 1336:                     oltPonCount = /*oltProposedPonCount =*/ 0;
 1337:  
 1338:                     foreach (var ponGroup in olt.PonGroupList)
 1339:                     {
 1340:                         oltPonCount += ponGroup.UsedPonInPonGroupList.Count;
 1341:  
 1342:                         //if (ponGroup.HasNewProposedPonList) oltProposedPonCount += ponGroup.UsedProposedPonInPonGroupList.Count;
 1343:                     }
 1344:  
 1345:                     //if (/*((oltPonCount == oltProposedPonCount) || oltProposedPonCount == 0) &&*/ oltPonCount % 32 == 0)
 1346:                     //{
 1347:                     foreach (var ponGroup in olt.PonGroupList)
 1348:                     {
 1349:                         //if (!ponGroup.HasNewProposedPonList || ponGroup.UsedPonInPonGroupList.Count == ponGroup.UsedProposedPonInPonGroupList.Count)
 1350:                         //{
 1351:                         // below: Note that I will use the INDEX of the PON number in the UsedPonList to construct the PON Id, this will make it possible 
 1352:                         // to match this index with that from the Ip, position list, because that list does not recognize PONs.
 1353:                         for (int ponGroupPonIndex = 0; ponGroupPonIndex < ponGroup.UsedPonInPonGroupList.Count; ponGroupPonIndex++)
 1354:                         {
 1355:                             if ((int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex] != 0)// && (!ponGroup.HasNewProposedPonList || (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex] != 0))
 1356:                             {
 1357:                                 pon = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon();
 1358:  
 1359:                                 ponNumber = (int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex];
 1360:  
 1361:                                 //if (ponGroup.HasNewProposedPonList) proposedPonNumber = (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex];
 1362:                                 //else proposedPonNumber = ponNumber;
 1363:  
 1364:                                 pon.Id = pon.PonId(ponGroup.Olt.Id, oltPonIndex);
 1365:  
 1366:                                 pon.Index = oltPonIndex;
 1367:                                 pon.PonGroupPonIndex = ponGroupPonIndex;
 1368:  
 1369:                                 pon.PonGroup = (from l in PonGroupList where l.Id == ponGroup.Id select l).SingleOrDefault();
 1370:  
 1371:                                 pon.Rack = pon.PonGroup.Olt.Rack;
 1372:                                 pon.Sub = pon.PonGroup.Olt.Sub;
 1373:  
 1374:                                 if (nokiaOdf)
 1375:                                 {
 1376:                                     pon.CardSlot = oltPonIndex / olt.NumberOfLts + 1;
 1377:                                     pon.Port = oltPonIndex % olt.NumberOfLts + 1;
 1378:                                 }
 1379:                                 else //if(huaweiOdf)
 1380:                                 {
 1381:                                     // Huawei skips slots 9 and 10 and goes directly from 8 to 11
 1382:  
 1383:                                     slot = oltPonIndex / (olt.NumberOfPonsPerLt * olt.NumberOfLts / 16) + 1;
 1384:  
 1385:                                     if (slot > 8) slot += 2;
 1386:  
 1387:                                     if (ponGroup.Olt.NumberOfFirstSlot == 0) slot--;
 1388:  
 1389:                                     pon.CardSlot = slot;
 1390:  
 1391:                                     pon.Port = (16 * oltPonIndex % olt.NumberOfPons) / (32 / olt.NumberOfOntsInPon) / 16;
 1392:  
 1393:                                 }
 1394:  
 1395:                                 pon.Number = ponNumber;
 1396:                                 //pon.ProposedNumber = proposedPonNumber;
 1397:                                 pon.Position = pon.PonGroup.Olt.AmsName + "-" + pon.CardSlot + "-" + pon.Port;
 1398:                                 pon.Name = pon.PonGroup.Symbol + "." + pon.Number;
 1399:  
 1400: #if DEBUG
 1401:                                 if (pon.Name == "SBA.618")
 1402:                                 {
 1403:  
 1404:                                 }
 1405: #endif
 1406:  
 1407: #if DEBUG
 1408:                                 // this will throw an exception if there is a duplicate pon.Id
 1409:                                 if (ponIdDictionary.ContainsKey(pon.Id))
 1410:                                 {
 1411:                                     throw new ArgumentOutOfRangeException(@"ponDictionary.ContainsKey(pon.Id)");
 1412:                                 }
 1413:                                 else ponIdDictionary[pon.Id] = pon.Name;
 1414: #endif
 1415:  
 1416:                                 ponList.Add(pon);
 1417:                             }
 1418: #if DEBUG
 1419:                             /*
 1420:                             else if ((int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex] != 0 && (ponGroup.HasNewProposedPonList && (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex] == 0))
 1421:                             {
 1422:                                 throw new ArgumentOutOfRangeException(@"Fault condition met: (int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex] != 0 && (!ponGroup.UsesProposedList || (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex] == 0)");
 1423:                             }
 1424:                             else if ((int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex] == 0 && (ponGroup.HasNewProposedPonList && (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex] != 0))
 1425:                             {
 1426:                                 throw new ArgumentOutOfRangeException(@"Fault condition met: (int)ponGroup.UsedPonInPonGroupList[ponGroupPonIndex] == 0 && (!ponGroup.UsesProposedList || (int)ponGroup.UsedProposedPonInPonGroupList[ponGroupPonIndex] != 0)");
 1427:                             }
 1428:                             else
 1429:                             {
 1430:                             }
 1431:                             */
 1432: #endif
 1433:                             oltPonIndex++;
 1434:                         }
 1435:                         //}
 1436:                         //else throw new ArgumentOutOfRangeException(@"Condition not met: (!ponGroup.UsesProposedList || ponGroup.UsedPonInPonGroupList.Count == ponGroup.UsedProposedPonInPonGroupList.Count)");
 1437:                     }
 1438:                     //}
 1439:                     //else throw new ArgumentOutOfRangeException(@"Condition not met: ((oltPonCount == oltProposedPonCount) || oltProposedPonCount == 0) && oltPonCount % 32 == 0");
 1440:                 }
 1441:  
 1442:                 return ponList;
 1443:             }
 1444:         }
 1445:  
 1446:         ////////////////////////////////////////////////////////////////////////////
 1447:  
 1448:         /// <summary>
 1449:         ///
 1450:         /// </summary>
 1451:         public static Dictionary<string, string> PonNameToPonIdDictionary
 1452:         {
 1453:             get
 1454:             {
 1455:                 if (ponNameToPonIdDictionary == null || ponNameToPonIdDictionary.Count == 0)
 1456:                 {
 1457:                     lock (objectLock)
 1458:                     {
 1459:                         ponNameToPonIdDictionary = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
 1460:                                                     select new { p.Name, p.Id }).ToDictionary(n => n.Name, n => n.Id);
 1461:                     }
 1462:                 }
 1463:  
 1464:                 return ponNameToPonIdDictionary;
 1465:             }
 1466:         }
 1467:  
 1468:         ////////////////////////////////////////////////////////////////////////////
 1469:  
 1470:         /// <summary>
 1471:         ///
 1472:         /// </summary>
 1473:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> PonIdToPonDictionary
 1474:         {
 1475:             get
 1476:             {
 1477:                 if (ponIdToPonDictionary == null || ponIdToPonDictionary.Count == 0)
 1478:                 {
 1479:                     lock (objectLock)
 1480:                     {
 1481:                         ponIdToPonDictionary = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
 1482:                                                 select new { p.Id, Pon = p }).ToDictionary(n => n.Id, n => n.Pon);
 1483:                     }
 1484:                 }
 1485:  
 1486:                 return ponIdToPonDictionary;
 1487:             }
 1488:         }
 1489:  
 1490:         ////////////////////////////////////////////////////////////////////////////
 1491:  
 1492:         /// <summary>
 1493:         ///
 1494:         /// </summary>
 1495:         public static Dictionary<string, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon> PonNameToPonDictionary
 1496:         {
 1497:             get
 1498:             {
 1499:                 if (ponNameToPonDictionary == null || ponNameToPonDictionary.Count == 0)
 1500:                 {
 1501:                     lock (objectLock)
 1502:                     {
 1503:                         ponNameToPonDictionary = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
 1504:                                                   select new { p.Name, Pon = p }).ToDictionary(n => n.Name, n => n.Pon);
 1505:                     }
 1506:                 }
 1507:  
 1508:                 return ponNameToPonDictionary;
 1509:             }
 1510:         }
 1511:  
 1512:         ////////////////////////////////////////////////////////////////////////////
 1513:  
 1514:         /// <summary>
 1515:         ///
 1516:         /// </summary>
 1517:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon PonByOltEmsNameAndSnAndPnAndOptionallyOntId(string emsName, int sn, int pn, int ontId)
 1518:         {
 1519:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pon pon;
 1520:  
 1521:             var olt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltByEmsName(emsName);
 1522:  
 1523:             if (olt.EmsName == "OLT-QRN-ABW-01") // ABW is all screwed up with multiple PON grouped. I will use ontId and read PON from OntList
 1524:             {
 1525:                 pon = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 1526:                        where o.Pon.PonGroup.Olt.Id == olt.Id && o.CardSlot == sn && o.Port == pn && o.InternalNumber == ontId
 1527:                        select o.Pon).SingleOrDefault();
 1528:             }
 1529:             else
 1530:             {
 1531:                 pon = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList
 1532:                        where p.PonGroup.Olt.Id == olt.Id && p.CardSlot == sn && p.Port == pn
 1533:                        select p).SingleOrDefault();
 1534:             }
 1535:  
 1536:             return pon;
 1537:         }
 1538:  
 1539:         ////////////////////////////////////////////////////////////////////////////
 1540:         ////////////////////////////////////////////////////////////////////////////
 1541:  
 1542:         /// <summary>
 1543:         ///
 1544:         /// </summary>
 1545:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup> PonGroupList
 1546:         {
 1547:             get
 1548:             {
 1549:                 if (ponGroupList == null || ponGroupList.Count == 0)
 1550:                 {
 1551:                     lock (objectLock)
 1552:                     {
 1553:                         ponGroupList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._PonGroupList;
 1554:                     }
 1555:                 }
 1556:  
 1557:                 return ponGroupList;
 1558:             }
 1559:         }
 1560:  
 1561:         ////////////////////////////////////////////////////////////////////////////
 1562:  
 1563:         /// <summary>
 1564:         ///
 1565:         /// </summary>
 1566:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup> _PonGroupList
 1567:         {
 1568:             get
 1569:             {
 1570:                 int networkId, siteId, routerId, odfId, oltId, id;
 1571:                 const string pattern = @"\d{1,3}\.\d{1,3}\.\d{1,3}\.0";
 1572:                 Regex regex;
 1573:                 Hashtable idHashtable, networkNumberHashtable;
 1574: #if DEBUG
 1575:                 Hashtable gatewayIpHashtable;
 1576: #endif
 1577:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup ponGroup;
 1578:  
 1579:                 regex = new Regex(pattern);
 1580:                 var ponGroupList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup>(16); // 16 is max number of ponGroup in ONT
 1581:                 idHashtable = new Hashtable();
 1582:                 networkNumberHashtable = new Hashtable();
 1583: #if DEBUG
 1584:                 gatewayIpHashtable = new Hashtable();
 1585: #endif
 1586:  
 1587:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 1588:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 1589:                                        select n).Single();
 1590:  
 1591:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("odf").Elements("olt").Elements("ponGroup"))
 1592:                 {
 1593:                     ponGroup = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PonGroup
 1594:                     {
 1595:                         Olt = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt()
 1596:                     };
 1597:                     ponGroup.Olt.Odf = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf();
 1598:                     ponGroup.Olt.Odf.Router = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router();
 1599:                     ponGroup.Olt.Odf.Router.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 1600:  
 1601:                     networkId = int.Parse(x.Parent.Parent.Parent.Parent.Parent.Attribute("id").Value);
 1602:                     siteId = int.Parse(x.Parent.Parent.Parent.Parent.Attribute("id").Value);
 1603:                     routerId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 1604:                     odfId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 1605:                     oltId = int.Parse(x.Parent.Attribute("id").Value);
 1606:                     id = int.Parse(x.Attribute("id").Value);
 1607:  
 1608:                     siteId = ponGroup.Olt.Odf.Router.Site.SiteId(networkId, siteId);
 1609:                     routerId = ponGroup.Olt.Odf.Router.RouterId(siteId, routerId);
 1610:                     odfId = ponGroup.Olt.Odf.OdfId(routerId, odfId);
 1611:                     oltId = ponGroup.Olt.OltId(odfId, oltId);
 1612:                     ponGroup.Id = ponGroup.PonGroupId(oltId, id);
 1613:  
 1614:                     ponGroup.Number = id;
 1615:  
 1616:                     ponGroup.Olt = (from o in OltList where o.Id == oltId select o).Single(); //.SingleOrDefault();
 1617:  
 1618:                     if (x.Attribute("symbol") != null) ponGroup.Symbol = x.Attribute("symbol").Value;
 1619:                     else ponGroup.Symbol = ponGroup.Olt.Symbol;
 1620:  
 1621:                     ponGroup.NetworkNumber = x.Attribute("networkNumber").Value;
 1622:                     // Network number must be unique and must end with *.*.*.0
 1623:                     if (networkNumberHashtable.ContainsKey(ponGroup.NetworkNumber)) throw new ArgumentException(@"Lt.NetworkNumber is not unique for LT under OLT name=" + ponGroup.Olt.Name + ". ");
 1624:                     else if (!regex.IsMatch(ponGroup.NetworkNumber)) throw new ArgumentException(@"Lt.NetworkNumber is not if format *.*.*.0 OLT name=" + ponGroup.Olt.Name + ". ");
 1625:                     else networkNumberHashtable[ponGroup.NetworkNumber] = 1;
 1626:  
 1627:  
 1628:                     ponGroup.PonListString = x.Attribute("list").Value;
 1629:                     // below: pass ponList and change "*" to "0"
 1630:                     ponGroup.UsedPonInPonGroupList = Ia.Cl.Models.Default.ConvertHyphenAndCommaSeperatedNumberStringToNumberList(ponGroup.PonListString.Replace("*", "0"));
 1631:  
 1632:                     /*
 1633:                     if (x.Attribute("proposedList") != null && x.Attribute("proposedList").Value.Length > 0)
 1634:                     {
 1635:                         ponGroup.ProposedPonListString = x.Attribute("proposedList").Value;
 1636: 
 1637:                         // below: pass ponList and change "*" to "0"
 1638:                         ponGroup.UsedProposedPonInPonGroupList = Ia.Cl.Models.Default.ConvertHyphenAndCommaSeperatedNumberStringToNumberList(ponGroup.ProposedPonListString.Replace("*", "0"));
 1639:                     }
 1640:                     else
 1641:                     {
 1642:                         ponGroup.ProposedPonListString = string.Empty;
 1643:                         ponGroup.UsedProposedPonInPonGroupList = new List<int>();
 1644:                     }
 1645:                     */
 1646:  
 1647:                     if (x.Attribute("gatewayIp") != null) ponGroup.GatewayIp = x.Attribute("gatewayIp").Value;
 1648:                     else if (x.Parent.Attribute("gatewayIp") != null) ponGroup.GatewayIp = x.Parent.Attribute("gatewayIp").Value;
 1649:                     else if (x.Parent.Parent.Attribute("gatewayIp") != null) ponGroup.GatewayIp = x.Parent.Parent.Attribute("gatewayIp").Value;
 1650:                     else throw new ArgumentException(@"ponGroup.GatewayIp could not be produced from XML document. ");
 1651:  
 1652:                     if (x.Attribute("mgcIp") != null) ponGroup.MgcIp = x.Attribute("mgcIp").Value;
 1653:                     else if (x.Parent.Attribute("mgcIp") != null) ponGroup.MgcIp = x.Parent.Attribute("mgcIp").Value;
 1654:                     else if (x.Parent.Parent.Attribute("mgcIp") != null) ponGroup.MgcIp = x.Parent.Parent.Attribute("mgcIp").Value;
 1655:                     else if (ponGroup.Olt.Name != "SAA-1" && (ponGroup.Olt.Name != "SDQ-1")) throw new ArgumentException(@"ponGroup.MgcIp could not be produced from XML document. ");
 1656:                     // note that MgcIp need some special handling on the PON.ONT level
 1657:  
 1658: #if DEBUG
 1659:                     // GatewayIp number must be unique
 1660:                     /*if (gatewayIpHashtable.ContainsKey(ponGroup.GatewayIp)) throw new ArgumentException(@"Lt.GatewayIp is not unique for LT under OLT name=" + ponGroup.Olt.Name + ". ");
 1661:                     else*/
 1662:                     gatewayIpHashtable[ponGroup.GatewayIp] = 1;
 1663:  
 1664:                     // Id
 1665:                     if (idHashtable.ContainsKey(ponGroup.Id)) throw new ArgumentException(@"ponGroup.Id is not unique for LT under OLT name=" + ponGroup.Olt.Name + ". ");
 1666:                     else idHashtable[ponGroup.Id] = 1;
 1667: #endif
 1668:                     ponGroupList.Add(ponGroup);
 1669:                 }
 1670:  
 1671:                 return ponGroupList;
 1672:             }
 1673:         }
 1674:  
 1675:         ////////////////////////////////////////////////////////////////////////////
 1676:  
 1677:         /// <summary>
 1678:         ///
 1679:         /// </summary>
 1680:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> OltList
 1681:         {
 1682:             get
 1683:             {
 1684:                 if (oltList == null || oltList.Count == 0)
 1685:                 {
 1686:                     lock (objectLock)
 1687:                     {
 1688:                         oltList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._OltList;
 1689:                     }
 1690:                 }
 1691:  
 1692:                 return oltList;
 1693:             }
 1694:         }
 1695:  
 1696:         ////////////////////////////////////////////////////////////////////////////
 1697:  
 1698:         /// <summary>
 1699:         ///
 1700:         /// </summary>
 1701:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> _OltList
 1702:         {
 1703:             get
 1704:             {
 1705:                 int networkId, siteId, routerId, odfId, id;
 1706:                 string fieldTypeString;
 1707:                 Hashtable networkNumberHashtable;
 1708:                 //Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState state;
 1709:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt;
 1710:  
 1711:                 var oltList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt>(100);
 1712:                 networkNumberHashtable = new Hashtable();
 1713:  
 1714:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 1715:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 1716:                                        select n).Single();
 1717:  
 1718:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("odf").Elements("olt"))
 1719:                 {
 1720:                     olt = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt();
 1721:                     olt.Odf = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf();
 1722:                     olt.Odf.Router = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router();
 1723:                     olt.Odf.Router.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 1724:  
 1725:                     networkId = int.Parse(x.Parent.Parent.Parent.Parent.Attribute("id").Value);
 1726:                     siteId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 1727:                     routerId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 1728:                     odfId = int.Parse(x.Parent.Attribute("id").Value);
 1729:                     id = int.Parse(x.Attribute("id").Value);
 1730:  
 1731:                     siteId = olt.Odf.Router.Site.SiteId(networkId, siteId);
 1732:                     routerId = olt.Odf.Router.RouterId(siteId, routerId);
 1733:                     odfId = olt.Odf.OdfId(routerId, odfId);
 1734:                     olt.Id = olt.OltId(odfId, id);
 1735:  
 1736:                     olt.Odf = (from o in OdfList where o.Id == odfId select o).Single(); //.SingleOrDefault();
 1737:  
 1738:                     olt.Name = x.Attribute("name").Value;
 1739:                     olt.AmsName = x.Attribute("amsName").Value;
 1740:  
 1741:                     if (x.Attribute("did") != null) olt.Did = int.Parse(x.Attribute("did").Value);
 1742:  
 1743:                     olt.Type = x.Attribute("type").Value;
 1744:  
 1745:                     /*
 1746:                     if (x.Attribute("state") != null)
 1747:                     {
 1748:                         switch (x.Attribute("state").Value)
 1749:                         {
 1750:                             case "is-nr": state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr; break;
 1751:                             case "oos-au": state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.OosAu; break;
 1752:                             case "oos-ma": state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.OosMa; break;
 1753:                             case "oos-auma": state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.OosAuma; break;
 1754:                             default: state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.Undefined; break;
 1755:                         }
 1756:                     }
 1757:                     else state = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.Undefined;
 1758:                     */
 1759:  
 1760:                     //olt.StateId = (int)state;
 1761:  
 1762:                     olt.IsSip = x.Attribute("isSip").Value == "true";
 1763:  
 1764:                     if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1765:                     {
 1766:                         olt.Rack = 1;
 1767:                         olt.Sub = 1;
 1768:                     }
 1769:                     else //if (olt.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 1770:                     {
 1771:                         olt.Rack = 0;
 1772:                         olt.Sub = 0;
 1773:                     }
 1774:  
 1775:                     if (x.Attribute("gatewayIp") != null) olt.GatewayIp = x.Attribute("gatewayIp").Value;
 1776:                     else if (x.Parent.Attribute("gatewayIp") != null) olt.GatewayIp = x.Parent.Attribute("gatewayIp").Value;
 1777:                     else olt.GatewayIp = string.Empty;
 1778:  
 1779:                     if (x.Attribute("mgcIp") != null) olt.MgcIp = x.Attribute("mgcIp").Value;
 1780:                     else if (x.Parent.Attribute("mgcIp") != null) olt.MgcIp = x.Parent.Attribute("mgcIp").Value;
 1781:                     else olt.MgcIp = string.Empty;
 1782:  
 1783:                     fieldTypeString = x.Attribute("fieldType").Value;
 1784:  
 1785:                     if (!string.IsNullOrEmpty(fieldTypeString))
 1786:                     {
 1787:                         if (fieldTypeString == "green") olt.FieldType = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green;
 1788:                         else if (fieldTypeString == "brown") olt.FieldType = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown;
 1789:                         else throw new ArgumentException(@"OLT field type unrecognized. ");
 1790:                     }
 1791:                     else throw new ArgumentException(@"OLT field type invalid. ");
 1792:  
 1793:                     olt.Symbol = x.Attribute("symbol").Value;
 1794:  
 1795:                     // below: the number of possible PONs differs between Nokia OLT types and Huawei
 1796:                     if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1797:                     {
 1798:                         olt.NumberOfPonsPerLt = 16;
 1799:                         olt.NumberOfOntsInPon = 32;
 1800:                         olt.NumberOfFirstSlot = 1;
 1801:  
 1802:                         if (olt.Type == "7342")
 1803:                         {
 1804:                             olt.NumberOfLts = 2;
 1805:                         }
 1806:                         else if (olt.Type == "7360")
 1807:                         {
 1808:                             olt.NumberOfLts = 16;
 1809:                         }
 1810:                         else
 1811:                         {
 1812:                             throw new ArgumentException(@"Nokia olt.Type unrecognized. ");
 1813:                         }
 1814:                     }
 1815:                     else if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1816:                     {
 1817:                         olt.NumberOfLts = 2;
 1818:  
 1819:                         if (olt.Type == "MA5600T")
 1820:                         {
 1821:                             olt.NumberOfPonsPerLt = 128;
 1822:                             olt.NumberOfOntsInPon = 32;
 1823:                             olt.NumberOfFirstSlot = 1;
 1824:                         }
 1825:                         else if (olt.Type == "MA5600T-2")
 1826:                         {
 1827:                             olt.NumberOfPonsPerLt = 128 * 8;
 1828:                             olt.NumberOfOntsInPon = 4;
 1829:                             olt.NumberOfFirstSlot = 1;
 1830:                         }
 1831:                         else if (olt.Type == "MA5603T")
 1832:                         {
 1833:                             olt.NumberOfPonsPerLt = 128;
 1834:                             olt.NumberOfOntsInPon = 32;
 1835:                             olt.NumberOfFirstSlot = 0;
 1836:                         }
 1837:                         else
 1838:                         {
 1839:                             throw new ArgumentException(@"Huawei olt.Type unrecognized. ");
 1840:                         }
 1841:                     }
 1842:                     else
 1843:                     {
 1844:                         throw new ArgumentException(@"olt.Odf.Vendor unrecognized. ");
 1845:                     }
 1846:  
 1847:                     olt.NumberOfPons = olt.NumberOfLts * olt.NumberOfPonsPerLt;
 1848: #if DEBUG
 1849:                     // check that the location of OLTs must adhere to the naming principles of OLTs by vendors (e.g. MUB-QRN-H is OLT-SITE-H, and OLT-QRN-ABF-01 is OLT-SITE-OLT-01).
 1850:  
 1851:                     var siteName = olt.Odf.Router.Site.Name;
 1852:  
 1853:                     if (siteName != "LAB")
 1854:                     {
 1855:                         var oltAmsName = olt.AmsName;
 1856:                         var odfName = olt.Odf.Name;
 1857:                         var oltSymbol = olt.Symbol;
 1858:  
 1859:                         if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia)
 1860:                         {
 1861:                             if (siteName == "JHB") siteName = "JHR";
 1862:                             if (oltSymbol == "ESU") oltSymbol = "SUL";
 1863:                             if (!oltAmsName.StartsWith(oltSymbol + "-" + siteName + "-")) throw new ArgumentException(@"Olt AmsName does not match the Olt naming convension for vendor.");
 1864:                         }
 1865:                         else if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei)
 1866:                         {
 1867:                             if (!oltAmsName.StartsWith("OLT-" + siteName + "-" + odfName)) throw new ArgumentException(@"Olt AmsName does not match the Olt naming convension for vendor.");
 1868:                         }
 1869:                         else throw new ArgumentException(@"Unknown vendor");
 1870:                     }
 1871:  
 1872:                     if ((olt.NumberOfPons * olt.NumberOfOntsInPon % 1024) != 0) throw new ArgumentException(@"(olt.NumberOfPons * olt.NumberOfOntsInPon % 1024) != 0");
 1873:                     if (olt.NumberOfFirstSlot != 0 && olt.NumberOfFirstSlot != 1) throw new ArgumentException(@"olt.NumberOfFirstSlot == 0 || olt.NumberOfFirstSlot == 1");
 1874: #endif
 1875:                     oltList.Add(olt);
 1876:                 }
 1877:  
 1878:                 return oltList;
 1879:             }
 1880:         }
 1881:  
 1882:         ////////////////////////////////////////////////////////////////////////////
 1883:         ////////////////////////////////////////////////////////////////////////////
 1884:  
 1885:         /// <summary>
 1886:         ///
 1887:         /// </summary>
 1888:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> NokiaOltList
 1889:         {
 1890:             get
 1891:             {
 1892:                 lock (objectLock)
 1893:                 {
 1894:                     return VendorOltList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia, 0);
 1895:                 }
 1896:             }
 1897:         }
 1898:  
 1899:         ////////////////////////////////////////////////////////////////////////////
 1900:  
 1901:         /// <summary>
 1902:         ///
 1903:         /// </summary>
 1904:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> HuaweiOltList
 1905:         {
 1906:             get
 1907:             {
 1908:                 lock (objectLock)
 1909:                 {
 1910:                     return VendorOltList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei, 0);
 1911:                 }
 1912:             }
 1913:         }
 1914:  
 1915:         ////////////////////////////////////////////////////////////////////////////
 1916:  
 1917:         /// <summary>
 1918:         ///
 1919:         /// </summary>
 1920:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> VendorOltList(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor, int siteId)
 1921:         {
 1922:             lock (objectLock)
 1923:             {
 1924:                 List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> list;
 1925:  
 1926:                 list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 1927:                         where o.Odf.Vendor == vendor && (o.Odf.Router.Site.Id == siteId || siteId == 0)
 1928:                         select o).ToList();
 1929:  
 1930:                 return list;
 1931:             }
 1932:         }
 1933:  
 1934:         ////////////////////////////////////////////////////////////////////////////
 1935:  
 1936:         /// <summary>
 1937:         ///
 1938:         /// </summary>
 1939:         public static List<int> NokiaOltIdList()
 1940:         {
 1941:             return OltIdByVendorAndSiteIdList("No", 0);
 1942:         }
 1943:  
 1944:         ////////////////////////////////////////////////////////////////////////////
 1945:  
 1946:         /// <summary>
 1947:         ///
 1948:         /// </summary>
 1949:         public static List<int> NokiaOltIdList(int siteId)
 1950:         {
 1951:             return OltIdByVendorAndSiteIdList("No", siteId);
 1952:         }
 1953:  
 1954:         ////////////////////////////////////////////////////////////////////////////
 1955:  
 1956:         /// <summary>
 1957:         ///
 1958:         /// </summary>
 1959:         public static List<int> HuaweiOltIdList()
 1960:         {
 1961:             return OltIdByVendorAndSiteIdList("Hu", 0);
 1962:         }
 1963:  
 1964:         ////////////////////////////////////////////////////////////////////////////
 1965:  
 1966:         /// <summary>
 1967:         ///
 1968:         /// </summary>
 1969:         public static List<int> HuaweiOltIdList(int siteId)
 1970:         {
 1971:             return OltIdByVendorAndSiteIdList("Hu", siteId);
 1972:         }
 1973:  
 1974:         ////////////////////////////////////////////////////////////////////////////
 1975:  
 1976:         /// <summary>
 1977:         ///
 1978:         /// </summary>
 1979:         public static List<int> OltIdByVendorAndSiteIdList(string vendorShortName, int siteId)
 1980:         {
 1981:             List<int> list;
 1982:  
 1983:             list = new List<int>();
 1984:  
 1985:             foreach (var olt in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList)
 1986:             {
 1987:                 // siteId 0 will return all sites
 1988:  
 1989:                 if (olt.Odf.Vendor.ShortName == vendorShortName && (olt.Odf.Router.Site.Id == siteId || siteId == 0))
 1990:                 {
 1991:                     list.Add(olt.Id);
 1992:                 }
 1993:             }
 1994:  
 1995:             return list;
 1996:         }
 1997:  
 1998:         ////////////////////////////////////////////////////////////////////////////
 1999:  
 2000:         /// <summary>
 2001:         ///
 2002:         /// </summary>
 2003:         public static List<int> NokiaRouterNokiaAccessOltIdList
 2004:         {
 2005:             get
 2006:             {
 2007:                 lock (objectLock)
 2008:                 {
 2009:                     var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2010:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 2011:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 2012:                                 select o.Id).ToList();
 2013:  
 2014:                     return list;
 2015:                 }
 2016:             }
 2017:         }
 2018:  
 2019:         ////////////////////////////////////////////////////////////////////////////
 2020:  
 2021:         /// <summary>
 2022:         ///
 2023:         /// </summary>
 2024:         public static List<int> HuaweiRouterNokiaAccessOltIdList
 2025:         {
 2026:             get
 2027:             {
 2028:                 lock (objectLock)
 2029:                 {
 2030:                     var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2031:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei
 2032:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 2033:                                 select o.Id).ToList();
 2034:  
 2035:                     return list;
 2036:                 }
 2037:             }
 2038:         }
 2039:  
 2040:         ////////////////////////////////////////////////////////////////////////////
 2041:  
 2042:         /// <summary>
 2043:         ///
 2044:         /// </summary>
 2045:         public static List<int> NokiaRouterHuaweiAccessOltIdList
 2046:         {
 2047:             get
 2048:             {
 2049:                 lock (objectLock)
 2050:                 {
 2051:                     var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2052:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 2053:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei
 2054:                                 select o.Id).ToList();
 2055:  
 2056:                     return list;
 2057:                 }
 2058:             }
 2059:         }
 2060:  
 2061:         ////////////////////////////////////////////////////////////////////////////
 2062:         ////////////////////////////////////////////////////////////////////////////
 2063:  
 2064:         /// <summary>
 2065:         ///
 2066:         /// </summary>
 2067:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt OltByEmsName(string emsName)
 2068:         {
 2069:             var olt = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2070:                        where o.EmsName == emsName
 2071:                        select o).SingleOrDefault();
 2072:  
 2073:             return olt;
 2074:         }
 2075:  
 2076:         ////////////////////////////////////////////////////////////////////////////
 2077:  
 2078:         /// <summary>
 2079:         ///
 2080:         /// </summary>
 2081:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt OltByAmsName(string amsName)
 2082:         {
 2083:             var olt = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2084:                        where o.AmsName == amsName
 2085:                        select o).SingleOrDefault();
 2086:  
 2087:             return olt;
 2088:         }
 2089:  
 2090:         ////////////////////////////////////////////////////////////////////////////
 2091:  
 2092:         /// <summary>
 2093:         ///
 2094:         /// </summary>
 2095:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt OltByDid(int did)
 2096:         {
 2097:             var olt = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2098:                        where o.Did == did
 2099:                        select o).SingleOrDefault();
 2100:  
 2101:             return olt;
 2102:         }
 2103:  
 2104:         ////////////////////////////////////////////////////////////////////////////
 2105:  
 2106:         /// <summary>
 2107:         ///
 2108:         /// </summary>
 2109:         public static Dictionary<int, int> DidToOltIdDictionary
 2110:         {
 2111:             get
 2112:             {
 2113:                 if (didToOltIdDictionary == null || didToOltIdDictionary.Count == 0)
 2114:                 {
 2115:                     lock (objectLock)
 2116:                     {
 2117:                         didToOltIdDictionary = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2118:                                                 where o.Did != 0
 2119:                                                 select new { o.Did, OltId = o.Id }).ToDictionary(n => n.Did, n => n.OltId);
 2120:                     }
 2121:                 }
 2122:  
 2123:                 return didToOltIdDictionary;
 2124:             }
 2125:         }
 2126:  
 2127:         ////////////////////////////////////////////////////////////////////////////
 2128:         ////////////////////////////////////////////////////////////////////////////
 2129:  
 2130:         /// <summary>
 2131:         ///
 2132:         /// </summary>
 2133:         public static List<int> SipOltIdList
 2134:         {
 2135:             get
 2136:             {
 2137:                 lock (objectLock)
 2138:                 {
 2139:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2140:                             where o.IsSip == true
 2141:                             select o.Id).ToList();
 2142:                 }
 2143:             }
 2144:         }
 2145:  
 2146:         ////////////////////////////////////////////////////////////////////////////
 2147:         ////////////////////////////////////////////////////////////////////////////
 2148:  
 2149:         /// <summary>
 2150:         ///
 2151:         /// </summary>
 2152:         public static List<int> GreenFieldOltIdList
 2153:         {
 2154:             get
 2155:             {
 2156:                 lock (objectLock)
 2157:                 {
 2158:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2159:                             where o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green
 2160:                             select o.Id).ToList();
 2161:                 }
 2162:             }
 2163:         }
 2164:  
 2165:         ////////////////////////////////////////////////////////////////////////////
 2166:  
 2167:         /// <summary>
 2168:         ///
 2169:         /// </summary>
 2170:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> GreenFieldOltList
 2171:         {
 2172:             get
 2173:             {
 2174:                 lock (objectLock)
 2175:                 {
 2176:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2177:                             where o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green
 2178:                             select o).ToList();
 2179:                 }
 2180:             }
 2181:         }
 2182:  
 2183:         ////////////////////////////////////////////////////////////////////////////
 2184:  
 2185:         /// <summary>
 2186:         ///
 2187:         /// </summary>
 2188:         public static List<int> GreenFieldSipOltIdList
 2189:         {
 2190:             get
 2191:             {
 2192:                 lock (objectLock)
 2193:                 {
 2194:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2195:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green
 2196:                             select o.Id).ToList();
 2197:                 }
 2198:             }
 2199:         }
 2200:  
 2201:         ////////////////////////////////////////////////////////////////////////////
 2202:  
 2203:         /// <summary>
 2204:         ///
 2205:         /// </summary>
 2206:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> GreenFieldSipOltList
 2207:         {
 2208:             get
 2209:             {
 2210:                 lock (objectLock)
 2211:                 {
 2212:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2213:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green
 2214:                             select o).ToList();
 2215:                 }
 2216:             }
 2217:         }
 2218:  
 2219:         ////////////////////////////////////////////////////////////////////////////
 2220:  
 2221:         /// <summary>
 2222:         ///
 2223:         /// </summary>
 2224:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> GreenFieldOntList
 2225:         {
 2226:             get
 2227:             {
 2228:                 if (greenFieldOntList == null || greenFieldOntList.Count == 0)
 2229:                 {
 2230:                     lock (objectLock)
 2231:                     {
 2232:                         greenFieldOntList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2233:                                              where o.Pon.PonGroup.Olt.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Green
 2234:                                              select o).ToList();
 2235:  
 2236:                     }
 2237:                 }
 2238:  
 2239:                 return greenFieldOntList;
 2240:             }
 2241:         }
 2242:  
 2243:         ////////////////////////////////////////////////////////////////////////////
 2244:         ////////////////////////////////////////////////////////////////////////////
 2245:  
 2246:         /// <summary>
 2247:         ///
 2248:         /// </summary>
 2249:         public static List<int> BrownFieldOltIdList
 2250:         {
 2251:             get
 2252:             {
 2253:                 lock (objectLock)
 2254:                 {
 2255:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2256:                             where o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown
 2257:                             select o.Id).ToList();
 2258:                 }
 2259:             }
 2260:         }
 2261:  
 2262:         ////////////////////////////////////////////////////////////////////////////
 2263:  
 2264:         /// <summary>
 2265:         ///
 2266:         /// </summary>
 2267:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> BrownFieldOltList
 2268:         {
 2269:             get
 2270:             {
 2271:                 lock (objectLock)
 2272:                 {
 2273:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2274:                             where o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown
 2275:                             select o).ToList();
 2276:                 }
 2277:             }
 2278:         }
 2279:  
 2280:         ////////////////////////////////////////////////////////////////////////////
 2281:  
 2282:         /// <summary>
 2283:         ///
 2284:         /// </summary>
 2285:         public static List<int> BrownFieldSipOltIdList
 2286:         {
 2287:             get
 2288:             {
 2289:                 lock (objectLock)
 2290:                 {
 2291:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2292:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown
 2293:                             select o.Id).ToList();
 2294:                 }
 2295:             }
 2296:         }
 2297:  
 2298:         ////////////////////////////////////////////////////////////////////////////
 2299:  
 2300:         /// <summary>
 2301:         ///
 2302:         /// </summary>
 2303:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt> BrownFieldSipOltList
 2304:         {
 2305:             get
 2306:             {
 2307:                 lock (objectLock)
 2308:                 {
 2309:                     return (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2310:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown
 2311:                             select o).ToList();
 2312:                 }
 2313:             }
 2314:         }
 2315:  
 2316:         ////////////////////////////////////////////////////////////////////////////
 2317:  
 2318:         /// <summary>
 2319:         ///
 2320:         /// </summary>
 2321:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont> BrownFieldOntList
 2322:         {
 2323:             get
 2324:             {
 2325:                 if (brownFieldOntList == null || brownFieldOntList.Count == 0)
 2326:                 {
 2327:                     lock (objectLock)
 2328:                     {
 2329:                         brownFieldOntList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
 2330:                                              where o.Pon.PonGroup.Olt.FieldType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.FieldType.Brown
 2331:                                              select o).ToList();
 2332:  
 2333:                     }
 2334:                 }
 2335:  
 2336:                 return brownFieldOntList;
 2337:             }
 2338:         }
 2339:  
 2340:         ////////////////////////////////////////////////////////////////////////////
 2341:         ////////////////////////////////////////////////////////////////////////////
 2342:  
 2343:         /// <summary>
 2344:         ///
 2345:         /// </summary>
 2346:         public static List<string> NokiaOltAmsNameList
 2347:         {
 2348:             get
 2349:             {
 2350:                 lock (objectLock)
 2351:                 {
 2352:                     List<string> list;
 2353:  
 2354:                     list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2355:                             where o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia
 2356:                             //&& o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr
 2357:                             select o.AmsName).ToList();
 2358:  
 2359:                     return list;
 2360:                 }
 2361:             }
 2362:         }
 2363:  
 2364:         ////////////////////////////////////////////////////////////////////////////
 2365:  
 2366:         /// <summary>
 2367:         ///
 2368:         /// </summary>
 2369:         public static List<string> HuaweiOltAmsNameList
 2370:         {
 2371:             get
 2372:             {
 2373:                 lock (objectLock)
 2374:                 {
 2375:                     List<string> list;
 2376:  
 2377:                     list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
 2378:                             where o.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei
 2379:                             //&& o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr
 2380:                             select o.AmsName).ToList();
 2381:  
 2382:                     return list;
 2383:                 }
 2384:             }
 2385:         }
 2386:  
 2387:         ////////////////////////////////////////////////////////////////////////////
 2388:  
 2389:         /// <summary>
 2390:         ///
 2391:         /// </summary>
 2392:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf> OdfList
 2393:         {
 2394:             get
 2395:             {
 2396:                 if (odfList == null || odfList.Count == 0)
 2397:                 {
 2398:                     lock (objectLock)
 2399:                     {
 2400:                         odfList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._OdfList;
 2401:                     }
 2402:                 }
 2403:  
 2404:                 return odfList;
 2405:             }
 2406:         }
 2407:  
 2408:         ////////////////////////////////////////////////////////////////////////////
 2409:  
 2410:         /// <summary>
 2411:         ///
 2412:         /// </summary>
 2413:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf> _OdfList
 2414:         {
 2415:             get
 2416:             {
 2417:                 int networkId, siteId, routerId, id;
 2418:                 string vendorShortName;
 2419:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf odf;
 2420:  
 2421:                 var odfList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf>();
 2422:  
 2423:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2424:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2425:                                        select n).Single();
 2426:  
 2427:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("odf"))
 2428:                 {
 2429:                     odf = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf();
 2430:                     odf.Router = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router();
 2431:                     odf.Router.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 2432:  
 2433:                     networkId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 2434:                     siteId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2435:                     routerId = int.Parse(x.Parent.Attribute("id").Value);
 2436:                     id = int.Parse(x.Attribute("id").Value);
 2437:  
 2438:                     siteId = odf.Router.Site.SiteId(networkId, siteId);
 2439:                     routerId = odf.Router.RouterId(siteId, routerId);
 2440:                     odf.Id = odf.OdfId(routerId, id);
 2441:  
 2442:                     odf.Name = x.Attribute("name").Value;
 2443:  
 2444:                     odf.GatewayIp = (x.Attribute("gatewayIp") != null) ? x.Attribute("gatewayIp").Value : string.Empty;
 2445:                     odf.MgcIp = (x.Attribute("mgcIp") != null) ? x.Attribute("mgcIp").Value : string.Empty;
 2446:  
 2447:                     vendorShortName = x.Attribute("vendorShortName").Value;
 2448:                     odf.Vendor = (from v in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.VendorList where v.ShortName == vendorShortName select v).Single(); //.si.SingleOrDefault();
 2449:  
 2450:                     odf.Router = (from r in RouterList where r.Id == routerId select r).Single(); //.SingleOrDefault();
 2451:  
 2452:                     odfList.Add(odf);
 2453:                 }
 2454:  
 2455:                 return odfList.ToList();
 2456:             }
 2457:         }
 2458:  
 2459:         ////////////////////////////////////////////////////////////////////////////
 2460:  
 2461:         /// <summary>
 2462:         ///
 2463:         /// </summary>
 2464:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam> OamList
 2465:         {
 2466:             get
 2467:             {
 2468:                 if (oamList == null || oamList.Count == 0)
 2469:                 {
 2470:                     lock (objectLock)
 2471:                     {
 2472:                         oamList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._OamList;
 2473:                     }
 2474:                 }
 2475:  
 2476:                 return oamList;
 2477:             }
 2478:         }
 2479:  
 2480:         ////////////////////////////////////////////////////////////////////////////
 2481:  
 2482:         /// <summary>
 2483:         ///
 2484:         /// </summary>
 2485:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam> _OamList
 2486:         {
 2487:             get
 2488:             {
 2489:                 int networkId, siteId, routerId, id;
 2490:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam oam;
 2491:  
 2492:                 var oamList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam>();
 2493:  
 2494:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2495:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2496:                                        select n).Single();
 2497:  
 2498:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("oam"))
 2499:                 {
 2500:                     oam = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Oam();
 2501:                     oam.Router = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router();
 2502:                     oam.Router.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 2503:  
 2504:                     networkId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 2505:                     siteId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2506:                     routerId = int.Parse(x.Parent.Attribute("id").Value);
 2507:                     id = int.Parse(x.Attribute("id").Value);
 2508:  
 2509:                     siteId = oam.Router.Site.SiteId(networkId, siteId);
 2510:                     routerId = oam.Router.RouterId(siteId, routerId);
 2511:                     oam.Id = oam.OamId(routerId, id);
 2512:  
 2513:                     oam.Network = x.Attribute("network").Value;
 2514:                     oam.Gateway = x.Attribute("gateway").Value;
 2515:                     oam.Vlan = int.Parse(x.Attribute("vlan").Value);
 2516:                     oam.Vpls = int.Parse(x.Attribute("vpls").Value);
 2517:                     oam.FtpIp = x.Attribute("ftpIp").Value;
 2518:                     oam.ConfigFile = x.Attribute("configFile").Value;
 2519:  
 2520:                     oam.Router = (from r in RouterList where r.Id == routerId select r).Single(); //.SingleOrDefault();
 2521:  
 2522:                     oamList.Add(oam);
 2523:                 }
 2524:  
 2525:                 return oamList;
 2526:             }
 2527:         }
 2528:  
 2529:         ////////////////////////////////////////////////////////////////////////////
 2530:  
 2531:         /// <summary>
 2532:         ///
 2533:         /// </summary>
 2534:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor SwitchVendorByService(string service)
 2535:         {
 2536:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
 2537:  
 2538:             if (int.TryParse(service, out int i))
 2539:             {
 2540:                 switchVendor = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
 2541:                                 where r.DomainList.Any(u => service.StartsWith(u.ToString()))
 2542:                                 select r.Vendor).FirstOrDefault(); //.SingleOrDefault();
 2543:  
 2544:                 if (switchVendor == null) switchVendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 2545:             }
 2546:             else switchVendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 2547:  
 2548:             return switchVendor;
 2549:         }
 2550:  
 2551:         ////////////////////////////////////////////////////////////////////////////
 2552:  
 2553:         /// <summary>
 2554:         ///
 2555:         /// </summary>
 2556:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> SwitchVendorListByServiceList(List<string> serviceList)
 2557:         {
 2558:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor switchVendor;
 2559:             var switchVendorList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>();
 2560:  
 2561:             foreach (var service in serviceList)
 2562:             {
 2563:                 if (int.TryParse(service, out int i))
 2564:                 {
 2565:                     switchVendor = (from r in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.RouterList
 2566:                                     where r.DomainList.Any(u => service.StartsWith(u.ToString()))
 2567:                                     select r.Vendor).FirstOrDefault(); //.SingleOrDefault();
 2568:  
 2569:                     if (switchVendor == null) switchVendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 2570:                 }
 2571:                 else switchVendor = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Undefined;
 2572:  
 2573:                 switchVendorList.Add(switchVendor);
 2574:             }
 2575:  
 2576:             return switchVendorList;
 2577:         }
 2578:  
 2579:         ////////////////////////////////////////////////////////////////////////////
 2580:  
 2581:         /// <summary>
 2582:         ///
 2583:         /// </summary>
 2584:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn PstnFromService(int number)
 2585:         {
 2586:             return PstnFromService(number.ToString());
 2587:         }
 2588:  
 2589:         ////////////////////////////////////////////////////////////////////////////
 2590:  
 2591:         /// <summary>
 2592:         ///
 2593:         /// </summary>
 2594:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn PstnFromService(string service)
 2595:         {
 2596:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn pstn;
 2597:  
 2598:             if (int.TryParse(service, out int i))
 2599:             {
 2600:                 pstn = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList
 2601:                         where p.DomainList.Any(u => service.StartsWith(u.ToString()))
 2602:                         select p).SingleOrDefault();
 2603:             }
 2604:             else pstn = null;
 2605:  
 2606:             return pstn;
 2607:         }
 2608:  
 2609:         ////////////////////////////////////////////////////////////////////////////
 2610:  
 2611:         /// <summary>
 2612:         ///
 2613:         /// </summary>
 2614:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> PstnThatUsesNpServerList
 2615:         {
 2616:             get
 2617:             {
 2618:                 var list = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList
 2619:                             where p.UsesNpServer == true
 2620:                             select p).ToList();
 2621:  
 2622:                 return list;
 2623:             }
 2624:         }
 2625:  
 2626:         ////////////////////////////////////////////////////////////////////////////
 2627:  
 2628:         /// <summary>
 2629:         ///
 2630:         /// </summary>
 2631:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> PstnList
 2632:         {
 2633:             get
 2634:             {
 2635:                 if (pstnList == null || pstnList.Count == 0)
 2636:                 {
 2637:                     lock (objectLock)
 2638:                     {
 2639:                         var networkId = 1; // <network id="1" name="Fixed Telecommunications Network">
 2640:  
 2641:                         pstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._PstnList(networkId);
 2642:                     }
 2643:                 }
 2644:  
 2645:                 return pstnList;
 2646:             }
 2647:         }
 2648:  
 2649:         ////////////////////////////////////////////////////////////////////////////
 2650:  
 2651:         /// <summary>
 2652:         ///
 2653:         /// </summary>
 2654:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> LegacyPstnList
 2655:         {
 2656:             get
 2657:             {
 2658:                 if (legacyPstnList == null || legacyPstnList.Count == 0)
 2659:                 {
 2660:                     lock (objectLock)
 2661:                     {
 2662:                         var networkId = 2; // <network id="2" name="Legacy">
 2663:  
 2664:                         legacyPstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._PstnList(networkId);
 2665:                     }
 2666:                 }
 2667:  
 2668:                 return legacyPstnList;
 2669:             }
 2670:         }
 2671:  
 2672:         ////////////////////////////////////////////////////////////////////////////
 2673:  
 2674:         /// <summary>
 2675:         ///
 2676:         /// </summary>
 2677:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> FtnAndLegacyPstnList
 2678:         {
 2679:             get
 2680:             {
 2681:                 var pstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList;
 2682:                 var legacyPstnList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.LegacyPstnList;
 2683:  
 2684:                 var list = pstnList.Union(legacyPstnList).ToList();
 2685:  
 2686:                 return list;
 2687:             }
 2688:         }
 2689:  
 2690:         ////////////////////////////////////////////////////////////////////////////
 2691:  
 2692:         /// <summary>
 2693:         ///
 2694:         /// </summary>
 2695:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn LegacyPstnFromService(int number)
 2696:         {
 2697:             return LegacyPstnFromService(number.ToString());
 2698:         }
 2699:  
 2700:         ////////////////////////////////////////////////////////////////////////////
 2701:  
 2702:         /// <summary>
 2703:         ///
 2704:         /// </summary>
 2705:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn LegacyPstnFromService(string service)
 2706:         {
 2707:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn pstn;
 2708:  
 2709:             if (int.TryParse(service, out int i))
 2710:             {
 2711:                 pstn = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.LegacyPstnList
 2712:                         where p.DomainList.Any(u => service.StartsWith(u.ToString()))
 2713:                         select p).SingleOrDefault();
 2714:             }
 2715:             else pstn = null;
 2716:  
 2717:             return pstn;
 2718:         }
 2719:  
 2720:         ////////////////////////////////////////////////////////////////////////////
 2721:  
 2722:         /// <summary>
 2723:         ///
 2724:         /// </summary>
 2725:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> _PstnList(int networkId)
 2726:         {
 2727:             int siteId, id;
 2728:             string pstnExchangeTypeString, usesNpServerString;
 2729: #if DEBUG
 2730:             //Dictionary<int, int> domainDictionary;
 2731: #endif
 2732:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn pstn;
 2733:  
 2734: #if DEBUG
 2735:             //domainDictionary = new Dictionary<int, int>(100);
 2736: #endif
 2737:             var pstnList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn>();
 2738:  
 2739:             var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2740:                                    where n.Attribute("id").Value == networkId.ToString()
 2741:                                    select n).Single();
 2742:  
 2743:             foreach (XElement x in networkXElement.Elements("site").Elements("pstn"))
 2744:             {
 2745:                 pstn = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn();
 2746:                 pstn.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 2747:  
 2748:                 networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2749:                 siteId = int.Parse(x.Parent.Attribute("id").Value);
 2750:                 id = int.Parse(x.Attribute("id").Value);
 2751:  
 2752:                 siteId = pstn.Site.SiteId(networkId, siteId);
 2753:                 pstn.Id = pstn.PstnId(siteId, id);
 2754:                 pstn.Name = x.Attribute("name").Value;
 2755:                 pstn.ArabicName = x.Attribute("arabicName").Value;
 2756:  
 2757:                 //if (x.Attribute("ip") != null) pstn.Ip = x.Attribute("ip").Value;
 2758:                 //else pstn.Ip = string.Empty;
 2759:  
 2760:                 pstn.DomainListString = x.Attribute("domainList").Value;
 2761:  
 2762:                 pstn.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(pstn.DomainListString);
 2763:  
 2764: #if DEBUG
 2765:                 /*
 2766:                 foreach (int i in pstn.DomainList)
 2767:                 {
 2768:                     // this will throw an exception if there are similar domains in pstns
 2769:                     if (domainDictionary.ContainsKey(i))
 2770:                     {
 2771:                         throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 2772:                     }
 2773:                     else domainDictionary[i] = 1;
 2774:                 }
 2775:                 */
 2776: #endif
 2777:  
 2778:                 pstnExchangeTypeString = x.Attribute("type").Value;
 2779:  
 2780:                 if (pstnExchangeTypeString == "EWSD") pstn.PstnExchangeType = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.SiemensEwsd;
 2781:                 else if (pstnExchangeTypeString == "AXE") pstn.PstnExchangeType = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.EricssonAxe;
 2782:                 else if (pstnExchangeTypeString == "MRD") pstn.PstnExchangeType = Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.NortelMeridian;
 2783: #if DEBUG
 2784:                 else throw new ArgumentOutOfRangeException(@"Unknown PSTN exchange type: " + pstnExchangeTypeString);
 2785: #endif
 2786:                 usesNpServerString = x.Attribute("usesNpServer") != null ? x.Attribute("usesNpServer").Value : "false";
 2787:                 pstn.UsesNpServer = usesNpServerString == "true";
 2788:  
 2789:                 if (networkId == 1) pstn.Site = (from s in SiteList where s.Id == siteId select s).Single(); // <network id="1" name="Fixed Telecommunications Network">
 2790:                 else /*if(networkId == 2)*/ pstn.Site = (from s in LegacySiteList where s.Id == siteId select s).Single(); // <network id="2" name="Legacy">
 2791:  
 2792:                 pstnList.Add(pstn);
 2793:             }
 2794:  
 2795:             return pstnList;
 2796:         }
 2797:  
 2798:         ////////////////////////////////////////////////////////////////////////////
 2799:  
 2800:         /// <summary>
 2801:         ///
 2802:         /// </summary>
 2803:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn PstnFromName(string name)
 2804:         {
 2805:             var pstn = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnList where p.Name == name select p).Single();
 2806:  
 2807:             return pstn;
 2808:         }
 2809:  
 2810:         ////////////////////////////////////////////////////////////////////////////
 2811:         ////////////////////////////////////////////////////////////////////////////
 2812:  
 2813:         /// <summary>
 2814:         ///
 2815:         /// </summary>
 2816:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan> MsanList
 2817:         {
 2818:             get
 2819:             {
 2820:                 if (msanList == null || msanList.Count == 0)
 2821:                 {
 2822:                     lock (objectLock)
 2823:                     {
 2824:                         msanList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._MsanList;
 2825:                     }
 2826:                 }
 2827:  
 2828:                 return msanList;
 2829:             }
 2830:         }
 2831:  
 2832:         ////////////////////////////////////////////////////////////////////////////
 2833:  
 2834:         /// <summary>
 2835:         ///
 2836:         /// </summary>
 2837:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan> _MsanList
 2838:         {
 2839:             get
 2840:             {
 2841:                 int networkId, siteId, id;
 2842:                 //string usesNpServerString;
 2843: #if DEBUG
 2844:                 //Dictionary<int, int> domainDictionary;
 2845: #endif
 2846:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan;
 2847:  
 2848: #if DEBUG
 2849:                 //domainDictionary = new Dictionary<int, int>(100);
 2850: #endif
 2851:                 var msanList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan>();
 2852:  
 2853:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2854:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2855:                                        select n).Single();
 2856:  
 2857:                 foreach (XElement x in networkXElement.Elements("site").Elements("msan"))
 2858:                 {
 2859:                     msan = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan();
 2860:                     msan.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 2861:  
 2862:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2863:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 2864:                     id = int.Parse(x.Attribute("id").Value);
 2865:  
 2866:                     siteId = msan.Site.SiteId(networkId, siteId);
 2867:                     msan.Id = msan.MsanId(siteId, id);
 2868:                     msan.NameSymbol = x.Attribute("nameSymbol").Value;
 2869:  
 2870:                     msan.DomainListString = x.Attribute("domainList").Value;
 2871:  
 2872:                     msan.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(msan.DomainListString);
 2873:  
 2874:                     //usesNpServerString = x.Attribute("usesNpServer").Value;
 2875:                     msan.UsesNpServer = false; // usesNpServerString == "true";
 2876:  
 2877:                     msan.Site = (from s in SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 2878:  
 2879: #if DEBUG
 2880:                     /*
 2881:                      
 2882:                     // You might have and MSAN on a site but the equivalent domains in another site
 2883:                     if (msan.DomainList != null)
 2884:                     {
 2885:                         foreach (var s in msan.DomainList)
 2886:                         {
 2887:                             if (!msan.Site.DomainList.Contains(s))
 2888:                             {
 2889:                                 throw new ArgumentOutOfRangeException(@"msan.Site.DomainList does not contain " + s + ".");
 2890:                             }
 2891:                         }
 2892:                     }
 2893:                     */
 2894:  
 2895:  
 2896:                     /*
 2897:                     foreach (int i in msan.DomainList)
 2898:                     {
 2899:                         // this will throw an exception if there are similar domains in pstns
 2900:                         if (domainDictionary.ContainsKey(i))
 2901:                         {
 2902:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 2903:                         }
 2904:                         else domainDictionary[i] = 1;
 2905:                     }
 2906:                     */
 2907: #endif
 2908:  
 2909:                     msanList.Add(msan);
 2910:                 }
 2911:  
 2912:                 return msanList;
 2913:             }
 2914:         }
 2915:  
 2916:         ////////////////////////////////////////////////////////////////////////////
 2917:  
 2918:         /// <summary>
 2919:         ///
 2920:         /// </summary>
 2921:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan MsanFromNameSymbol(string nameSymbol)
 2922:         {
 2923:             var msanList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.MsanList;
 2924:  
 2925:             var msan = (from m in msanList
 2926:                         where m.NameSymbol == nameSymbol
 2927:                         select m).SingleOrDefault();
 2928:  
 2929:             return msan;
 2930:         }
 2931:  
 2932:         ////////////////////////////////////////////////////////////////////////////
 2933:  
 2934:         /// <summary>
 2935:         ///
 2936:         /// </summary>
 2937:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan MsanFromSiteName(string siteName)
 2938:         {
 2939:             var siteList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList;
 2940:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan;
 2941:  
 2942:             var site = (from s in siteList
 2943:                         where s.Name == siteName
 2944:                         select s).SingleOrDefault();
 2945:  
 2946:             msan = (site != null && site.Msans.Count != 0) ? site.Msans.FirstOrDefault() : null;
 2947:  
 2948:             return msan;
 2949:         }
 2950:  
 2951:         ////////////////////////////////////////////////////////////////////////////
 2952:         ////////////////////////////////////////////////////////////////////////////
 2953:  
 2954:         /// <summary>
 2955:         ///
 2956:         /// </summary>
 2957:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX> SoftXList
 2958:         {
 2959:             get
 2960:             {
 2961:                 if (softXList == null || softXList.Count == 0)
 2962:                 {
 2963:                     lock (objectLock)
 2964:                     {
 2965:                         softXList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._SoftXList;
 2966:                     }
 2967:                 }
 2968:  
 2969:                 return softXList;
 2970:             }
 2971:         }
 2972:  
 2973:         ////////////////////////////////////////////////////////////////////////////
 2974:  
 2975:         /// <summary>
 2976:         ///
 2977:         /// </summary>
 2978:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX> _SoftXList
 2979:         {
 2980:             get
 2981:             {
 2982:                 int networkId, siteId, id;
 2983: #if DEBUG
 2984:                 //Dictionary<int, int> domainDictionary;
 2985: #endif
 2986:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX softX;
 2987:  
 2988: #if DEBUG
 2989:                 //domainDictionary = new Dictionary<int, int>(100);
 2990: #endif
 2991:                 var softXList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX>();
 2992:  
 2993:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2994:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2995:                                        select n).Single();
 2996:  
 2997:                 foreach (XElement x in networkXElement.Elements("site").Elements("softx"))
 2998:                 {
 2999:                     softX = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.SoftX();
 3000:                     softX.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 3001:  
 3002:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 3003:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 3004:                     id = int.Parse(x.Attribute("id").Value);
 3005:  
 3006:                     siteId = softX.Site.SiteId(networkId, siteId);
 3007:                     softX.Id = softX.SoftXId(siteId, id);
 3008:  
 3009:                     softX.DomainListString = x.Attribute("domainList").Value;
 3010:  
 3011:                     softX.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(softX.DomainListString);
 3012:  
 3013:                     softX.Site = (from s in SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 3014:  
 3015: #if DEBUG
 3016:                     /*
 3017:                     if (softX.DomainList != null)
 3018:                     {
 3019:                         foreach (var s in softX.DomainList)
 3020:                         {
 3021:                             if (!softX.Site.DomainList.Contains(s))
 3022:                             {
 3023:                                 throw new ArgumentOutOfRangeException(@"softX.Site.DomainList does not contain " + s + ".");
 3024:                             }
 3025:                         }
 3026:                     }
 3027:                     */
 3028:  
 3029:                     /*
 3030:                     foreach (int i in softX.DomainList)
 3031:                     {
 3032:                         // this will throw an exception if there are similar domains in sps
 3033:                         if (domainDictionary.ContainsKey(i))
 3034:                         {
 3035:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 3036:                         }
 3037:                         else domainDictionary[i] = 1;
 3038:                     }
 3039:                     */
 3040: #endif
 3041:  
 3042:                     softXList.Add(softX);
 3043:                 }
 3044:  
 3045:                 return softXList;
 3046:             }
 3047:         }
 3048:  
 3049:         ////////////////////////////////////////////////////////////////////////////
 3050:         ////////////////////////////////////////////////////////////////////////////
 3051:  
 3052:         /// <summary>
 3053:         ///
 3054:         /// </summary>
 3055:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router> RouterList
 3056:         {
 3057:             get
 3058:             {
 3059:                 if (routerList == null || routerList.Count == 0)
 3060:                 {
 3061:                     lock (objectLock)
 3062:                     {
 3063:                         routerList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._RouterList;
 3064:                     }
 3065:                 }
 3066:  
 3067:                 return routerList;
 3068:             }
 3069:         }
 3070:  
 3071:         ////////////////////////////////////////////////////////////////////////////
 3072:  
 3073:         /// <summary>
 3074:         ///
 3075:         /// </summary>
 3076:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router> _RouterList
 3077:         {
 3078:             get
 3079:             {
 3080:                 int networkId, siteId, id;
 3081:                 string vendorShortName;
 3082: #if DEBUG
 3083:                 //Dictionary<int, int> domainDictionary;
 3084: #endif
 3085:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router router;
 3086:  
 3087: #if DEBUG
 3088:                 //domainDictionary = new Dictionary<int, int>(100);
 3089: #endif
 3090:                 var routerList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router>();
 3091:  
 3092:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 3093:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 3094:                                        select n).Single();
 3095:  
 3096:                 foreach (XElement x in networkXElement.Elements("site").Elements("router"))
 3097:                 {
 3098:                     router = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router();
 3099:                     router.Site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 3100:  
 3101:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 3102:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 3103:                     id = int.Parse(x.Attribute("id").Value);
 3104:  
 3105:                     siteId = router.Site.SiteId(networkId, siteId);
 3106:                     router.Id = router.RouterId(siteId, id);
 3107:                     router.Name = x.Attribute("name").Value;
 3108:                     router.Type = x.Attribute("type").Value;
 3109:  
 3110:                     router.DomainListString = x.Attribute("domainList").Value;
 3111:  
 3112:                     router.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(router.DomainListString);
 3113:  
 3114: #if DEBUG
 3115:                     /*
 3116:                     foreach (int i in router.DomainList)
 3117:                     {
 3118:                         // this will throw an exception if there are similar domains in routers
 3119:                         if (domainDictionary.ContainsKey(i))
 3120:                         {
 3121:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 3122:                         }
 3123:                         else domainDictionary[i] = 1;
 3124:                     }
 3125:                     */
 3126: #endif
 3127:  
 3128:                     vendorShortName = x.Attribute("vendorShortName").Value;
 3129:                     router.Vendor = (from v in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.VendorList where v.ShortName == vendorShortName select v).Single(); //.s.SingleOrDefault();
 3130:  
 3131:                     router.Site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 3132:  
 3133:                     routerList.Add(router);
 3134:                 }
 3135:  
 3136:                 return routerList;
 3137:             }
 3138:         }
 3139:  
 3140:         ////////////////////////////////////////////////////////////////////////////
 3141:         ////////////////////////////////////////////////////////////////////////////
 3142:  
 3143:         /// <summary>
 3144:         ///
 3145:         /// </summary>
 3146:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> SiteList
 3147:         {
 3148:             get
 3149:             {
 3150:                 if (siteList == null || siteList.Count == 0)
 3151:                 {
 3152:                     lock (objectLock)
 3153:                     {
 3154:                         var networkId = 1; // <network id="1" name="Fixed Telecommunications Network">
 3155:  
 3156:                         siteList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._SiteList(networkId);
 3157:                     }
 3158:                 }
 3159:  
 3160:                 return siteList;
 3161:             }
 3162:         }
 3163:  
 3164:         ////////////////////////////////////////////////////////////////////////////
 3165:  
 3166:         /// <summary>
 3167:         ///
 3168:         /// </summary>
 3169:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> LegacySiteList
 3170:         {
 3171:             get
 3172:             {
 3173:                 if (legacySiteList == null || legacySiteList.Count == 0)
 3174:                 {
 3175:                     lock (objectLock)
 3176:                     {
 3177:                         var networkId = 2; // <network id="2" name="Legacy">
 3178:  
 3179:                         legacySiteList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument._SiteList(networkId);
 3180:                     }
 3181:                 }
 3182:  
 3183:                 return legacySiteList;
 3184:             }
 3185:         }
 3186:  
 3187:         ////////////////////////////////////////////////////////////////////////////
 3188:  
 3189:         /// <summary>
 3190:         ///
 3191:         /// </summary>
 3192:         private static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site> _SiteList(int networkId)
 3193:         {
 3194:             int id;
 3195:             Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site site;
 3196:  
 3197:             var siteList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>();
 3198:  
 3199:             var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 3200:                                    where n.Attribute("id").Value == networkId.ToString()
 3201:                                    select n).Single();
 3202:  
 3203:             foreach (XElement x in networkXElement.Elements("site"))
 3204:             {
 3205:                 site = new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site();
 3206:                 networkId = int.Parse(x.Parent.Attribute("id").Value);
 3207:                 id = int.Parse(x.Attribute("id").Value);
 3208:  
 3209:                 site.Id = site.SiteId(networkId, id);
 3210:                 site.Name = x.Attribute("name").Value;
 3211:                 site.ArabicName = x.Attribute("arabicName").Value;
 3212:  
 3213:                 site.Network = (from n in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.NetworkList
 3214:                                 where n.Id == networkId
 3215:                                 select n).Single();
 3216:  
 3217:                 siteList.Add(site);
 3218:             }
 3219:  
 3220:             return siteList;
 3221:         }
 3222:  
 3223:         ////////////////////////////////////////////////////////////////////////////
 3224:  
 3225:         /// <summary>
 3226:         ///
 3227:         /// </summary>
 3228:         public static Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site SiteFromName(string name)
 3229:         {
 3230:             var site = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList where s.Name == name select s).Single();
 3231:  
 3232:             return site;
 3233:         }
 3234:  
 3235:         ////////////////////////////////////////////////////////////////////////////
 3236:         ////////////////////////////////////////////////////////////////////////////
 3237:  
 3238:         /// <summary>
 3239:         ///
 3240:         /// </summary>
 3241:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Network> NetworkList
 3242:         {
 3243:             get
 3244:             {
 3245:                 if (networkList == null || networkList.Count == 0)
 3246:                 {
 3247:                     lock (objectLock)
 3248:                     {
 3249:                         networkList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Network>
 3250:                         {
 3251:                             new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Network(1, "Fixed Telecommunications Network"),
 3252:                             new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Network(2, "Legacy")
 3253:                         };
 3254:                     }
 3255:                 }
 3256:  
 3257:                 return networkList;
 3258:             }
 3259:         }
 3260:  
 3261:         ////////////////////////////////////////////////////////////////////////////
 3262:         ////////////////////////////////////////////////////////////////////////////
 3263:  
 3264:         /// <summary>
 3265:         ///
 3266:         /// </summary>
 3267:         public static List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor> VendorList
 3268:         {
 3269:             get
 3270:             {
 3271:                 if (vendorList == null || vendorList.Count == 0)
 3272:                 {
 3273:                     lock (objectLock)
 3274:                     {
 3275:                         vendorList = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor>
 3276:                     {
 3277:                         new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor(0, "Undefined", "Un", "غير معرف", @"\image\undefined.png"),
 3278:                         new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor(1, "Nokia", "No", "نوكيا", @"\image\nokia-icon.png"),
 3279:                         new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor(2, "Huawei", "Hu", "هواوي", @"\image\huawei-icon.png"),
 3280:                         new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor(3, "Ericsson", "Er", "إريكسون", @"\image\ericsson-icon.png"),
 3281:                         new Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor(4, "Siemens", "Si", "سيمينس", @"\image\siemens-icon.png")
 3282:                     };
 3283:                     }
 3284:                 }
 3285:  
 3286:                 return vendorList;
 3287:             }
 3288:         }
 3289:  
 3290:         ////////////////////////////////////////////////////////////////////////////
 3291:  
 3292:         /// <summary>
 3293:         ///
 3294:         /// </summary>
 3295:         public static string AmsNameFromOltId(int oltId)
 3296:         {
 3297:             var amsName = (from o in OltList
 3298:                            where o.Id == oltId
 3299:                            select o.AmsName).FirstOrDefault();
 3300:  
 3301:             return amsName;
 3302:         }
 3303:  
 3304:         ////////////////////////////////////////////////////////////////////////////
 3305:  
 3306:         /// <summary>
 3307:         ///
 3308:         /// </summary>
 3309:         public static string XDocument2()
 3310:         {
 3311:             return xDocument.ToString();
 3312:         }
 3313:  
 3314:         ////////////////////////////////////////////////////////////////////////////
 3315:         ////////////////////////////////////////////////////////////////////////////
 3316:  
 3317:         /// <summary>
 3318:         /// 
 3319:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 3320:         /// 
 3321:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 3322:         /// 2. Add "using System.Reflection".
 3323:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
 3324:         /// 
 3325:         /// </summary>
 3326:         private static XDocument XDocument
 3327:         {
 3328:             get
 3329:             {
 3330:                 if (xDocument == null)
 3331:                 {
 3332:                     lock (objectLock)
 3333:                     {
 3334:                         Assembly assembly;
 3335:                         StreamReader xmlDocumentStreamReader, xsdDocumentStreamReader;
 3336:  
 3337:                         assembly = Assembly.GetExecutingAssembly();
 3338:                         xmlDocumentStreamReader = new StreamReader(assembly.GetManifestResourceStream("Ia.Ftn.Cl.Models.Data.network-design-document.xml"));
 3339:                         xsdDocumentStreamReader = new StreamReader(assembly.GetManifestResourceStream("Ia.Ftn.Cl.Models.Data.network-design-document.xsd"));
 3340:  
 3341:                         if (xmlDocumentStreamReader.Peek() != -1)// && xsdDocumentStreamReader.Peek() != -1)
 3342:                         {
 3343:                             xDocument = XDocument.Load(xmlDocumentStreamReader);
 3344:  
 3345:                             var xmlDocument = xDocument.ToXmlDocument();
 3346:  
 3347:                             var schema = XmlSchema.Read(xsdDocumentStreamReader, null);
 3348:  
 3349:                             xmlDocument.Schemas.Add(schema);
 3350:  
 3351:                             xmlDocument.Validate((sender, args) => throw args.Exception);
 3352:                         }
 3353:                     }
 3354:                 }
 3355:  
 3356:                 return xDocument;
 3357:             }
 3358:         }
 3359:     }
 3360:  
 3361:     ////////////////////////////////////////////////////////////////////////////
 3362:     ////////////////////////////////////////////////////////////////////////////    
 3363: }