Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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:          /// Flag to indicate of the system should be running
  45:          /// </summary>
  46:          public static bool AllowSystemToRun
  47:          {
  48:              get
  49:              {
  50:                  bool b;
  51:                  DateTime dateTime;
  52:   
  53:                  dateTime = DateTime.UtcNow.AddHours(3);
  54:   
  55:                  b = (dateTime.Year == 2018 && dateTime.Month <= 11);
  56:   
  57:                  return b;
  58:              }
  59:          }
  60:   
  61:          ////////////////////////////////////////////////////////////////////////////
  62:   
  63:          /// <summary>
  64:          ///
  65:          /// </summary>
  66:          public static string OntId(string ponId, int ontNumber)
  67:          {
  68:              string id;
  69:   
  70:              id = ponId + ontNumber.ToString().PadLeft(2, '0');
  71:   
  72:              if (id.Length != fixedLengthOfOntId)
  73:              {
  74:                  throw new ArgumentOutOfRangeException(@"OntId(): Id length is not " + fixedLengthOfOntId);
  75:              }
  76:   
  77:              return id;
  78:          }
  79:   
  80:          ////////////////////////////////////////////////////////////////////////////
  81:   
  82:          /// <summary>
  83:          ///
  84:          /// </summary>
  85:          public static string ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value)
  86:          {
  87:              bool isValid;
  88:              int oltId, ponNumber, ontNumber;
  89:              string accessName;
  90:              Dictionary<int, string> typeDictionary;
  91:   
  92:              typeDictionary = new Dictionary<int, string>(1);
  93:              typeDictionary.Add(1, value);
  94:   
  95:              isValid = ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
  96:   
  97:              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();
  98:              else accessName = string.Empty;
  99:   
 100:              return accessName;
 101:          }
 102:   
 103:          ////////////////////////////////////////////////////////////////////////////
 104:   
 105:          /// <summary>
 106:          ///
 107:          /// </summary>
 108:          public static Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont NddOntFromHuaweiEmsMduNameFormat(string mduName)
 109:          {
 110:              string accessName, s;
 111:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
 112:   
 113:              s = Ia.Ngn.Cl.Model.Business.Huawei.Ems.RemoveMduNameInHuaweiOntActivationReportSpecificNameFormat(mduName);
 114:   
 115:              accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(s);
 116:   
 117:              ont = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntByAccessName(accessName);
 118:   
 119:              return ont;
 120:          }
 121:   
 122:          ////////////////////////////////////////////////////////////////////////////
 123:   
 124:          /// <summary>
 125:          ///
 126:          /// </summary>
 127:          public static string ExtractPonNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value)
 128:          {
 129:              bool isValid;
 130:              int oltId, ponNumber, ontNumber;
 131:              string ponName;
 132:              Dictionary<int, string> typeDictionary;
 133:   
 134:              // below: we will replace ' ' and '/' with '.' to avoid errors
 135:              value = value.Replace(" ", ".");
 136:              value = value.Replace("/", ".");
 137:   
 138:              typeDictionary = new Dictionary<int, string>(1);
 139:              typeDictionary.Add(1, value + ".1"); // to mimic a WWW.D.1 format
 140:   
 141:              isValid = ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
 142:   
 143:              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();
 144:              else ponName = string.Empty;
 145:   
 146:              return ponName;
 147:          }
 148:   
 149:          ////////////////////////////////////////////////////////////////////////////
 150:   
 151:          /// <summary>
 152:          ///
 153:          /// </summary>
 154:          public static string StandardizeAccessNameInLegalFormatFromValue(string value)
 155:          {
 156:              string accessName;
 157:              Dictionary<int, string> typeDictionary;
 158:   
 159:              typeDictionary = new Dictionary<int, string>(1);
 160:              typeDictionary.Add(1, value);
 161:   
 162:              accessName = ExtractAccessNameInLegalFormatFromDictionaryValueList(typeDictionary);
 163:   
 164:              return accessName;
 165:          }
 166:   
 167:          ////////////////////////////////////////////////////////////////////////////
 168:   
 169:          /// <summary>
 170:          ///
 171:          /// </summary>
 172:          public static bool ExtractOntNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(string value, out int oltId, out int ponNumber, out int ontNumber)
 173:          {
 174:              Dictionary<int, string> typeDictionary;
 175:   
 176:              typeDictionary = new Dictionary<int, string>(1);
 177:              typeDictionary.Add(1, value);
 178:   
 179:              return ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(typeDictionary, out oltId, out ponNumber, out ontNumber);
 180:          }
 181:   
 182:          ////////////////////////////////////////////////////////////////////////////
 183:   
 184:          /// <summary>
 185:          ///
 186:          /// </summary>
 187:          public static bool ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromDictionaryValueList(Dictionary<int, string> typeDictionary, out int oltId, out int ponNumber, out int ontNumber)
 188:          {
 189:              bool b, isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt;
 190:              int p, o;
 191:              string p1, p2, p3, p4, p5, p45, p55, symbol;
 192:              Match match;
 193:   
 194:              b = isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 195:              oltId = ponNumber = ontNumber = 0;
 196:   
 197:              p1 = (typeDictionary.ContainsKey(1)) ? typeDictionary[1] : "";
 198:              p2 = (typeDictionary.ContainsKey(2)) ? typeDictionary[2] : "";
 199:              p3 = (typeDictionary.ContainsKey(3)) ? typeDictionary[3] : "";
 200:              p4 = (typeDictionary.ContainsKey(4)) ? typeDictionary[4] : "";
 201:              p5 = (typeDictionary.ContainsKey(5)) ? typeDictionary[5] : "";
 202:              p45 = (typeDictionary.ContainsKey(45)) ? typeDictionary[45] : "";
 203:              p55 = (typeDictionary.ContainsKey(55)) ? typeDictionary[55] : "";
 204:   
 205:              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p2, out match);
 206:   
 207:              if (!b)
 208:              {
 209:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p1, out match);
 210:   
 211:                  if (!b)
 212:                  {
 213:                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p55, out match);
 214:   
 215:                      if (!b)
 216:                      {
 217:                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p2, out match);
 218:   
 219:                          if (!b)
 220:                          {
 221:                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p45, out match);
 222:   
 223:                              if (!b)
 224:                              {
 225:                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p2, p45, out match);
 226:   
 227:                                  if (!b)
 228:                                  {
 229:                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p4, out match);
 230:   
 231:                                      if (!b)
 232:                                      {
 233:                                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p4, out match);
 234:   
 235:                                          if (!b)
 236:                                          {
 237:                                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p5, out match);
 238:   
 239:                                              if (!b)
 240:                                              {
 241:                                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p3, out match);
 242:   
 243:                                                  if (!b)
 244:                                                  {
 245:                                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p3, out match);
 246:                                                  }
 247:                                              }
 248:                                          }
 249:                                      }
 250:                                  }
 251:                              }
 252:                          }
 253:                      }
 254:                  }
 255:              }
 256:   
 257:              if (b)
 258:              {
 259:                  if (match.Success)
 260:                  {
 261:                      symbol = match.Groups[1].Captures[0].Value;
 262:                      ponNumber = p = int.Parse(match.Groups[2].Captures[0].Value);
 263:                      ontNumber = o = int.Parse(match.Groups[3].Captures[0].Value);
 264:   
 265:                      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();
 266:   
 267:                      if (oltId != 0)
 268:                      {
 269:                          isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = true;
 270:                      }
 271:                      else
 272:                      {
 273:                          oltId = ponNumber = ontNumber = 0;
 274:                          isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 275:                      }
 276:                  }
 277:                  else
 278:                  {
 279:                      oltId = ponNumber = ontNumber = 0;
 280:                      isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 281:                  }
 282:              }
 283:              else isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt = false;
 284:   
 285:              return isValidAccessNameWithValidSymbolAndLegalFormatForPonAndOnt;
 286:          }
 287:   
 288:          ////////////////////////////////////////////////////////////////////////////
 289:   
 290:          /// <summary>
 291:          ///
 292:          /// </summary>
 293:          public static string ExtractAccessNameInLegalFormatFromDictionaryValueList(Dictionary<int, string> typeDictionary)
 294:          {
 295:              bool b;
 296:              int ponNumber, ontNumber;
 297:              string p1, p2, p3, p4, p5, p45, symbol, accessName;
 298:              Match match;
 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:   
 307:              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p2, out match);
 308:   
 309:              if (!b)
 310:              {
 311:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p1, out match);
 312:   
 313:                  if (!b)
 314:                  {
 315:                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p2, out match);
 316:   
 317:                      if (!b)
 318:                      {
 319:                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p45, out match);
 320:   
 321:                          if (!b)
 322:                          {
 323:                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p2, p45, out match);
 324:   
 325:                              if (!b)
 326:                              {
 327:                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p4, out match);
 328:   
 329:                                  if (!b)
 330:                                  {
 331:                                      b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p4, out match);
 332:   
 333:                                      if (!b)
 334:                                      {
 335:                                          b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p5, out match);
 336:   
 337:                                          if (!b)
 338:                                          {
 339:                                              b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(p3, out match);
 340:   
 341:                                              if (!b)
 342:                                              {
 343:                                                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(p1, p3, out match);
 344:                                              }
 345:                                          }
 346:                                      }
 347:                                  }
 348:                              }
 349:                          }
 350:                      }
 351:                  }
 352:              }
 353:   
 354:              if (b)
 355:              {
 356:                  if (match.Success)
 357:                  {
 358:                      symbol = match.Groups[1].Captures[0].Value;
 359:   
 360:                      ponNumber = int.Parse(match.Groups[2].Captures[0].Value);
 361:                      ontNumber = int.Parse(match.Groups[3].Captures[0].Value);
 362:   
 363:                      accessName = symbol.ToUpper() + "." + ponNumber + "." + ontNumber;
 364:                  }
 365:                  else
 366:                  {
 367:                      accessName = string.Empty;
 368:                  }
 369:              }
 370:              else
 371:              {
 372:                  accessName = string.Empty;
 373:              }
 374:   
 375:              return accessName;
 376:          }
 377:   
 378:          ////////////////////////////////////////////////////////////////////////////
 379:   
 380:          /// <summary>
 381:          ///
 382:          /// </summary>
 383:          private static bool ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(string s, out Match match)
 384:          {
 385:              // below: this checks if string conferms
 386:              bool b;
 387:              string pattern = @"([a-zA-Z]{3})\.(\d{1,4})\.(\d{1,3})";
 388:   
 389:              match = null;
 390:   
 391:              if (!string.IsNullOrEmpty(s))
 392:              {
 393:                  s = s.ToUpper();
 394:   
 395:                  if (!Regex.IsMatch(s, pattern))
 396:                  {
 397:                      s = s.Replace("-", ".");
 398:                      s = s.Replace("/", ".");
 399:                      s = s.Replace(" ", ".");
 400:   
 401:                      if (!Regex.IsMatch(s, pattern))
 402:                      {
 403:                          s = s.Replace(". ", ".");
 404:   
 405:                          if (!Regex.IsMatch(s, pattern))
 406:                          {
 407:                              s = s.Replace(" .", ".");
 408:   
 409:                              if (!Regex.IsMatch(s, pattern))
 410:                              {
 411:                                  s = s.Replace(".00", ".");
 412:                                  s = s.Replace(".0", ".");
 413:   
 414:                                  if (!Regex.IsMatch(s, pattern))
 415:                                  {
 416:                                      s = s.Replace("...", ".");
 417:                                      s = s.Replace("..", ".");
 418:   
 419:                                      if (!Regex.IsMatch(s, pattern))
 420:                                      {
 421:                                          s = Regex.Replace(s, @"\.$", @"");
 422:   
 423:                                          if (!Regex.IsMatch(s, pattern))
 424:                                          {
 425:                                              s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{1,4})\.(\d{1,3})", @"$1.$2.$3");
 426:   
 427:                                              if (!Regex.IsMatch(s, pattern))
 428:                                              {
 429:                                                  s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{3})(\d{3})", @"$1.$2.$3");
 430:   
 431:                                                  if (!Regex.IsMatch(s, pattern))
 432:                                                  {
 433:                                                      s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{4})(\d{3})", @"$1.$2.$3");
 434:   
 435:                                                      if (!Regex.IsMatch(s, pattern))
 436:                                                      {
 437:                                                          s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{3})(\d{3})", @"$1.$2.$3");
 438:   
 439:                                                          if (!Regex.IsMatch(s, pattern))
 440:                                                          {
 441:                                                              s = Regex.Replace(s, @"([a-zA-Z]{3})(\d{4})(\d{3})", @"$1.$2.$3");
 442:   
 443:                                                              if (!Regex.IsMatch(s, pattern))
 444:                                                              {
 445:                                                                  s = Regex.Replace(s, @"([a-zA-Z]{3})\.(\d{1,4}) (\d{1,3})", @"$1.$2.$3");
 446:   
 447:                                                                  if (!Regex.IsMatch(s, pattern))
 448:                                                                  {
 449:                                                                      s = Regex.Replace(s, @"([a-zA-Z]{3}) (\d{1,4}) (\d{1,3})", @"$1.$2.$3");
 450:                                                                  }
 451:                                                              }
 452:                                                          }
 453:                                                      }
 454:                                                  }
 455:                                              }
 456:                                          }
 457:                                      }
 458:                                  }
 459:                              }
 460:                          }
 461:                      }
 462:                  }
 463:   
 464:                  match = Regex.Match(s, pattern);
 465:   
 466:                  if (match.Success) b = true;
 467:                  else b = false;
 468:              }
 469:              else b = false;
 470:   
 471:              return b;
 472:          }
 473:   
 474:          ////////////////////////////////////////////////////////////////////////////
 475:   
 476:          /// <summary>
 477:          ///
 478:          /// </summary>
 479:          private static bool ExtractAccessNameWithLegalFormatForPonAndOntMatchFromTwoStrings(string s1, string s2, out Match match)
 480:          {
 481:              // below: this checks if string conferms
 482:              bool b;
 483:              match = null;
 484:   
 485:              s1 = s1.Replace("-", ".");
 486:              s1 = s1.Replace("/", ".");
 487:              s1 = s1.Replace(" /", "/");
 488:              s1 = s1.ToUpper();
 489:              s1 = s1.Replace("ZHA", "ZAH");
 490:              s1 = s1.Replace("JAB", "JBA");
 491:   
 492:              s1 = Regex.Replace(s1, @"([a-zA-Z]{3})(\d{1,4})", @"$1.$2");
 493:   
 494:              if (Regex.IsMatch(s1, @"[a-zA-Z]{3}\.\d{1,4}") && Regex.IsMatch(s2, @"\d{1,3}"))
 495:              {
 496:                  b = ExtractAccessNameWithLegalFormatForPonAndOntMatchFromString(s1 + @"." + s2, out match);
 497:              }
 498:              else b = false;
 499:   
 500:              return b;
 501:          }
 502:   
 503:          ////////////////////////////////////////////////////////////////////////////
 504:   
 505:          /// <summary>
 506:          /// ASP.NET State Management
 507:          /// below: remove later to default.cs or state.cs
 508:          /// <remarks>https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx</remarks>
 509:          /// </summary>
 510:          public static bool Application(string name, int lifeInMinutes, object o)
 511:          {
 512:              bool valueStored;
 513:              DateTime expiration;
 514:   
 515:              if (name != string.Empty)
 516:              {
 517:                  expiration = DateTime.UtcNow.AddMinutes(3 * 60 + lifeInMinutes);
 518:   
 519:                  HttpContext.Current.Application[name + "|" + lifeInMinutes.ToString()] = o;
 520:   
 521:                  valueStored = true;
 522:              }
 523:              else valueStored = false;
 524:   
 525:              return valueStored;
 526:          }
 527:   
 528:          ////////////////////////////////////////////////////////////////////////////
 529:   
 530:          /// <summary>
 531:          /// 
 532:          /// </summary>
 533:          public static object Application(string name)
 534:          {
 535:              string expirationString;
 536:              DateTime expiration;
 537:              object o;
 538:   
 539:              o = null;
 540:   
 541:              // below: loop through keys to find the one that starts with name
 542:              foreach(string s in HttpContext.Current.Application.AllKeys)
 543:              {
 544:                  if(s.Contains(name + "|"))
 545:                  {
 546:                      expirationString = Ia.Cl.Model.Default.Match(s, @"\|(.+)");
 547:   
 548:                      expiration = DateTime.Parse(expirationString);
 549:   
 550:                      if (expiration < DateTime.UtcNow.AddHours(3))
 551:                      {
 552:                          // below: did not expire
 553:   
 554:                          o = HttpContext.Current.Application[s];
 555:                      }
 556:                      else o = null;
 557:                  }
 558:              }
 559:   
 560:              return o;
 561:          }
 562:   
 563:          ////////////////////////////////////////////////////////////////////////////
 564:   
 565:          /// <summary>
 566:          /// RecordState holds the current state of the record according to user and system interactions with it. It could be used as an
 567:          /// indicator to define the current state of the record and how it should be handle in state monitoring execution cycles.
 568:          /// </summary>
 569:          public enum RecordState
 570:          {
 571:              Undefined = 0, Synchronized = 10, Synchronize = 20, Modified = 30, Updated = 40, Etc = 50
 572:          };
 573:   
 574:          ////////////////////////////////////////////////////////////////////////////
 575:   
 576:          /// <summary>
 577:          ///
 578:          /// </summary>
 579:          public Default() { }
 580:   
 581:          ////////////////////////////////////////////////////////////////////////////
 582:   
 583:          /// <summary>
 584:          ///
 585:          /// </summary>
 586:          public static string CorrectCustomerAddress(string addressString)
 587:          {
 588:              addressString = addressString.Trim();
 589:   
 590:              //line = Ia.Cl.Model.Language.ConvertSingleLatinDigitsToArabicWordEquivalents(line);
 591:              //line = Ia.Cl.Model.Language.RemoveNonArabicAndNonArabicExtendedLettersAndDigits(line);
 592:              //line = Ia.Cl.Model.Language.CorrectArabicNameNounStringFormat(line);
 593:              // to do line = Ia.Cl.Model.Language.RemoveTitlesFromNames(line);
 594:              // to do line = Ia.Cl.Model.Language.CorrectArabicNameNounFormat(line);
 595:              // to do line = Ia.Cl.Model.Language.CorrectArabicNonNameNounStringFormat(line);
 596:              //line = Ia.Cl.Model.Language.RemoveWrongSpaceBetweenArabicDefinitArticleAndItsWord(line);
 597:              //line = Regex.Replace(line, @"\s+", @" ");
 598:   
 599:              addressString = Regex.Replace(addressString, @"[0]{2,}", "0"); // "000" to "0"
 600:   
 601:              addressString = addressString.Replace("جادة جاده", "جادة ");
 602:              addressString = addressString.Replace("جادة جادة", "جادة ");
 603:              addressString = addressString.Replace("شارع الاول", "شارع 1");
 604:              addressString = addressString.Replace("شارع الثانى", "شارع 2");
 605:              addressString = addressString.Replace("شارع الثالث", "شارع 3");
 606:              addressString = addressString.Replace("شارع الرابع", "شارع 4");
 607:              addressString = addressString.Replace("شارع الخامس", "شارع 5");
 608:              addressString = addressString.Replace("شارع السادس", "شارع 6");
 609:              addressString = addressString.Replace("شارع السابع", "شارع 7");
 610:              addressString = addressString.Replace("شارع الثامن", "شارع 8");
 611:              addressString = addressString.Replace("شارع التاسع", "شارع 9");
 612:   
 613:              addressString = addressString.Trim();
 614:   
 615:              return addressString;
 616:          }
 617:   
 618:          ////////////////////////////////////////////////////////////////////////////
 619:   
 620:          /// <summary>
 621:          ///
 622:          /// </summary>
 623:          public static string CorrectCustomerAddressMissingProvinceArea(string service, string addressString)
 624:          {
 625:              // correct some missing information in address lines based on service number
 626:   
 627:              if (service.StartsWith("2453") || service.StartsWith("2454")) addressString = "الجهراء سعد العبدالله" + addressString;
 628:              else if (service.StartsWith("2466")) addressString = "الفروانية القيروان" + addressString;
 629:              else if (service.StartsWith("2435") || service.StartsWith("2436")) addressString = "الفروانية عبدالله المبارك" + addressString;
 630:              else if (service.StartsWith("2363")) addressString = "الأحمدي فهد الأحمد" + addressString;
 631:              else if (service.StartsWith("2368")) addressString = "الأحمدي لآلئ الخيران" + addressString;
 632:   
 633:              return addressString;
 634:          }
 635:   
 636:          ////////////////////////////////////////////////////////////////////////////
 637:   
 638:          /// <summary>
 639:          ///
 640:          /// </summary>
 641:          public static string CorrectCustomerName(string line)
 642:          {
 643:              line = line.Trim();
 644:              //line = Ia.Cl.Model.Language.ConvertSingleLatinDigitsToArabicWordEquivalents(line);
 645:              line = Ia.Cl.Model.Language.RemoveNonNativeAndNonNativeExtendedLettersAndDigitsAccordingToLanguage("ar", line);
 646:              line = Ia.Cl.Model.Language.CorrectArabicNameNounStringFormat(line);
 647:              // to do line = Ia.Cl.Model.Language.RemoveTitlesFromNames(line);
 648:              // to do line = Ia.Cl.Model.Language.CorrectArabicNameNounFormat(line);
 649:              // to do line = Ia.Cl.Model.Language.CorrectArabicNonNameNounStringFormat(line);
 650:              line = Ia.Cl.Model.Language.RemoveWrongSpaceBetweenNativeDefinitArticleAndItsWord("ar", line);
 651:              line = Regex.Replace(line, @"\s+", @" ");
 652:              line = line.Trim();
 653:   
 654:              return line;
 655:          }
 656:   
 657:          ////////////////////////////////////////////////////////////////////////////
 658:   
 659:          /// <summary>
 660:          ///
 661:          /// </summary>
 662:          public static DataTable ReturnDataTableOfServiceAdministrativeStateOfANumberInOldNgnDatabase(long dn)
 663:          {
 664:              string sql;
 665:              DataTable dt;
 666:              Ia.Cl.Model.Db.SqlServer ngn;
 667:   
 668:              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 + ")";
 669:              dt = null;
 670:   
 671:              try
 672:              {
 673:                  ngn = new Ia.Cl.Model.Db.SqlServer(ConfigurationManager.ConnectionStrings["DefaultConnectionToNgn"].ConnectionString);
 674:   
 675:                  dt = ngn.Select(sql);
 676:              }
 677:              catch (Exception)
 678:              {
 679:              }
 680:   
 681:              return dt;
 682:          }
 683:   
 684:          ////////////////////////////////////////////////////////////////////////////
 685:   
 686:          /// <summary>
 687:          ///
 688:          /// </summary>
 689:          public static void UpdateServiceAdministrativeStateOfANumberInOldNgnDatabase(long dn, string state)
 690:          {
 691:              string sql;
 692:              Ia.Cl.Model.Db.SqlServer ngn;
 693:   
 694:              sql = @"UPDATE ia_service_administrative SET state = " + state + " WHERE dn = " + dn;
 695:   
 696:              try
 697:              {
 698:                  ngn = new Ia.Cl.Model.Db.SqlServer(ConfigurationManager.ConnectionStrings["DefaultConnectionToNgn"].ConnectionString);
 699:   
 700:                  ngn.Sql(sql);
 701:              }
 702:              catch (Exception)
 703:              {
 704:              }
 705:          }
 706:   
 707:          ////////////////////////////////////////////////////////////////////////////
 708:          ////////////////////////////////////////////////////////////////////////////
 709:   
 710:          /// <summary>
 711:          ///
 712:          /// </summary>
 713:          public static int ChangeOldSevenDigitNumbersToEightDigitFormat(int o)
 714:          {
 715:              // below: take an old 7 digit number and covert it to the new 8 digit number according to plan
 716:   
 717:              int n;
 718:   
 719:              // below: check if it is already an 8 digit number
 720:              if (o >= 10000000) n = o;
 721:   
 722:              // 2 (MOC):
 723:              else if (
 724:              (o >= 2000000 && o <= 2999999) ||
 725:              (o >= 3000000 && o <= 3999999) ||
 726:              (o >= 4100000 && o <= 4399999) ||
 727:              (o >= 4500000 && o <= 4999999) ||
 728:              (o >= 5000000 && o <= 5009999) ||
 729:              (o >= 5030000 && o <= 5049999) ||
 730:              (o >= 5200000 && o <= 5499999) ||
 731:              (o >= 5510000 && o <= 5539999) ||
 732:              (o >= 5600000 && o <= 5699999) ||
 733:              (o >= 5710000 && o <= 5779999)) { n = 20000000 + o; }
 734:   
 735:              //6 (Wataniya):
 736:              else if (
 737:              (o >= 5010000 && o <= 5029999) ||
 738:              (o >= 5050000 && o <= 5099999) ||
 739:              (o >= 5100000 && o <= 5199999) ||
 740:              (o >= 5500000 && o <= 5509999) ||
 741:              (o >= 5540000 && o <= 5599999) ||
 742:              (o >= 5700000 && o <= 5709999) ||
 743:              (o >= 5780000 && o <= 5799999) ||
 744:              (o >= 5800000 && o <= 5999999) ||
 745:              (o >= 6000000 && o <= 6999999) ||
 746:              (o >= 7000000 && o <= 7019999) ||
 747:              (o >= 7030000 && o <= 7099999) ||
 748:              (o >= 7700000 && o <= 7769999) ||
 749:              (o >= 7780000 && o <= 7799999)) { n = 60000000 + o; }
 750:   
 751:              //1 (MOC):
 752:              else if (o >= 800000 && o <= 899999) { n = 1000000 + o; }
 753:   
 754:              //9 (Zain):
 755:              else if (
 756:              (o >= 7020000 && o <= 7029999) ||
 757:              (o >= 7100000 && o <= 7699999) ||
 758:              (o >= 7800000 && o <= 7999999) ||
 759:              (o >= 9000000 && o <= 9999999) ||
 760:              (o >= 4400000 && o <= 4499999) ||
 761:              (o >= 4000000 && o <= 4099999)) { n = 90000000 + o; }
 762:   
 763:              else n = o;
 764:   
 765:              return n;
 766:   
 767:              /*
 768:  New numbering list
 769:  
 770:  Add digit,Old Numbers Ranges,Operator
 771:  ,From,To,
 772:  2,2-000000,2-999999,MOC
 773:  2,3-000000,3-999999,MOC
 774:  9,40-00000,40-99999,Zain
 775:  2,41-00000,43-99999,MOC
 776:  9,44-00000,44-99999,Zain
 777:  2,45-00000,49-99999,MOC
 778:  2,500-0000,500-9999,MOC
 779:  6,501-0000,502-9999,Wataniya
 780:  2,503-0000,504-9999,MOC
 781:  6,505-0000,509-9999,Wataniya
 782:  6,51-00000,51-99999,Wataniya
 783:  2,52-00000,54-99999,MOC
 784:  6,550-0000,550-9999,Wataniya
 785:  2,551-0000,553-9999,MOC
 786:  6,554-0000,559-9999,Wataniya
 787:  2,56-00000,56-99999,MOC
 788:  6,570-0000,570-9999,Wataniya
 789:  2,571-0000,577-9999,MOC
 790:  6,578-0000,579-9999,Wataniya
 791:  6,58-00000,59-99999,Wataniya
 792:  6,6-000000,6-999999,Wataniya
 793:  6,700-0000,701-9999,Wataniya
 794:  9,702-0000,702-9999,Zain
 795:  6,703-0000,709-9999,Wataniya
 796:  9,71-00000,76-99999,Zain
 797:  6,770-0000,776-9999,Wataniya
 798:  6,778-0000,779-9999,Wataniya
 799:  9,78-00000,79-99999,Zain
 800:  1,800-000,899-999,MOC
 801:  9,9-000000,9-999999,Zain
 802:  
 803:  
 804:  Example: the number 2123456 will become 2 2123456.
 805:  
 806:  Notice: Unchanged numbers:
 807:  •,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.
 808:  •,The country code for Kuwait 965 stays the same (for international incoming calls).
 809:  •,The 3 digits numbers do not change (numbers from 100 to 179). For example, for the Inquiry Directory, dial 101.
 810:  •,The emergency number in Kuwait 777 does not change.
 811:               */
 812:          }
 813:   
 814:          ////////////////////////////////////////////////////////////////////////////    
 815:          ////////////////////////////////////////////////////////////////////////////    
 816:      }
 817:   
 818:      ////////////////////////////////////////////////////////////////////////////
 819:   
 820:      /// <summary>
 821:      /// Number Format Covnerter for Nokia and Huaweri Number Formats for the Optical Fiber Network - Kuwait
 822:      /// </summary>
 823:      /// 
 824:      /// <remarks> 
 825:      /// Copyright © 2001-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
 826:      ///
 827:      /// 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
 828:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 829:      ///
 830:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 831:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 832:      /// 
 833:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
 834:      /// 
 835:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
 836:      /// </remarks> 
 837:      public class NumberFormatConverter
 838:      {
 839:          /// <summary/>
 840:          public NumberFormatConverter()
 841:          {
 842:              /*
 843:          <Dn>+96522239100</Dn>
 844:          <PrividUser>priv_96522239100</PrividUser>
 845:          <PartyId>+96522239501</PartyId>
 846:          <PrimaryPUID>+96522239501</PrimaryPUID>
 847:          <aid>+96522239501</aid>
 848:          <PublicUID>+96522239100@ims.moc1.kw</PublicUID>
 849:          <PrivateId>priv_96522239100</PrivateId>
 850:          <Puid>sip:+96522239100</Puid>
 851:          <PridUser>priv_96522239100</PridUser>
 852:               * 
 853:               *             impu = "tel:+" + Ia.Ngn.Cl.Model.Data.Service.CountryCode + number;
 854:                                     sip:+96523900012@ims.moc.kw
 855:  
 856:               */
 857:          }
 858:   
 859:          /// <summary/>
 860:          public static string Dn(string service)
 861:          {
 862:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 863:          }
 864:   
 865:          /// <summary/>
 866:          public static string ServiceWithCountryCode(string service)
 867:          {
 868:              return Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 869:          }
 870:   
 871:          /// <summary>
 872:          /// This will check if service is a regex match to a service number with a country code
 873:          /// </summary>
 874:          public static bool IsMatchToServiceWithCountryCode(string service)
 875:          {
 876:              return Regex.IsMatch(service, @"^" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
 877:          }
 878:   
 879:          /// <summary/>
 880:          public static string PrividUser(string service)
 881:          {
 882:              return "priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 883:          }
 884:   
 885:          /// <summary/>
 886:          public static string PartyId(string service)
 887:          {
 888:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
 889:          }
 890:   
 891:          /// <summary/>
 892:          public static string PrimaryPuid(string service)
 893:          {
 894:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 895:          }
 896:   
 897:          /// <summary/>
 898:          public static string Aid(string service)
 899:          {
 900:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 901:          }
 902:   
 903:          /// <summary/>
 904:          public static string PublicUid(string service)
 905:          {
 906:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service + "@ims.moc1.kw";
 907:          }
 908:   
 909:          /// <summary/>
 910:          public static string PrivateId(string service)
 911:          {
 912:              return "priv_"+ Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 913:          }
 914:   
 915:          /// <summary/>
 916:          public static string Puid(string service)
 917:          {
 918:              return "sip:+"+ Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 919:          }
 920:   
 921:          /// <summary/>
 922:          public static string PridUser(string service)
 923:          {
 924:              return "priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + service;
 925:          }
 926:   
 927:          /// <summary>
 928:          /// This will check if service is a regex match to PridUser number
 929:          /// </summary>
 930:          public static bool IsMatchToPridUser(string service)
 931:          {
 932:              return Regex.IsMatch(service, @"^priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
 933:          }
 934:   
 935:          /// <summary/>
 936:          public static string Impu(int number)
 937:          {
 938:              return "tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + number;
 939:          }
 940:   
 941:          /// <summary/>
 942:          public static string Impi(string service)
 943:          {
 944:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service) + "@ims.moc.kw";
 945:          }
 946:   
 947:          /// <summary>
 948:          /// This will check if service is a regex match to Impi number
 949:          /// </summary>
 950:          public static bool IsMatchToImpi(string service)
 951:          {
 952:              return Regex.IsMatch(service, @"^\+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}@ims.moc.kw$");
 953:          }
 954:   
 955:          /// <summary/>
 956:          public static string Impu(string service)
 957:          {
 958:              return "tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
 959:          }
 960:   
 961:          /// <summary/>
 962:          public static string ImpuSipDomain(int number)
 963:          {
 964:              return "sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + number + "@ims.moc.kw";
 965:          }
 966:   
 967:          /// <summary/>
 968:          public static string ImpuAid(string service)
 969:          {
 970:              return "+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
 971:          }
 972:   
 973:          /// <summary>
 974:          /// This will check if service is a regex match to ImpuAid number
 975:          /// </summary>
 976:          public static bool IsMatchToImpuAid(string service)
 977:          {
 978:              return Regex.IsMatch(service, @"^\+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + @"\d{8}$");
 979:          }
 980:   
 981:          /// <summary/>
 982:          public static string E164ProtocolUserNumber(string service)
 983:          {
 984:              string s, u, v;
 985:   
 986:              if (!string.IsNullOrEmpty(service))
 987:              {
 988:                  u = Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service);
 989:   
 990:                  if (u.Length > 0)
 991:                  {
 992:                      // convert number to E164 protocol user number format
 993:                      v = string.Empty;
 994:   
 995:                      for (int i = u.Length - 1; i >= 0; i--) v += u[i] + ".";
 996:   
 997:                      s = v + "e164.arpa";
 998:                  }
 999:                  else s = string.Empty;
1000:              }
1001:              else s = string.Empty;
1002:   
1003:              return s;
1004:          }
1005:   
1006:          /// <summary/>
1007:          public static string SubId(string service)
1008:          {
1009:              return Impi(service);
1010:          }
1011:   
1012:          /// <summary/>
1013:          public static string ImpuSipDomain(string service)
1014:          {
1015:              return "sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode + Service(service) + "@ims.moc.kw";
1016:          }
1017:   
1018:          /// <summary/>
1019:          public static int Number(string service)
1020:          {
1021:              int i, number;
1022:   
1023:              service = Service(service);
1024:   
1025:              number = int.TryParse(service, out i) ? i : 0;
1026:   
1027:              return number;
1028:          }
1029:   
1030:          /// <summary/>
1031:          public static string Service(string someNumberFormat)
1032:          {
1033:              string s;
1034:   
1035:              if (someNumberFormat.Contains("tel:")) s = someNumberFormat.Replace("tel:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1036:              else if (someNumberFormat.Contains("sip:"))
1037:              {
1038:                  s = someNumberFormat.Replace("sip:+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1039:                  s = s.Replace("@ims.moc.kw", "");
1040:              }
1041:              else if (someNumberFormat.Contains("priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode)) s = someNumberFormat.Replace("priv_" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1042:              else if (someNumberFormat.Contains("+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode)) s = someNumberFormat.Replace("+" + Ia.Ngn.Cl.Model.Business.Service.CountryCode, "");
1043:              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, "");
1044:              else if (Regex.IsMatch(someNumberFormat, @"\d{8}")) s = someNumberFormat; // order important
1045:              else s = Ia.Cl.Model.Default.Match(someNumberFormat, @".+(\d{8})");
1046:   
1047:              return s;
1048:          }
1049:   
1050:          ////////////////////////////////////////////////////////////////////////////
1051:          ////////////////////////////////////////////////////////////////////////////
1052:      }
1053:   
1054:      ////////////////////////////////////////////////////////////////////////////
1055:      ////////////////////////////////////////////////////////////////////////////   
1056:  }