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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Access

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

Access support class for Next Generation Network (NGN) business model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.Security;
   6:  using System.Text.RegularExpressions;
   7:  using System.Data.Entity;
   8:   
   9:  namespace Ia.Ngn.Cl.Model.Business
  10:  {
  11:      ////////////////////////////////////////////////////////////////////////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Access support class for Next Generation Network (NGN) business model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet 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 Access
  31:      {
  32:          private const int fixedLengthOfId = 16;
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static int FixedLengthOfId { get { return fixedLengthOfId; } }
  40:   
  41:          /// <summary/>
  42:          public Access() { }
  43:   
  44:          ////////////////////////////////////////////////////////////////////////////
  45:   
  46:          /// <summary>
  47:          ///
  48:          /// </summary>
  49:          public static string AccessId(int oltId, int ponNumber, int ontNumber)
  50:          {
  51:              string id;
  52:   
  53:              id = oltId.ToString() + ponNumber.ToString().PadLeft(4, '0') + ontNumber.ToString().PadLeft(3, '0');
  54:   
  55:              if (id.Length != fixedLengthOfId)
  56:              {
  57:                  throw new ArgumentOutOfRangeException(@"AccessId(): Id length is not " + fixedLengthOfId);
  58:              }
  59:   
  60:              return id;
  61:          }
  62:   
  63:          ////////////////////////////////////////////////////////////////////////////
  64:   
  65:          /// <summary>
  66:          ///
  67:          /// </summary>
  68:          public static string AccessId(string ontId)
  69:          {
  70:              string id;
  71:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont ont;
  72:   
  73:              ont = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.ReadOnt(ontId);
  74:   
  75:              if (ont != null) id = AccessId(ont.Pon.PonGroup.Olt.Id, ont.Pon.Number, ont.Number);
  76:              else id = "0";
  77:   
  78:              return id;
  79:          }
  80:   
  81:          ////////////////////////////////////////////////////////////////////////////
  82:   
  83:          /// <summary>
  84:          ///
  85:          /// </summary>
  86:          public static string Name(Ia.Ngn.Cl.Model.Access access)
  87:          {
  88:              string name;
  89:   
  90:              name = Name(access.Id);
  91:   
  92:              return name;
  93:          }
  94:   
  95:          ////////////////////////////////////////////////////////////////////////////
  96:   
  97:          /// <summary>
  98:          ///
  99:          /// </summary>
 100:          public static string Name(string accessId)
 101:          {
 102:              string name;
 103:   
 104:              var dictionary = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 105:   
 106:              if (!string.IsNullOrEmpty(accessId))
 107:              {
 108:                  if (dictionary.ContainsKey(accessId))
 109:                  {
 110:                      name = dictionary[accessId];
 111:                  }
 112:                  else name = string.Empty;
 113:              }
 114:              else name = string.Empty;
 115:   
 116:              return name;
 117:          }
 118:   
 119:          /*
 120:          ////////////////////////////////////////////////////////////////////////////
 121:  
 122:          /// <summary>
 123:          ///
 124:          /// </summary>
 125:          public static string Name(string accessId)
 126:          {
 127:              string name;
 128:              int oltId, ponNumber, ontNumber;
 129:  
 130:              ExtractOltIdAndPonNumberAndOntNumberFromAccessId(accessId, out oltId, out ponNumber, out ontNumber);
 131:  
 132:              if (oltId > 0 && ponNumber > 0 && ontNumber > 0)
 133:              {
 134:                  name = (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();
 135:              }
 136:              else name = string.Empty;
 137:  
 138:              return name;
 139:          }
 140:          */
 141:   
 142:          ////////////////////////////////////////////////////////////////////////////
 143:   
 144:          /// <summary>
 145:          ///
 146:          /// </summary>
 147:          public static string Name(string areaSymbol, int pon, int ont)
 148:          {
 149:              string name;
 150:   
 151:              name = areaSymbol + "." + pon + "." + ont;
 152:   
 153:              return name;
 154:          }
 155:   
 156:          ////////////////////////////////////////////////////////////////////////////
 157:   
 158:          /// <summary>
 159:          ///
 160:          /// </summary>
 161:          private static void ExtractOltIdAndPonNumberAndOntNumberFromAccessId(string accessId, out int oltId, out int ponNumber, out int ontNumber)
 162:          {
 163:              string s;
 164:   
 165:              if (!string.IsNullOrEmpty(accessId))
 166:              {
 167:                  s = accessId.Substring(accessId.Length - 3, 3);
 168:   
 169:                  if (int.TryParse(s, out ontNumber))
 170:                  {
 171:                      accessId = accessId.Remove(accessId.Length - 3, 3);
 172:   
 173:                      s = accessId.Substring(accessId.Length - 4, 4);
 174:   
 175:                      if (int.TryParse(s, out ponNumber))
 176:                      {
 177:                          s = accessId.Remove(accessId.Length - 4, 4);
 178:   
 179:                          if (int.TryParse(s, out oltId))
 180:                          {
 181:   
 182:                          }
 183:                          else oltId = ponNumber = ontNumber = 0;
 184:                      }
 185:                      else oltId = ponNumber = ontNumber = 0;
 186:                  }
 187:                  else oltId = ponNumber = ontNumber = 0;
 188:              }
 189:              else oltId = ponNumber = ontNumber = 0;
 190:          }
 191:   
 192:          ////////////////////////////////////////////////////////////////////////////
 193:   
 194:          /// <summary>
 195:          ///
 196:          /// </summary>
 197:          public static void ExtractOltIdAndPonNumberAndOntNumberFromOntName(string accessName, out int oltId, out int pon, out int ontInternalNumber)
 198:          {
 199:              // below: this expects accessName in exact format like SUR.12.3
 200:              int ponNumber;
 201:              string ponGroupSymbol;
 202:              string[] sp;
 203:   
 204:              sp = accessName.Split('.');
 205:   
 206:              ponGroupSymbol = sp[0];
 207:              pon = ponNumber = int.Parse(sp[1]);
 208:              ontInternalNumber = int.Parse(sp[2]);
 209:   
 210:              oltId = (from Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Pon p in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.PonList where p.PonGroup.Symbol == ponGroupSymbol && p.Number == ponNumber select p.PonGroup.Olt.Id).SingleOrDefault();
 211:          }
 212:   
 213:          ////////////////////////////////////////////////////////////////////////////
 214:   
 215:          /// <summary>
 216:          ///
 217:          /// </summary>
 218:          public static string SqlInsertCommand(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, int areaId, string block, string street, string premisesOld, string premisesNew, string paci)
 219:          {
 220:              string id, sa, odf;
 221:              Guid userId;
 222:              DateTime dateTime;
 223:   
 224:              id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number);
 225:              odf = "";
 226:              userId = Guid.Empty;
 227:              dateTime = DateTime.UtcNow.AddHours(3);
 228:   
 229:              // Id Olt Pon Ont Odf AreaId  Block Street  PremisesOld PremisesNew Created Updated UserId
 230:              // 102010101001001 102010101   1   1   NULL    50502   8   17  271 22  2014 - 11 - 18 10:17:17.000 2015 - 03 - 12 12:25:45.680 4E42E245 - 2BAF - 4C11 - B4BF - 4D681123999F
 231:   
 232:              sa = @"insert into Accesses (Id,Olt,Pon,Ont,Odf,AreaId,Block,Street,PremisesOld,PremisesNew,Paci,Created,Updated,UserId) values ('" + id + "'," + nddOnt.Pon.PonGroup.Olt.Id + "," + nddOnt.Pon.Number + "," + nddOnt.Number + ",'" + odf + "'," + areaId + "," + block + ",'" + street + "','" + premisesOld + "','" + premisesNew + "','" + paci + "','" + dateTime + "','" + dateTime + "','" + userId.ToString() + "')";
 233:   
 234:              return sa;
 235:          }
 236:   
 237:          ////////////////////////////////////////////////////////////////////////////
 238:   
 239:          /// <summary>
 240:          ///
 241:          /// </summary>
 242:          public static Ia.Ngn.Cl.Model.Access Create(string input, string kuwaitNgnAreaSymbol, string block, string street, string premisesOld, string premisesNew, string odf, string paci, string note, Guid userId, out Ia.Cl.Model.Result result)
 243:          {
 244:              string accessName;
 245:              Ia.Ngn.Cl.Model.Access access;
 246:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 247:              Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 248:   
 249:              result = new Ia.Cl.Model.Result();
 250:              access = null;
 251:   
 252:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 253:              {
 254:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 255:   
 256:                  if (nddOnt != null)
 257:                  {
 258:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 259:   
 260:                      if (kuwaitNgnArea != null)
 261:                      {
 262:                          access = new Ia.Ngn.Cl.Model.Access
 263:                          {
 264:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 265:                              AreaId = kuwaitNgnArea.Id,
 266:                              Block = block,
 267:                              Street = street,
 268:                              PremisesOld = premisesOld,
 269:                              PremisesNew = premisesNew,
 270:                              Paci = paci,
 271:                              Note = note,
 272:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 273:                              Odf = odf,
 274:                              Pon = nddOnt.Pon.Number,
 275:                              Ont = nddOnt.Number,
 276:                              UserId = userId
 277:                          };
 278:   
 279:                          Ia.Ngn.Cl.Model.Data.Access.Create(access, out result);
 280:   
 281:                          if (result.IsSuccessful)
 282:                          {
 283:                              Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(access.Name);
 284:                          }
 285:                      }
 286:                      else
 287:                      {
 288:                          result.AddError("kuwaitNgnArea is null. ");
 289:                      }
 290:                  }
 291:                  else
 292:                  {
 293:                      result.AddError("nddOnt is null. ");
 294:                  }
 295:              }
 296:              else
 297:              {
 298:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network. ");
 299:              }
 300:   
 301:              return access;
 302:          }
 303:   
 304:          ////////////////////////////////////////////////////////////////////////////
 305:   
 306:          /// <summary>
 307:          ///
 308:          /// </summary>
 309:          public static Ia.Ngn.Cl.Model.Access CreateObject(string input, string kuwaitNgnAreaSymbol, string block, string street, string premisesOld, string premisesNew, string odf, string paci, string note, Guid userId, out Ia.Cl.Model.Result result)
 310:          {
 311:              string accessName;
 312:              Ia.Ngn.Cl.Model.Access access;
 313:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 314:              Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 315:   
 316:              result = new Ia.Cl.Model.Result();
 317:   
 318:              access = null;
 319:   
 320:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 321:              {
 322:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 323:   
 324:                  if (nddOnt != null)
 325:                  {
 326:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 327:   
 328:                      if (kuwaitNgnArea != null)
 329:                      {
 330:                          access = new Ia.Ngn.Cl.Model.Access
 331:                          {
 332:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 333:                              AreaId = kuwaitNgnArea.Id,
 334:                              Block = block,
 335:                              Street = street,
 336:                              PremisesOld = premisesOld,
 337:                              PremisesNew = premisesNew,
 338:                              Paci = paci,
 339:                              Note = note,
 340:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 341:                              Odf = odf,
 342:                              Pon = nddOnt.Pon.Number,
 343:                              Ont = nddOnt.Number,
 344:                              Created = DateTime.UtcNow.AddHours(3),
 345:                              Updated = DateTime.UtcNow.AddHours(3),
 346:                              UserId = userId
 347:                          };
 348:                      }
 349:                      else
 350:                      {
 351:                          result.AddError("kuwaitNgnArea is null. ");
 352:                      }
 353:                  }
 354:                  else
 355:                  {
 356:                      result.AddError("nddOnt is null. ");
 357:                  }
 358:              }
 359:              else
 360:              {
 361:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 362:              }
 363:   
 364:              return access;
 365:          }
 366:   
 367:          ////////////////////////////////////////////////////////////////////////////
 368:   
 369:          /// <summary>
 370:          ///
 371:          /// </summary>
 372:          public static void Delete(string inputAccessName, Guid userId, out Ia.Cl.Model.Result result)
 373:          {
 374:              string accessName, r;
 375:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 376:   
 377:              result = new Ia.Cl.Model.Result();
 378:   
 379:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(inputAccessName, out accessName))
 380:              {
 381:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 382:   
 383:                  if (nddOnt != null)
 384:                  {
 385:                      try
 386:                      {
 387:                          /*
 388:  --update ServiceRequestServices set Access_Id = null where Access_Id = '1040101010009013'
 389:  --update EmsOnts set Access_Id = null where Access_Id = '1040101010009013'
 390:  --update Onts set Access_Id = null where Access_Id = '1040101010009013'
 391:  --delete from Events where Ont_Id = (select id from Onts where Access_Id = '1040101010009013')
 392:  
 393:  --delete from ServiceRequestOntDetails where ServiceRequestOnts _Id = (select id from ServiceRequestOnts where Access_Id = '1040101010009013')
 394:  --delete from ServiceRequestOnts where Access_Id = '1040101010009013'
 395:  
 396:  --delete from Accesses where id = '1040101010009013'
 397:                           */
 398:                          Ia.Ngn.Cl.Model.Data.ServiceRequestService.NullifyAccessIdByAccessId(nddOnt.Access.Id, out r);
 399:   
 400:                          Ia.Ngn.Cl.Model.Data.Huawei.Ont.NullifyAccessIdByAccessId(nddOnt.Access.Id, out r);
 401:   
 402:                          Ia.Ngn.Cl.Model.Data.Nokia.Ont.NullifyAccessIdByAccessId(nddOnt.Access.Id, out r);
 403:   
 404:                          Ia.Ngn.Cl.Model.Data.Event.DeleteByAccessId(nddOnt.Access.Id, out r);
 405:   
 406:                          Ia.Ngn.Cl.Model.Data.ServiceRequestOntDetail.DeleteByAccessId(nddOnt.Access.Id, out r);
 407:   
 408:                          Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.DeleteByAccessId(nddOnt.Access.Id, out r);
 409:   
 410:                          Ia.Ngn.Cl.Model.Data.Access.Delete(nddOnt.Access.Id, out result);
 411:   
 412:                          if (result.IsSuccessful)
 413:                          {
 414:                              Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(nddOnt.Access.Name);
 415:                          }
 416:                          else
 417:                          {
 418:                              result.AddError("Error in Ia.Ngn.Cl.Model.Data.Access.Delete(): " + result);
 419:                          }
 420:                      }
 421:                      catch(Exception e)
 422:                      {
 423:                          result.AddError("Error in Ia.Ngn.Cl.Model.Business.Access.Delete(): inputAccessName: " + inputAccessName + ", exception string: " + e.ToString());
 424:                      }
 425:                  }
 426:                  else
 427:                  {
 428:                      result.AddError("nddOnt is null. ");
 429:                  }
 430:              }
 431:              else
 432:              {
 433:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 434:              }
 435:          }
 436:   
 437:          ////////////////////////////////////////////////////////////////////////////
 438:   
 439:          /// <summary>
 440:          ///
 441:          /// </summary>
 442:          public static void DeleteByAccessId(string accessId, Guid userId, out Ia.Cl.Model.Result result)
 443:          {
 444:              result = new Ia.Cl.Model.Result();
 445:   
 446:              Ia.Ngn.Cl.Model.Data.Access.Delete(accessId, out result);
 447:          }
 448:   
 449:          ////////////////////////////////////////////////////////////////////////////
 450:   
 451:          /// <summary>
 452:          ///
 453:          /// </summary>
 454:          public static string NormalizeBlockEntry(string input)
 455:          {
 456:              return input.ToLower();
 457:          }
 458:   
 459:          ////////////////////////////////////////////////////////////////////////////
 460:   
 461:          /// <summary>
 462:          /// Remove and replace inappropriate strings in access street data
 463:          /// </summary>
 464:          public static string NormalizeStreetEntry(string input)
 465:          {
 466:              string s;
 467:   
 468:              s = input.ToLower();
 469:   
 470:              if (s == "na") s = string.Empty;
 471:              else if (s == "n/a") s = string.Empty;
 472:              else if (s == "0") s = string.Empty;
 473:              else if (s == "#") s = string.Empty;
 474:   
 475:              s = s.Replace("#", "");
 476:   
 477:              return s;
 478:          }
 479:   
 480:          ////////////////////////////////////////////////////////////////////////////
 481:   
 482:          /// <summary>
 483:          /// Remove and replace inappropriate strings in access premises data
 484:          /// </summary>
 485:          public static string NormalizePremisesEntry(string input)
 486:          {
 487:              string s;
 488:   
 489:              s = input.ToLower();
 490:   
 491:              if (s == "na") s = string.Empty;
 492:              else if (s == "n/a") s = string.Empty;
 493:              else if (s == "0") s = string.Empty;
 494:              else if (s == "#") s = string.Empty;
 495:   
 496:              s = s.Replace("#", "");
 497:   
 498:              return s;
 499:          }
 500:   
 501:          ////////////////////////////////////////////////////////////////////////////
 502:   
 503:          /// <summary>
 504:          /// Remove and replace inappropriate strings in access PACI data. PACI numbers be have 8 digits
 505:          /// </summary>
 506:          public static string NormalizePaciEntry(string input)
 507:          {
 508:              if (Regex.IsMatch(input, @"\d{8}")) { }
 509:              else input = string.Empty;
 510:   
 511:              return input;
 512:          }
 513:   
 514:          ////////////////////////////////////////////////////////////////////////////
 515:   
 516:          /// <summary>
 517:          /// Correct the ONT serial number field
 518:          /// </summary>
 519:          public static string NormalizeOntSerialNumberEntry(string input)
 520:          {
 521:              string serial;
 522:   
 523:              serial = input.ToUpper();
 524:   
 525:              return serial;
 526:          }
 527:   
 528:          ////////////////////////////////////////////////////////////////////////////
 529:          ////////////////////////////////////////////////////////////////////////////
 530:      }
 531:   
 532:      ////////////////////////////////////////////////////////////////////////////
 533:      ////////////////////////////////////////////////////////////////////////////
 534:  }