)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » NetworkDesignDocument (Ia.Ftn.Cl.Model.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 Ia.Ftn.Cl.Model.Business;
    2: using Microsoft.CodeAnalysis.CSharp.Syntax;
    3: using System;
    4: using System.Collections;
    5: using System.Collections.Generic;
    6: using System.Data;
    7: using System.IO;
    8: using System.Linq;
    9: using System.Reflection;
   10: using System.Text;
   11: using System.Text.RegularExpressions;
   12: using System.Xml.Linq;
   13:  
   14: namespace Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Site> routerDomainToSiteDictionary, msanDomainToSiteDictionary, pstnDomainToSiteDictionary;
   43:         private static Dictionary<int, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PstnExchangeType> pstnFiveDigitDomainToPstnExchangeTypeDictionary;
   44:         private static Dictionary<int, Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont> ontAccessIdToOntDictionary, ontIdToOntDictionary, ontIpToOntDictionary, ontAccessNameToOntDictionary, ontPositionToOntDictionary;
   47:         private static Dictionary<string, Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon> ponIdToPonDictionary, ponNameToPonDictionary;
   48:         private static Dictionary<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn, List<int>> pstnToFiveDigitDomainListDictionary;
   49:  
   50:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Network> networkList;
   51:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor> vendorList;
   52:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site> siteList, legacySiteList;
   53:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> pstnList, legacyPstnList;
   54:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan> msanList;
   55:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX> softXList;
   56:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router> routerList;
   57:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam> oamList;
   58:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf> odfList;
   59:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> oltList;
   60:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PonGroup> ponGroupList;
   61:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon> ponList;
   62:         private static List<Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.Ont ont;
  114:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Access access;
  115:                 Ia.Ftn.Cl.Model.Business.Ims.ImsBasicService imsBasicService;
  116:  
  117:                 var ontList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont>(Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PonList.Count * 32);
  118: #if DEBUG
  119:                 ontDictionary = new Dictionary<string, string>(Ia.Ftn.Cl.Model.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.Model.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.Model.Data.NetworkDesignDocument.PonGroupList)
  127:                 {
  128:                     nokiaRouter = (ponGroup.Olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
  129:                     huaweiRouter = !nokiaRouter;
  130:  
  131:                     nokiaOdf = (ponGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Model.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.Model.Business.Ims.NokiaImsBasicServiceItem(ponGroup);
  142:                         else imsBasicService = Ia.Ftn.Cl.Model.Business.Ims.SpecialHuaweiIpHandlingForNokiaImsBasicServiceItem(ponGroup);
  143:                     }
  144:                     else imsBasicService = Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont();
  158:                             access = new Ia.Ftn.Cl.Model.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.Model.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.Model.Business.Ims.NokiaImsBasicServiceItemForAccessWithPbx(ont);
  226:                                     }
  227:                                     else ont.ImsBasicService = Ia.Ftn.Cl.Model.Business.Ims.SpecialHuaweiIpHandlingForNokiaImsBasicServiceItem(ont) ?? imsBasicService;
  228:                                 }
  229:                                 else
  230:                                 {
  231:                                     if (nokiaAccessNameWithPbxList.Contains(ont.Access.Name))
  232:                                     {
  233:                                         ont.ImsBasicService = Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.PrecautionaryHardCodedNumberOfOntRecords)
  281:                 {
  282:                     throw new ArgumentOutOfRangeException(@"(ontList.Count != " + Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.Ont> OntAccessIdToOntForOltIdListDictionary(List<int> oltIdList)
  407:         {
  408:             lock (objectLock)
  409:             {
  410:                 var list = (from o in Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont> OntIpToOntForOltIdListDictionary(List<int> oltIdList)
  424:         {
  425:             lock (objectLock)
  426:             {
  427:                 var list = (from o in Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont> OntAccessIdToOntForOltSymbolListDictionary(List<string> oltSymbolList)
  441:         {
  442:             lock (objectLock)
  443:             {
  444:                 var list = (from o in Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Site>();
  466:  
  467:                         var routerList = Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Site>();
  494:  
  495:                         var msanList = Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Site>();
  522:  
  523:                         var pstnList = Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Pstn, List<int>>();
  548:  
  549:                     var pstnList = Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.PstnExchangeType>();
  589:  
  590:                     var pstnList = Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Vendor>();
  628:  
  629:                         var routerList = Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.Data.Service.AllowedToBeMigratedOltIdList;
  811:  
  812:                         ontAccessIdToOntAccessNameWithinAllowedToBeMigratedOltDictionary = (from o in Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.Data.NetworkDesignDocument.OntList
  945:                                                                       where o.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Ont OntById(string ontId)
  986:         {
  987:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
  988:  
  989:             if (!string.IsNullOrEmpty(ontId))
  990:             {
  991:                 var d = Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont OntByAccessName(string accessName)
 1007:         {
 1008:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1009:  
 1010:             if (!string.IsNullOrEmpty(accessName))
 1011:             {
 1012:                 accessName = accessName.ToUpper();
 1013:  
 1014:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1015:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont OntByOntAccessId(string accessId)
 1028:         {
 1029:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1030:  
 1031:             if (!string.IsNullOrEmpty(accessId))
 1032:             {
 1033:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(accessId) ?
 1034:                     Ia.Ftn.Cl.Model.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.Model.Data.NetworkDesignDocument.OntIdToOntDictionary.ContainsKey(ontId) ?
 1053:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Ont OntByIp(string ip)
 1072:         {
 1073:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1074:  
 1075:             if (!string.IsNullOrEmpty(ip))
 1076:             {
 1077:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntIpToOntDictionary.ContainsKey(ip) ?
 1078:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor> AccessVendorListByOntIdList(List<string> ontIdList)
 1091:         {
 1092:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 1093:             var vendorList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor>();
 1094:  
 1095:             foreach (var ontId in ontIdList)
 1096:             {
 1097:                 if (!string.IsNullOrEmpty(ontId))
 1098:                 {
 1099:                     var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntById(ontId);
 1100:  
 1101:                     vendor = (nddOnt != null) ? nddOnt.Pon.PonGroup.Olt.Odf.Vendor : Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1102:                 }
 1103:                 else vendor = Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor> SwitchVendorListByOntIdList(List<string> ontIdList)
 1117:         {
 1118:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 1119:             var vendorList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor>();
 1120:  
 1121:             foreach (var ontId in ontIdList)
 1122:             {
 1123:                 if (!string.IsNullOrEmpty(ontId))
 1124:                 {
 1125:                     var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntById(ontId);
 1126:  
 1127:                     vendor = (nddOnt != null) ? nddOnt.Pon.PonGroup.Olt.Odf.Router.Vendor : Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1128:                 }
 1129:                 else vendor = Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor AccessVendorByOntAccessId(string ontAccessId)
 1143:         {
 1144:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 1145:  
 1146:             if (!string.IsNullOrEmpty(ontAccessId))
 1147:             {
 1148:                 var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(ontAccessId) ?
 1149:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1156:             }
 1157:             else vendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1158:  
 1159:             return vendor;
 1160:         }
 1161:  
 1162:         ////////////////////////////////////////////////////////////////////////////
 1163:  
 1164:         /// <summary>
 1165:         ///
 1166:         /// </summary>
 1167:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor AccessVendorByAccessName(string accessName)
 1168:         {
 1169:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 1170:  
 1171:             if (!string.IsNullOrEmpty(accessName))
 1172:             {
 1173:                 accessName = accessName.ToUpper();
 1174:  
 1175:                 var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1176:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1183:             }
 1184:             else vendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1185:  
 1186:             return vendor;
 1187:         }
 1188:  
 1189:         ////////////////////////////////////////////////////////////////////////////
 1190:  
 1191:         /// <summary>
 1192:         ///
 1193:         /// </summary>
 1194:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor SwitchVendorByAccessName(string accessName)
 1195:         {
 1196:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 1197:  
 1198:             if (!string.IsNullOrEmpty(accessName))
 1199:             {
 1200:                 accessName = accessName.ToUpper();
 1201:  
 1202:                 var nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntAccessNameToOntDictionary.ContainsKey(accessName) ?
 1203:                     Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1210:             }
 1211:             else vendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 1212:  
 1213:             return vendor;
 1214:         }
 1215:  
 1216:         ////////////////////////////////////////////////////////////////////////////
 1217:  
 1218:         /// <summary>
 1219:         ///
 1220:         /// </summary>
 1221:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router RouterFromService(string service)
 1222:         {
 1223:             Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.Ont OntByPosition(string position)
 1246:         {
 1247:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 1248:  
 1249:             if (!string.IsNullOrEmpty(position))
 1250:             {
 1251:                 nddOnt = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntPositionToOntDictionary.ContainsKey(position) ?
 1252:                     Ia.Ftn.Cl.Model.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.Model.Data.NetworkDesignDocument.OntPositionToOntDictionary.ContainsKey(position) ?
 1271:                     Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.Pon pon;
 1329:  
 1330:                 var ponList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon>(Ia.Ftn.Cl.Model.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.Model.Data.NetworkDesignDocument.PonGroupList.Count * 32);
 1333: #endif
 1334:                 foreach (var olt in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList)
 1335:                 {
 1336:                     oltPonIndex = 0;
 1337:  
 1338:                     nokiaRouter = (olt.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia) ? true : false; // false for Huawei
 1339:                     huaweiRouter = !nokiaRouter;
 1340:  
 1341:                     nokiaOdf = (olt.Odf.Vendor == Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.Pon PonByOltEmsNameAndSnAndPnAndOptionallyOntId(string emsName, int sn, int pn, int ontId)
 1528:         {
 1529:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pon pon;
 1530:  
 1531:             var olt = Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.PonGroup ponGroup;
 1588:  
 1589:                 regex = new Regex(pattern);
 1590:                 var ponGroupList = new List<Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.PonGroup
 1604:                     {
 1605:                         Olt = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt()
 1606:                     };
 1607:                     ponGroup.Olt.Odf = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf();
 1608:                     ponGroup.Olt.Odf.Router = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router();
 1609:                     ponGroup.Olt.Odf.Router.Site = new Ia.Ftn.Cl.Model.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.Model.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.Model.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.Model.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.Model.Business.NetworkDesignDocument.Olt olt;
 1720:  
 1721:                 var oltList = new List<Ia.Ftn.Cl.Model.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.Model.Business.NetworkDesignDocument.Olt();
 1731:                     olt.Odf = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf();
 1732:                     olt.Odf.Router = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router();
 1733:                     olt.Odf.Router.Site = new Ia.Ftn.Cl.Model.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.Model.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.Model.Business.NetworkDesignDocument.FieldType.Green;
 1798:                         else if (fieldTypeString == "brown") olt.FieldType = Ia.Ftn.Cl.Model.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.Model.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.Model.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:                     var oltAmsName = olt.AmsName;
 1863:                     var oltSymbol = olt.Symbol;
 1864:  
 1865:                     if (olt.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 1866:                     {
 1867:                         if (!oltAmsName.StartsWith("OLT-" + siteName + "-" + oltSymbol)) throw new ArgumentException(@"Olt AmsName does not match the Olt naming convension for vendor.");
 1868:                     }
 1869:                     else if (olt.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 1870:                     {
 1871:                         if (!oltAmsName.StartsWith(oltSymbol + "-" + siteName + "-H")) throw new ArgumentException(@"Olt AmsName does not match the Olt naming convension for vendor.");
 1872:                     }
 1873:                     else throw new ArgumentException(@"Unknown vendor");
 1874:  
 1875:                     if ((olt.NumberOfPons * olt.NumberOfOntsInPon % 1024) != 0) throw new ArgumentException(@"(olt.NumberOfPons * olt.NumberOfOntsInPon % 1024) != 0");
 1876:                     if (olt.NumberOfFirstSlot != 0 && olt.NumberOfFirstSlot != 1) throw new ArgumentException(@"olt.NumberOfFirstSlot == 0 || olt.NumberOfFirstSlot == 1");
 1877: #endif
 1878:                     oltList.Add(olt);
 1879:                 }
 1880:  
 1881:                 return oltList;
 1882:             }
 1883:         }
 1884:  
 1885:         ////////////////////////////////////////////////////////////////////////////
 1886:         ////////////////////////////////////////////////////////////////////////////
 1887:  
 1888:         /// <summary>
 1889:         ///
 1890:         /// </summary>
 1891:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> NokiaOltList
 1892:         {
 1893:             get
 1894:             {
 1895:                 lock (objectLock)
 1896:                 {
 1897:                     return VendorOltList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia, 0);
 1898:                 }
 1899:             }
 1900:         }
 1901:  
 1902:         ////////////////////////////////////////////////////////////////////////////
 1903:  
 1904:         /// <summary>
 1905:         ///
 1906:         /// </summary>
 1907:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> HuaweiOltList
 1908:         {
 1909:             get
 1910:             {
 1911:                 lock (objectLock)
 1912:                 {
 1913:                     return VendorOltList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei, 0);
 1914:                 }
 1915:             }
 1916:         }
 1917:  
 1918:         ////////////////////////////////////////////////////////////////////////////
 1919:  
 1920:         /// <summary>
 1921:         ///
 1922:         /// </summary>
 1923:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> VendorOltList(Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor, int siteId)
 1924:         {
 1925:             lock (objectLock)
 1926:             {
 1927:                 List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> list;
 1928:  
 1929:                 list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 1930:                         where o.Odf.Vendor == vendor && (o.Odf.Router.Site.Id == siteId || siteId == 0)
 1931:                         select o).ToList();
 1932:  
 1933:                 return list;
 1934:             }
 1935:         }
 1936:  
 1937:         ////////////////////////////////////////////////////////////////////////////
 1938:  
 1939:         /// <summary>
 1940:         ///
 1941:         /// </summary>
 1942:         public static List<int> NokiaOltIdList()
 1943:         {
 1944:             return OltIdByVendorAndSiteIdList("No", 0);
 1945:         }
 1946:  
 1947:         ////////////////////////////////////////////////////////////////////////////
 1948:  
 1949:         /// <summary>
 1950:         ///
 1951:         /// </summary>
 1952:         public static List<int> NokiaOltIdList(int siteId)
 1953:         {
 1954:             return OltIdByVendorAndSiteIdList("No", siteId);
 1955:         }
 1956:  
 1957:         ////////////////////////////////////////////////////////////////////////////
 1958:  
 1959:         /// <summary>
 1960:         ///
 1961:         /// </summary>
 1962:         public static List<int> HuaweiOltIdList()
 1963:         {
 1964:             return OltIdByVendorAndSiteIdList("Hu", 0);
 1965:         }
 1966:  
 1967:         ////////////////////////////////////////////////////////////////////////////
 1968:  
 1969:         /// <summary>
 1970:         ///
 1971:         /// </summary>
 1972:         public static List<int> HuaweiOltIdList(int siteId)
 1973:         {
 1974:             return OltIdByVendorAndSiteIdList("Hu", siteId);
 1975:         }
 1976:  
 1977:         ////////////////////////////////////////////////////////////////////////////
 1978:  
 1979:         /// <summary>
 1980:         ///
 1981:         /// </summary>
 1982:         public static List<int> OltIdByVendorAndSiteIdList(string vendorShortName, int siteId)
 1983:         {
 1984:             List<int> list;
 1985:  
 1986:             list = new List<int>();
 1987:  
 1988:             foreach (var olt in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList)
 1989:             {
 1990:                 // siteId 0 will return all sites
 1991:  
 1992:                 if (olt.Odf.Vendor.ShortName == vendorShortName && (olt.Odf.Router.Site.Id == siteId || siteId == 0))
 1993:                 {
 1994:                     list.Add(olt.Id);
 1995:                 }
 1996:             }
 1997:  
 1998:             return list;
 1999:         }
 2000:  
 2001:         ////////////////////////////////////////////////////////////////////////////
 2002:  
 2003:         /// <summary>
 2004:         ///
 2005:         /// </summary>
 2006:         public static List<int> NokiaRouterNokiaAccessOltIdList
 2007:         {
 2008:             get
 2009:             {
 2010:                 lock (objectLock)
 2011:                 {
 2012:                     var list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2013:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 2014:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 2015:                                 select o.Id).ToList();
 2016:  
 2017:                     return list;
 2018:                 }
 2019:             }
 2020:         }
 2021:  
 2022:         ////////////////////////////////////////////////////////////////////////////
 2023:  
 2024:         /// <summary>
 2025:         ///
 2026:         /// </summary>
 2027:         public static List<int> HuaweiRouterNokiaAccessOltIdList
 2028:         {
 2029:             get
 2030:             {
 2031:                 lock (objectLock)
 2032:                 {
 2033:                     var list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2034:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei
 2035:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 2036:                                 select o.Id).ToList();
 2037:  
 2038:                     return list;
 2039:                 }
 2040:             }
 2041:         }
 2042:  
 2043:         ////////////////////////////////////////////////////////////////////////////
 2044:  
 2045:         /// <summary>
 2046:         ///
 2047:         /// </summary>
 2048:         public static List<int> NokiaRouterHuaweiAccessOltIdList
 2049:         {
 2050:             get
 2051:             {
 2052:                 lock (objectLock)
 2053:                 {
 2054:                     var list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2055:                                 where o.Odf.Router.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 2056:                                 && o.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei
 2057:                                 select o.Id).ToList();
 2058:  
 2059:                     return list;
 2060:                 }
 2061:             }
 2062:         }
 2063:  
 2064:         ////////////////////////////////////////////////////////////////////////////
 2065:         ////////////////////////////////////////////////////////////////////////////
 2066:  
 2067:         /// <summary>
 2068:         ///
 2069:         /// </summary>
 2070:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt OltByEmsName(string emsName)
 2071:         {
 2072:             var olt = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2073:                        where o.EmsName == emsName
 2074:                        select o).SingleOrDefault();
 2075:  
 2076:             return olt;
 2077:         }
 2078:  
 2079:         ////////////////////////////////////////////////////////////////////////////
 2080:  
 2081:         /// <summary>
 2082:         ///
 2083:         /// </summary>
 2084:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt OltByAmsName(string amsName)
 2085:         {
 2086:             var olt = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2087:                        where o.AmsName == amsName
 2088:                        select o).SingleOrDefault();
 2089:  
 2090:             return olt;
 2091:         }
 2092:  
 2093:         ////////////////////////////////////////////////////////////////////////////
 2094:  
 2095:         /// <summary>
 2096:         ///
 2097:         /// </summary>
 2098:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt OltByDid(int did)
 2099:         {
 2100:             var olt = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2101:                        where o.Did == did
 2102:                        select o).SingleOrDefault();
 2103:  
 2104:             return olt;
 2105:         }
 2106:  
 2107:         ////////////////////////////////////////////////////////////////////////////
 2108:  
 2109:         /// <summary>
 2110:         ///
 2111:         /// </summary>
 2112:         public static Dictionary<int, int> DidToOltIdDictionary
 2113:         {
 2114:             get
 2115:             {
 2116:                 if (didToOltIdDictionary == null || didToOltIdDictionary.Count == 0)
 2117:                 {
 2118:                     lock (objectLock)
 2119:                     {
 2120:                         didToOltIdDictionary = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2121:                                                 where o.Did != 0
 2122:                                                 select new { o.Did, OltId = o.Id }).ToDictionary(n => n.Did, n => n.OltId);
 2123:                     }
 2124:                 }
 2125:  
 2126:                 return didToOltIdDictionary;
 2127:             }
 2128:         }
 2129:  
 2130:         ////////////////////////////////////////////////////////////////////////////
 2131:         ////////////////////////////////////////////////////////////////////////////
 2132:  
 2133:         /// <summary>
 2134:         ///
 2135:         /// </summary>
 2136:         public static List<int> SipOltIdList
 2137:         {
 2138:             get
 2139:             {
 2140:                 lock (objectLock)
 2141:                 {
 2142:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2143:                             where o.IsSip == true
 2144:                             select o.Id).ToList();
 2145:                 }
 2146:             }
 2147:         }
 2148:  
 2149:         ////////////////////////////////////////////////////////////////////////////
 2150:         ////////////////////////////////////////////////////////////////////////////
 2151:  
 2152:         /// <summary>
 2153:         ///
 2154:         /// </summary>
 2155:         public static List<int> GreenFieldOltIdList
 2156:         {
 2157:             get
 2158:             {
 2159:                 lock (objectLock)
 2160:                 {
 2161:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2162:                             where o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green
 2163:                             select o.Id).ToList();
 2164:                 }
 2165:             }
 2166:         }
 2167:  
 2168:         ////////////////////////////////////////////////////////////////////////////
 2169:  
 2170:         /// <summary>
 2171:         ///
 2172:         /// </summary>
 2173:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> GreenFieldOltList
 2174:         {
 2175:             get
 2176:             {
 2177:                 lock (objectLock)
 2178:                 {
 2179:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2180:                             where o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green
 2181:                             select o).ToList();
 2182:                 }
 2183:             }
 2184:         }
 2185:  
 2186:         ////////////////////////////////////////////////////////////////////////////
 2187:  
 2188:         /// <summary>
 2189:         ///
 2190:         /// </summary>
 2191:         public static List<int> GreenFieldSipOltIdList
 2192:         {
 2193:             get
 2194:             {
 2195:                 lock (objectLock)
 2196:                 {
 2197:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2198:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green
 2199:                             select o.Id).ToList();
 2200:                 }
 2201:             }
 2202:         }
 2203:  
 2204:         ////////////////////////////////////////////////////////////////////////////
 2205:  
 2206:         /// <summary>
 2207:         ///
 2208:         /// </summary>
 2209:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> GreenFieldSipOltList
 2210:         {
 2211:             get
 2212:             {
 2213:                 lock (objectLock)
 2214:                 {
 2215:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2216:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green
 2217:                             select o).ToList();
 2218:                 }
 2219:             }
 2220:         }
 2221:  
 2222:         ////////////////////////////////////////////////////////////////////////////
 2223:  
 2224:         /// <summary>
 2225:         ///
 2226:         /// </summary>
 2227:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont> GreenFieldOntList
 2228:         {
 2229:             get
 2230:             {
 2231:                 if (greenFieldOntList == null || greenFieldOntList.Count == 0)
 2232:                 {
 2233:                     lock (objectLock)
 2234:                     {
 2235:                         greenFieldOntList = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntList
 2236:                                              where o.Pon.PonGroup.Olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green
 2237:                                              select o).ToList();
 2238:  
 2239:                     }
 2240:                 }
 2241:  
 2242:                 return greenFieldOntList;
 2243:             }
 2244:         }
 2245:  
 2246:         ////////////////////////////////////////////////////////////////////////////
 2247:         ////////////////////////////////////////////////////////////////////////////
 2248:  
 2249:         /// <summary>
 2250:         ///
 2251:         /// </summary>
 2252:         public static List<int> BrownFieldOltIdList
 2253:         {
 2254:             get
 2255:             {
 2256:                 lock (objectLock)
 2257:                 {
 2258:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2259:                             where o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown
 2260:                             select o.Id).ToList();
 2261:                 }
 2262:             }
 2263:         }
 2264:  
 2265:         ////////////////////////////////////////////////////////////////////////////
 2266:  
 2267:         /// <summary>
 2268:         ///
 2269:         /// </summary>
 2270:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> BrownFieldOltList
 2271:         {
 2272:             get
 2273:             {
 2274:                 lock (objectLock)
 2275:                 {
 2276:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2277:                             where o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown
 2278:                             select o).ToList();
 2279:                 }
 2280:             }
 2281:         }
 2282:  
 2283:         ////////////////////////////////////////////////////////////////////////////
 2284:  
 2285:         /// <summary>
 2286:         ///
 2287:         /// </summary>
 2288:         public static List<int> BrownFieldSipOltIdList
 2289:         {
 2290:             get
 2291:             {
 2292:                 lock (objectLock)
 2293:                 {
 2294:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2295:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown
 2296:                             select o.Id).ToList();
 2297:                 }
 2298:             }
 2299:         }
 2300:  
 2301:         ////////////////////////////////////////////////////////////////////////////
 2302:  
 2303:         /// <summary>
 2304:         ///
 2305:         /// </summary>
 2306:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Olt> BrownFieldSipOltList
 2307:         {
 2308:             get
 2309:             {
 2310:                 lock (objectLock)
 2311:                 {
 2312:                     return (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2313:                             where o.IsSip == true && o.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown
 2314:                             select o).ToList();
 2315:                 }
 2316:             }
 2317:         }
 2318:  
 2319:         ////////////////////////////////////////////////////////////////////////////
 2320:  
 2321:         /// <summary>
 2322:         ///
 2323:         /// </summary>
 2324:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Ont> BrownFieldOntList
 2325:         {
 2326:             get
 2327:             {
 2328:                 if (brownFieldOntList == null || brownFieldOntList.Count == 0)
 2329:                 {
 2330:                     lock (objectLock)
 2331:                     {
 2332:                         brownFieldOntList = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntList
 2333:                                              where o.Pon.PonGroup.Olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown
 2334:                                              select o).ToList();
 2335:  
 2336:                     }
 2337:                 }
 2338:  
 2339:                 return brownFieldOntList;
 2340:             }
 2341:         }
 2342:  
 2343:         ////////////////////////////////////////////////////////////////////////////
 2344:         ////////////////////////////////////////////////////////////////////////////
 2345:  
 2346:         /// <summary>
 2347:         ///
 2348:         /// </summary>
 2349:         public static List<string> NokiaOltAmsNameList
 2350:         {
 2351:             get
 2352:             {
 2353:                 lock (objectLock)
 2354:                 {
 2355:                     List<string> list;
 2356:  
 2357:                     list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2358:                             where o.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia
 2359:                             //&& o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr
 2360:                             select o.AmsName).ToList();
 2361:  
 2362:                     return list;
 2363:                 }
 2364:             }
 2365:         }
 2366:  
 2367:         ////////////////////////////////////////////////////////////////////////////
 2368:  
 2369:         /// <summary>
 2370:         ///
 2371:         /// </summary>
 2372:         public static List<string> HuaweiOltAmsNameList
 2373:         {
 2374:             get
 2375:             {
 2376:                 lock (objectLock)
 2377:                 {
 2378:                     List<string> list;
 2379:  
 2380:                     list = (from o in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OltList
 2381:                             where o.Odf.Vendor == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei
 2382:                             //&& o.StateId == (int)Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.BellcoreState.IsNr
 2383:                             select o.AmsName).ToList();
 2384:  
 2385:                     return list;
 2386:                 }
 2387:             }
 2388:         }
 2389:  
 2390:         ////////////////////////////////////////////////////////////////////////////
 2391:  
 2392:         /// <summary>
 2393:         ///
 2394:         /// </summary>
 2395:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf> OdfList
 2396:         {
 2397:             get
 2398:             {
 2399:                 if (odfList == null || odfList.Count == 0)
 2400:                 {
 2401:                     lock (objectLock)
 2402:                     {
 2403:                         odfList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._OdfList;
 2404:                     }
 2405:                 }
 2406:  
 2407:                 return odfList;
 2408:             }
 2409:         }
 2410:  
 2411:         ////////////////////////////////////////////////////////////////////////////
 2412:  
 2413:         /// <summary>
 2414:         ///
 2415:         /// </summary>
 2416:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf> _OdfList
 2417:         {
 2418:             get
 2419:             {
 2420:                 int networkId, siteId, routerId, id;
 2421:                 string vendorShortName;
 2422:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf odf;
 2423:  
 2424:                 var odfList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf>();
 2425:  
 2426:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2427:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2428:                                        select n).Single();
 2429:  
 2430:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("odf"))
 2431:                 {
 2432:                     odf = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Odf();
 2433:                     odf.Router = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router();
 2434:                     odf.Router.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 2435:  
 2436:                     networkId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 2437:                     siteId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2438:                     routerId = int.Parse(x.Parent.Attribute("id").Value);
 2439:                     id = int.Parse(x.Attribute("id").Value);
 2440:  
 2441:                     siteId = odf.Router.Site.SiteId(networkId, siteId);
 2442:                     routerId = odf.Router.RouterId(siteId, routerId);
 2443:                     odf.Id = odf.OdfId(routerId, id);
 2444:  
 2445:                     odf.Name = x.Attribute("name").Value;
 2446:  
 2447:                     odf.GatewayIp = (x.Attribute("gatewayIp") != null) ? x.Attribute("gatewayIp").Value : string.Empty;
 2448:                     odf.MgcIp = (x.Attribute("mgcIp") != null) ? x.Attribute("mgcIp").Value : string.Empty;
 2449:  
 2450:                     vendorShortName = x.Attribute("vendorShortName").Value;
 2451:                     odf.Vendor = (from v in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.VendorList where v.ShortName == vendorShortName select v).Single(); //.si.SingleOrDefault();
 2452:  
 2453:                     odf.Router = (from r in RouterList where r.Id == routerId select r).Single(); //.SingleOrDefault();
 2454:  
 2455:                     odfList.Add(odf);
 2456:                 }
 2457:  
 2458:                 return odfList.ToList();
 2459:             }
 2460:         }
 2461:  
 2462:         ////////////////////////////////////////////////////////////////////////////
 2463:  
 2464:         /// <summary>
 2465:         ///
 2466:         /// </summary>
 2467:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam> OamList
 2468:         {
 2469:             get
 2470:             {
 2471:                 if (oamList == null || oamList.Count == 0)
 2472:                 {
 2473:                     lock (objectLock)
 2474:                     {
 2475:                         oamList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._OamList;
 2476:                     }
 2477:                 }
 2478:  
 2479:                 return oamList;
 2480:             }
 2481:         }
 2482:  
 2483:         ////////////////////////////////////////////////////////////////////////////
 2484:  
 2485:         /// <summary>
 2486:         ///
 2487:         /// </summary>
 2488:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam> _OamList
 2489:         {
 2490:             get
 2491:             {
 2492:                 int networkId, siteId, routerId, id;
 2493:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam oam;
 2494:  
 2495:                 var oamList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam>();
 2496:  
 2497:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2498:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2499:                                        select n).Single();
 2500:  
 2501:                 foreach (XElement x in networkXElement.Elements("site").Elements("router").Elements("oam"))
 2502:                 {
 2503:                     oam = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Oam();
 2504:                     oam.Router = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router();
 2505:                     oam.Router.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 2506:  
 2507:                     networkId = int.Parse(x.Parent.Parent.Parent.Attribute("id").Value);
 2508:                     siteId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2509:                     routerId = int.Parse(x.Parent.Attribute("id").Value);
 2510:                     id = int.Parse(x.Attribute("id").Value);
 2511:  
 2512:                     siteId = oam.Router.Site.SiteId(networkId, siteId);
 2513:                     routerId = oam.Router.RouterId(siteId, routerId);
 2514:                     oam.Id = oam.OamId(routerId, id);
 2515:  
 2516:                     oam.Network = x.Attribute("network").Value;
 2517:                     oam.Gateway = x.Attribute("gateway").Value;
 2518:                     oam.Vlan = int.Parse(x.Attribute("vlan").Value);
 2519:                     oam.Vpls = int.Parse(x.Attribute("vpls").Value);
 2520:                     oam.FtpIp = x.Attribute("ftpIp").Value;
 2521:                     oam.ConfigFile = x.Attribute("configFile").Value;
 2522:  
 2523:                     oam.Router = (from r in RouterList where r.Id == routerId select r).Single(); //.SingleOrDefault();
 2524:  
 2525:                     oamList.Add(oam);
 2526:                 }
 2527:  
 2528:                 return oamList;
 2529:             }
 2530:         }
 2531:  
 2532:         ////////////////////////////////////////////////////////////////////////////
 2533:  
 2534:         /// <summary>
 2535:         ///
 2536:         /// </summary>
 2537:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor SwitchVendorByService(string service)
 2538:         {
 2539:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor switchVendor;
 2540:  
 2541:             if (int.TryParse(service, out int i))
 2542:             {
 2543:                 switchVendor = (from r in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.RouterList
 2544:                                 where r.DomainList.Any(u => service.StartsWith(u.ToString()))
 2545:                                 select r.Vendor).FirstOrDefault(); //.SingleOrDefault();
 2546:  
 2547:                 if (switchVendor == null) switchVendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 2548:             }
 2549:             else switchVendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 2550:  
 2551:             return switchVendor;
 2552:         }
 2553:  
 2554:         ////////////////////////////////////////////////////////////////////////////
 2555:  
 2556:         /// <summary>
 2557:         ///
 2558:         /// </summary>
 2559:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor> SwitchVendorListByServiceList(List<string> serviceList)
 2560:         {
 2561:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor switchVendor;
 2562:             var switchVendorList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor>();
 2563:  
 2564:             foreach (var service in serviceList)
 2565:             {
 2566:                 if (int.TryParse(service, out int i))
 2567:                 {
 2568:                     switchVendor = (from r in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.RouterList
 2569:                                     where r.DomainList.Any(u => service.StartsWith(u.ToString()))
 2570:                                     select r.Vendor).FirstOrDefault(); //.SingleOrDefault();
 2571:  
 2572:                     if (switchVendor == null) switchVendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 2573:                 }
 2574:                 else switchVendor = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined;
 2575:  
 2576:                 switchVendorList.Add(switchVendor);
 2577:             }
 2578:  
 2579:             return switchVendorList;
 2580:         }
 2581:  
 2582:         ////////////////////////////////////////////////////////////////////////////
 2583:  
 2584:         /// <summary>
 2585:         ///
 2586:         /// </summary>
 2587:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn PstnFromService(int number)
 2588:         {
 2589:             return PstnFromService(number.ToString());
 2590:         }
 2591:  
 2592:         ////////////////////////////////////////////////////////////////////////////
 2593:  
 2594:         /// <summary>
 2595:         ///
 2596:         /// </summary>
 2597:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn PstnFromService(string service)
 2598:         {
 2599:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn pstn;
 2600:  
 2601:             if (int.TryParse(service, out int i))
 2602:             {
 2603:                 pstn = (from p in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PstnList
 2604:                         where p.DomainList.Any(u => service.StartsWith(u.ToString()))
 2605:                         select p).SingleOrDefault();
 2606:             }
 2607:             else pstn = null;
 2608:  
 2609:             return pstn;
 2610:         }
 2611:  
 2612:         ////////////////////////////////////////////////////////////////////////////
 2613:  
 2614:         /// <summary>
 2615:         ///
 2616:         /// </summary>
 2617:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> PstnThatUsesNpServerList
 2618:         {
 2619:             get
 2620:             {
 2621:                 var list = (from p in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PstnList
 2622:                             where p.UsesNpServer == true
 2623:                             select p).ToList();
 2624:  
 2625:                 return list;
 2626:             }
 2627:         }
 2628:  
 2629:         ////////////////////////////////////////////////////////////////////////////
 2630:  
 2631:         /// <summary>
 2632:         ///
 2633:         /// </summary>
 2634:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> PstnList
 2635:         {
 2636:             get
 2637:             {
 2638:                 if (pstnList == null || pstnList.Count == 0)
 2639:                 {
 2640:                     lock (objectLock)
 2641:                     {
 2642:                         var networkId = 1; // <network id="1" name="Fixed Telecommunications Network">
 2643:  
 2644:                         pstnList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._PstnList(networkId);
 2645:                     }
 2646:                 }
 2647:  
 2648:                 return pstnList;
 2649:             }
 2650:         }
 2651:  
 2652:         ////////////////////////////////////////////////////////////////////////////
 2653:  
 2654:         /// <summary>
 2655:         ///
 2656:         /// </summary>
 2657:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> LegacyPstnList
 2658:         {
 2659:             get
 2660:             {
 2661:                 if (legacyPstnList == null || legacyPstnList.Count == 0)
 2662:                 {
 2663:                     lock (objectLock)
 2664:                     {
 2665:                         var networkId = 2; // <network id="2" name="Legacy">
 2666:  
 2667:                         legacyPstnList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._PstnList(networkId);
 2668:                     }
 2669:                 }
 2670:  
 2671:                 return legacyPstnList;
 2672:             }
 2673:         }
 2674:  
 2675:         ////////////////////////////////////////////////////////////////////////////
 2676:  
 2677:         /// <summary>
 2678:         ///
 2679:         /// </summary>
 2680:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> FtnAndLegacyPstnList
 2681:         {
 2682:             get
 2683:             {
 2684:                 var pstnList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PstnList;
 2685:                 var legacyPstnList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.LegacyPstnList;
 2686:  
 2687:                 var list = pstnList.Union(legacyPstnList).ToList();
 2688:  
 2689:                 return list;
 2690:             }
 2691:         }
 2692:  
 2693:         ////////////////////////////////////////////////////////////////////////////
 2694:  
 2695:         /// <summary>
 2696:         ///
 2697:         /// </summary>
 2698:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn LegacyPstnFromService(int number)
 2699:         {
 2700:             return LegacyPstnFromService(number.ToString());
 2701:         }
 2702:  
 2703:         ////////////////////////////////////////////////////////////////////////////
 2704:  
 2705:         /// <summary>
 2706:         ///
 2707:         /// </summary>
 2708:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn LegacyPstnFromService(string service)
 2709:         {
 2710:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn pstn;
 2711:  
 2712:             if (int.TryParse(service, out int i))
 2713:             {
 2714:                 pstn = (from p in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.LegacyPstnList
 2715:                         where p.DomainList.Any(u => service.StartsWith(u.ToString()))
 2716:                         select p).SingleOrDefault();
 2717:             }
 2718:             else pstn = null;
 2719:  
 2720:             return pstn;
 2721:         }
 2722:  
 2723:         ////////////////////////////////////////////////////////////////////////////
 2724:  
 2725:         /// <summary>
 2726:         ///
 2727:         /// </summary>
 2728:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn> _PstnList(int networkId)
 2729:         {
 2730:             int siteId, id;
 2731:             string pstnExchangeTypeString, usesNpServerString;
 2732: #if DEBUG
 2733:             //Dictionary<int, int> domainDictionary;
 2734: #endif
 2735:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn pstn;
 2736:  
 2737: #if DEBUG
 2738:             //domainDictionary = new Dictionary<int, int>(100);
 2739: #endif
 2740:             var pstnList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn>();
 2741:  
 2742:             var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2743:                                    where n.Attribute("id").Value == networkId.ToString()
 2744:                                    select n).Single();
 2745:  
 2746:             foreach (XElement x in networkXElement.Elements("site").Elements("pstn"))
 2747:             {
 2748:                 pstn = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn();
 2749:                 pstn.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 2750:  
 2751:                 networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2752:                 siteId = int.Parse(x.Parent.Attribute("id").Value);
 2753:                 id = int.Parse(x.Attribute("id").Value);
 2754:  
 2755:                 siteId = pstn.Site.SiteId(networkId, siteId);
 2756:                 pstn.Id = pstn.PstnId(siteId, id);
 2757:                 pstn.Name = x.Attribute("name").Value;
 2758:                 pstn.ArabicName = x.Attribute("arabicName").Value;
 2759:  
 2760:                 //if (x.Attribute("ip") != null) pstn.Ip = x.Attribute("ip").Value;
 2761:                 //else pstn.Ip = string.Empty;
 2762:  
 2763:                 pstn.DomainListString = x.Attribute("domainList").Value;
 2764:  
 2765:                 pstn.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(pstn.DomainListString);
 2766:  
 2767: #if DEBUG
 2768:                 /*
 2769:                 foreach (int i in pstn.DomainList)
 2770:                 {
 2771:                     // this will throw an exception if there are similar domains in pstns
 2772:                     if (domainDictionary.ContainsKey(i))
 2773:                     {
 2774:                         throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 2775:                     }
 2776:                     else domainDictionary[i] = 1;
 2777:                 }
 2778:                 */
 2779: #endif
 2780:  
 2781:                 pstnExchangeTypeString = x.Attribute("type").Value;
 2782:  
 2783:                 if (pstnExchangeTypeString == "EWSD") pstn.PstnExchangeType = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PstnExchangeType.SiemensEwsd;
 2784:                 else if (pstnExchangeTypeString == "AXE") pstn.PstnExchangeType = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PstnExchangeType.EricssonAxe;
 2785:                 else if (pstnExchangeTypeString == "MRD") pstn.PstnExchangeType = Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.PstnExchangeType.NortelMeridian;
 2786: #if DEBUG
 2787:                 else throw new ArgumentOutOfRangeException(@"Unknown PSTN exchange type: " + pstnExchangeTypeString);
 2788: #endif
 2789:                 usesNpServerString = x.Attribute("usesNpServer") != null ? x.Attribute("usesNpServer").Value : "false";
 2790:                 pstn.UsesNpServer = usesNpServerString == "true";
 2791:  
 2792:                 if (networkId == 1) pstn.Site = (from s in SiteList where s.Id == siteId select s).Single(); // <network id="1" name="Fixed Telecommunications Network">
 2793:                 else /*if(networkId == 2)*/ pstn.Site = (from s in LegacySiteList where s.Id == siteId select s).Single(); // <network id="2" name="Legacy">
 2794:  
 2795:                 pstnList.Add(pstn);
 2796:             }
 2797:  
 2798:             return pstnList;
 2799:         }
 2800:  
 2801:         ////////////////////////////////////////////////////////////////////////////
 2802:  
 2803:         /// <summary>
 2804:         ///
 2805:         /// </summary>
 2806:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Pstn PstnFromName(string name)
 2807:         {
 2808:             var pstn = (from p in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.PstnList where p.Name == name select p).Single();
 2809:  
 2810:             return pstn;
 2811:         }
 2812:  
 2813:         ////////////////////////////////////////////////////////////////////////////
 2814:         ////////////////////////////////////////////////////////////////////////////
 2815:  
 2816:         /// <summary>
 2817:         ///
 2818:         /// </summary>
 2819:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan> MsanList
 2820:         {
 2821:             get
 2822:             {
 2823:                 if (msanList == null || msanList.Count == 0)
 2824:                 {
 2825:                     lock (objectLock)
 2826:                     {
 2827:                         msanList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._MsanList;
 2828:                     }
 2829:                 }
 2830:  
 2831:                 return msanList;
 2832:             }
 2833:         }
 2834:  
 2835:         ////////////////////////////////////////////////////////////////////////////
 2836:  
 2837:         /// <summary>
 2838:         ///
 2839:         /// </summary>
 2840:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan> _MsanList
 2841:         {
 2842:             get
 2843:             {
 2844:                 int networkId, siteId, id;
 2845:                 //string usesNpServerString;
 2846: #if DEBUG
 2847:                 //Dictionary<int, int> domainDictionary;
 2848: #endif
 2849:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan msan;
 2850:  
 2851: #if DEBUG
 2852:                 //domainDictionary = new Dictionary<int, int>(100);
 2853: #endif
 2854:                 var msanList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan>();
 2855:  
 2856:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2857:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2858:                                        select n).Single();
 2859:  
 2860:                 foreach (XElement x in networkXElement.Elements("site").Elements("msan"))
 2861:                 {
 2862:                     msan = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan();
 2863:                     msan.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 2864:  
 2865:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 2866:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 2867:                     id = int.Parse(x.Attribute("id").Value);
 2868:  
 2869:                     siteId = msan.Site.SiteId(networkId, siteId);
 2870:                     msan.Id = msan.MsanId(siteId, id);
 2871:                     msan.NameSymbol = x.Attribute("nameSymbol").Value;
 2872:  
 2873:                     msan.DomainListString = x.Attribute("domainList").Value;
 2874:  
 2875:                     msan.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(msan.DomainListString);
 2876:  
 2877:                     //usesNpServerString = x.Attribute("usesNpServer").Value;
 2878:                     msan.UsesNpServer = false; // usesNpServerString == "true";
 2879:  
 2880:                     msan.Site = (from s in SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 2881:  
 2882: #if DEBUG
 2883:                     /*
 2884:                      
 2885:                     // You might have and MSAN on a site but the equivalent domains in another site
 2886:                     if (msan.DomainList != null)
 2887:                     {
 2888:                         foreach (var s in msan.DomainList)
 2889:                         {
 2890:                             if (!msan.Site.DomainList.Contains(s))
 2891:                             {
 2892:                                 throw new ArgumentOutOfRangeException(@"msan.Site.DomainList does not contain " + s + ".");
 2893:                             }
 2894:                         }
 2895:                     }
 2896:                     */
 2897:  
 2898:  
 2899:                     /*
 2900:                     foreach (int i in msan.DomainList)
 2901:                     {
 2902:                         // this will throw an exception if there are similar domains in pstns
 2903:                         if (domainDictionary.ContainsKey(i))
 2904:                         {
 2905:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 2906:                         }
 2907:                         else domainDictionary[i] = 1;
 2908:                     }
 2909:                     */
 2910: #endif
 2911:  
 2912:                     msanList.Add(msan);
 2913:                 }
 2914:  
 2915:                 return msanList;
 2916:             }
 2917:         }
 2918:  
 2919:         ////////////////////////////////////////////////////////////////////////////
 2920:  
 2921:         /// <summary>
 2922:         ///
 2923:         /// </summary>
 2924:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan MsanFromNameSymbol(string nameSymbol)
 2925:         {
 2926:             var msanList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.MsanList;
 2927:  
 2928:             var msan = (from m in msanList
 2929:                         where m.NameSymbol == nameSymbol
 2930:                         select m).SingleOrDefault();
 2931:  
 2932:             return msan;
 2933:         }
 2934:  
 2935:         ////////////////////////////////////////////////////////////////////////////
 2936:  
 2937:         /// <summary>
 2938:         ///
 2939:         /// </summary>
 2940:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan MsanFromSiteName(string siteName)
 2941:         {
 2942:             var siteList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.SiteList;
 2943:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Msan msan;
 2944:  
 2945:             var site = (from s in siteList
 2946:                         where s.Name == siteName
 2947:                         select s).SingleOrDefault();
 2948:  
 2949:             msan = (site != null && site.Msans.Count != 0) ? site.Msans.FirstOrDefault() : null;
 2950:  
 2951:             return msan;
 2952:         }
 2953:  
 2954:         ////////////////////////////////////////////////////////////////////////////
 2955:         ////////////////////////////////////////////////////////////////////////////
 2956:  
 2957:         /// <summary>
 2958:         ///
 2959:         /// </summary>
 2960:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX> SoftXList
 2961:         {
 2962:             get
 2963:             {
 2964:                 if (softXList == null || softXList.Count == 0)
 2965:                 {
 2966:                     lock (objectLock)
 2967:                     {
 2968:                         softXList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._SoftXList;
 2969:                     }
 2970:                 }
 2971:  
 2972:                 return softXList;
 2973:             }
 2974:         }
 2975:  
 2976:         ////////////////////////////////////////////////////////////////////////////
 2977:  
 2978:         /// <summary>
 2979:         ///
 2980:         /// </summary>
 2981:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX> _SoftXList
 2982:         {
 2983:             get
 2984:             {
 2985:                 int networkId, siteId, id;
 2986: #if DEBUG
 2987:                 //Dictionary<int, int> domainDictionary;
 2988: #endif
 2989:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX softX;
 2990:  
 2991: #if DEBUG
 2992:                 //domainDictionary = new Dictionary<int, int>(100);
 2993: #endif
 2994:                 var softXList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX>();
 2995:  
 2996:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 2997:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 2998:                                        select n).Single();
 2999:  
 3000:                 foreach (XElement x in networkXElement.Elements("site").Elements("softx"))
 3001:                 {
 3002:                     softX = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.SoftX();
 3003:                     softX.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 3004:  
 3005:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 3006:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 3007:                     id = int.Parse(x.Attribute("id").Value);
 3008:  
 3009:                     siteId = softX.Site.SiteId(networkId, siteId);
 3010:                     softX.Id = softX.SoftXId(siteId, id);
 3011:  
 3012:                     softX.DomainListString = x.Attribute("domainList").Value;
 3013:  
 3014:                     softX.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(softX.DomainListString);
 3015:  
 3016:                     softX.Site = (from s in SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 3017:  
 3018: #if DEBUG
 3019:                     /*
 3020:                     if (softX.DomainList != null)
 3021:                     {
 3022:                         foreach (var s in softX.DomainList)
 3023:                         {
 3024:                             if (!softX.Site.DomainList.Contains(s))
 3025:                             {
 3026:                                 throw new ArgumentOutOfRangeException(@"softX.Site.DomainList does not contain " + s + ".");
 3027:                             }
 3028:                         }
 3029:                     }
 3030:                     */
 3031:  
 3032:                     /*
 3033:                     foreach (int i in softX.DomainList)
 3034:                     {
 3035:                         // this will throw an exception if there are similar domains in sps
 3036:                         if (domainDictionary.ContainsKey(i))
 3037:                         {
 3038:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 3039:                         }
 3040:                         else domainDictionary[i] = 1;
 3041:                     }
 3042:                     */
 3043: #endif
 3044:  
 3045:                     softXList.Add(softX);
 3046:                 }
 3047:  
 3048:                 return softXList;
 3049:             }
 3050:         }
 3051:  
 3052:         ////////////////////////////////////////////////////////////////////////////
 3053:         ////////////////////////////////////////////////////////////////////////////
 3054:  
 3055:         /// <summary>
 3056:         ///
 3057:         /// </summary>
 3058:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router> RouterList
 3059:         {
 3060:             get
 3061:             {
 3062:                 if (routerList == null || routerList.Count == 0)
 3063:                 {
 3064:                     lock (objectLock)
 3065:                     {
 3066:                         routerList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._RouterList;
 3067:                     }
 3068:                 }
 3069:  
 3070:                 return routerList;
 3071:             }
 3072:         }
 3073:  
 3074:         ////////////////////////////////////////////////////////////////////////////
 3075:  
 3076:         /// <summary>
 3077:         ///
 3078:         /// </summary>
 3079:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router> _RouterList
 3080:         {
 3081:             get
 3082:             {
 3083:                 int networkId, siteId, id;
 3084:                 string vendorShortName;
 3085: #if DEBUG
 3086:                 //Dictionary<int, int> domainDictionary;
 3087: #endif
 3088:                 Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router router;
 3089:  
 3090: #if DEBUG
 3091:                 //domainDictionary = new Dictionary<int, int>(100);
 3092: #endif
 3093:                 var routerList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router>();
 3094:  
 3095:                 var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 3096:                                        where n.Attribute("id").Value == "1" // <network id="1" name="Fixed Telecommunications Network">
 3097:                                        select n).Single();
 3098:  
 3099:                 foreach (XElement x in networkXElement.Elements("site").Elements("router"))
 3100:                 {
 3101:                     router = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Router();
 3102:                     router.Site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 3103:  
 3104:                     networkId = int.Parse(x.Parent.Parent.Attribute("id").Value);
 3105:                     siteId = int.Parse(x.Parent.Attribute("id").Value);
 3106:                     id = int.Parse(x.Attribute("id").Value);
 3107:  
 3108:                     siteId = router.Site.SiteId(networkId, siteId);
 3109:                     router.Id = router.RouterId(siteId, id);
 3110:                     router.Name = x.Attribute("name").Value;
 3111:                     router.Type = x.Attribute("type").Value;
 3112:  
 3113:                     router.DomainListString = x.Attribute("domainList").Value;
 3114:  
 3115:                     router.DomainList = Ia.Cl.Models.Default.CommaSeperatedNumberStringToNumberList(router.DomainListString);
 3116:  
 3117: #if DEBUG
 3118:                     /*
 3119:                     foreach (int i in router.DomainList)
 3120:                     {
 3121:                         // this will throw an exception if there are similar domains in routers
 3122:                         if (domainDictionary.ContainsKey(i))
 3123:                         {
 3124:                             throw new ArgumentOutOfRangeException(@"domainDictionary.ContainsKey(" + i + ")");
 3125:                         }
 3126:                         else domainDictionary[i] = 1;
 3127:                     }
 3128:                     */
 3129: #endif
 3130:  
 3131:                     vendorShortName = x.Attribute("vendorShortName").Value;
 3132:                     router.Vendor = (from v in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.VendorList where v.ShortName == vendorShortName select v).Single(); //.s.SingleOrDefault();
 3133:  
 3134:                     router.Site = (from s in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Id == siteId select s).Single(); //.SingleOrDefault();
 3135:  
 3136:                     routerList.Add(router);
 3137:                 }
 3138:  
 3139:                 return routerList;
 3140:             }
 3141:         }
 3142:  
 3143:         ////////////////////////////////////////////////////////////////////////////
 3144:         ////////////////////////////////////////////////////////////////////////////
 3145:  
 3146:         /// <summary>
 3147:         ///
 3148:         /// </summary>
 3149:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site> SiteList
 3150:         {
 3151:             get
 3152:             {
 3153:                 if (siteList == null || siteList.Count == 0)
 3154:                 {
 3155:                     lock (objectLock)
 3156:                     {
 3157:                         var networkId = 1; // <network id="1" name="Fixed Telecommunications Network">
 3158:  
 3159:                         siteList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._SiteList(networkId);
 3160:                     }
 3161:                 }
 3162:  
 3163:                 return siteList;
 3164:             }
 3165:         }
 3166:  
 3167:         ////////////////////////////////////////////////////////////////////////////
 3168:  
 3169:         /// <summary>
 3170:         ///
 3171:         /// </summary>
 3172:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site> LegacySiteList
 3173:         {
 3174:             get
 3175:             {
 3176:                 if (legacySiteList == null || legacySiteList.Count == 0)
 3177:                 {
 3178:                     lock (objectLock)
 3179:                     {
 3180:                         var networkId = 2; // <network id="2" name="Legacy">
 3181:  
 3182:                         legacySiteList = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument._SiteList(networkId);
 3183:                     }
 3184:                 }
 3185:  
 3186:                 return legacySiteList;
 3187:             }
 3188:         }
 3189:  
 3190:         ////////////////////////////////////////////////////////////////////////////
 3191:  
 3192:         /// <summary>
 3193:         ///
 3194:         /// </summary>
 3195:         private static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site> _SiteList(int networkId)
 3196:         {
 3197:             int id;
 3198:             Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site site;
 3199:  
 3200:             var siteList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site>();
 3201:  
 3202:             var networkXElement = (from n in XDocument.Element("networkDesignDocument").Elements("network")
 3203:                                    where n.Attribute("id").Value == networkId.ToString()
 3204:                                    select n).Single();
 3205:  
 3206:             foreach (XElement x in networkXElement.Elements("site"))
 3207:             {
 3208:                 site = new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site();
 3209:                 networkId = int.Parse(x.Parent.Attribute("id").Value);
 3210:                 id = int.Parse(x.Attribute("id").Value);
 3211:  
 3212:                 site.Id = site.SiteId(networkId, id);
 3213:                 site.Name = x.Attribute("name").Value;
 3214:                 site.ArabicName = x.Attribute("arabicName").Value;
 3215:  
 3216:                 site.Network = (from n in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.NetworkList
 3217:                                 where n.Id == networkId
 3218:                                 select n).Single();
 3219:  
 3220:                 siteList.Add(site);
 3221:             }
 3222:  
 3223:             return siteList;
 3224:         }
 3225:  
 3226:         ////////////////////////////////////////////////////////////////////////////
 3227:  
 3228:         /// <summary>
 3229:         ///
 3230:         /// </summary>
 3231:         public static Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Site SiteFromName(string name)
 3232:         {
 3233:             var site = (from s in Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.Name == name select s).Single();
 3234:  
 3235:             return site;
 3236:         }
 3237:  
 3238:         ////////////////////////////////////////////////////////////////////////////
 3239:         ////////////////////////////////////////////////////////////////////////////
 3240:  
 3241:         /// <summary>
 3242:         ///
 3243:         /// </summary>
 3244:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Network> NetworkList
 3245:         {
 3246:             get
 3247:             {
 3248:                 if (networkList == null || networkList.Count == 0)
 3249:                 {
 3250:                     lock (objectLock)
 3251:                     {
 3252:                         networkList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Network>
 3253:                         {
 3254:                             new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Network(1, "Fixed Telecommunications Network"),
 3255:                             new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Network(2, "Legacy")
 3256:                         };
 3257:                     }
 3258:                 }
 3259:  
 3260:                 return networkList;
 3261:             }
 3262:         }
 3263:  
 3264:         ////////////////////////////////////////////////////////////////////////////
 3265:         ////////////////////////////////////////////////////////////////////////////
 3266:  
 3267:         /// <summary>
 3268:         ///
 3269:         /// </summary>
 3270:         public static List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor> VendorList
 3271:         {
 3272:             get
 3273:             {
 3274:                 if (vendorList == null || vendorList.Count == 0)
 3275:                 {
 3276:                     lock (objectLock)
 3277:                     {
 3278:                         vendorList = new List<Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor>
 3279:                     {
 3280:                         new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor(0, "Undefined", "Un", "غير معرف", @"~\image\undefined.png"),
 3281:                         new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor(1, "Nokia", "No", "نوكيا", @"~\image\nokia-icon.png"),
 3282:                         new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor(2, "Huawei", "Hu", "هواوي", @"~\image\huawei-icon.png"),
 3283:                         new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor(3, "Ericsson", "Er", "إريكسون", @"~\image\ericsson-icon.png"),
 3284:                         new Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.Vendor(4, "Siemens", "Si", "سيمينس", @"~\image\siemens-icon.png")
 3285:                     };
 3286:                     }
 3287:                 }
 3288:  
 3289:                 return vendorList;
 3290:             }
 3291:         }
 3292:  
 3293:         ////////////////////////////////////////////////////////////////////////////
 3294:  
 3295:         /// <summary>
 3296:         ///
 3297:         /// </summary>
 3298:         public static string AmsNameFromOltId(int oltId)
 3299:         {
 3300:             var amsName = (from o in OltList
 3301:                            where o.Id == oltId
 3302:                            select o.AmsName).FirstOrDefault();
 3303:  
 3304:             return amsName;
 3305:         }
 3306:  
 3307:         ////////////////////////////////////////////////////////////////////////////
 3308:  
 3309:         /// <summary>
 3310:         ///
 3311:         /// </summary>
 3312:         public static string XDocument2()
 3313:         {
 3314:             return xDocument.ToString();
 3315:         }
 3316:  
 3317:         ////////////////////////////////////////////////////////////////////////////
 3318:         ////////////////////////////////////////////////////////////////////////////
 3319:  
 3320:         /// <summary>
 3321:         /// 
 3322:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 3323:         /// 
 3324:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 3325:         /// 2. Add "using System.Reflection".
 3326:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
 3327:         /// 
 3328:         /// </summary>
 3329:         private static XDocument XDocument
 3330:         {
 3331:             get
 3332:             {
 3333:                 if (xDocument == null)
 3334:                 {
 3335:                     lock (objectLock)
 3336:                     {
 3337:                         Assembly _assembly;
 3338:                         StreamReader streamReader;
 3339:  
 3340:                         _assembly = Assembly.GetExecutingAssembly();
 3341:                         streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ftn.Cl.model.data.network-design-document.xml"));
 3342:  
 3343:                         try
 3344:                         {
 3345:                             if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
 3346:                         }
 3347:                         catch (Exception)
 3348:                         {
 3349:                         }
 3350:                         finally
 3351:                         {
 3352:                         }
 3353:                     }
 3354:                 }
 3355:  
 3356:                 return xDocument;
 3357:             }
 3358:         }
 3359:     }
 3360:  
 3361:     ////////////////////////////////////////////////////////////////////////////
 3362:     ////////////////////////////////////////////////////////////////////////////    
 3363: }