شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » ServiceRequest

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

Service Request support class of Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text.RegularExpressions;
   5:  using System.Data;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Business
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Service Request support class of Next Generation Network'a (NGN's) business model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  17:      ///
  18:      /// 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
  19:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  20:      ///
  21:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  22:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  23:      /// 
  24:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  25:      /// 
  26:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  27:      /// </remarks> 
  28:      public partial class ServiceRequest
  29:      {
  30:          /// <summary/>
  31:          public ServiceRequest() { }
  32:   
  33:          private static int sequentialProvisioningWorkflowQueueOriginalCount;
  34:          private static Dictionary<string, DateTime> provisioningWorkflowServiceIdDateTimeDictionary = new Dictionary<string, DateTime>();
  35:          private static Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>();
  36:   
  37:          public const string ServiceRequestCustomerIdInputTypeString = "serviceRequestCustomerId";
  38:   
  39:          /// <summary/>
  40:          public enum Procedure { Create, Read, Update, Delete, None };
  41:   
  42:          /// <summary/>
  43:          public struct ProvisioningWorkflow<T>
  44:          {
  45:              /// <summary/>
  46:              public T Item { get; set; }
  47:   
  48:              /// <summary/>
  49:              public Procedure Procedure { get; set; }
  50:   
  51:              /// <summary/>
  52:              public DateTime DateTime { get; set; }
  53:          }
  54:   
  55:          ////////////////////////////////////////////////////////////////////////////    
  56:   
  57:          /// <summary>
  58:          ///
  59:          /// </summary>
  60:          public struct NumberSerial
  61:          {
  62:              public long Id
  63:              {
  64:                  get { return (long)Number * 100 + Serial; }
  65:              }
  66:              public int Number { get; set; }
  67:              public int Serial { get; set; }
  68:          }
  69:   
  70:          ////////////////////////////////////////////////////////////////////////////
  71:          ////////////////////////////////////////////////////////////////////////////
  72:   
  73:          /// <summary>
  74:          ///
  75:          /// </summary>
  76:          public static ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> SequentialProvisioningWorkflowOfOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseListItem(out int sequentialProvisioningWorkflowQueueCount, out string progressCounterString)
  77:          {
  78:              ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> pw;
  79:              List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> list;
  80:   
  81:              if (sequentialProvisioningWorkflowQueue.Count == 0)
  82:              {
  83:                  list = Ia.Ngn.Cl.Model.Business.ServiceRequest.ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList;
  84:   
  85:                  sequentialProvisioningWorkflowQueue = new Queue<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>(list);
  86:   
  87:                  sequentialProvisioningWorkflowQueueOriginalCount = sequentialProvisioningWorkflowQueue.Count;
  88:              }
  89:   
  90:              if (sequentialProvisioningWorkflowQueue.Count > 0) pw = sequentialProvisioningWorkflowQueue.Dequeue();
  91:              else pw = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = null, Procedure = Procedure.None };
  92:   
  93:              progressCounterString = "(" + sequentialProvisioningWorkflowQueue.Count + "/" + sequentialProvisioningWorkflowQueueOriginalCount + ")";
  94:   
  95:              sequentialProvisioningWorkflowQueueCount = sequentialProvisioningWorkflowQueue.Count;
  96:   
  97:              return pw;
  98:          }
  99:   
 100:          ////////////////////////////////////////////////////////////////////////////
 101:   
 102:          /// <summary>
 103:          ///
 104:          /// </summary>
 105:          public static List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> ProvisioningWorkflowOfServiceRequestOntDetailSyncWithCustomerDepartmentDatabaseList
 106:          {
 107:              get
 108:              {
 109:                  DateTime dateTime;
 110:                  ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> provisioningWorkflow;
 111:                  List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>> provisioningWorkflowList;
 112:                  List<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, serviceRequestOntDetailDeleteList;
 113:   
 114:                  dateTime = DateTime.UtcNow.AddHours(3);
 115:   
 116:                  provisioningWorkflowList = new List<ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail>>();
 117:   
 118:                  Ia.Ngn.Cl.Model.Data.ServiceRequestOntDetail.ServiceRequestOntDetailCreateAndDeleteList(out serviceRequestOntDetailCreateList, out serviceRequestOntDetailDeleteList);
 119:   
 120:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailCreateList)
 121:                  {
 122:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Create, DateTime = dateTime };
 123:                      provisioningWorkflowList.Add(provisioningWorkflow);
 124:   
 125:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
 126:                      provisioningWorkflowList.Add(provisioningWorkflow);
 127:                  }
 128:   
 129:                  foreach (Ia.Ngn.Cl.Model.ServiceRequestOntDetail srod in serviceRequestOntDetailDeleteList)
 130:                  {
 131:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Delete, DateTime = dateTime };
 132:                      provisioningWorkflowList.Add(provisioningWorkflow);
 133:   
 134:                      provisioningWorkflow = new ProvisioningWorkflow<Ia.Ngn.Cl.Model.ServiceRequestOntDetail> { Item = srod, Procedure = Procedure.Read, DateTime = dateTime };
 135:                      provisioningWorkflowList.Add(provisioningWorkflow);
 136:                  }
 137:   
 138:                  return provisioningWorkflowList;
 139:              }
 140:          }
 141:   
 142:          ////////////////////////////////////////////////////////////////////////////
 143:          ////////////////////////////////////////////////////////////////////////////
 144:   
 145:          /// <summary>
 146:          ///
 147:          /// </summary>
 148:          public static Ia.Ngn.Cl.Model.Business.ServiceAddress StatisticalServiceAddress(string service, string customerAddress, out string level)
 149:          {
 150:              string provinceArea;
 151:              Match match;
 152:              Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
 153:   
 154:              serviceAddress = new ServiceAddress();
 155:   
 156:              serviceAddress.Service = service;
 157:   
 158:              if (customerAddress != null)
 159:              {
 160:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddress(customerAddress);
 161:   
 162:                  // below: special handeling needed here
 163:                  customerAddress = Ia.Ngn.Cl.Model.Business.Default.CorrectCustomerAddressMissingProvinceArea(service, customerAddress);
 164:   
 165:                  // ',قطعة 4 قسيمة 538,'
 166:                  // below:
 167:                  // (.+),قطعة
 168:                  // ? entries
 169:                  match = Regex.Match(customerAddress, @"^(.+),قطعة", RegexOptions.Singleline);
 170:   
 171:                  if (match.Success)
 172:                  {
 173:                      level = "1";
 174:   
 175:                      provinceArea = match.Groups[1].Value;
 176:                      serviceAddress.AreaId = (from a in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where provinceArea == a.ServiceRequestAddressProvinceAreaName select a.Id).SingleOrDefault();
 177:                  }
 178:                  else
 179:                  {
 180:                      serviceAddress.AreaId = 0;
 181:                  }
 182:   
 183:                  // below:
 184:                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5 قسيمة 17, منزل 17
 185:                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 186:   
 187:                  if (match.Success)
 188:                  {
 189:                      level = "1-";
 190:   
 191:                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 192:                      serviceAddress.Street = match.Groups[3].Value;
 193:                      serviceAddress.Boulevard = match.Groups[4].Value;
 194:                      serviceAddress.PremisesOld = match.Groups[5].Value;
 195:                      serviceAddress.PremisesNew = match.Groups[6].Value;
 196:                  }
 197:                  else
 198:                  {
 199:                      level = "2";
 200:   
 201:                      // below:
 202:                      // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17, منزل 17
 203:                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 204:   
 205:                      if (match.Success)
 206:                      {
 207:                          level = "2-";
 208:   
 209:                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 210:                          serviceAddress.Street = match.Groups[3].Value;
 211:                          serviceAddress.Boulevard = null;
 212:                          serviceAddress.PremisesOld = match.Groups[4].Value;
 213:                          serviceAddress.PremisesNew = match.Groups[5].Value;
 214:                      }
 215:                      else
 216:                      {
 217:                          level = "3";
 218:   
 219:                          // below:
 220:                          // الجهراء الجهراء المدينة,قطعة 79 شارع 5, منزل 17
 221:                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+), منزل (.+)$", RegexOptions.Singleline);
 222:   
 223:                          if (match.Success)
 224:                          {
 225:                              level = "3-";
 226:   
 227:                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 228:                              serviceAddress.Street = match.Groups[3].Value;
 229:                              serviceAddress.Boulevard = null;
 230:                              serviceAddress.PremisesOld = null;
 231:                              serviceAddress.PremisesNew = match.Groups[4].Value;
 232:                          }
 233:                          else
 234:                          {
 235:                              level = "4";
 236:   
 237:                              // below:
 238:                              // الجهراء الجهراء المدينة,قطعة 79 شارع 5 قسيمة 17
 239:                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) قسيمة (.+),$", RegexOptions.Singleline);
 240:   
 241:                              if (match.Success)
 242:                              {
 243:                                  level = "4-";
 244:   
 245:                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 246:                                  serviceAddress.Street = match.Groups[3].Value;
 247:                                  serviceAddress.Boulevard = null;
 248:                                  serviceAddress.PremisesOld = match.Groups[4].Value;
 249:                                  serviceAddress.PremisesNew = null;
 250:                              }
 251:                              else
 252:                              {
 253:                                  level = "5";
 254:   
 255:                                  // below:
 256:                                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5 جادة 5
 257:                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+) جادة (.+),$", RegexOptions.Singleline);
 258:   
 259:                                  if (match.Success)
 260:                                  {
 261:                                      level = "5-";
 262:   
 263:                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 264:                                      serviceAddress.Street = match.Groups[3].Value;
 265:                                      serviceAddress.Boulevard = match.Groups[4].Value;
 266:                                      serviceAddress.PremisesOld = null;
 267:                                      serviceAddress.PremisesNew = null;
 268:                                  }
 269:                                  else
 270:                                  {
 271:                                      level = "6";
 272:   
 273:                                      // below:
 274:                                      // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17, منزل 17
 275:                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+), منزل (.+)$", RegexOptions.Singleline);
 276:   
 277:                                      if (match.Success)
 278:                                      {
 279:                                          level = "6-";
 280:   
 281:                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 282:                                          serviceAddress.Street = null;
 283:                                          serviceAddress.Boulevard = null;
 284:                                          serviceAddress.PremisesOld = match.Groups[3].Value;
 285:                                          serviceAddress.PremisesNew = match.Groups[4].Value;
 286:                                      }
 287:                                      else
 288:                                      {
 289:                                          level = "7";
 290:   
 291:                                          // below:
 292:                                          // الجهراء الجهراء المدينة,قطعة 79 قسيمة 17
 293:                                          match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) قسيمة (.+),$", RegexOptions.Singleline);
 294:   
 295:                                          if (match.Success)
 296:                                          {
 297:                                              level = "7-";
 298:   
 299:                                              serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 300:                                              serviceAddress.Street = null;
 301:                                              serviceAddress.Boulevard = null;
 302:                                              serviceAddress.PremisesOld = match.Groups[3].Value;
 303:                                              serviceAddress.PremisesNew = null;
 304:                                          }
 305:                                          else
 306:                                          {
 307:                                              level = "8";
 308:   
 309:                                              // below:
 310:                                              // الجهراء الجهراء المدينة,قطعة 79, منزل 17
 311:                                              match = Regex.Match(customerAddress, @"^(.+),قطعة (.+), منزل (.+)$", RegexOptions.Singleline);
 312:   
 313:                                              if (match.Success)
 314:                                              {
 315:                                                  level = "8-";
 316:   
 317:                                                  serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 318:                                                  serviceAddress.Street = null;
 319:                                                  serviceAddress.Boulevard = null;
 320:                                                  serviceAddress.PremisesOld = null;
 321:                                                  serviceAddress.PremisesNew = match.Groups[3].Value;
 322:                                              }
 323:                                              else
 324:                                              {
 325:                                                  level = "9";
 326:   
 327:                                                  // below:
 328:                                                  // الجهراء الجهراء المدينة,قطعة 79 شارع 5
 329:                                                  match = Regex.Match(customerAddress, @"^(.+),قطعة (.+) شارع (.+)$", RegexOptions.Singleline);
 330:   
 331:                                                  if (match.Success)
 332:                                                  {
 333:                                                      level = "9-";
 334:   
 335:                                                      serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 336:                                                      serviceAddress.Street = match.Groups[3].Value;
 337:                                                      serviceAddress.Boulevard = null;
 338:                                                      serviceAddress.PremisesOld = null;
 339:                                                      serviceAddress.PremisesNew = null;
 340:                                                  }
 341:                                                  else
 342:                                                  {
 343:                                                      level = "10";
 344:   
 345:                                                      // below:
 346:                                                      // الجهراء الجهراء المدينة,قطعة 79
 347:                                                      match = Regex.Match(customerAddress, @"^(.+),قطعة (.+),$", RegexOptions.Singleline);
 348:   
 349:                                                      if (match.Success)
 350:                                                      {
 351:                                                          level = "10-";
 352:   
 353:                                                          serviceAddress.Block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(match.Groups[2].Value);
 354:                                                          serviceAddress.Street = null;
 355:                                                          serviceAddress.Boulevard = null;
 356:                                                          serviceAddress.PremisesOld = null;
 357:                                                          serviceAddress.PremisesNew = null;
 358:                                                      }
 359:                                                      else
 360:                                                      {
 361:                                                          level = "11";
 362:                                                      }
 363:                                                  }
 364:                                              }
 365:                                          }
 366:                                      }
 367:                                  }
 368:                              }
 369:                          }
 370:                      }
 371:                  }
 372:   
 373:                  // below: we will try to store integers in integer format
 374:   
 375:                  //serviceAddress.Block this is already in int format
 376:                  serviceAddress.Street = int.TryParse(serviceAddress.Street, out int i) ? i.ToString() : serviceAddress.Street;
 377:                  serviceAddress.Boulevard = int.TryParse(serviceAddress.Boulevard, out i) ? i.ToString() : serviceAddress.Boulevard;
 378:                  serviceAddress.PremisesOld = int.TryParse(serviceAddress.PremisesOld, out i) ? i.ToString() : serviceAddress.PremisesOld;
 379:                  serviceAddress.PremisesNew = int.TryParse(serviceAddress.PremisesNew, out i) ? i.ToString() : serviceAddress.PremisesNew;
 380:              }
 381:              else
 382:              {
 383:                  level = "0";
 384:   
 385:                  serviceAddress.AreaId = 0;
 386:              }
 387:   
 388:              return serviceAddress;
 389:          }
 390:   
 391:          ////////////////////////////////////////////////////////////////////////////    
 392:      }
 393:   
 394:      ////////////////////////////////////////////////////////////////////////////    
 395:      ////////////////////////////////////////////////////////////////////////////
 396:   
 397:      /// <summary>
 398:      ///
 399:      /// </summary>
 400:      public static class ServiceRequestExtension
 401:      {
 402:          ////////////////////////////////////////////////////////////////////////////
 403:   
 404:          /// <summary>
 405:          /// Extension method: Collect distinct numbers Number list
 406:          /// </summary>
 407:          public static List<int> DistinctNumberList(this List<Ia.Ngn.Cl.Model.ServiceRequest> sourceList)
 408:          {
 409:              List<int> numberList;
 410:   
 411:              numberList = (from n in sourceList select n.Number).Distinct().ToList<int>();
 412:   
 413:              return numberList;
 414:          }
 415:   
 416:          ////////////////////////////////////////////////////////////////////////////
 417:   
 418:          /// <summary>
 419:          /// Extension method: Collect distinct number-serials into NumberSerial list
 420:          /// </summary>
 421:          public static List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> DistinctNumberSerialList(this List<Ia.Ngn.Cl.Model.ServiceRequest> sourceList)
 422:          {
 423:              List<Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial> numberSerialList;
 424:   
 425:              numberSerialList = (from n in sourceList select new Ia.Ngn.Cl.Model.Business.ServiceRequest.NumberSerial { Number = n.Number, Serial = n.Serial }).Distinct().ToList();
 426:   
 427:              return numberSerialList;
 428:          }
 429:   
 430:          ////////////////////////////////////////////////////////////////////////////
 431:          ////////////////////////////////////////////////////////////////////////////
 432:      }
 433:   
 434:      ////////////////////////////////////////////////////////////////////////////
 435:      ////////////////////////////////////////////////////////////////////////////
 436:  }