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