)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Default (Ia.Ftn.Cl.Models.Business)

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

Default general support class of Fixed Telecommunications Network (FTN) business model.

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