شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة ش.ش.و.

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Service

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

Service support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.IO;
   5:  using System.Linq;
   6:  using System.Reflection;
   7:  using System.Web;
   8:  using System.Xml.Linq;
   9:  using System.Text.RegularExpressions;
  10:   
  11:  namespace Ia.Ngn.Cl.Model.Data
  12:  {
  13:      ////////////////////////////////////////////////////////////////////////////
  14:   
  15:      /// <summary publish="true">
  16:      /// Service support class for Next Generation Network (NGN) data model.
  17:      /// </summary>
  18:      /// 
  19:      /// <remarks> 
  20:      /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  21:      ///
  22:      /// 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
  23:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  24:      ///
  25:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  26:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  27:      /// 
  28:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  29:      /// 
  30:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  31:      /// </remarks> 
  32:      public partial class Service
  33:      {
  34:          private static XDocument xDocument;
  35:          private static List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea> kuwaitNgnAreaList;
  36:          private static List<int> domainList, pstnDomainList, migrationDomainList, nokiaSwitchDomainList, huaweiSwitchDomainList;
  37:          private static List<Ia.Ngn.Cl.Model.Business.Service.ServiceType> serviceTypeList;
  38:          private static Dictionary<string, int> serviceIdPositionDictionary;
  39:   
  40:          private static readonly object objectLock = new object();
  41:   
  42:          ////////////////////////////////////////////////////////////////////////////
  43:   
  44:          /// <summary>
  45:          ///
  46:          /// </summary>
  47:          public Service() { }
  48:   
  49:   
  50:          ////////////////////////////////////////////////////////////////////////////
  51:   
  52:          /// <summary>
  53:          ///
  54:          /// </summary>
  55:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> GponServiceToOntRouterVendorInAllowedToBeMigratedOltDictionary
  56:          {
  57:              get
  58:              {
  59:                  string service, accessId;
  60:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor> dictionary;
  61:   
  62:                  var gponServiceToAccessIdInAllowedToBeMigratedOltDictionary = Ia.Ngn.Cl.Model.Data.Service2.GponServiceToAccessIdInAllowedToBeMigratedOltDictionary;
  63:   
  64:                  var allowedToBeMigratedAccessIdToOntDictionary = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedAccessIdToOntDictionary;
  65:   
  66:                  dictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor>();
  67:   
  68:                  foreach (KeyValuePair<string, string> kvp in gponServiceToAccessIdInAllowedToBeMigratedOltDictionary)
  69:                  {
  70:                      service = kvp.Key;
  71:                      accessId = kvp.Value;
  72:   
  73:                      dictionary[service] = allowedToBeMigratedAccessIdToOntDictionary[accessId].Pon.PonGroup.Olt.Odf.Router.Vendor;
  74:                  }
  75:   
  76:                  return dictionary;
  77:              }
  78:          }
  79:   
  80:          ////////////////////////////////////////////////////////////////////////////
  81:   
  82:          /// <summary>
  83:          ///
  84:          /// </summary>
  85:          public static List<string> ServiceThatDoNotExistInServiceRequestServiceServiceIdList()
  86:          {
  87:              List<string> list;
  88:   
  89:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  90:              {
  91:                  list = (from s in db.Service2s
  92:                          join srs in db.ServiceRequestServices on s.Id equals srs.Id into gj
  93:                          from subsrs in gj.DefaultIfEmpty()
  94:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && subsrs.Id == null
  95:                          select s.Id).ToList();
  96:              }
  97:   
  98:              return list;
  99:          }
 100:   
 101:          ////////////////////////////////////////////////////////////////////////////
 102:   
 103:          /// <summary>
 104:          ///
 105:          /// </summary>
 106:          public static void DifferenceBetweenServiceAndServiceRequestOntDetailsOfTheCustomerDepartmentDatabase(out List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> toInsertIntoCustomerDepartment, out List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> toRemoveFromCustomerDepartment)
 107:          {
 108:              List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> toRemoveBecauseServicePositionIsUndefinedList, toRemoveFromCustomerDepartmentBecauseDoesNotExistInService, toOverwriteByRemovingFirstInCustomerDepartment;
 109:              Dictionary<string, int> serviceIdPositionDictionary;
 110:   
 111:              toRemoveBecauseServicePositionIsUndefinedList = new List<Business.ServiceServiceRequestOnt>();
 112:   
 113:              serviceIdPositionDictionary = Ia.Ngn.Cl.Model.Data.Service.ServiceIdPositionDictionary;
 114:   
 115:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 116:              {
 117:                  // insert into db:
 118:                  /*
 119:  select distinct s.Id, s.Service, s.ServiceType, sro.Id from Service2 s
 120:  inner join ServiceRequestOnts sro on s.Access_Id = sro.Access_Id
 121:  left outer join ServiceRequestOntDetails srod on sro.Id = srod.ServiceRequestOnt_Id
 122:  where srod.Id is null and s.Access_Id is not null and sro.Access_Id is not null 
 123:  order by s.Service
 124:  */
 125:                  toInsertIntoCustomerDepartment = (from s in db.Service2s
 126:                                                    join sro in db.ServiceRequestOnts on s.Access.Id equals sro.Access.Id
 127:                                                    join srod in db.ServiceRequestOntDetails on sro.Id equals srod.ServiceRequestOnt.Id
 128:                                                    into gj
 129:                                                    from srodgj in gj.DefaultIfEmpty()
 130:                                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && srodgj.Id == null && s.Access != null && sro.Access != null
 131:                                                    select new Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt()
 132:                                                    {
 133:                                                        ServiceId = s.Id,
 134:                                                        Service = s.Service,
 135:                                                        ServiceType = s.ServiceType,
 136:                                                        ServiceRequestOnt = sro
 137:                                                    }).Distinct().ToList();
 138:   
 139:                  foreach (var v in toInsertIntoCustomerDepartment)
 140:                  {
 141:                      if (serviceIdPositionDictionary.ContainsKey(v.ServiceId))
 142:                      {
 143:                          v.ServicePosition = serviceIdPositionDictionary[v.ServiceId];
 144:                      }
 145:                      else
 146:                      {
 147:                          toRemoveBecauseServicePositionIsUndefinedList.Add(v);
 148:                      }
 149:                  }
 150:   
 151:                  // I will remove the following from list because the service position is not defined
 152:                  foreach (var v in toRemoveBecauseServicePositionIsUndefinedList) toInsertIntoCustomerDepartment.Remove(v);
 153:   
 154:                  toInsertIntoCustomerDepartment = toInsertIntoCustomerDepartment.OrderBy(u => u.Service).ToList();
 155:   
 156:   
 157:                  // remove from db:
 158:   
 159:                  toOverwriteByRemovingFirstInCustomerDepartment = (from s in db.Service2s
 160:                                                                    join sro in db.ServiceRequestOnts on s.Access.Id equals sro.Access.Id
 161:                                                                    join srod in db.ServiceRequestOntDetails on s.Service equals srod.Service
 162:                                                                    where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && srod.ServiceRequestOnt != null && srod.ServiceRequestOnt.Id != sro.Access.Id //&& s.Service == "25488888"
 163:                                                                    select new Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt()
 164:                                                                    {
 165:                                                                        ServiceId = s.Id,
 166:                                                                        Service = s.Service,
 167:                                                                        ServiceType = s.ServiceType,
 168:                                                                        ServiceRequestOnt = srod.ServiceRequestOnt
 169:                                                                    }).Distinct().ToList();
 170:   
 171:                  toRemoveFromCustomerDepartmentBecauseDoesNotExistInService = (from srod in db.ServiceRequestOntDetails
 172:                                                                                join sro in db.ServiceRequestOnts on srod.ServiceRequestOnt.Id equals sro.Id
 173:                                                                                join s in db.Service2s on srod.Service equals s.Service
 174:                                                                                into gj
 175:                                                                                from subs in gj.DefaultIfEmpty()
 176:                                                                                where subs.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && subs.Id == null && sro.Access != null //&& srod.Service == "25488888"
 177:                                                                                select new Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt()
 178:                                                                                {
 179:                                                                                    Service = srod.Service,
 180:                                                                                    ServiceRequestOnt = sro
 181:                                                                                }).Distinct().ToList();
 182:   
 183:                  toRemoveFromCustomerDepartment = toRemoveFromCustomerDepartmentBecauseDoesNotExistInService.Union(toOverwriteByRemovingFirstInCustomerDepartment).Distinct().ToList();
 184:              }
 185:          }
 186:   
 187:          ////////////////////////////////////////////////////////////////////////////
 188:   
 189:          /// <summary>
 190:          ///
 191:          /// </summary>
 192:          public static List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> ServiceServiceRequestOntDetailWithMismatchedInformationInServiceRequestOntDetailList()
 193:          {
 194:              List<Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt> list;
 195:              Dictionary<string, int> serviceIdPositionDictionary;
 196:   
 197:              serviceIdPositionDictionary = Ia.Ngn.Cl.Model.Data.Service.ServiceIdPositionDictionary;
 198:   
 199:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 200:              {
 201:                  list = (from s in db.Service2s
 202:                          join sro in db.ServiceRequestOnts on s.Access.Id equals sro.Access.Id
 203:                          join srod in db.ServiceRequestOntDetails on sro.Id equals srod.ServiceRequestOnt.Id /*into gj
 204:                          from subsrod in gj.DefaultIfEmpty()*/
 205:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && /*subsrod.Id == null &&*/ s.Access != null && sro.Access != null
 206:                          select new Ia.Ngn.Cl.Model.Business.ServiceServiceRequestOnt()
 207:                          {
 208:                              ServiceId = s.Id,
 209:                              Service = s.Service,
 210:                              ServiceType = s.ServiceType,
 211:                              ServiceRequestOnt = sro
 212:                          }).ToList();
 213:   
 214:                  foreach (var v in list)
 215:                  {
 216:                      if (serviceIdPositionDictionary.ContainsKey(v.ServiceId))
 217:                      {
 218:                          v.ServicePosition = serviceIdPositionDictionary[v.ServiceId];
 219:                      }
 220:                  }
 221:              }
 222:   
 223:              return list.OrderBy(u => u.Service).ToList();
 224:          }
 225:   
 226:          ////////////////////////////////////////////////////////////////////////////
 227:   
 228:          /// <summary>
 229:          ///
 230:          /// </summary>
 231:          public static Dictionary<string, int> ServiceIdPositionDictionary
 232:          {
 233:              get
 234:              {
 235:                  lock (objectLock)
 236:                  {
 237:                      if (serviceIdPositionDictionary == null || serviceIdPositionDictionary.Count == 0) serviceIdPositionDictionary = Ia.Ngn.Cl.Model.Data.Service._ServiceIdPositionDictionary;
 238:   
 239:                      return serviceIdPositionDictionary;
 240:                  }
 241:              }
 242:          }
 243:   
 244:          ////////////////////////////////////////////////////////////////////////////
 245:   
 246:          /// <summary>
 247:          ///
 248:          /// </summary>
 249:          private static Dictionary<string, int> _ServiceIdPositionDictionary
 250:          {
 251:              get
 252:              {
 253:                  string key;
 254:                  Dictionary<string, int> dictionary, nokiaToNokiaDictionary, nokiaToHuaweiEmsOntSipInfoesDictionary, nokiaToHuaweiEmsVoipPstnUsersDictionary, huaweiToHuaweiEmsOntSipInfoesDictionary, huaweiToHuaweiEmsVoipPstnUsersDictionary;
 255:   
 256:                  nokiaToNokiaDictionary = new Dictionary<string, int>();
 257:                  nokiaToHuaweiEmsOntSipInfoesDictionary = new Dictionary<string, int>();
 258:                  nokiaToHuaweiEmsVoipPstnUsersDictionary = new Dictionary<string, int>();
 259:                  huaweiToHuaweiEmsOntSipInfoesDictionary = new Dictionary<string, int>();
 260:   
 261:                  var dummyVarToDrawRefractorToBelow = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service("0000000");
 262:   
 263:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 264:                  {
 265:                      // No-No
 266:                      nokiaToNokiaDictionary = (from s in db.Subscribers
 267:                                                join sp in db.SubParties on s.SubParty.Id equals sp.Id
 268:                                                join ep in db.AgcfEndpoints on sp.AgcfEndpoint.Id equals ep.Id
 269:                                                select new { s.Id, ep.FlatTermID }).Distinct().ToDictionary(u => u.Id, u => u.FlatTermID);
 270:   
 271:   
 272:                      // No-Hu ONT with EmsOntSipInfo
 273:                      // select * from Subscribers as s inner join EmsOntSipInfoes as eosi on s.PartyId = eosi.SIPUSERNAME 
 274:                      var list = (from s in db.Subscribers
 275:                                  join eosi in db.EmsOntSipInfos on s.PartyId equals eosi.SIPUSERNAME
 276:                                  select new { s.Id, eosi.TEL }).ToList();
 277:   
 278:                      foreach (var l in list) if (!nokiaToHuaweiEmsOntSipInfoesDictionary.ContainsKey(l.Id)) nokiaToHuaweiEmsOntSipInfoesDictionary[l.Id] = l.TEL;
 279:   
 280:   
 281:                      // No-Hu MDU
 282:                      // select s.Id, evpu.PN from Subscribers as s inner join EmsVoipPstnUsers as evpu on s.PartyId = '+' + evpu.DN
 283:                      var list2 = (from s in db.Subscribers
 284:                                   join evpu in db.EmsVoipPstnUsers on s.PartyId equals "+" + evpu.DN // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode()
 285:                                   select new { s.Id, evpu.PN }).ToList();
 286:   
 287:                      foreach (var l in list2) if (!nokiaToHuaweiEmsVoipPstnUsersDictionary.ContainsKey(l.Id)) nokiaToHuaweiEmsVoipPstnUsersDictionary[l.Id] = l.PN;
 288:   
 289:   
 290:                      // Hu-Hu ONT
 291:                      // I will use SIPUSERNAME because looks similar for Nokia and Huawei switches, but SIPNAME sometimes like +96525422460@ims.moc.kw and like priv_96524602282
 292:                      // select s.IMPU, eosi.SIPUSERNAME, eosi.TEL from HuSbrs as s inner join EmsOntSipInfoes as eosi on s.IMPU = 'sip:' + eosi.SIPNAME
 293:                      var list3 = (from s in db.HuSbrs
 294:                                   join eosi in db.EmsOntSipInfos on s.IMPU equals "sip:" + eosi.SIPNAME  // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ImpuSipDomain()
 295:                                   select new { s.IMPU, eosi.TEL }).ToList();
 296:   
 297:                      foreach (var l in list3) if (!huaweiToHuaweiEmsOntSipInfoesDictionary.ContainsKey(l.IMPU)) huaweiToHuaweiEmsOntSipInfoesDictionary[l.IMPU] = l.TEL;
 298:   
 299:   
 300:                      // Hu-Hu MDU
 301:                      // select * from HuSbrs s inner join EmsVoipPstnUsers evpu on s.IMPU = 'sip:+' + evpu.DN + '@ims.moc.kw'
 302:                      huaweiToHuaweiEmsVoipPstnUsersDictionary = (from s in db.HuSbrs
 303:                                                                  join evpu in db.EmsVoipPstnUsers on s.IMPU equals "sip:+" + evpu.DN + "@ims.moc.kw" // see: Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ServiceWithCountryCode()
 304:                                                                  select new { s.IMPU, evpu.PN }).Distinct().ToDictionary(u => u.IMPU, u => u.PN);
 305:   
 306:   
 307:                      dictionary = new Dictionary<string, int>(nokiaToNokiaDictionary.Count + nokiaToHuaweiEmsOntSipInfoesDictionary.Count + huaweiToHuaweiEmsOntSipInfoesDictionary.Count + huaweiToHuaweiEmsVoipPstnUsersDictionary.Count);
 308:   
 309:   
 310:                      foreach (KeyValuePair<string, int> kvp in nokiaToNokiaDictionary)
 311:                      {
 312:                          key = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(kvp.Key);
 313:                          key = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(key, 1);
 314:                          dictionary[key] = kvp.Value;
 315:                      }
 316:   
 317:                      foreach (KeyValuePair<string, int> kvp in nokiaToHuaweiEmsOntSipInfoesDictionary)
 318:                      {
 319:                          key = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(kvp.Key);
 320:                          key = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(key, 1);
 321:                          dictionary[key] = kvp.Value;
 322:                      }
 323:   
 324:                      foreach (KeyValuePair<string, int> kvp in nokiaToHuaweiEmsVoipPstnUsersDictionary)
 325:                      {
 326:                          key = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(kvp.Key);
 327:                          key = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(key, 1);
 328:                          dictionary[key] = Ia.Ngn.Cl.Model.Business.Service.ConvertEmsVoipPstnUsersPnToServiceRequestServicePosition(kvp.Value);
 329:                      }
 330:   
 331:                      foreach (KeyValuePair<string, int> kvp in huaweiToHuaweiEmsOntSipInfoesDictionary)
 332:                      {
 333:                          key = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(kvp.Key);
 334:                          key = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(key, 1);
 335:                          dictionary[key] = kvp.Value;
 336:                      }
 337:   
 338:                      foreach (KeyValuePair<string, int> kvp in huaweiToHuaweiEmsVoipPstnUsersDictionary)
 339:                      {
 340:                          key = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.Service(kvp.Key);
 341:                          key = Ia.Ngn.Cl.Model.Business.Service.ServiceToServiceId(key, 1);
 342:                          dictionary[key] = Ia.Ngn.Cl.Model.Business.Service.ConvertEmsVoipPstnUsersPnToServiceRequestServicePosition(kvp.Value);
 343:                      }
 344:                  }
 345:   
 346:                  return dictionary;
 347:              }
 348:          }
 349:   
 350:          ////////////////////////////////////////////////////////////////////////////
 351:   
 352:          /// <summary>
 353:          ///
 354:          /// </summary>
 355:          public static int ServicePosition(string service)
 356:          {
 357:              int port;
 358:              string partyId, impu;
 359:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor switchVendor;
 360:   
 361:              switchVendor = Ia.Ngn.Cl.Model.Business.Service.SwitchVendor(service);
 362:   
 363:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 364:              {
 365:                  if (switchVendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 366:                  {
 367:                      partyId = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.PartyId(service);
 368:   
 369:                      // No-No (db.Subscribers partyId and Id format +96523230000)
 370:                      var ep1 = (from s in db.Subscribers
 371:                                 join sp in db.SubParties on s.SubParty.Id equals sp.Id
 372:                                 join ep in db.AgcfEndpoints on sp.AgcfEndpoint.Id equals ep.Id
 373:                                 where s.PartyId == partyId
 374:                                 select ep).SingleOrDefault();
 375:   
 376:                      if (ep1 != null) port = ep1.FlatTermID;
 377:                      else
 378:                      {
 379:                          // No-Hu ONT with EmsOntSipInfo (db.Subscribers partyId and Id have format +96523230000)
 380:                          var eosi1 = (from s in db.Subscribers
 381:                                       join eosi in db.EmsOntSipInfos on s.PartyId equals eosi.SIPUSERNAME
 382:                                       where s.PartyId == partyId
 383:                                       select eosi).SingleOrDefault();
 384:   
 385:                          if (eosi1 != null) port = eosi1.TEL;
 386:                          else
 387:                          {
 388:                              // No-Hu MDU (db.Subscribers partyId and Id have format +96523230000)
 389:                              var evpu1 = (from s in db.Subscribers
 390:                                           join evpu in db.EmsVoipPstnUsers on s.PartyId equals "+" + evpu.DN
 391:                                           where s.PartyId == partyId
 392:                                           select evpu).SingleOrDefault();
 393:   
 394:                              if (evpu1 != null)
 395:                              {
 396:                                  port = evpu1.PN;
 397:                                  port = Ia.Ngn.Cl.Model.Business.Service.ConvertEmsVoipPstnUsersPnToServiceRequestServicePosition(port);
 398:                              }
 399:                              else port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
 400:                          }
 401:                      }
 402:                  }
 403:                  else if (switchVendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 404:                  {
 405:                      impu = Ia.Ngn.Cl.Model.Business.NumberFormatConverter.ImpuSipDomain(service);
 406:   
 407:                      // Hu-Hu ONT (db.HuSbrs IMPU have format sip:+96523610000@ims.moc.kw)
 408:                      var eosi1 = (from s in db.HuSbrs
 409:                                   join eosi in db.EmsOntSipInfos on s.IMPU equals "sip:" + eosi.SIPNAME
 410:                                   where s.IMPU == impu
 411:                                   select eosi).SingleOrDefault();
 412:   
 413:                      if (eosi1 != null) port = eosi1.TEL;
 414:                      else
 415:                      {
 416:                          // Hu-Hu MDU (db.HuSbrs IMPU have format sip:+96523610000@ims.moc.kw)
 417:                          var evpu1 = (from s in db.HuSbrs
 418:                                       join evpu in db.EmsVoipPstnUsers on s.IMPU equals "sip:+" + evpu.DN + "@ims.moc.kw"
 419:                                       where s.IMPU == impu
 420:                                       select evpu).SingleOrDefault();
 421:   
 422:                          if (evpu1 != null)
 423:                          {
 424:                              port = evpu1.PN;
 425:                              port = Ia.Ngn.Cl.Model.Business.Service.ConvertEmsVoipPstnUsersPnToServiceRequestServicePosition(port);
 426:                          }
 427:                          else port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
 428:                      }
 429:                  }
 430:                  else //if (switchVendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Undefined)
 431:                  {
 432:                      port = Ia.Ngn.Cl.Model.Business.Default.PortUndefinedOrInvalidOrUnknown;
 433:                  }
 434:              }
 435:   
 436:              return port;
 437:          }
 438:   
 439:          ////////////////////////////////////////////////////////////////////////////
 440:   
 441:          /// <summary>
 442:          ///
 443:          /// </summary>
 444:          public static List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea> KuwaitNgnAreaList
 445:          {
 446:              get
 447:              {
 448:                  lock (objectLock)
 449:                  {
 450:                      if (kuwaitNgnAreaList == null || kuwaitNgnAreaList.Count == 0) kuwaitNgnAreaList = Ia.Ngn.Cl.Model.Data.Service._KuwaitNgnAreaList;
 451:   
 452:                      return kuwaitNgnAreaList;
 453:                  }
 454:              }
 455:          }
 456:   
 457:          ////////////////////////////////////////////////////////////////////////////
 458:   
 459:          /// <summary>
 460:          ///
 461:          /// </summary>
 462:          private static List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea> _KuwaitNgnAreaList
 463:          {
 464:              get
 465:              {
 466:                  int id;
 467:                  string symbol, text, key, value;
 468:                  List<int> list;
 469:                  Dictionary<string, List<string>> dictionaryList;
 470:                  Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 471:   
 472:                  kuwaitNgnAreaList = new List<Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea>();
 473:   
 474:                  foreach (XElement xe in XDocument.Element("service").Elements("areaList").Elements("area"))
 475:                  {
 476:                      kuwaitNgnArea = new Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea();
 477:   
 478:                      id = int.Parse(xe.Attribute("id").Value);
 479:                      kuwaitNgnArea.Id = id;
 480:   
 481:                      symbol = xe.Attribute("symbol").Value;
 482:                      kuwaitNgnArea.Symbol = symbol;
 483:   
 484:                      kuwaitNgnArea.ServiceRequestAddressProvinceAreaName = xe.Attribute("serviceRequestAddressProvinceAreaName").Value;
 485:   
 486:                      kuwaitNgnArea.Name = (from ka in Ia.Cl.Model.Kuwait.KuwaitAreaList where ka.Id == id select ka.Name).SingleOrDefault();
 487:                      kuwaitNgnArea.ArabicName = (from ka in Ia.Cl.Model.Kuwait.KuwaitAreaList where ka.Id == id select ka.ArabicName).SingleOrDefault();
 488:   
 489:                      kuwaitNgnArea.SiteList = (from s in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where s.AreaSymbolList.Contains(symbol) select s).ToList();
 490:   
 491:                      if (kuwaitNgnArea.SiteList != null) kuwaitNgnAreaList.Add(kuwaitNgnArea);
 492:                  }
 493:   
 494:                  return kuwaitNgnAreaList;
 495:              }
 496:          }
 497:   
 498:          ////////////////////////////////////////////////////////////////////////////
 499:   
 500:          /// <summary>
 501:          ///
 502:          /// </summary>
 503:          public static Dictionary<int, string> AreaIdToSymbolDictionary
 504:          {
 505:              get
 506:              {
 507:                  Dictionary<int, string> dictionary;
 508:   
 509:                  dictionary = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList select new { kna.Id, kna.Symbol }).ToDictionary(u => u.Id, u => u.Symbol);
 510:   
 511:                  return dictionary;
 512:              }
 513:          }
 514:   
 515:          ////////////////////////////////////////////////////////////////////////////
 516:   
 517:          /// <summary>
 518:          ///
 519:          /// </summary>
 520:          public static Dictionary<int, string> AreaIdToNameArabicNameDictionary
 521:          {
 522:              get
 523:              {
 524:                  Dictionary<int, string> dictionary;
 525:   
 526:                  dictionary = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList select new { kna.Id, kna.NameArabicName }).ToDictionary(u => u.Id, u => u.NameArabicName);
 527:   
 528:                  return dictionary;
 529:              }
 530:          }
 531:   
 532:          ////////////////////////////////////////////////////////////////////////////
 533:   
 534:          /// <summary>
 535:          ///
 536:          /// </summary>
 537:          public static Dictionary<int, int> AreaIdToSiteIdDictionary
 538:          {
 539:              get
 540:              {
 541:                  Dictionary<int, int> dictionary;
 542:   
 543:                  dictionary = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.SiteList.Count > 0 select new { kna.Id, SiteId = kna.SiteList.FirstOrDefault().Id }).ToDictionary(u => u.Id, u => u.SiteId);
 544:   
 545:                  return dictionary;
 546:              }
 547:          }
 548:   
 549:          ////////////////////////////////////////////////////////////////////////////
 550:          ////////////////////////////////////////////////////////////////////////////
 551:   
 552:          /// <summary>
 553:          ///
 554:          /// </summary>
 555:          public static List<int> DomainList
 556:          {
 557:              get
 558:              {
 559:                  lock (objectLock)
 560:                  {
 561:                      if (domainList == null || domainList.Count == 0) domainList = Ia.Ngn.Cl.Model.Data.Service._DomainList;
 562:   
 563:                      return domainList;
 564:                  }
 565:              }
 566:          }
 567:   
 568:          ////////////////////////////////////////////////////////////////////////////
 569:   
 570:          /// <summary>
 571:          ///
 572:          /// </summary>
 573:          private static List<int> _DomainList
 574:          {
 575:              get
 576:              {
 577:                  domainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList select r).SelectMany(r => r.DomainList).Distinct().ToList();
 578:   
 579:                  domainList.Sort();
 580:   
 581:                  return domainList;
 582:              }
 583:          }
 584:   
 585:          ////////////////////////////////////////////////////////////////////////////
 586:          ////////////////////////////////////////////////////////////////////////////
 587:   
 588:          /// <summary>
 589:          ///
 590:          /// </summary>
 591:          public static List<int> PstnDomainList
 592:          {
 593:              get
 594:              {
 595:                  lock (objectLock)
 596:                  {
 597:                      if (pstnDomainList == null || pstnDomainList.Count == 0) pstnDomainList = Ia.Ngn.Cl.Model.Data.Service._PstnDomainList;
 598:   
 599:                      return pstnDomainList;
 600:                  }
 601:              }
 602:          }
 603:   
 604:          ////////////////////////////////////////////////////////////////////////////
 605:   
 606:          /// <summary>
 607:          ///
 608:          /// </summary>
 609:          private static List<int> _PstnDomainList
 610:          {
 611:              get
 612:              {
 613:                  pstnDomainList = (from p in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PstnList select p).SelectMany(r => r.DomainList).Distinct().ToList();
 614:   
 615:                  pstnDomainList.Sort();
 616:   
 617:                  return pstnDomainList;
 618:              }
 619:          }
 620:   
 621:          ////////////////////////////////////////////////////////////////////////////
 622:          ////////////////////////////////////////////////////////////////////////////
 623:   
 624:          /// <summary>
 625:          ///
 626:          /// </summary>
 627:          public static List<int> MigrationDomainList
 628:          {
 629:              get
 630:              {
 631:                  lock (objectLock)
 632:                  {
 633:                      if (migrationDomainList == null || migrationDomainList.Count == 0) migrationDomainList = Ia.Ngn.Cl.Model.Data.Service._MigrationDomainList;
 634:   
 635:                      return migrationDomainList;
 636:                  }
 637:              }
 638:          }
 639:   
 640:          ////////////////////////////////////////////////////////////////////////////
 641:   
 642:          /// <summary>
 643:          ///
 644:          /// </summary>
 645:          private static List<int> _MigrationDomainList
 646:          {
 647:              get
 648:              {
 649:                  var pstnDomainList = Ia.Ngn.Cl.Model.Data.Service.PstnDomainList;
 650:                  var domainList = Ia.Ngn.Cl.Model.Data.Service.DomainList;
 651:   
 652:                  var list = domainList.Intersect(pstnDomainList);
 653:   
 654:                  return pstnDomainList;
 655:              }
 656:          }
 657:   
 658:          ////////////////////////////////////////////////////////////////////////////
 659:   
 660:          /// <summary>
 661:          ///
 662:          /// </summary>
 663:          public static List<int> NokiaSwitchDomainList
 664:          {
 665:              get
 666:              {
 667:                  lock (objectLock)
 668:                  {
 669:                      if (nokiaSwitchDomainList == null || nokiaSwitchDomainList.Count == 0) nokiaSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service._NokiaSwitchDomainList;
 670:   
 671:                      return nokiaSwitchDomainList;
 672:                  }
 673:              }
 674:          }
 675:   
 676:          ////////////////////////////////////////////////////////////////////////////
 677:   
 678:          /// <summary>
 679:          ///
 680:          /// </summary>
 681:          private static List<int> _NokiaSwitchDomainList
 682:          {
 683:              get
 684:              {
 685:                  Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 686:   
 687:                  vendor = (from v in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.VendorList where v == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia select v).Single();
 688:   
 689:                  return DomainListWithinSwitchVendor(vendor);
 690:              }
 691:          }
 692:   
 693:          ////////////////////////////////////////////////////////////////////////////
 694:   
 695:          /// <summary>
 696:          ///
 697:          /// </summary>
 698:          public static List<int> HuaweiSwitchDomainList
 699:          {
 700:              get
 701:              {
 702:                  lock (objectLock)
 703:                  {
 704:                      if (huaweiSwitchDomainList == null || huaweiSwitchDomainList.Count == 0) huaweiSwitchDomainList = Ia.Ngn.Cl.Model.Data.Service._HuaweiSwitchDomainList;
 705:   
 706:                      return huaweiSwitchDomainList;
 707:                  }
 708:              }
 709:          }
 710:   
 711:          ////////////////////////////////////////////////////////////////////////////
 712:   
 713:          /// <summary>
 714:          ///
 715:          /// </summary>
 716:          private static List<int> _HuaweiSwitchDomainList
 717:          {
 718:              get
 719:              {
 720:                  Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
 721:   
 722:                  vendor = (from v in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.VendorList where v == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei select v).Single();
 723:   
 724:                  return Ia.Ngn.Cl.Model.Data.Service.DomainListWithinSwitchVendor(vendor);
 725:              }
 726:          }
 727:   
 728:          ////////////////////////////////////////////////////////////////////////////
 729:   
 730:          /// <summary>
 731:          ///
 732:          /// </summary>
 733:          private static List<int> DomainListWithinSwitchVendor(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor)
 734:          {
 735:              List<int> list;
 736:   
 737:              list = (from d in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where d.Vendor == vendor select d).SelectMany(r => r.DomainList).ToList();
 738:   
 739:              list.Sort();
 740:   
 741:              return list;
 742:          }
 743:   
 744:          ////////////////////////////////////////////////////////////////////////////
 745:   
 746:          /// <summary>
 747:          ///
 748:          /// 
 749:          /// </summary>
 750:          private static List<int> DomainListWithinAccessVendor(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor)
 751:          {
 752:              List<int> list;
 753:   
 754:              list = (from d in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OdfList where d.Vendor == vendor select d.Router).SelectMany(r => r.DomainList).ToList();
 755:   
 756:              list.Sort();
 757:   
 758:              return list;
 759:          }
 760:   
 761:          ////////////////////////////////////////////////////////////////////////////
 762:   
 763:          /// <summary>
 764:          ///
 765:          /// </summary>
 766:          public static List<int> AllPossibleServiceNumberList
 767:          {
 768:              get
 769:              {
 770:                  int n, length;
 771:                  string s;
 772:                  List<int> list;
 773:   
 774:                  list = new List<int>(10000 * Ia.Ngn.Cl.Model.Data.Service.DomainList.Count);
 775:   
 776:                  foreach (int d in Ia.Ngn.Cl.Model.Data.Service.DomainList)
 777:                  {
 778:                      s = d.ToString();
 779:   
 780:                      length = s.Length;
 781:   
 782:                      if (length == 4)
 783:                      {
 784:                          for (int i = 0; i < 10000; i++)
 785:                          {
 786:                              n = d * 10000 + i;
 787:   
 788:                              list.Add(n);
 789:                          }
 790:                      }
 791:                      else if (length == 5)
 792:                      {
 793:                          for (int p = 0; p < 1000; p++)
 794:                          {
 795:                              n = d * 1000 + p;
 796:   
 797:                              list.Add(n);
 798:                          }
 799:                      }
 800:                      else
 801:                      {
 802:                          throw new Exception("length " + length + " is unknown");
 803:                      }
 804:                  }
 805:   
 806:                  return list;
 807:              }
 808:          }
 809:   
 810:          ////////////////////////////////////////////////////////////////////////////
 811:   
 812:          /// <summary>
 813:          ///
 814:          /// </summary>
 815:          public static List<int> AllPossiblePstnServiceNumberList
 816:          {
 817:              get
 818:              {
 819:                  int n, length;
 820:                  string s;
 821:                  List<int> list;
 822:   
 823:                  list = new List<int>(10000 * Ia.Ngn.Cl.Model.Data.Service.PstnDomainList.Count);
 824:   
 825:                  foreach (int d in Ia.Ngn.Cl.Model.Data.Service.PstnDomainList)
 826:                  {
 827:                      s = d.ToString();
 828:   
 829:                      length = s.Length;
 830:   
 831:                      if (length == 4)
 832:                      {
 833:                          for (int i = 0; i < 10000; i++)
 834:                          {
 835:                              n = d * 10000 + i;
 836:   
 837:                              list.Add(n);
 838:                          }
 839:                      }
 840:                      else if (length == 5)
 841:                      {
 842:                          for (int p = 0; p < 1000; p++)
 843:                          {
 844:                              n = d * 1000 + p;
 845:   
 846:                              list.Add(n);
 847:                          }
 848:                      }
 849:                      else
 850:                      {
 851:                          throw new Exception("length " + length + " is unknown");
 852:                      }
 853:                  }
 854:   
 855:                  return list;
 856:              }
 857:          }
 858:   
 859:          ////////////////////////////////////////////////////////////////////////////
 860:   
 861:          /// <summary>
 862:          ///
 863:          /// </summary>
 864:          public static List<int> AllPossibleServiceNumberListWithinDomain(int domain)
 865:          {
 866:              int n, length;
 867:              string s;
 868:              List<int> list;
 869:   
 870:              s = domain.ToString();
 871:   
 872:              length = s.Length;
 873:   
 874:              list = new List<int>(10000);
 875:   
 876:              if (length == 4)
 877:              {
 878:                  for (int i = 0; i < 10000; i++)
 879:                  {
 880:                      n = domain * 10000 + i;
 881:   
 882:                      list.Add(n);
 883:                  }
 884:              }
 885:              else if (length == 5)
 886:              {
 887:                  for (int p = 0; p < 1000; p++)
 888:                  {
 889:                      n = domain * 1000 + p;
 890:   
 891:                      list.Add(n);
 892:                  }
 893:              }
 894:              else
 895:              {
 896:                  throw new Exception("length " + length + " is unknown");
 897:              }
 898:   
 899:              return list;
 900:          }
 901:   
 902:          ////////////////////////////////////////////////////////////////////////////
 903:   
 904:          /// <summary>
 905:          ///
 906:          /// </summary>
 907:          public static int NumberOfPossibleServicesWithinDomainList(List<int> domainList)
 908:          {
 909:              int n, length;
 910:   
 911:              n = 0;
 912:   
 913:              foreach (int domain in domainList)
 914:              {
 915:                  length = domain.ToString().Length;
 916:   
 917:                  if (length == 4) n += 10000;
 918:                  else if (length == 5) n += 1000;
 919:                  else
 920:                  {
 921:                      throw new Exception("length " + length + " is unknown");
 922:                  }
 923:              }
 924:   
 925:              return n;
 926:          }
 927:   
 928:          ////////////////////////////////////////////////////////////////////////////
 929:   
 930:          /// <summary>
 931:          ///
 932:          /// </summary>
 933:          public static List<int> AllPossibleServiceNumberListWithinNokiaSwitch
 934:          {
 935:              get
 936:              {
 937:                  Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor nokia;
 938:                  List<int> list;
 939:   
 940:                  nokia = (from v in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.VendorList where v == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia select v).Single();
 941:   
 942:                  list = AllPossibleServiceNumberListWithinSwitchVendor(nokia);
 943:   
 944:                  return list;
 945:              }
 946:          }
 947:   
 948:          ////////////////////////////////////////////////////////////////////////////
 949:   
 950:          /// <summary>
 951:          ///
 952:          /// </summary>
 953:          public static List<int> AllPossibleServiceNumberListWithinHuaweiSwitch
 954:          {
 955:              get
 956:              {
 957:                  Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor huawei;
 958:                  List<int> list;
 959:   
 960:                  huawei = (from v in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.VendorList where v == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei select v).Single();
 961:   
 962:                  list = AllPossibleServiceNumberListWithinSwitchVendor(huawei);
 963:   
 964:                  return list;
 965:              }
 966:          }
 967:   
 968:          ////////////////////////////////////////////////////////////////////////////
 969:   
 970:          /// <summary>
 971:          ///
 972:          /// </summary>
 973:          private static List<int> AllPossibleServiceNumberListWithinSwitchVendor(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor)
 974:          {
 975:              int n, length;
 976:              string s;
 977:              List<int> list;
 978:              List<int> domainListWithinSwitchVendor;
 979:   
 980:              domainListWithinSwitchVendor = Ia.Ngn.Cl.Model.Data.Service.DomainListWithinSwitchVendor(vendor);
 981:   
 982:              list = new List<int>(10000 * domainListWithinSwitchVendor.Count);
 983:   
 984:              foreach (int domain in domainListWithinSwitchVendor)
 985:              {
 986:                  s = domain.ToString();
 987:   
 988:                  length = s.Length;
 989:   
 990:                  if (length == 4)
 991:                  {
 992:                      for (int i = 0; i < 10000; i++)
 993:                      {
 994:                          n = domain * 10000 + i;
 995:   
 996:                          list.Add(n);
 997:                      }
 998:                  }
 999:                  else if (length == 5)
1000:                  {
1001:                      for (int p = 0; p < 1000; p++)
1002:                      {
1003:                          n = domain * 1000 + p;
1004:   
1005:                          list.Add(n);
1006:                      }
1007:                  }
1008:                  else
1009:                  {
1010:                      throw new Exception("length " + length + " is unknown");
1011:                  }
1012:              }
1013:   
1014:              return list;
1015:          }
1016:   
1017:          ////////////////////////////////////////////////////////////////////////////    
1018:          ////////////////////////////////////////////////////////////////////////////
1019:   
1020:          /// <summary>
1021:          ///
1022:          /// </summary>
1023:          public static List<int> AllPossibleServiceNumberWithinSite(string siteName)
1024:          {
1025:              int n, length;
1026:              string s;
1027:              List<int> list;
1028:              List<int> domainList;
1029:   
1030:              domainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where r.Site.Name == siteName select r).SelectMany(r => r.DomainList).ToList();
1031:   
1032:              list = new List<int>(10000 * domainList.Count);
1033:   
1034:              foreach (int domain in domainList)
1035:              {
1036:                  s = domain.ToString();
1037:   
1038:                  length = s.Length;
1039:   
1040:                  if (length == 4)
1041:                  {
1042:                      for (int i = 0; i < 10000; i++)
1043:                      {
1044:                          n = domain * 10000 + i;
1045:   
1046:                          list.Add(n);
1047:                      }
1048:                  }
1049:                  else if (length == 5)
1050:                  {
1051:                      for (int p = 0; p < 1000; p++)
1052:                      {
1053:                          n = domain * 1000 + p;
1054:   
1055:                          list.Add(n);
1056:                      }
1057:                  }
1058:                  else
1059:                  {
1060:                      throw new Exception("length " + length + " is unknown");
1061:                  }
1062:              }
1063:   
1064:              list.Sort();
1065:   
1066:              return list.OrderBy(u => u).ToList(); // (u => u >= 25410000 && u <= 25440000).ToList();
1067:          }
1068:   
1069:          ////////////////////////////////////////////////////////////////////////////
1070:   
1071:          /// <summary>
1072:          ///
1073:          /// </summary>
1074:          public static List<string> AllPossiblePstnServiceNumbersWithinSite(string siteName)
1075:          {
1076:              int n, length;
1077:              string s;
1078:              List<string> list;
1079:              List<int> domainList;
1080:   
1081:              domainList = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PstnList where r.Site.Name == siteName select r).SelectMany(r => r.DomainList).ToList();
1082:   
1083:              list = new List<string>(10000 * domainList.Count);
1084:   
1085:              foreach (int domain in domainList)
1086:              {
1087:                  s = domain.ToString();
1088:   
1089:                  length = s.Length;
1090:   
1091:                  if (length == 4)
1092:                  {
1093:                      for (int i = 0; i < 10000; i++)
1094:                      {
1095:                          n = domain * 10000 + i;
1096:   
1097:                          list.Add(n.ToString());
1098:                      }
1099:                  }
1100:                  else if (length == 5)
1101:                  {
1102:                      for (int p = 0; p < 1000; p++)
1103:                      {
1104:                          n = domain * 1000 + p;
1105:   
1106:                          list.Add(n.ToString());
1107:                      }
1108:                  }
1109:                  else
1110:                  {
1111:                      throw new Exception("length " + length + " is unknown");
1112:                  }
1113:              }
1114:   
1115:              list.Sort();
1116:   
1117:              return list.OrderBy(u => u).ToList(); // (u => u >= 25410000 && u <= 25440000).ToList();
1118:          }
1119:   
1120:          ////////////////////////////////////////////////////////////////////////////
1121:   
1122:          /// <summary>
1123:          ///
1124:          /// </summary>
1125:          public static List<int> AllPossiblePstnServiceNumbersWithinPstnSite(string pstnSiteName)
1126:          {
1127:              int n, length;
1128:              string s;
1129:              List<int> list;
1130:              List<int> domainList;
1131:   
1132:              domainList = (from p in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PstnList where p.Name == pstnSiteName select p).SelectMany(r => r.DomainList).ToList();
1133:   
1134:              list = new List<int>(10000 * domainList.Count);
1135:   
1136:              foreach (int domain in domainList)
1137:              {
1138:                  s = domain.ToString();
1139:   
1140:                  length = s.Length;
1141:   
1142:                  if (length == 4)
1143:                  {
1144:                      for (int i = 0; i < 10000; i++)
1145:                      {
1146:                          n = domain * 10000 + i;
1147:   
1148:                          list.Add(n);
1149:                      }
1150:                  }
1151:                  else if (length == 5)
1152:                  {
1153:                      for (int p = 0; p < 1000; p++)
1154:                      {
1155:                          n = domain * 1000 + p;
1156:   
1157:                          list.Add(n);
1158:                      }
1159:                  }
1160:                  else
1161:                  {
1162:                      throw new Exception("length " + length + " is unknown");
1163:                  }
1164:              }
1165:   
1166:              list.Sort();
1167:   
1168:              return list.OrderBy(u => u).ToList(); // (u => u >= 25410000 && u <= 25440000).ToList();
1169:          }
1170:   
1171:          ////////////////////////////////////////////////////////////////////////////
1172:   
1173:          /// <summary>
1174:          ///
1175:          /// </summary>
1176:          public static List<string> SiteDomainList(string siteName)
1177:          {
1178:              List<int> list;
1179:              List<string> sList;
1180:   
1181:              list = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.RouterList where r.Site.Name == siteName select r).SelectMany(r => r.DomainList).ToList();
1182:   
1183:              list.Sort();
1184:   
1185:              sList = (from n in list select n.ToString()).ToList<string>();
1186:   
1187:              return sList;
1188:          }
1189:   
1190:          ////////////////////////////////////////////////////////////////////////////
1191:   
1192:          /// <summary>
1193:          ///
1194:          /// </summary>
1195:          public static List<string> SitePstnDomainList(string siteName)
1196:          {
1197:              List<int> list;
1198:              List<string> sList;
1199:   
1200:              list = (from r in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PstnList where r.Site.Name == siteName select r).SelectMany(r => r.DomainList).ToList();
1201:   
1202:              list.Sort();
1203:   
1204:              sList = (from n in list select n.ToString()).ToList<string>();
1205:   
1206:              return sList;
1207:          }
1208:   
1209:          ////////////////////////////////////////////////////////////////////////////
1210:   
1211:          /// <summary>
1212:          ///
1213:          /// </summary>
1214:          public static bool ServiceListIsWithinSitePstnDomainList(string siteName, List<string> serviceList)
1215:          {
1216:              bool b;
1217:   
1218:              b = Ia.Ngn.Cl.Model.Data.Service.SitePstnDomainList(siteName).Any(u => serviceList.Any(v => v.StartsWith(u)));
1219:   
1220:              return b;
1221:          }
1222:   
1223:          ////////////////////////////////////////////////////////////////////////////
1224:   
1225:          /// <summary>
1226:          ///
1227:          /// </summary>
1228:          public static bool ServiceIsWithinPstnDomainList(string service)
1229:          {
1230:              bool b;
1231:   
1232:              b = Ia.Ngn.Cl.Model.Data.Service.PstnDomainList.Any(u => service.StartsWith(u.ToString()));
1233:   
1234:              return b;
1235:          }
1236:   
1237:          ////////////////////////////////////////////////////////////////////////////
1238:   
1239:          /// <summary>
1240:          ///
1241:          /// </summary>
1242:          public static bool ServiceListIsWithinPstnDomainList(List<string> serviceList)
1243:          {
1244:              bool b;
1245:   
1246:              b = Ia.Ngn.Cl.Model.Data.Service.PstnDomainList.Any(u => serviceList.Any(v => v.StartsWith(u.ToString())));
1247:   
1248:              return b;
1249:          }
1250:   
1251:          ////////////////////////////////////////////////////////////////////////////    
1252:          ////////////////////////////////////////////////////////////////////////////    
1253:   
1254:          /// <summary>
1255:          ///
1256:          /// </summary>
1257:          public static List<string> ActiveServiceRequestServiceNumbersWithinDomainList(string domain)
1258:          {
1259:              List<string> list;
1260:   
1261:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1262:              {
1263:                  list = (from srs in db.ServiceRequestServices
1264:                          where srs.ServiceType == 1 && srs.Service.StartsWith(domain) && srs.Provisioned == true
1265:                          select srs.Service).ToList();
1266:              }
1267:   
1268:              return list;
1269:          }
1270:   
1271:          ////////////////////////////////////////////////////////////////////////////    
1272:   
1273:          /// <summary>
1274:          ///
1275:          /// </summary>
1276:          public static List<string> ActiveServiceNumbersWithinDomainList(string domain)
1277:          {
1278:              int serviceType;
1279:              List<string> list;
1280:   
1281:              serviceType = Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService;
1282:   
1283:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
1284:              {
1285:                  list = (from s in db.Service2s
1286:                          where s.ServiceType == Ia.Ngn.Cl.Model.Business.Service.ServiceType.GponService && s.ServiceType == serviceType && s.Service.StartsWith(domain)
1287:                          select s.Service).ToList();
1288:              }
1289:   
1290:              return list;
1291:          }
1292:   
1293:          ////////////////////////////////////////////////////////////////////////////
1294:   
1295:          /// <summary>
1296:          ///
1297:          /// </summary>
1298:          public static List<string> InactiveServiceRequestServiceNumbersWithinDomainList(string domain)
1299:          {
1300:              List<int> possibleServiceList;
1301:              List<string> serviceList, inactiveServiceList;
1302:   
1303:              serviceList = ActiveServiceRequestServiceNumbersWithinDomainList(domain);
1304:   
1305:              possibleServiceList = Ia.Ngn.Cl.Model.Data.Service.AllPossibleServiceNumberListWithinDomain(int.Parse(domain));
1306:   
1307:              inactiveServiceList = new List<string>(possibleServiceList.Count - serviceList.Count);
1308:   
1309:              // below: extract numbers within possible but not in serviceList
1310:              foreach (int i in possibleServiceList)
1311:              {
1312:                  if (!serviceList.Contains(i.ToString())) inactiveServiceList.Add(i.ToString());
1313:              }
1314:   
1315:              return inactiveServiceList;
1316:          }
1317:   
1318:          ////////////////////////////////////////////////////////////////////////////
1319:   
1320:          /// <summary>
1321:          ///
1322:          /// </summary>
1323:          public static List<string> InactiveServiceNumbersWithinDomainList(string domain)
1324:          {
1325:              List<int> possibleServiceList;
1326:              List<string> serviceList, inactiveServiceList;
1327:   
1328:              serviceList = ActiveServiceNumbersWithinDomainList(domain);
1329:   
1330:              possibleServiceList = Ia.Ngn.Cl.Model.Data.Service.AllPossibleServiceNumberListWithinDomain(int.Parse(domain));
1331:   
1332:              inactiveServiceList = new List<string>(possibleServiceList.Count - serviceList.Count);
1333:   
1334:              // below: extract numbers within possible but not in serviceList
1335:              foreach (int i in possibleServiceList)
1336:              {
1337:                  if (!serviceList.Contains(i.ToString())) inactiveServiceList.Add(i.ToString());
1338:              }
1339:   
1340:              return inactiveServiceList;
1341:          }
1342:   
1343:          ////////////////////////////////////////////////////////////////////////////
1344:   
1345:          /// <summary>
1346:          ///
1347:          /// </summary>
1348:          public static List<string> ServicePbxList
1349:          {
1350:              get
1351:              {
1352:                  List<string> list, nokiaPbxList, huaweiPbxList;
1353:   
1354:                  nokiaPbxList = Ia.Ngn.Cl.Model.Data.Nokia.SubParty.ServicePbxList();
1355:                  huaweiPbxList = Ia.Ngn.Cl.Model.Data.Huawei.HuSbr.ServicePbxList();
1356:   
1357:                  list = nokiaPbxList.Concat(huaweiPbxList).ToList();
1358:   
1359:                  return list;
1360:              }
1361:          }
1362:   
1363:          ////////////////////////////////////////////////////////////////////////////
1364:          ////////////////////////////////////////////////////////////////////////////
1365:   
1366:          /// <summary>
1367:          ///
1368:          /// </summary>
1369:          public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt> AllowedToBeProvisionedOltList
1370:          {
1371:              get
1372:              {
1373:                  return Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.GreenFieldOltList.Union(AllowedToBeMigratedOltList).ToList();
1374:              }
1375:          }
1376:   
1377:          ////////////////////////////////////////////////////////////////////////////
1378:   
1379:          /// <summary>
1380:          ///
1381:          /// </summary>
1382:          public static List<int> AllowedToBeProvisionedOltIdList
1383:          {
1384:              get
1385:              {
1386:                  return Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.GreenFieldOltIdList.Union(AllowedToBeMigratedOltIdList).ToList();
1387:              }
1388:          }
1389:   
1390:          ////////////////////////////////////////////////////////////////////////////
1391:   
1392:          /// <summary>
1393:          ///
1394:          /// </summary>
1395:          public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt> AllowedToBeProvisionedSipOltList
1396:          {
1397:              get
1398:              {
1399:                  return Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.GreenFieldSipOltList.Union(AllowedToBeMigratedSipOltList).ToList();
1400:              }
1401:          }
1402:   
1403:          ////////////////////////////////////////////////////////////////////////////
1404:   
1405:          /// <summary>
1406:          ///
1407:          /// </summary>
1408:          public static List<int> AllowedToBeProvisionedSipOltIdList
1409:          {
1410:              get
1411:              {
1412:                  return Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.GreenFieldSipOltIdList.Union(AllowedToBeMigratedSipOltIdList).ToList();
1413:              }
1414:          }
1415:   
1416:          ////////////////////////////////////////////////////////////////////////////
1417:          ////////////////////////////////////////////////////////////////////////////
1418:   
1419:          /// <summary>
1420:          ///
1421:          /// </summary>
1422:          public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt> AllowedToBeMigratedOltList
1423:          {
1424:              get
1425:              {
1426:                  return (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList
1427:                          where Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Symbol) || Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => o.PonGroupList.Any(pg => pg.Symbol == u))
1428:                          select o).ToList();
1429:              }
1430:          }
1431:   
1432:          ////////////////////////////////////////////////////////////////////////////
1433:   
1434:          /// <summary>
1435:          ///
1436:          /// </summary>
1437:          public static List<int> AllowedToBeMigratedOltIdList
1438:          {
1439:              get
1440:              {
1441:                  return (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList
1442:                          where Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Symbol) || Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => o.PonGroupList.Any(pg => pg.Symbol == u))
1443:                          select o.Id).ToList();
1444:              }
1445:          }
1446:   
1447:          ////////////////////////////////////////////////////////////////////////////
1448:   
1449:          /// <summary>
1450:          ///
1451:          /// </summary>
1452:          public static List<Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Olt> AllowedToBeMigratedSipOltList
1453:          {
1454:              get
1455:              {
1456:                  return (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList
1457:                          where Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Symbol) || Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => o.PonGroupList.Any(pg => pg.Symbol == u))
1458:                          select o).ToList();
1459:              }
1460:          }
1461:   
1462:          ////////////////////////////////////////////////////////////////////////////
1463:   
1464:          /// <summary>
1465:          ///
1466:          /// </summary>
1467:          public static List<int> AllowedToBeMigratedSipOltIdList
1468:          {
1469:              get
1470:              {
1471:                  return (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OltList
1472:                          where Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Symbol) || Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => o.PonGroupList.Any(pg => pg.Symbol == u))
1473:                          select o.Id).ToList();
1474:              }
1475:          }
1476:   
1477:          ////////////////////////////////////////////////////////////////////////////
1478:   
1479:          /// <summary>
1480:          ///
1481:          /// </summary>
1482:          public static Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> AllowedToBeMigratedAccessIdToOntDictionary
1483:          {
1484:              get
1485:              {
1486:                  Dictionary<string, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont> dictionary;
1487:   
1488:                  var list = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList
1489:                              where Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Pon.PonGroup.Olt.Symbol) || Ia.Ngn.Cl.Model.Business.Service.AllowedToBeMigratedOltSymbolList.Any(u => u == o.Pon.PonGroup.Symbol)
1490:                              select o).ToList();
1491:   
1492:                  dictionary = list.ToDictionary(u => u.Access.Id, u => u);
1493:   
1494:                  return dictionary;
1495:              }
1496:          }
1497:   
1498:          ////////////////////////////////////////////////////////////////////////////
1499:          ////////////////////////////////////////////////////////////////////////////
1500:   
1501:          /// <summary>
1502:          ///
1503:          /// </summary>
1504:          public static Ia.Ngn.Cl.Model.Business.Service.ServiceType ServiceType(int typeId)
1505:          {
1506:              return (from s in Ia.Ngn.Cl.Model.Data.Service.ServiceTypeList where s.Id == typeId select s).SingleOrDefault();
1507:          }
1508:   
1509:          ////////////////////////////////////////////////////////////////////////////
1510:   
1511:          /// <summary>
1512:          ///
1513:          /// </summary>
1514:          public static string ServiceTypeNameFromId(int id)
1515:          {
1516:              return (from s in Ia.Ngn.Cl.Model.Data.Service.ServiceTypeList where s.Id == id select s.Name).SingleOrDefault();
1517:          }
1518:   
1519:          ////////////////////////////////////////////////////////////////////////////
1520:   
1521:          /// <summary>
1522:          ///
1523:          /// </summary>
1524:          public static List<Ia.Ngn.Cl.Model.Business.Service.ServiceType> ServiceTypeList
1525:          {
1526:              get
1527:              {
1528:                  if (serviceTypeList == null || serviceTypeList.Count == 0)
1529:                  {
1530:                      serviceTypeList = new List<Ia.Ngn.Cl.Model.Business.Service.ServiceType>();
1531:   
1532:                      serviceTypeList = new List<Ia.Ngn.Cl.Model.Business.Service.ServiceType>
1533:                      {
1534:                          // do not change "Ngn" and "Pstn" values, they will effect class ServiceType values
1535:                          new Ia.Ngn.Cl.Model.Business.Service.ServiceType(1, "Ngn", "Fiber (فايبر)", "fiber-blue"),
1536:                          new Ia.Ngn.Cl.Model.Business.Service.ServiceType(2, "Pstn", "Copper (نحاس)", "copper-brown")
1537:                      };
1538:   
1539:                      /*
1540:  
1541:                      /// 0:IMSSIPUE(IMSSIPUSER): The subscriber is an IMS SIP-UE subscriber.
1542:                      /// 1:POTS(POTSUSER): The subscriber is a SIP subscriber connected to the SIPIAD of the AGCF.
1543:                      /// 4:G/U(GUUSER): The subscriber is a G/U subscriber.
1544:                      /// 5:CDMA(CDMAUSER): The subscriber is a CDMA subscriber.
1545:                      /// 6:PSTN(PSTNUSER): The subscriber is a PSTN subscriber.
1546:  
1547:                      <type id="0" name="?"/>
1548:                      <type id="1" name="DN" Idlike="25212254:1:965"/>
1549:                      <type id="2" name="HSI" Idlike="SLA.82.13.1.2:2:965 SLA.PON.ONT.CARD.PORT"/>
1550:                      <type id="3" name="CDMA"/>
1551:                      <type id="4" name="G/U"/>
1552:                      <type id="5" name="POTS"/>
1553:                      <type id="6" name="PSTN"/>
1554:                       */
1555:                  }
1556:   
1557:                  return serviceTypeList.ToList();
1558:              }
1559:          }
1560:   
1561:          ////////////////////////////////////////////////////////////////////////////
1562:   
1563:          /// <summary>
1564:          /// 
1565:          /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
1566:          /// 
1567:          /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
1568:          /// 2. Add "using System.Reflection".
1569:          /// 3. See sample below.
1570:          /// 
1571:          /// </summary>
1572:   
1573:          private static XDocument XDocument
1574:          {
1575:              get
1576:              {
1577:                  if (xDocument == null)
1578:                  {
1579:                      Assembly _assembly;
1580:                      StreamReader streamReader;
1581:   
1582:                      _assembly = Assembly.GetExecutingAssembly();
1583:                      streamReader = new StreamReader(_assembly.GetManifestResourceStream("Ia.Ngn.Cl.model.data.service.xml"));
1584:   
1585:                      try
1586:                      {
1587:                          if (streamReader.Peek() != -1)
1588:                          {
1589:                              xDocument = System.Xml.Linq.XDocument.Load(streamReader);
1590:                          }
1591:                      }
1592:                      catch (Exception)
1593:                      {
1594:                      }
1595:                      finally
1596:                      {
1597:                      }
1598:                  }
1599:   
1600:                  return xDocument;
1601:              }
1602:          }
1603:   
1604:          ////////////////////////////////////////////////////////////////////////////    
1605:          ////////////////////////////////////////////////////////////////////////////
1606:      }
1607:   
1608:      ////////////////////////////////////////////////////////////////////////////
1609:      ////////////////////////////////////////////////////////////////////////////   
1610:  }