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