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