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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Default

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

Default general support class of Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Configuration;
   4:  using System.Data;
   5:  using System.Linq;
   6:  using System.Text.RegularExpressions;
   7:  using System.Web;
   8:   
   9:  namespace Ia.Ngn.Cl.Model.Business
  10:  {
  11:      ////////////////////////////////////////////////////////////////////////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Default general support class of Next Generation Network'a (NGN's) business model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
  19:      ///
  20:      /// 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
  21:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  22:      ///
  23:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  24:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  25:      /// 
  26:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  27:      /// 
  28:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  29:      /// </remarks> 
  30:      public partial class Default
  31:      {
  32:          private const int fixedLengthOfOntId = 16;
  33:          private static int visitorCounter;
  34:   
  35:          private static readonly object objectLock = new object();
  36:   
  37:          ////////////////////////////////////////////////////////////////////////////
  38:   
  39:          /// <summary>
  40:          ///
  41:          /// </summary>
  42:          public static int FixedLengthOfOntId { get { return fixedLengthOfOntId; } }
  43:   
  44:          ////////////////////////////////////////////////////////////////////////////
  45:   
  46:          /// <summary>
  47:          ///
  48:          /// </summary>
  49:          public const int PortUndefinedOrInvalidOrUnknown = -1;
  50:   
  51:          ////////////////////////////////////////////////////////////////////////////
  52:   
  53:          /// <summary>
  54:          ///
  55:          /// </summary>
  56:          public enum ProjectState { Running = 1, PartiallyRunning, Idle, Down, Unknown };
  57:   
  58:          ////////////////////////////////////////////////////////////////////////////
  59:   
  60:          /// <summary>
  61:          ///
  62:          /// </summary>
  63:          //public enum Process { Create = 1, Read, Update, Delete };
  64:   
  65:          ////////////////////////////////////////////////////////////////////////////
  66:   
  67:          /// <summary>
  68:          ///
  69:          /// </summary>
  70:          public enum Protocol { DefaultAsInNdd = 1, Sip, H248 };
  71:   
  72:          ////////////////////////////////////////////////////////////////////////////
  73:   
  74:          /// <summary>
  75:          ///
  76:          /// </summary>
  77:          public enum SwitchRoute
  78:          {
  79:              NokiaIms = 1, HuaweiIms = 2, SiemensEwsdCopper = 3, EricssonAxeCopper = 4, Unknown = -1
  80:          };
  81:   
  82:          ////////////////////////////////////////////////////////////////////////////
  83:   
  84:          /// <summary>
  85:          ///
  86:          /// </summary>
  87:          public enum SchedulerInterval { Year, Month, Week, Day, Hour, Minute, Second }
  88:   
  89:          ////////////////////////////////////////////////////////////////////////////
  90:   
  91:          /// <summary>
  92:          ///
  93:          /// </summary>
  94:          public static List<string> H248ToSipUpdateOltSymbolList
  95:          {
  96:              get
  97:              {
  98:                  return new List<string> { }; // "SAA" }; // "SDQ", "SAA", "ADS" ,"LAB"
  99:              }
 100:          }
 101:   
 102:          ////////////////////////////////////////////////////////////////////////////
 103:   
 104:          /// <summary>
 105:          ///
 106:          /// </summary>
 107:          public static int VisitorCounter
 108:          {
 109:              get
 110:              {
 111:                  lock (objectLock)
 112:                  {
 113:                      if (visitorCounter == 0) visitorCounter = 100;
 114:   
 115:                      return visitorCounter++;
 116:                  }
 117:              }
 118:          }
 119:   
 120:          /*
 121:          ////////////////////////////////////////////////////////////////////////////
 122:  
 123:          /// <summary>
 124:          ///
 125:          /// </summary>
 126:          public static Ia.Ngn.Cl.Model.Business.Default.Process Translate(string processNameString)
 127:          {
 128:              Ia.Ngn.Cl.Model.Business.Default.Process process;
 129:  
 130:              switch (processNameString)
 131:              {
 132:                  case "Create": process = Ia.Ngn.Cl.Model.Business.Default.Process.Create; break;
 133:                  case "Read": process = Ia.Ngn.Cl.Model.Business.Default.Process.Read; break;
 134:                  case "Update": process = Ia.Ngn.Cl.Model.Business.Default.Process.Update; break;
 135:                  case "Delete": process = Ia.Ngn.Cl.Model.Business.Default.Process.Delete; break;
 136:                  default: process = Ia.Ngn.Cl.Model.Business.Default.Process.Read; break;
 137:              }
 138:  
 139:              return process;
 140:          }
 141:          */
 142:   
 143:          ////////////////////////////////////////////////////////////////////////////
 144:   
 145:          /// <summary>
 146:          /// Flag to indicate of the system should be running
 147:          /// </summary>
 148:          public static bool AllowSystemToRun
 149:          {
 150:              get
 151:              {
 152:                  bool b;
 153:                  DateTime dateTime;
 154:   
 155:                  dateTime = DateTime.UtcNow.AddHours(3);
 156:   
 157:                  // below: I decided to keep the system always running pending a possible contract
 158:                  b = true; // dateTime.Year == 2019 && dateTime.Month <= 10;
 159:   
 160:                  return b;
 161:              }
 162:          }
 163:   
 164:          ////////////////////////////////////////////////////////////////////////////
 165:   
 166:          /// <summary>
 167:          ///
 168:          /// </summary>
 169:          public static string OntId(string ponId, int ontNumber)
 170:          {
 171:              string id;
 172:   
 173:              id = ponId + ontNumber.ToString().PadLeft(2, '0');
 174:   
 175:              if (id.Length != fixedLengthOfOntId)
 176:              {
 177:                  throw new ArgumentOutOfRangeException(@"OntId(): Id length is not " + fixedLengthOfOntId);
 178:              }
 179:   
 180:              return id;
 181:          }
 182:   
 183:          ////////////////////////////////////////////////////////////////////////////
 184:   
 185:          /// <summary>
 186:          ///
 187:          /// </summary>
 188:          public static string ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value)
 189:          {
 190:              bool isValid;
 191:              int oltId, ponNumber, ontNumber;
 192:              string accessName;
 193:              Dictionary<int, string> typeDictionary;
 194:   
 195:              typeDictionary = new Dictionary<int, string>(1);
 196:              typeDictionary.Add(1, value);
 197:   
 198:              isValid = ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
 199:   
 200:              if (isValid) accessName = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Pon.PonGroup.Olt.Id == oltId && o.Pon.Number == ponNumber && o.Number == ontNumber select o.Access.Name).SingleOrDefault();
 201:              else accessName = string.Empty;
 202:   
 203:              return accessName;
 204:          }
 205:   
 206:          ////////////////////////////////////////////////////////////////////////////
 207:   
 208:          /// <summary>
 209:          ///
 210:          /// </summary>
 211:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddOntFromHuaweiEmsAccessNameFormat(string mduName)
 212:          {
 213:              string accessName, s;
 214:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
 215:   
 216:              s = Ia.Ngn.Cl.Model.Business.Huawei.Ems.HuaweiAccessNameFormatFromInaccurateHuaweiFileAndEmsNameFormat(mduName);
 217:   
 218:              accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(s);
 219:   
 220:              ont = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
 221:   
 222:              return ont;
 223:          }
 224:   
 225:          ////////////////////////////////////////////////////////////////////////////
 226:   
 227:          /// <summary>
 228:          ///
 229:          /// </summary>
 230:          public static string ExtractPonNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value)
 231:          {
 232:              bool isValid;
 233:              int oltId, ponNumber, ontNumber;
 234:              string ponName;
 235:              Dictionary<int, string> typeDictionary;
 236:   
 237:              // below: we will replace ' ' and '/' with '.' to avoid errors
 238:              value = value.Replace(" ", ".");
 239:              value = value.Replace("/", ".");
 240:   
 241:              typeDictionary = new Dictionary<int, string>(1);
 242:              typeDictionary.Add(1, value + ".1"); // to mimic a WWW.D.1 format
 243:   
 244:              isValid = ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
 245:   
 246:              if (isValid) ponName = (from p in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PonList where p.PonGroup.Olt.Id == oltId && p.Number == ponNumber select p.Name).SingleOrDefault();
 247:              else ponName = string.Empty;
 248:   
 249:              return ponName;
 250:          }
 251:   
 252:          ////////////////////////////////////////////////////////////////////////////
 253:   
 254:          /// <summary>
 255:          ///
 256:          /// </summary>
 257:          public static string StandardizeAccessNameInLegalFormatFromValue(string value)
 258:          {
 259:              string accessName;
 260:              Dictionary<int, string> typeDictionary;
 261:   
 262:              typeDictionary = new Dictionary<int, string>(1);
 263:              typeDictionary.Add(1, value);
 264:   
 265:              accessName = ExtractAccessNameInLegalFormatFromDictionaryValueList(typeDictionary);
 266:   
 267:              return accessName;
 268:          }
 269:   
 270:          ////////////////////////////////////////////////////////////////////////////
 271:   
 272:          /// <summary>
 273:          ///
 274:          /// </summary>
 275:          public static bool ExtractOntNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value, out int oltId, out int ponNumber, out int ontNumber)
 276:          {
 277:              Dictionary<int, string> typeDictionary;
 278:   
 279:              typeDictionary = new Dictionary<int, string>(1);
 280:              typeDictionary.Add(1, value);
 281:   
 282:              return ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
 283:          }
 284:   
 285:          ////////////////////////////////////////////////////////////////////////////
 286:   
 287:          /// <summary>
 288:          ///
 289:          /// </summary>
 290:          public static bool ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(Dictionary<int, string> typeDictionary, out int oltId, out int ponNumber, out int ontNumber)
 291:          {
 292:              bool b, isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt;
 293:              int p, o;
 294:              string p1, p2, p3, p4, p5, p45, p55, symbol;
 295:              Match match;
 296:   
 297:              b = isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 298:              oltId = ponNumber = ontNumber = 0;
 299:   
 300:              p1 = (typeDictionary.ContainsKey(1)) ? typeDictionary[1] : "";
 301:              p2 = (typeDictionary.ContainsKey(2)) ? typeDictionary[2] : "";
 302:              p3 = (typeDictionary.ContainsKey(3)) ? typeDictionary[3] : "";
 303:              p4 = (typeDictionary.ContainsKey(4)) ? typeDictionary[4] : "";
 304:              p5 = (typeDictionary.ContainsKey(5)) ? typeDictionary[5] : "";
 305:              p45 = (typeDictionary.ContainsKey(45)) ? typeDictionary[45] : "";
 306:              p55 = (typeDictionary.ContainsKey(55)) ? typeDictionary[55] : "";
 307:   
 308:              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p2, out match);
 309:   
 310:              if (!b)
 311:              {
 312:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p1, out match);
 313:   
 314:                  if (!b)
 315:                  {
 316:                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p55, out match);
 317:   
 318:                      if (!b)
 319:                      {
 320:                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p2, out match);
 321:   
 322:                          if (!b)
 323:                          {
 324:                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p45, out match);
 325:   
 326:                              if (!b)
 327:                              {
 328:                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p2, p45, out match);
 329:   
 330:                                  if (!b)
 331:                                  {
 332:                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p4, out match);
 333:   
 334:                                      if (!b)
 335:                                      {
 336:                                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p4, out match);
 337:   
 338:                                          if (!b)
 339:                                          {
 340:                                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p5, out match);
 341:   
 342:                                              if (!b)
 343:                                              {
 344:                                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p3, out match);
 345:   
 346:                                                  if (!b)
 347:                                                  {
 348:                                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p3, out match);
 349:                                                  }
 350:                                              }
 351:                                          }
 352:                                      }
 353:                                  }
 354:                              }
 355:                          }
 356:                      }
 357:                  }
 358:              }
 359:   
 360:              if (b)
 361:              {
 362:                  if (match.Success)
 363:                  {
 364:                      symbol = match.Groups[1].Captures[0].Value;
 365:                      ponNumber = p = int.Parse(match.Groups[2].Captures[0].Value);
 366:                      ontNumber = o = int.Parse(match.Groups[3].Captures[0].Value);
 367:   
 368:                      oltId = (from _o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where _o.Pon.PonGroup.Symbol == symbol && _o.Pon.Number == p && _o.Number == o select _o.Pon.PonGroup.Olt.Id).SingleOrDefault();
 369:   
 370:                      if (oltId != 0)
 371:                      {
 372:                          isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = true;
 373:                      }
 374:                      else
 375:                      {
 376:                          oltId = ponNumber = ontNumber = 0;
 377:                          isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 378:                      }
 379:                  }
 380:                  else
 381:                  {
 382:                      oltId = ponNumber = ontNumber = 0;
 383:                      isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 384:                  }
 385:              }
 386:              else isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 387:   
 388:              return isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt;
 389:          }
 390:   
 391:          ////////////////////////////////////////////////////////////////////////////
 392:   
 393:          /// <summary>
 394:          ///
 395:          /// </summary>
 396:          public static string ExtractAccessNameInLegalFormatFromDictionaryValueList(Dictionary<int, string> typeDictionary)
 397:          {
 398:              bool b;
 399:              int ponNumber, ontNumber;
 400:              string p1, p2, p3, p4, p5, p45, symbol, accessName;
 401:              Match match;
 402:   
 403:              p1 = (typeDictionary.ContainsKey(1)) ? typeDictionary[1] : "";
 404:              p2 = (typeDictionary.ContainsKey(2)) ? typeDictionary[2] : "";
 405:              p3 = (typeDictionary.ContainsKey(3)) ? typeDictionary[3] : "";
 406:              p4 = (typeDictionary.ContainsKey(4)) ? typeDictionary[4] : "";
 407:              p5 = (typeDictionary.ContainsKey(5)) ? typeDictionary[5] : "";
 408:              p45 = (typeDictionary.ContainsKey(45)) ? typeDictionary[45] : "";
 409:   
 410:              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p2, out match);
 411:   
 412:              if (!b)
 413:              {
 414:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p1, out match);
 415:   
 416:                  if (!b)
 417:                  {
 418:                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p2, out match);
 419:   
 420:                      if (!b)
 421:                      {
 422:                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p45, out match);
 423:   
 424:                          if (!b)
 425:                          {
 426:                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p2, p45, out match);
 427:   
 428:                              if (!b)
 429:                              {
 430:                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p4, out match);
 431:   
 432:                                  if (!b)
 433:                                  {
 434:                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p4, out match);
 435:   
 436:                                      if (!b)
 437:                                      {
 438:                                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p5, out match);
 439:   
 440:                                          if (!b)
 441:                                          {
 442:                                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p3, out match);
 443:   
 444:                                              if (!b)
 445:                                              {
 446:                                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p3, out match);
 447:                                              }
 448:                                          }
 449:                                      }
 450:                                  }
 451:                              }
 452:                          }
 453:                      }
 454:                  }
 455:              }
 456:   
 457:              if (b)
 458:              {
 459:                  if (match.Success)
 460:                  {
 461:                      symbol = match.Groups[1].Captures[0].Value;
 462:   
 463:                      ponNumber = int.Parse(match.Groups[2].Captures[0].Value);
 464:                      ontNumber = int.Parse(match.Groups[3].Captures[0].Value);
 465:   
 466:                      accessName = symbol.ToUpper() + "." + ponNumber + "." + ontNumber;
 467:                  }
 468:                  else
 469:                  {
 470:                      accessName = string.Empty;
 471:                  }
 472:              }
 473:              else
 474:              {
 475:                  accessName = string.Empty;
 476:              }
 477:   
 478:              return accessName;
 479:          }
 480:   
 481:          ////////////////////////////////////////////////////////////////////////////
 482:   
 483:          /// <summary>
 484:          ///
 485:          /// </summary>
 486:          private static bool ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(string s, out Match match)
 487:          {
 488:              // below: this checks if string conferms
 489:              bool b;
 490:              const string pattern = @"([a-zA-Z]{3})\.(\d{1,4})\.(\d{1,3})";
 491:              Regex regex;
 492:   
 493:              match = null;
 494:              regex = new Regex(pattern);
 495:   
 496:              if (!string.IsNullOrEmpty(s))
 497:              {
 498:                  s = s.ToUpper();
 499:   
 500:                  if (!regex.IsMatch(s))
 501:                  {
 502:                      s = s.Replace("-", ".");
 503:                      s = s.Replace("/", ".");
 504:                      s = s.Replace(" ", ".");
 505:   
 506:                      if (!regex.IsMatch(s))
 507:                      {
 508:                          s = s.Replace(". ", ".");
 509:   
 510:                          if (!regex.IsMatch(s))
 511:                          {
 512:                              s = s.Replace(" .", ".");
 513:   
 514:                              if (!regex.IsMatch(s))
 515:                              {
 516:                                  s = s.Replace(".00", ".");
 517:                                  s = s.Replace(".0", ".");
 518:   
 519:                                  if (!regex.IsMatch(s))
 520:                                  {
 521:                                      s = s.Replace("...", ".");
 522:                                      s = s.Replace("..", ".");
 523:   
 524:                                      if (!regex.IsMatch(s))
 525:                                      {
 526:                                          s = Regex.Replace(s, @"\.$", @"");
 527:   
 528:                                          if (!regex.IsMatch(s))
 529:                                          {
 530:                                              s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{1,4})\.(\d{1,3})", @"$1.$2.$3");
 531:   
 532:                                              if (!regex.IsMatch(s))
 533:                                              {
 534:                                                  s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{3})(\d{3})", @"$1.$2.$3");
 535:   
 536:                                                  if (!regex.IsMatch(s))
 537:                                                  {
 538:                                                      s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{4})(\d{3})", @"$1.$2.$3");
 539:   
 540:                                                      if (!regex.IsMatch(s))
 541:                                                      {
 542:                                                          s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{3})(\d{3})", @"$1.$2.$3");
 543:   
 544:                                                          if (!regex.IsMatch(s))
 545:                                                          {
 546:                                                              s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{4})(\d{3})", @"$1.$2.$3");
 547:   
 548:                                                              if (!regex.IsMatch(s))
 549:                                                              {
 550:                                                                  s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{1,4}) (\d{1,3})", @"$1.$2.$3");
 551:   
 552:                                                                  if (!regex.IsMatch(s))
 553:                                                                  {
 554:                                                                      s = Regex.Replace(s, @"([a-zA-Z]{3}) (\d{1,4}) (\d{1,3})", @"$1.$2.$3");
 555:                                                                  }
 556:                                                              }
 557:                                                          }
 558:                                                      }
 559:                                                  }
 560:                                              }
 561:                                          }
 562:                                      }
 563:                                  }
 564:                              }
 565:                          }
 566:                      }
 567:                  }
 568:   
 569:                  match = Regex.Match(s, pattern);
 570:   
 571:                  if (match.Success) b = true;
 572:                  else b = false;
 573:              }
 574:              else b = false;
 575:   
 576:              return b;
 577:          }
 578:   
 579:          ////////////////////////////////////////////////////////////////////////////
 580:   
 581:          /// <summary>
 582:          ///
 583:          /// </summary>
 584:          private static bool ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(string s1, string s2, out Match match)
 585:          {
 586:              // below: this checks if string conferms
 587:              bool b;
 588:              match = null;
 589:   
 590:              s1 = s1.Replace("-", ".");
 591:              s1 = s1.Replace("/", ".");
 592:              s1 = s1.Replace(" /", "/");
 593:              s1 = s1.ToUpper();
 594:              s1 = s1.Replace("ZHA", "ZAH");
 595:              s1 = s1.Replace("JAB", "JBA");
 596:   
 597:              s1 = Regex.Replace(s1, @"([a-zA-Z]{3})(\d{1,4})", @"$1.$2");
 598:   
 599:              if (Regex.IsMatch(s1, @"[a-zA-Z]{3}\.\d{1,4}") && Regex.IsMatch(s2, @"\d{1,3}"))
 600:              {
 601:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(s1 + @"." + s2, out match);
 602:              }
 603:              else b = false;
 604:   
 605:              return b;
 606:          }
 607:   
 608:          ////////////////////////////////////////////////////////////////////////////
 609:   
 610:          /// <summary>
 611:          /// ASP.NET State Management
 612:          /// below: remove later to default.cs or state.cs
 613:          /// <remarks>https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx</remarks>
 614:          /// </summary>
 615:          public static bool Application(string name, int lifeInMinutes, object o)
 616:          {
 617:              bool valueStored;
 618:              DateTime expiration;
 619:   
 620:              if (name != string.Empty)
 621:              {
 622:                  expiration = DateTime.UtcNow.AddMinutes(3 * 60 + lifeInMinutes);
 623:   
 624:                  HttpContext.Current.Application[name + "|" + lifeInMinutes.ToString()] = o;
 625:   
 626:                  valueStored = true;
 627:              }
 628:              else valueStored = false;
 629:   
 630:              return valueStored;
 631:          }
 632:   
 633:          ////////////////////////////////////////////////////////////////////////////
 634:   
 635:          /// <summary>
 636:          /// 
 637:          /// </summary>
 638:          public static object Application(string name)
 639:          {
 640:              string expirationString;
 641:              DateTime expiration;
 642:              object o;
 643:   
 644:              o = null;
 645:   
 646:              // below: loop through keys to find the one that starts with name
 647:              foreach (string s in HttpContext.Current.Application.AllKeys)
 648:              {
 649:                  if (s.Contains(name + "|"))
 650:                  {
 651:                      expirationString = Ia.Cl.Model.Default.Match(s, @"\|(.+)");
 652:   
 653:                      expiration = DateTime.Parse(expirationString);
 654:   
 655:                      if (expiration < DateTime.UtcNow.AddHours(3))
 656:                      {
 657:                          // below: did not expire
 658:   
 659:                          o = HttpContext.Current.Application[s];
 660:                      }
 661:                      else o = null;
 662:                  }
 663:              }
 664:   
 665:              return o;
 666:          }
 667:   
 668:          ////////////////////////////////////////////////////////////////////////////
 669:   
 670:          /// <summary>
 671:          /// RecordState holds the current state of the record according to user and system interactions with it. It could be used as an
 672:          /// indicator to define the current state of the record and how it should be handle in state monitoring execution cycles.
 673:          /// </summary>
 674:          public enum RecordState
 675:          {
 676:              Undefined = 0, Synchronized = 10, Synchronize = 20, Modified = 30, Updated = 40, Etc = 50
 677:          };
 678:   
 679:          ////////////////////////////////////////////////////////////////////////////
 680:   
 681:          /// <summary>
 682:          ///
 683:          /// </summary>
 684:          public Default() { }
 685:   
 686:          ////////////////////////////////////////////////////////////////////////////
 687:   
 688:          /// <summary>
 689:          ///
 690:          /// </summary>
 691:          public static string CorrectCustomerAddress(string addressString)
 692:          {
 693:              addressString = addressString.Trim();
 694:   
 695:              //line = Ia.Cl.Model.Language.ConvertSingleLatinDigitsToArabicWordEquivalents(line);
 696:              //line = Ia.Cl.Model.Language.RemoveNonArabicAndNonArabicExtendedLettersAndDigits(line);
 697:              //line = Ia.Cl.Model.Language.CorrectArabicNameNounStringFormat(line);
 698:              // to do line = Ia.Cl.Model.Language.RemoveTitlesFromNames(line);
 699:              // to do line = Ia.Cl.Model.Language.CorrectArabicNameNounFormat(line);
 700:              // to do line = Ia.Cl.Model.Language.CorrectArabicNonNameNounStringFormat(line);
 701:              //line = Ia.Cl.Model.Language.RemoveWrongSpaceBetweenArabicDefinitArticleAndItsWord(line);
 702:              //line = Regex.Replace(line, @"\s+", @" ");
 703:   
 704:              // order is important
 705:   
 706:              // BYN
 707:              addressString = addressString.Replace(" جادة الفتره 1-20/2009 المرحله الثانيه", "");
 708:              addressString = addressString.Replace(" جادة جادة الفتره 23/11-20/12/2009 1-20/12/2009", "");
 709:              addressString = addressString.Replace(" جادة الفتره 23/11-20/12/2009", "");
 710:              addressString = addressString.Replace(" جادة الفتره  23/11-20/12/2009", "");
 711:              addressString = addressString.Replace(" جادة الفتره /23/11-20/12/2009", "");
 712:              addressString = addressString.Replace(" شارع المرحله الثانيه /قاعه التحرير", " شارع قاعة التحرير");
 713:              addressString = addressString.Replace(" جادة الفتره 1-20/12/2009", "");
 714:              addressString = addressString.Replace(" جادة الفتره/1-20/12/2009", "");
 715:              addressString = addressString.Replace(" جادة الفتره -1-20/12/2009", "");
 716:              addressString = addressString.Replace(" جادة الفتره/1-20/12/2009", "");
 717:              addressString = addressString.Replace(" جادة الفترة1-20-12-2009", "");
 718:              addressString = addressString.Replace(" جادة الفترهة 1-20/12/2009", "");
 719:              addressString = addressString.Replace(" جادة 1-20/12/2009", "");
 720:              addressString = addressString.Replace(" جادة الفتره1-20-12-2009", "");
 721:              addressString = addressString.Replace(" جادة الفتره 1-200/12/2009", "");
 722:              addressString = addressString.Replace(" جادة الفتره-1-20/12/2009", "");
 723:              addressString = addressString.Replace(" جادة الفتره 1-20/2009", "");
 724:              addressString = addressString.Replace("قطعة قصر بيان", "قطعة 2");
 725:              addressString = addressString.Replace("حولى مشرف,, منزل قصر بيان", "حولى بيان,قطعة 2, منزل قصر بيان");
 726:              addressString = addressString.Replace("حولى بيان,, منزل قصر بيان", "حولى بيان,قطعة 2, منزل قصر بيان");
 727:              addressString = addressString.Replace("منزل قصربيان", "منزل قصر بيان");
 728:              // end BYN
 729:   
 730:              // 
 731:              // 
 732:   
 733:              addressString = addressString.Replace("جادة جاده", "جادة ");
 734:              addressString = addressString.Replace("جادة جادة", "جادة ");
 735:              addressString = addressString.Replace("شارع الأول", "شارع 1");
 736:              addressString = addressString.Replace("شارع الاول", "شارع 1");
 737:              addressString = addressString.Replace("شارع الثانى", "شارع 2");
 738:              addressString = addressString.Replace("شارع الثاني", "شارع 2");
 739:              addressString = addressString.Replace("شارع الثالث", "شارع 3");
 740:              addressString = addressString.Replace("شارع الرابع", "شارع 4");
 741:              addressString = addressString.Replace("شارع الخامس", "شارع 5");
 742:              addressString = addressString.Replace("شارع السادس", "شارع 6");
 743:              addressString = addressString.Replace("شارع السابع", "شارع 7");
 744:              addressString = addressString.Replace("شارع الثامن", "شارع 8");
 745:              addressString = addressString.Replace("شارع التاسع", "شارع 9");
 746:   
 747:              addressString = addressString.Replace("شارع طريق ", "شارع ");
 748:              addressString = addressString.Replace(" جاده ", " جادة ");
 749:              addressString = addressString.Replace("_", " ");
 750:              addressString = addressString.Replace("***", "0");
 751:              addressString = addressString.Replace("**", "0");
 752:              addressString = addressString.Replace("*", "0");
 753:   
 754:              // SLA
 755:              addressString = addressString.Replace("شارع علي الجسار", "شارع 22");
 756:              addressString = addressString.Replace(@"شارع 26 / علي نقي النقي", "شارع 26");
 757:              addressString = addressString.Replace(@"شارع علي النقي", "شارع 26");
 758:              // end SLA
 759:   
 760:              addressString = addressString.Trim();
 761:   
 762:              return addressString;
 763:          }
 764:   
 765:          ////////////////////////////////////////////////////////////////////////////
 766:   
 767:          /// <summary>
 768:          ///
 769:          /// </summary>
 770:          public static string CorrectCustomerAddressMissingProvinceArea(string service, string addressString)
 771:          {
 772:              // correct some missing information in address lines based on service number
 773:   
 774:              if (service.StartsWith("2453") || service.StartsWith("2454")) addressString = "الجهراء سعد العبدالله" + addressString;
 775:              else if (service.StartsWith("2466")) addressString = "الفروانية القيروان" + addressString;
 776:              else if (service.StartsWith("2435") || service.StartsWith("2436")) addressString = "الفروانية عبدالله المبارك" + addressString;
 777:              else if (service.StartsWith("2363")) addressString = "الأحمدي فهد الأحمد" + addressString;
 778:              else if (service.StartsWith("2368")) addressString = "الأحمدي لآلئ الخيران" + addressString;
 779:   
 780:              return addressString;
 781:          }
 782:   
 783:          ////////////////////////////////////////////////////////////////////////////
 784:   
 785:          /// <summary>
 786:          ///
 787:          /// </summary>
 788:          public static string CorrectCustomerName(string line)
 789:          {
 790:              line = line.Trim();
 791:              //line = Ia.Cl.Model.Language.ConvertSingleLatinDigitsToArabicWordEquivalents(line);
 792:              line = Ia.Cl.Model.Language.RemoveNonNativeAndNonNativeExtendedLettersAndDigitsAccordingToLanguage("ar", line);
 793:              line = Ia.Cl.Model.Language.CorrectArabicNameNounStringFormat(line);
 794:              // to do line = Ia.Cl.Model.Language.RemoveTitlesFromNames(line);
 795:              // to do line = Ia.Cl.Model.Language.CorrectArabicNameNounFormat(line);
 796:              // to do line = Ia.Cl.Model.Language.CorrectArabicNonNameNounStringFormat(line);
 797:              line = Ia.Cl.Model.Language.RemoveWrongSpaceBetweenNativeDefinitArticleAndItsWord("ar", line);
 798:              line = Regex.Replace(line, @"\s+", @" ");
 799:              line = line.Trim();
 800:   
 801:              return line;
 802:          }
 803:   
 804:          ////////////////////////////////////////////////////////////////////////////
 805:   
 806:          /// <summary>
 807:          ///
 808:          /// </summary>
 809:          public static DataTable ReturnDataTableOfServiceAdministrativeStateOfANumberInOldNgnDatabase(long dn)
 810:          {
 811:              string sql;
 812:              DataTable dt;
 813:              Ia.Cl.Model.Db.SqlServer ngn;
 814:   
 815:              sql = @"SELECT sa.state, srs.active FROM ia_service_administrative AS sa LEFT OUTER JOIN ia_service_request_service AS srs ON srs.dn = sa.dn WHERE (sa.dn = " + dn + ")";
 816:              dt = null;
 817:   
 818:              try
 819:              {
 820:                  ngn = new Ia.Cl.Model.Db.SqlServer(ConfigurationManager.ConnectionStrings["DefaultConnectionToNgn"].ConnectionString);
 821:   
 822:                  dt = ngn.Select(sql);
 823:              }
 824:              catch (Exception)
 825:              {
 826:              }
 827:   
 828:              return dt;
 829:          }
 830:   
 831:          ////////////////////////////////////////////////////////////////////////////
 832:   
 833:          /// <summary>
 834:          ///
 835:          /// </summary>
 836:          public static void UpdateServiceAdministrativeStateOfANumberInOldNgnDatabase(long dn, string state)
 837:          {
 838:              string sql;
 839:              Ia.Cl.Model.Db.SqlServer ngn;
 840:   
 841:              sql = @"UPDATE ia_service_administrative SET state = " + state + " WHERE dn = " + dn;
 842:   
 843:              try
 844:              {
 845:                  ngn = new Ia.Cl.Model.Db.SqlServer(ConfigurationManager.ConnectionStrings["DefaultConnectionToNgn"].ConnectionString);
 846:   
 847:                  ngn.Sql(sql);
 848:              }
 849:              catch (Exception)
 850:              {
 851:              }
 852:          }
 853:   
 854:          ////////////////////////////////////////////////////////////////////////////
 855:          ////////////////////////////////////////////////////////////////////////////
 856:   
 857:          /// <summary>
 858:          ///
 859:          /// </summary>
 860:          public static int ChangeOldSevenDigitNumbersToEightDigitFormat(int o)
 861:          {
 862:              // below: take an old 7 digit number and covert it to the new 8 digit number according to plan
 863:   
 864:              int n;
 865:   
 866:              // below: check if it is already an 8 digit number
 867:              if (o >= 10000000) n = o;
 868:   
 869:              // 2 (NGN):
 870:              else if (
 871:              (o >= 2000000 && o <= 2999999) ||
 872:              (o >= 3000000 && o <= 3999999) ||
 873:              (o >= 4100000 && o <= 4399999) ||
 874:              (o >= 4500000 && o <= 4999999) ||
 875:              (o >= 5000000 && o <= 5009999) ||
 876:              (o >= 5030000 && o <= 5049999) ||
 877:              (o >= 5200000 && o <= 5499999) ||
 878:              (o >= 5510000 && o <= 5539999) ||
 879:              (o >= 5600000 && o <= 5699999) ||
 880:              (o >= 5710000 && o <= 5779999)) { n = 20000000 + o; }
 881:   
 882:              //6 (Wataniya):
 883:              else if (
 884:              (o >= 5010000 && o <= 5029999) ||
 885:              (o >= 5050000 && o <= 5099999) ||
 886:              (o >= 5100000 && o <= 5199999) ||
 887:              (o >= 5500000 && o <= 5509999) ||
 888:              (o >= 5540000 && o <= 5599999) ||
 889:              (o >= 5700000 && o <= 5709999) ||
 890:              (o >= 5780000 && o <= 5799999) ||
 891:              (o >= 5800000 && o <= 5999999) ||
 892:              (o >= 6000000 && o <= 6999999) ||
 893:              (o >= 7000000 && o <= 7019999) ||
 894:              (o >= 7030000 && o <= 7099999) ||
 895:              (o >= 7700000 && o <= 7769999) ||
 896:              (o >= 7780000 && o <= 7799999)) { n = 60000000 + o; }
 897:   
 898:              //1 (NGN):
 899:              else if (o >= 800000 && o <= 899999) { n = 1000000 + o; }
 900:   
 901:              //9 (Zain):
 902:              else if (
 903:              (o >= 7020000 && o <= 7029999) ||
 904:              (o >= 7100000 && o <= 7699999) ||
 905:              (o >= 7800000 && o <= 7999999) ||
 906:              (o >= 9000000 && o <= 9999999) ||
 907:              (o >= 4400000 && o <= 4499999) ||
 908:              (o >= 4000000 && o <= 4099999)) { n = 90000000 + o; }
 909:   
 910:              else n = o;
 911:   
 912:              return n;
 913:   
 914:              /*
 915:  New numbering list
 916:  
 917:  Add digit,Old Numbers Ranges,Operator
 918:  ,From,To,
 919:  2,2-000000,2-999999,MOC
 920:  2,3-000000,3-999999,MOC
 921:  9,40-00000,40-99999,Zain
 922:  2,41-00000,43-99999,MOC
 923:  9,44-00000,44-99999,Zain
 924:  2,45-00000,49-99999,MOC
 925:  2,500-0000,500-9999,MOC
 926:  6,501-0000,502-9999,Wataniya
 927:  2,503-0000,504-9999,MOC
 928:  6,505-0000,509-9999,Wataniya
 929:  6,51-00000,51-99999,Wataniya
 930:  2,52-00000,54-99999,MOC
 931:  6,550-0000,550-9999,Wataniya
 932:  2,551-0000,553-9999,MOC
 933:  6,554-0000,559-9999,Wataniya
 934:  2,56-00000,56-99999,MOC
 935:  6,570-0000,570-9999,Wataniya
 936:  2,571-0000,577-9999,MOC
 937:  6,578-0000,579-9999,Wataniya
 938:  6,58-00000,59-99999,Wataniya
 939:  6,6-000000,6-999999,Wataniya
 940:  6,700-0000,701-9999,Wataniya
 941:  9,702-0000,702-9999,Zain
 942:  6,703-0000,709-9999,Wataniya
 943:  9,71-00000,76-99999,Zain
 944:  6,770-0000,776-9999,Wataniya
 945:  6,778-0000,779-9999,Wataniya
 946:  9,78-00000,79-99999,Zain
 947:  1,800-000,899-999,MOC
 948:  9,9-000000,9-999999,Zain
 949:  
 950:  
 951:  Example: the number 2123456 will become 2 2123456.
 952:  
 953:  Notice: Unchanged numbers:
 954:  •,The international numbers outside Kuwait do not change and need the prefix 00 followed by the country code. For example, for the United Kingdom, dial 00 44 1234567890.
 955:  •,The country code for Kuwait 965 stays the same (for international incoming calls).
 956:  •,The 3 digits numbers do not change (numbers from 100 to 179). For example, for the Inquiry Directory, dial 101.
 957:  •,The emergency number in Kuwait 777 does not change.
 958:               */
 959:          }
 960:   
 961:          ////////////////////////////////////////////////////////////////////////////
 962:          ////////////////////////////////////////////////////////////////////////////
 963:   
 964:          /// <summary>
 965:          /// 
 966:          /// </summary>
 967:          public static void DifferencesBetweenServiceRequestAndServiceRequestHistoryAndServiceRequestServiceData(out List<string> mismatchBetweenSrAndSrsList, out List<string> mismatchBetweenSrAndSrhList, out List<string> inSrhNotInSrList, out List<string> inSrNotInSrhList, out string serviceIdIssue, out int serviceRequestServiceListCount, out int serviceRequestNumberSerialComplementaryServiceDictionaryCount, out int serviceRequestHistoryNumberSerialComplementaryServiceDictionaryCount, out int matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionaryCount, out int matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionaryCount)
 968:          {
 969:              int number, serial, status, serviceId;
 970:              string service, serviceSerial;
 971:              Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService serviceSerialRequestService;
 972:              List<string> serviceSerialsToRemoveList;
 973:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 974:              List<Ia.Ngn.Cl.Model.ServiceRequestHistory> serviceRequestHistoryList;
 975:              List<Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> serviceRequestServiceList;
 976:              Dictionary<string, int> serviceToLastSerialDictionary;
 977:              Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> serviceRequestServiceNumberSerialComplementaryServiceDictionary, serviceRequestNumberSerialComplementaryServiceDictionary, serviceRequestHistoryNumberSerialComplementaryServiceDictionary, matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionary, matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionary;
 978:   
 979:              mismatchBetweenSrAndSrsList = new List<string>();
 980:              mismatchBetweenSrAndSrhList = new List<string>();
 981:              serviceSerialsToRemoveList = new List<string>();
 982:              inSrhNotInSrList = new List<string>();
 983:              inSrNotInSrhList = new List<string>();
 984:   
 985:              number = 0; // 24555994;// 25210209;// 24550208;
 986:   
 987:              if (number == 0)
 988:              {
 989:                  serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List();
 990:                  serviceRequestHistoryList = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List();
 991:                  serviceRequestServiceList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceSerialRequestServiceList();
 992:              }
 993:              else
 994:              {
 995:                  serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(number);
 996:                  serviceRequestHistoryList = Ia.Ngn.Cl.Model.Data.ServiceRequestHistory.List(number);
 997:                  serviceRequestServiceList = Ia.Ngn.Cl.Model.Data.ServiceRequestService.ServiceSerialRequestServiceList(number.ToString());
 998:              }
 999:   
1000:              serviceIdIssue = string.Empty;
1001:   
1002:              serviceRequestNumberSerialComplementaryServiceDictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService>(serviceRequestList.Count);
1003:   
1004:              serviceToLastSerialDictionary = new Dictionary<string, int>(serviceRequestList.Count + serviceRequestHistoryList.Count);
1005:   
1006:              // build service request service from service requests
1007:              //var list = serviceRequestList.OrderBy(p => p.RequestDateTime.Date).ThenBy(p => p.ServiceId == 38); // <service id="38" arabicName="مجموعة الخدمات" />
1008:              var list = serviceRequestList.OrderBy(p => p.RequestDateTime.Date).ThenBy(p => p.ServiceId == 38).ThenBy(p => p.Id); // <service id="38" arabicName="مجموعة الخدمات" />
1009:              //var list = serviceRequestHistoryList.OrderBy(p => p.ServiceDateTime).ThenBy(p => p.ServiceId == 38); // <service id="38" arabicName="مجموعة الخدمات" />
1010:              foreach (var serviceRequest in list)
1011:              {
1012:                  if (serviceRequest.ServiceCategoryId == 3)
1013:                  {
1014:                      // <category id="3" arabicName="هاتف" />
1015:   
1016:                      if (serviceRequest.Status == 2003 || serviceRequest.Status == 2005)
1017:                      {
1018:                          // <status id="2003" arabicName="قيد التنفيذ" />
1019:                          // <status id="2005" arabicName="تم التنفيذ" />
1020:   
1021:                          service = serviceRequest.Number.ToString();
1022:                          serial = serviceRequest.Serial;
1023:                          serviceId = serviceRequest.ServiceId;
1024:                          status = -1;
1025:                          serviceSerial = service + ":" + serial;
1026:   
1027:                          if (!serviceRequestNumberSerialComplementaryServiceDictionary.ContainsKey(serviceSerial) || serviceRequestNumberSerialComplementaryServiceDictionary.ContainsKey(serviceSerial) && serviceRequestNumberSerialComplementaryServiceDictionary[serviceSerial].Provisioned == false)
1028:                          {
1029:                              if (serviceId == 1 || serviceId == 129 || serviceId == 54)
1030:                              {
1031:                                  // <service id="1" arabicName="خط هاتف" />
1032:                                  // <service id="129" arabicName="خط هاتف مع نداء آلي"/>
1033:                                  // <service id="54" arabicName="اعادة تركيب" />
1034:   
1035:                                  serviceSerialRequestService = new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService();
1036:   
1037:                                  serviceSerialRequestService.Id = serviceSerial;
1038:                                  serviceSerialRequestService.Service = service;
1039:                                  serviceSerialRequestService.Serial = serial;
1040:                                  serviceSerialRequestService.Provisioned = true;
1041:   
1042:                                  serviceRequestNumberSerialComplementaryServiceDictionary[serviceSerial] = serviceSerialRequestService;
1043:   
1044:                                  Ia.Ngn.Cl.Model.Business.ServiceRequestService.TelephonyService2(ref serviceRequestNumberSerialComplementaryServiceDictionary, serviceSerial, status, serviceId, ref serviceIdIssue);
1045:   
1046:                                  if (serviceToLastSerialDictionary.ContainsKey(service))
1047:                                  {
1048:                                      if (serviceToLastSerialDictionary[service] < serial) serviceToLastSerialDictionary[service] = serial;
1049:                                  }
1050:                                  else serviceToLastSerialDictionary[service] = serial;
1051:                              }
1052:                              else
1053:                              {
1054:                                  // incomplete service request list for serial
1055:                              }
1056:                          }
1057:                          else
1058:                          {
1059:                              if (serviceRequestNumberSerialComplementaryServiceDictionary[serviceSerial].Provisioned && serviceRequestNumberSerialComplementaryServiceDictionary[serviceSerial].Serial == serial)
1060:                              {
1061:                                  if (serviceId == 41)
1062:                                  {
1063:                                      // <service id="41" arabicName="تغيير رقم" />
1064:                                  }
1065:                                  else
1066:                                  {
1067:                                      Ia.Ngn.Cl.Model.Business.ServiceRequestService.TelephonyService2(ref serviceRequestNumberSerialComplementaryServiceDictionary, serviceSerial, status, serviceId, ref serviceIdIssue);
1068:                                  }
1069:                              }
1070:                          }
1071:                      }
1072:                      else
1073:                      {
1074:                      }
1075:                  }
1076:              }
1077:   
1078:   
1079:              serviceRequestHistoryNumberSerialComplementaryServiceDictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService>(serviceRequestHistoryList.Count);
1080:   
1081:              // build service request service from service request histories.
1082:              var list2 = serviceRequestHistoryList.OrderBy(p => p.ServiceDateTime.Date).ThenBy(p => p.ServiceId == 38); // <service id="38" arabicName="مجموعة الخدمات" />
1083:              foreach (var serviceRequestHistory in list2)
1084:              {
1085:                  if (serviceRequestHistory.ServiceCategoryId == 3)
1086:                  {
1087:                      // <category id="3" arabicName="هاتف" />
1088:                      service = serviceRequestHistory.Number.ToString();
1089:                      serial = serviceRequestHistory.Serial;
1090:                      serviceId = serviceRequestHistory.ServiceId;
1091:                      status = serviceRequestHistory.Status;
1092:   
1093:                      serviceSerial = service + ":" + serial;
1094:   
1095:                      if (serviceToLastSerialDictionary.ContainsKey(service))
1096:                      {
1097:                          if (serviceToLastSerialDictionary[service] < serial) serviceToLastSerialDictionary[service] = serial;
1098:                      }
1099:                      else serviceToLastSerialDictionary[service] = serial;
1100:   
1101:                      if (!serviceRequestHistoryNumberSerialComplementaryServiceDictionary.ContainsKey(serviceSerial) || serviceRequestHistoryNumberSerialComplementaryServiceDictionary.ContainsKey(serviceSerial) && serviceRequestHistoryNumberSerialComplementaryServiceDictionary[serviceSerial].Provisioned == false)
1102:                      {
1103:                          if (serviceId == 1 || serviceId == 129 || serviceId == 54)
1104:                          {
1105:                              // <service id="1" arabicName="خط هاتف" />
1106:                              // <service id="129" arabicName="خط هاتف مع نداء آلي"/>
1107:                              // <service id="54" arabicName="اعادة تركيب" />
1108:   
1109:                              serviceSerialRequestService = new Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService();
1110:   
1111:                              serviceSerialRequestService.Id = serviceSerial;
1112:                              serviceSerialRequestService.Service = service;
1113:                              serviceSerialRequestService.Serial = serial;
1114:                              serviceSerialRequestService.Provisioned = true;
1115:   
1116:                              serviceRequestHistoryNumberSerialComplementaryServiceDictionary[serviceSerial] = serviceSerialRequestService;
1117:                          }
1118:                          else
1119:                          {
1120:                              // incomplete service request list for serial
1121:                          }
1122:                      }
1123:                      else
1124:                      {
1125:                          if (serviceRequestHistoryNumberSerialComplementaryServiceDictionary[serviceSerial].Provisioned && serviceRequestHistoryNumberSerialComplementaryServiceDictionary[serviceSerial].Serial == serial)
1126:                          {
1127:                              if (serviceId == 41)
1128:                              {
1129:                                  // <service id="41" arabicName="تغيير رقم" />
1130:                              }
1131:                              else
1132:                              {
1133:                                  Ia.Ngn.Cl.Model.Business.ServiceRequestService.TelephonyService2(ref serviceRequestHistoryNumberSerialComplementaryServiceDictionary, serviceSerial, status, serviceId, ref serviceIdIssue);
1134:                              }
1135:                          }
1136:                      }
1137:                  }
1138:              }
1139:   
1140:   
1141:              // collect all numbers serials that are not the last in their serial series:
1142:              foreach (KeyValuePair<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> kvp in serviceRequestNumberSerialComplementaryServiceDictionary)
1143:              {
1144:                  if (serviceToLastSerialDictionary.ContainsKey(kvp.Value.Service))
1145:                  {
1146:                      if (serviceToLastSerialDictionary[kvp.Value.Service] > kvp.Value.Serial) serviceSerialsToRemoveList.Add(kvp.Key);
1147:                  }
1148:                  else
1149:                  {
1150:                      serviceIdIssue += "Error: serviceToLastSerialDictionary does not contain kvp.Value.Service: " + kvp.Value.Service + "\r\n";
1151:                  }
1152:              }
1153:   
1154:              foreach (KeyValuePair<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> kvp in serviceRequestHistoryNumberSerialComplementaryServiceDictionary)
1155:              {
1156:                  if (serviceToLastSerialDictionary.ContainsKey(kvp.Value.Service))
1157:                  {
1158:                      if (serviceToLastSerialDictionary[kvp.Value.Service] > kvp.Value.Serial) serviceSerialsToRemoveList.Add(kvp.Key);
1159:                  }
1160:                  else
1161:                  {
1162:                      serviceIdIssue += "Error: serviceToLastSerialDictionary does not contain kvp.Value.Service: " + kvp.Value.Service + "\r\n";
1163:                  }
1164:              }
1165:   
1166:   
1167:              // remove previous service-serials
1168:              foreach (string s in serviceSerialsToRemoveList)
1169:              {
1170:                  serviceRequestNumberSerialComplementaryServiceDictionary.Remove(s);
1171:                  serviceRequestHistoryNumberSerialComplementaryServiceDictionary.Remove(s);
1172:              }
1173:   
1174:   
1175:              serviceRequestServiceNumberSerialComplementaryServiceDictionary = new Dictionary<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService>(serviceRequestServiceList.Count);
1176:   
1177:              foreach (var srs in serviceRequestServiceList)
1178:              {
1179:                  serviceSerial = srs.Service + ":" + srs.Serial;
1180:   
1181:                  if (!serviceRequestServiceNumberSerialComplementaryServiceDictionary.ContainsKey(serviceSerial))
1182:                  {
1183:                      serviceRequestServiceNumberSerialComplementaryServiceDictionary[serviceSerial] = srs;
1184:                  }
1185:              }
1186:   
1187:   
1188:              mismatchBetweenSrAndSrsList = new List<string>(1000);
1189:              mismatchBetweenSrAndSrhList = new List<string>(1000);
1190:              inSrNotInSrhList = new List<string>(serviceRequestNumberSerialComplementaryServiceDictionary.Count);
1191:              inSrhNotInSrList = new List<string>(serviceRequestHistoryNumberSerialComplementaryServiceDictionary.Count);
1192:   
1193:              matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionary = new Dictionary<string, ServiceSerialRequestService>(serviceRequestNumberSerialComplementaryServiceDictionary.Count + serviceRequestHistoryNumberSerialComplementaryServiceDictionary.Count);
1194:              matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionary = new Dictionary<string, ServiceSerialRequestService>(serviceRequestNumberSerialComplementaryServiceDictionary.Count + serviceRequestServiceNumberSerialComplementaryServiceDictionary.Count);
1195:   
1196:              foreach (KeyValuePair<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> kvp in serviceRequestNumberSerialComplementaryServiceDictionary)
1197:              {
1198:                  if (serviceRequestServiceNumberSerialComplementaryServiceDictionary.ContainsKey(kvp.Key))
1199:                  {
1200:                      if (kvp.Value != serviceRequestServiceNumberSerialComplementaryServiceDictionary[kvp.Key])
1201:                      {
1202:                          if (!mismatchBetweenSrAndSrsList.Contains(kvp.Key))
1203:                          {
1204:                              mismatchBetweenSrAndSrsList.Add(kvp.Key);
1205:                          }
1206:                          else
1207:                          {
1208:   
1209:                          }
1210:                      }
1211:                      else
1212:                      {
1213:                          matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionary[kvp.Key] = kvp.Value;
1214:                      }
1215:                  }
1216:                  //else inSrhNotInSrsList.Add(kvp.Key);
1217:   
1218:                  if (serviceRequestHistoryNumberSerialComplementaryServiceDictionary.ContainsKey(kvp.Key))
1219:                  {
1220:                      if (kvp.Value != serviceRequestHistoryNumberSerialComplementaryServiceDictionary[kvp.Key])
1221:                      {
1222:                          mismatchBetweenSrAndSrhList.Add(kvp.Key);
1223:                      }
1224:                      else
1225:                      {
1226:                          matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionary[kvp.Key] = kvp.Value;
1227:                      }
1228:                  }
1229:                  else inSrNotInSrhList.Add(kvp.Key);
1230:              }
1231:   
1232:              foreach (KeyValuePair<string, Ia.Ngn.Cl.Model.Business.ServiceSerialRequestService> kvp in serviceRequestHistoryNumberSerialComplementaryServiceDictionary)
1233:              {
1234:                  if (serviceRequestNumberSerialComplementaryServiceDictionary.ContainsKey(kvp.Key))
1235:                  {
1236:                      if (kvp.Value != serviceRequestNumberSerialComplementaryServiceDictionary[kvp.Key])
1237:                      {
1238:                          if (!mismatchBetweenSrAndSrhList.Contains(kvp.Key))
1239:                          {
1240:                              mismatchBetweenSrAndSrhList.Add(kvp.Key);
1241:                          }
1242:                          else
1243:                          {
1244:   
1245:                          }
1246:                      }
1247:                      else
1248:                      {
1249:                          matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionary[kvp.Key] = kvp.Value;
1250:                      }
1251:                  }
1252:                  else inSrhNotInSrList.Add(kvp.Key);
1253:              }
1254:   
1255:   
1256:              serviceRequestServiceListCount = serviceRequestServiceList.Count;
1257:              serviceRequestNumberSerialComplementaryServiceDictionaryCount = serviceRequestNumberSerialComplementaryServiceDictionary.Count;
1258:              serviceRequestHistoryNumberSerialComplementaryServiceDictionaryCount = serviceRequestHistoryNumberSerialComplementaryServiceDictionary.Count;
1259:              matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionaryCount = matchedServiceRequestAndServiceRequestHistoryNumberSerialComplementaryServiceDictionary.Count;
1260:              matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionaryCount = matchedServiceRequestAndServiceRequestServiceNumberSerialComplementaryServiceDictionary.Count;
1261:          }
1262:   
1263:          ////////////////////////////////////////////////////////////////////////////    
1264:          ////////////////////////////////////////////////////////////////////////////    
1265:      }
1266:   
1267:      ////////////////////////////////////////////////////////////////////////////
1268:      ////////////////////////////////////////////////////////////////////////////
1269:   
1270:   
1271:   
1272:   
1273:   
1274:   
1275:   
1276:   
1277:      ////////////////////////////////////////////////////////////////////////////
1278:   
1279:      /// <summary>
1280:      /// Number Format Covnerter for Nokia and Huaweri Number Formats for the Optical Fiber Network - Kuwait
1281:      /// </summary>
1282:      /// 
1283:      /// <remarks> 
1284:      /// Copyright © 2001-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
1285:      ///
1286:      /// 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
1287:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
1288:      ///
1289:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1290:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1291:      /// 
1292:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
1293:      /// 
1294:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
1295:      /// </remarks> 
1296:      public class NumberFormatConverter
1297:      {
1298:          /// <summary/>
1299:          public NumberFormatConverter()
1300:          {
1301:              /*
1302:          <Dn>+96522239100</Dn>
1303:          <PrividUser>priv_96522239100</PrividUser>
1304:          <PartyId>+96522239501</PartyId>
1305:          <PrimaryPUID>+96522239501</PrimaryPUID>
1306:          <aid>+96522239501</aid>
1307:          <PublicUID>+96522239100@ims.moc1.kw</PublicUID>
1308:          <PrivateId>priv_96522239100</PrivateId>
1309:          <Puid>sip:+96522239100</Puid>
1310:          <PridUser>priv_96522239100</PridUser>
1311:               * 
1312:               *             impu = "tel:+" + Ia.Ngn.Cl.Model.Data.Service.CountryCode + number;
1313:                                     sip:+96523900012@ims.moc.kw
1314:  
1315:               */
1316:          }
1317:   
1318:          /// <summary/>
1319:          public static string Dn(string service)
1320:          {
1321:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1322:          }
1323:   
1324:          public static string SipUserName(string service)
1325:          {
1326:              return Dn(service);
1327:          }
1328:   
1329:          /// <summary/>
1330:          public static string ServiceWithCountryCode(string service)
1331:          {
1332:              return Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1333:          }
1334:   
1335:          /// <summary>
1336:          /// This will check if service is a regex match to a service number with a country code
1337:          /// </summary>
1338:          public static bool IsMatchToServiceWithCountryCode(string service)
1339:          {
1340:              return Regex.IsMatch(service, @"^" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
1341:          }
1342:   
1343:          /// <summary/>
1344:          public static string PrividUser(string service)
1345:          {
1346:              return "priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1347:          }
1348:   
1349:          /// <summary/>
1350:          public static string PartyId(string service)
1351:          {
1352:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
1353:          }
1354:   
1355:          /// <summary/>
1356:          public static string PrimaryPuid(string service)
1357:          {
1358:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1359:          }
1360:   
1361:          /// <summary/>
1362:          public static string Aid(string service)
1363:          {
1364:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1365:          }
1366:   
1367:          /// <summary/>
1368:          public static string PublicUid(string service)
1369:          {
1370:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service + "@ims.moc1.kw";
1371:          }
1372:   
1373:          /// <summary/>
1374:          public static string PrivateId(string service)
1375:          {
1376:              return "priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1377:          }
1378:   
1379:          /// <summary/>
1380:          public static string Puid(string service)
1381:          {
1382:              return "sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1383:          }
1384:   
1385:          /// <summary/>
1386:          public static string PridUser(string service)
1387:          {
1388:              return "priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
1389:          }
1390:   
1391:          /// <summary>
1392:          /// This will check if service is a regex match to PridUser number
1393:          /// </summary>
1394:          public static bool IsMatchToPridUser(string service)
1395:          {
1396:              return Regex.IsMatch(service, @"^priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
1397:          }
1398:   
1399:          /// <summary/>
1400:          public static string Impu(int number)
1401:          {
1402:              return "tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + number;
1403:          }
1404:   
1405:          /// <summary/>
1406:          public static string Impi(string service)
1407:          {
1408:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service) + "@ims.moc.kw";
1409:          }
1410:   
1411:          /// <summary/>
1412:          public static string SipName(string service)
1413:          {
1414:              return Impi(service);
1415:          }
1416:   
1417:          /// <summary>
1418:          /// This will check if service is a regex match to Impi number
1419:          /// </summary>
1420:          public static bool IsMatchToImpi(string service)
1421:          {
1422:              return Regex.IsMatch(service, @"^\+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}@ims.moc.kw$");
1423:          }
1424:   
1425:          /// <summary/>
1426:          public static string Impu(string service)
1427:          {
1428:              return "tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
1429:          }
1430:   
1431:          /// <summary/>
1432:          public static string ImpuSipDomain(int number)
1433:          {
1434:              return "sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + number + "@ims.moc.kw";
1435:          }
1436:   
1437:          /// <summary/>
1438:          public static string ImpuAid(string service)
1439:          {
1440:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
1441:          }
1442:   
1443:          /// <summary>
1444:          /// This will check if service is a regex match to ImpuAid number
1445:          /// </summary>
1446:          public static bool IsMatchToImpuAid(string service)
1447:          {
1448:              return Regex.IsMatch(service, @"^\+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
1449:          }
1450:   
1451:          /// <summary/>
1452:          public static string E164ProtocolUserNumber(string service)
1453:          {
1454:              string s, u, v;
1455:   
1456:              if (!string.IsNullOrEmpty(service))
1457:              {
1458:                  u = Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
1459:   
1460:                  if (u.Length > 0)
1461:                  {
1462:                      // convert number to E164 protocol user number format
1463:                      v = string.Empty;
1464:   
1465:                      for (int i = u.Length - 1; i >= 0; i--) v += u[i] + ".";
1466:   
1467:                      s = v + "e164.arpa";
1468:                  }
1469:                  else s = string.Empty;
1470:              }
1471:              else s = string.Empty;
1472:   
1473:              return s;
1474:          }
1475:   
1476:          /// <summary/>
1477:          public static string SubId(string service)
1478:          {
1479:              return Impi(service);
1480:          }
1481:   
1482:          /// <summary/>
1483:          public static string ImpuSipDomain(string service)
1484:          {
1485:              return "sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service) + "@ims.moc.kw";
1486:          }
1487:   
1488:          /// <summary/>
1489:          public static int Number(string service)
1490:          {
1491:              int i, number;
1492:   
1493:              service = Service(service);
1494:   
1495:              number = int.TryParse(service, out i) ? i : 0;
1496:   
1497:              return number;
1498:          }
1499:   
1500:          /// <summary/>
1501:          public static string Service(string someNumberFormat)
1502:          {
1503:              string s;
1504:   
1505:              if (!string.IsNullOrEmpty(someNumberFormat))
1506:              {
1507:                  if (someNumberFormat.Contains("tel:")) s = someNumberFormat.Replace("tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1508:                  else if (someNumberFormat.Contains("sip:"))
1509:                  {
1510:                      s = someNumberFormat.Replace("sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1511:                      s = s.Replace("@ims.moc.kw", "");
1512:                  }
1513:                  else if (someNumberFormat.Contains("priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode)) s = someNumberFormat.Replace("priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1514:                  else if (someNumberFormat.Contains("+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode)) s = someNumberFormat.Replace("+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1515:                  else if (Regex.IsMatch(someNumberFormat, @"^" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}")) s = Regex.Replace(someNumberFormat, @"^" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1516:                  else if (Regex.IsMatch(someNumberFormat, @"\d{8}")) s = someNumberFormat; // order important
1517:                  else s = Ia.Cl.Model.Default.Match(someNumberFormat, @".+(\d{8})");
1518:              }
1519:              else s = string.Empty;
1520:   
1521:              return s;
1522:          }
1523:   
1524:          ////////////////////////////////////////////////////////////////////////////
1525:          ////////////////////////////////////////////////////////////////////////////
1526:      }
1527:   
1528:      ////////////////////////////////////////////////////////////////////////////
1529:      ////////////////////////////////////////////////////////////////////////////   
1530:  }