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