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