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

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