Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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:              if (!string.IsNullOrEmpty(accessId))
 105:              {
 106:                  //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();
 107:                  name = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary[accessId];
 108:              }
 109:              else name = string.Empty;
 110:   
 111:              return name;
 112:          }
 113:   
 114:          /*
 115:          ////////////////////////////////////////////////////////////////////////////
 116:  
 117:          /// <summary>
 118:          ///
 119:          /// </summary>
 120:          public static string Name(string accessId)
 121:          {
 122:              string name;
 123:              int oltId, ponNumber, ontNumber;
 124:  
 125:              ExtractOltIdAndPonNumberAndOntNumberFromAccessId(accessId, out oltId, out ponNumber, out ontNumber);
 126:  
 127:              if (oltId > 0 && ponNumber > 0 && ontNumber > 0)
 128:              {
 129:                  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();
 130:              }
 131:              else name = string.Empty;
 132:  
 133:              return name;
 134:          }
 135:          */
 136:   
 137:          ////////////////////////////////////////////////////////////////////////////
 138:   
 139:          /// <summary>
 140:          ///
 141:          /// </summary>
 142:          public static string Name(string areaSymbol, int pon, int ont)
 143:          {
 144:              string name;
 145:   
 146:              name = areaSymbol + "." + pon + "." + ont;
 147:   
 148:              return name;
 149:          }
 150:   
 151:          ////////////////////////////////////////////////////////////////////////////
 152:   
 153:          /// <summary>
 154:          ///
 155:          /// </summary>
 156:          private static void ExtractOltIdAndPonNumberAndOntNumberFromAccessId(string accessId, out int oltId, out int ponNumber, out int ontNumber)
 157:          {
 158:              string s;
 159:   
 160:              if (!string.IsNullOrEmpty(accessId))
 161:              {
 162:                  s = accessId.Substring(accessId.Length - 3, 3);
 163:   
 164:                  if (int.TryParse(s, out ontNumber))
 165:                  {
 166:                      accessId = accessId.Remove(accessId.Length - 3, 3);
 167:   
 168:                      s = accessId.Substring(accessId.Length - 4, 4);
 169:   
 170:                      if (int.TryParse(s, out ponNumber))
 171:                      {
 172:                          s = accessId.Remove(accessId.Length - 4, 4);
 173:   
 174:                          if (int.TryParse(s, out oltId))
 175:                          {
 176:   
 177:                          }
 178:                          else oltId = ponNumber = ontNumber = 0;
 179:                      }
 180:                      else oltId = ponNumber = ontNumber = 0;
 181:                  }
 182:                  else oltId = ponNumber = ontNumber = 0;
 183:              }
 184:              else oltId = ponNumber = ontNumber = 0;
 185:          }
 186:   
 187:          ////////////////////////////////////////////////////////////////////////////
 188:   
 189:          /// <summary>
 190:          ///
 191:          /// </summary>
 192:          public static void ExtractOltIdAndPonNumberAndOntNumberFromOntName(string accessName, out int oltId, out int pon, out int ontInternalNumber)
 193:          {
 194:              // below: this expects accessName in exact format like SUR.12.3
 195:              int ponNumber;
 196:              string ponGroupSymbol;
 197:              string[] sp;
 198:   
 199:              sp = accessName.Split('.');
 200:   
 201:              ponGroupSymbol = sp[0];
 202:              pon = ponNumber = int.Parse(sp[1]);
 203:              ontInternalNumber = int.Parse(sp[2]);
 204:   
 205:              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();
 206:          }
 207:   
 208:          ////////////////////////////////////////////////////////////////////////////
 209:   
 210:          /// <summary>
 211:          ///
 212:          /// </summary>
 213:          public static string SqlInsertCommand(Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt, int areaId, string block, string street, string premisesOld, string premisesNew, string paci)
 214:          {
 215:              string id, sa, odf;
 216:              Guid userId;
 217:              DateTime dateTime;
 218:   
 219:              id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number);
 220:              odf = "";
 221:              userId = Guid.Empty;
 222:              dateTime = DateTime.UtcNow.AddHours(3);
 223:   
 224:              // Id Olt Pon Ont Odf AreaId  Block Street  PremisesOld PremisesNew Created Updated UserId
 225:              // 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
 226:   
 227:              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() + "')";
 228:   
 229:              return sa;
 230:          }
 231:   
 232:          ////////////////////////////////////////////////////////////////////////////
 233:   
 234:          /// <summary>
 235:          ///
 236:          /// </summary>
 237:          public static Ia.Ngn.Cl.Model.Access Create(string _ontName, string kuwaitNgnAreaSymbol, string block, string street, string premisesOld, string premisesNew, string odf, string paci, string note, Guid userId, out Ia.Cl.Model.Result result)
 238:          {
 239:              string accessName;
 240:              Ia.Ngn.Cl.Model.Access access;
 241:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 242:              Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 243:   
 244:              result = new Ia.Cl.Model.Result();
 245:              access = null;
 246:   
 247:              accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(_ontName);
 248:   
 249:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(accessName))
 250:              {
 251:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 252:   
 253:                  if (nddOnt != null)
 254:                  {
 255:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 256:   
 257:                      if (kuwaitNgnArea != null)
 258:                      {
 259:                          access = new Ia.Ngn.Cl.Model.Access
 260:                          {
 261:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 262:                              AreaId = kuwaitNgnArea.Id,
 263:                              Block = block,
 264:                              Street = street,
 265:                              PremisesOld = premisesOld,
 266:                              PremisesNew = premisesNew,
 267:                              Paci = paci,
 268:                              Note = note,
 269:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 270:                              Odf = odf,
 271:                              Pon = nddOnt.Pon.Number,
 272:                              Ont = nddOnt.Number,
 273:                              UserId = userId
 274:                          };
 275:   
 276:                          Ia.Ngn.Cl.Model.Data.Access.Create(access, out result);
 277:   
 278:                          if (result.IsSuccessful)
 279:                          {
 280:                              Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(access.Name);
 281:                          }
 282:                      }
 283:                      else
 284:                      {
 285:                          result.AddError("kuwaitNgnArea is null. ");
 286:                      }
 287:                  }
 288:                  else
 289:                  {
 290:                      result.AddError("nddOnt is null. ");
 291:                  }
 292:              }
 293:              else
 294:              {
 295:                  result.AddError("The ONT \"" + _ontName + "\" does not belong to the network. ");
 296:              }
 297:   
 298:              return access;
 299:          }
 300:   
 301:          ////////////////////////////////////////////////////////////////////////////
 302:   
 303:          /// <summary>
 304:          ///
 305:          /// </summary>
 306:          public static Ia.Ngn.Cl.Model.Access CreateObject(string _ontName, string kuwaitNgnAreaSymbol, string block, string street, string premisesOld, string premisesNew, string odf, string paci, string note, Guid userId, out Ia.Cl.Model.Result result)
 307:          {
 308:              string accessName;
 309:              Ia.Ngn.Cl.Model.Access access;
 310:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 311:              Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 312:   
 313:              result = new Ia.Cl.Model.Result();
 314:   
 315:              access = null;
 316:   
 317:              accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(_ontName);
 318:   
 319:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(accessName))
 320:              {
 321:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 322:   
 323:                  if (nddOnt != null)
 324:                  {
 325:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 326:   
 327:                      if (kuwaitNgnArea != null)
 328:                      {
 329:                          access = new Ia.Ngn.Cl.Model.Access
 330:                          {
 331:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 332:                              AreaId = kuwaitNgnArea.Id,
 333:                              Block = block,
 334:                              Street = street,
 335:                              PremisesOld = premisesOld,
 336:                              PremisesNew = premisesNew,
 337:                              Paci = paci,
 338:                              Note = note,
 339:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 340:                              Odf = odf,
 341:                              Pon = nddOnt.Pon.Number,
 342:                              Ont = nddOnt.Number,
 343:                              Created = DateTime.UtcNow.AddHours(3),
 344:                              Updated = DateTime.UtcNow.AddHours(3),
 345:                              UserId = userId
 346:                          };
 347:                      }
 348:                      else
 349:                      {
 350:                          result.AddError("kuwaitNgnArea is null. ");
 351:                      }
 352:                  }
 353:                  else
 354:                  {
 355:                      result.AddError("nddOnt is null. ");
 356:                  }
 357:              }
 358:              else
 359:              {
 360:                  result.AddError("The ONT \"" + _ontName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 361:              }
 362:   
 363:              return access;
 364:          }
 365:   
 366:          ////////////////////////////////////////////////////////////////////////////
 367:   
 368:          /// <summary>
 369:          ///
 370:          /// </summary>
 371:          public static void Delete(string _ontName, Guid userId, out Ia.Cl.Model.Result result)
 372:          {
 373:              string accessName;
 374:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 375:   
 376:              result = new Ia.Cl.Model.Result();
 377:   
 378:              accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(_ontName);
 379:   
 380:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(accessName))
 381:              {
 382:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 383:   
 384:                  if (nddOnt != null)
 385:                  {
 386:                      Ia.Ngn.Cl.Model.Data.Access.Delete(nddOnt.Access.Id, out result);
 387:   
 388:                      if (result.IsSuccessful)
 389:                      {
 390:                          Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(nddOnt.Access.Name);
 391:                      }
 392:                  }
 393:                  else
 394:                  {
 395:                      result.AddError("nddOnt is null. ");
 396:                  }
 397:              }
 398:              else
 399:              {
 400:                  result.AddError("The ONT \"" + _ontName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 401:              }
 402:          }
 403:   
 404:          ////////////////////////////////////////////////////////////////////////////
 405:   
 406:          /// <summary>
 407:          /// Remove and replace inappropriate strings in access block data
 408:          /// </summary>
 409:          public static string NormalizeBlockEntry(string input)
 410:          {
 411:              string block;
 412:   
 413:              block = input.ToUpper();
 414:   
 415:              return block;
 416:          }
 417:   
 418:          ////////////////////////////////////////////////////////////////////////////
 419:   
 420:          /// <summary>
 421:          /// Remove and replace inappropriate strings in access street data
 422:          /// </summary>
 423:          public static string NormalizeStreetEntry(string input)
 424:          {
 425:              string street;
 426:   
 427:              if (input.ToUpper() == "N/A") input = string.Empty;
 428:              else if (input.ToUpper() == "NA") input = string.Empty;
 429:              else if (input.ToUpper() == "0") input = string.Empty;
 430:   
 431:              street = input.ToLower();
 432:   
 433:              return street;
 434:          }
 435:   
 436:          ////////////////////////////////////////////////////////////////////////////
 437:   
 438:          /// <summary>
 439:          /// Remove and replace inappropriate strings in access premises data
 440:          /// </summary>
 441:          public static string NormalizePremisesEntry(string input)
 442:          {
 443:              string premises;
 444:   
 445:              if (input.ToUpper() == "N/A") input = string.Empty;
 446:              else if (input.ToUpper() == "NA") input = string.Empty;
 447:              else if (input.ToUpper() == "0") input = string.Empty;
 448:   
 449:              premises = input.ToLower();
 450:   
 451:              return premises;
 452:          }
 453:   
 454:          ////////////////////////////////////////////////////////////////////////////
 455:   
 456:          /// <summary>
 457:          /// Remove and replace inappropriate strings in access PACI data. PACI numbers be have 8 digits
 458:          /// </summary>
 459:          public static string NormalizePaciEntry(string input)
 460:          {
 461:              if (Regex.IsMatch(input, @"\d{8}")) { }
 462:              else input = string.Empty;
 463:   
 464:              return input;
 465:          }
 466:   
 467:          ////////////////////////////////////////////////////////////////////////////
 468:   
 469:          /// <summary>
 470:          /// Correct the ONT serial number field
 471:          /// </summary>
 472:          public static string NormalizeOntSerialNumberEntry(string input)
 473:          {
 474:              string serial;
 475:   
 476:              serial = input.ToUpper();
 477:   
 478:              return serial;
 479:          }
 480:   
 481:          ////////////////////////////////////////////////////////////////////////////
 482:          ////////////////////////////////////////////////////////////////////////////
 483:      }
 484:   
 485:      ////////////////////////////////////////////////////////////////////////////
 486:      ////////////////////////////////////////////////////////////////////////////
 487:  }