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

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