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

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:              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 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)
 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:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 248:              {
 249:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 250:   
 251:                  if (nddOnt != null)
 252:                  {
 253:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 254:   
 255:                      if (kuwaitNgnArea != null)
 256:                      {
 257:                          access = new Ia.Ngn.Cl.Model.Access
 258:                          {
 259:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 260:                              AreaId = kuwaitNgnArea.Id,
 261:                              Block = block,
 262:                              Street = street,
 263:                              PremisesOld = premisesOld,
 264:                              PremisesNew = premisesNew,
 265:                              Paci = paci,
 266:                              Note = note,
 267:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 268:                              Odf = odf,
 269:                              Pon = nddOnt.Pon.Number,
 270:                              Ont = nddOnt.Number,
 271:                              UserId = userId
 272:                          };
 273:   
 274:                          Ia.Ngn.Cl.Model.Data.Access.Create(access, out result);
 275:   
 276:                          if (result.IsSuccessful)
 277:                          {
 278:                              Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(access.Name);
 279:                          }
 280:                      }
 281:                      else
 282:                      {
 283:                          result.AddError("kuwaitNgnArea is null. ");
 284:                      }
 285:                  }
 286:                  else
 287:                  {
 288:                      result.AddError("nddOnt is null. ");
 289:                  }
 290:              }
 291:              else
 292:              {
 293:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network. ");
 294:              }
 295:   
 296:              return access;
 297:          }
 298:   
 299:          ////////////////////////////////////////////////////////////////////////////
 300:   
 301:          /// <summary>
 302:          ///
 303:          /// </summary>
 304:          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)
 305:          {
 306:              string accessName;
 307:              Ia.Ngn.Cl.Model.Access access;
 308:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 309:              Ia.Ngn.Cl.Model.Business.Service.KuwaitNgnArea kuwaitNgnArea;
 310:   
 311:              result = new Ia.Cl.Model.Result();
 312:   
 313:              access = null;
 314:   
 315:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 316:              {
 317:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 318:   
 319:                  if (nddOnt != null)
 320:                  {
 321:                      kuwaitNgnArea = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Symbol == kuwaitNgnAreaSymbol select kna).SingleOrDefault();
 322:   
 323:                      if (kuwaitNgnArea != null)
 324:                      {
 325:                          access = new Ia.Ngn.Cl.Model.Access
 326:                          {
 327:                              Id = Ia.Ngn.Cl.Model.Business.Access.AccessId(nddOnt.Pon.PonGroup.Olt.Id, nddOnt.Pon.Number, nddOnt.Number),
 328:                              AreaId = kuwaitNgnArea.Id,
 329:                              Block = block,
 330:                              Street = street,
 331:                              PremisesOld = premisesOld,
 332:                              PremisesNew = premisesNew,
 333:                              Paci = paci,
 334:                              Note = note,
 335:                              Olt = nddOnt.Pon.PonGroup.Olt.Id,
 336:                              Odf = odf,
 337:                              Pon = nddOnt.Pon.Number,
 338:                              Ont = nddOnt.Number,
 339:                              Created = DateTime.UtcNow.AddHours(3),
 340:                              Updated = DateTime.UtcNow.AddHours(3),
 341:                              UserId = userId
 342:                          };
 343:                      }
 344:                      else
 345:                      {
 346:                          result.AddError("kuwaitNgnArea is null. ");
 347:                      }
 348:                  }
 349:                  else
 350:                  {
 351:                      result.AddError("nddOnt is null. ");
 352:                  }
 353:              }
 354:              else
 355:              {
 356:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 357:              }
 358:   
 359:              return access;
 360:          }
 361:   
 362:          ////////////////////////////////////////////////////////////////////////////
 363:   
 364:          /// <summary>
 365:          ///
 366:          /// </summary>
 367:          public static void Delete(string input, Guid userId, out Ia.Cl.Model.Result result)
 368:          {
 369:              string accessName;
 370:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
 371:   
 372:              result = new Ia.Cl.Model.Result();
 373:   
 374:              if (Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.AccessNameIsWithinAllowedOntList(input, out accessName))
 375:              {
 376:                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 377:   
 378:                  if (nddOnt != null)
 379:                  {
 380:                      Ia.Ngn.Cl.Model.Data.Access.Delete(nddOnt.Access.Id, out result);
 381:   
 382:                      if (result.IsSuccessful)
 383:                      {
 384:                          Ia.Ngn.Cl.Model.Data.Msmq.AccessNameQueue.Enqueue(nddOnt.Access.Name);
 385:                      }
 386:                  }
 387:                  else
 388:                  {
 389:                      result.AddError("nddOnt is null. ");
 390:                  }
 391:              }
 392:              else
 393:              {
 394:                  result.AddError("The ONT \"" + accessName + "\" does not belong to the network (الصندوق لا ينتمي للشبكة). ");
 395:              }
 396:          }
 397:   
 398:          ////////////////////////////////////////////////////////////////////////////
 399:   
 400:          /// <summary>
 401:          ///
 402:          /// </summary>
 403:          public static void DeleteByAccessId(string accessId, Guid userId, out Ia.Cl.Model.Result result)
 404:          {
 405:              result = new Ia.Cl.Model.Result();
 406:   
 407:              Ia.Ngn.Cl.Model.Data.Access.Delete(accessId, out result);
 408:          }
 409:   
 410:          ////////////////////////////////////////////////////////////////////////////
 411:   
 412:          /// <summary>
 413:          /// Block must be a number
 414:          /// </summary>
 415:          public static string NormalizeBlockEntry(string input)
 416:          {
 417:              return input.ToLower();
 418:          }
 419:   
 420:          ////////////////////////////////////////////////////////////////////////////
 421:   
 422:          /// <summary>
 423:          /// Remove and replace inappropriate strings in access street data
 424:          /// </summary>
 425:          public static string NormalizeStreetEntry(string input)
 426:          {
 427:              string street;
 428:   
 429:              if (input.ToUpper() == "N/A") input = string.Empty;
 430:              else if (input.ToUpper() == "NA") input = string.Empty;
 431:              else if (input.ToUpper() == "0") input = string.Empty;
 432:   
 433:              street = input.ToLower();
 434:   
 435:              return street;
 436:          }
 437:   
 438:          ////////////////////////////////////////////////////////////////////////////
 439:   
 440:          /// <summary>
 441:          /// Remove and replace inappropriate strings in access premises data
 442:          /// </summary>
 443:          public static string NormalizePremisesEntry(string input)
 444:          {
 445:              string premises;
 446:   
 447:              if (input.ToUpper() == "N/A") input = string.Empty;
 448:              else if (input.ToUpper() == "NA") input = string.Empty;
 449:              else if (input.ToUpper() == "0") input = string.Empty;
 450:   
 451:              premises = input.ToLower();
 452:   
 453:              return premises;
 454:          }
 455:   
 456:          ////////////////////////////////////////////////////////////////////////////
 457:   
 458:          /// <summary>
 459:          /// Remove and replace inappropriate strings in access PACI data. PACI numbers be have 8 digits
 460:          /// </summary>
 461:          public static string NormalizePaciEntry(string input)
 462:          {
 463:              if (Regex.IsMatch(input, @"\d{8}")) { }
 464:              else input = string.Empty;
 465:   
 466:              return input;
 467:          }
 468:   
 469:          ////////////////////////////////////////////////////////////////////////////
 470:   
 471:          /// <summary>
 472:          /// Correct the ONT serial number field
 473:          /// </summary>
 474:          public static string NormalizeOntSerialNumberEntry(string input)
 475:          {
 476:              string serial;
 477:   
 478:              serial = input.ToUpper();
 479:   
 480:              return serial;
 481:          }
 482:   
 483:          ////////////////////////////////////////////////////////////////////////////
 484:          ////////////////////////////////////////////////////////////////////////////
 485:      }
 486:   
 487:      ////////////////////////////////////////////////////////////////////////////
 488:      ////////////////////////////////////////////////////////////////////////////
 489:  }