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

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) ui model.

   1:  using System;
   2:  using System.Data;
   3:  using System.IO;
   4:  using System.Linq;
   5:  using System.Text;
   6:  using System.Text.RegularExpressions;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Ui.Provision
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Access support class for Next Generation Network (NGN) ui model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class Access
  30:      {
  31:          /// <summary/>
  32:          public Access() { }
  33:   
  34:          /////////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static void Manage(Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact, string opcode, string operand, out string responseSubject, out string responseContent)
  40:          {
  41:              int i;
  42:              string line, accessNameRow, accessName, odf, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, paci, note;
  43:              string ontFamilyTypeString, ontSerialNumber, ip;
  44:              StringBuilder stringBuilder;
  45:              DateTime now;
  46:              Ia.Cl.Model.Result documentValidityResult;
  47:              Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType ontFamilyType;
  48:              Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType emsOntEquipmentType;
  49:              Ia.Ngn.Cl.Model.Access access;
  50:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt;
  51:   
  52:              documentValidityResult = new Ia.Cl.Model.Result();
  53:   
  54:              opcode = opcode.ToLower();
  55:   
  56:              now = DateTime.UtcNow.AddHours(3);
  57:   
  58:              // subject can't have \r\n
  59:              responseSubject = "Optical Fiber Network (OFN) Access Manager (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
  60:              responseContent = "Optical Fiber Network (OFN) Access Manager: " + now.ToString("yyyy-MM-dd HH:mm") + "\r\n";
  61:   
  62:              if (opcode.Contains("help"))
  63:              {
  64:                  responseContent += Ia.Ngn.Cl.Model.Data.Help.Text("mail/provision/access");
  65:                  responseContent += "\r\n";
  66:              }
  67:              else
  68:              {
  69:                  if (opcode.StartsWith("mail/provision/access/create"))
  70:                  {
  71:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Create, staffContact))
  72:                      {
  73:                          responseContent += @"Opcode: """ + opcode + @"""." + "\r\n";
  74:                          //content += @"Operand: """ + operand + @"""." + "\r\n";
  75:                          responseContent += "\r\n";
  76:   
  77:                          stringBuilder = new StringBuilder(10000);
  78:   
  79:                          using (StringReader reader = new StringReader(operand))
  80:                          {
  81:                              if (operand.Length > 0)
  82:                              {
  83:                                  while ((line = reader.ReadLine()) != null)
  84:                                  {
  85:                                      if (!string.IsNullOrEmpty(line)) // skip empty lines
  86:                                      {
  87:                                          if (ParseLine(line, ref stringBuilder, out accessNameRow, out kuwaitNgnAreaSymbol, out block, out street, out premisesOld, out premisesNew, out ontSerialNumber, out ip, out ontFamilyTypeString, out odf, out paci))
  88:                                          {
  89:                                              if (ontSerialNumber != "0" && !string.IsNullOrEmpty(ontSerialNumber))
  90:                                              {
  91:                                                  if (Ia.Ngn.Cl.Model.Business.Huawei.Ont.IsValidSerialNumber(ontSerialNumber) || Ia.Ngn.Cl.Model.Business.Nokia.Ont.IsValidSerialNumber(ontSerialNumber)) // to check Huawei and Nokia ONTs
  92:                                                  {
  93:                                                      block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(block);
  94:                                                      street = Ia.Ngn.Cl.Model.Business.Access.NormalizeStreetEntry(street);
  95:                                                      premisesOld = Ia.Ngn.Cl.Model.Business.Access.NormalizePremisesEntry(premisesOld);
  96:                                                      premisesNew = Ia.Ngn.Cl.Model.Business.Access.NormalizePremisesEntry(premisesNew);
  97:                                                      paci = Ia.Ngn.Cl.Model.Business.Access.NormalizePaciEntry(paci);
  98:                                                      odf = string.Empty; // odfPort;
  99:   
 100:                                                      // temp: I will exclude SBA for now from PACI requirements
 101:                                                      if (/*kuwaitNgnAreaSymbol == "SBA" ||*/ !string.IsNullOrEmpty(paci) && int.TryParse(paci, out i))
 102:                                                      {
 103:                                                          if (!string.IsNullOrEmpty(block) /*&& int.TryParse(block, out i)*/) // there are blocks with letters like block 7B
 104:                                                          {
 105:                                                              //if (!string.IsNullOrEmpty(street) && int.TryParse(street, out i))
 106:                                                              //{
 107:                                                              if (string.IsNullOrEmpty(premisesOld) || int.TryParse(premisesOld, out i))
 108:                                                              {
 109:                                                                  //if (string.IsNullOrEmpty(premisesNew) || int.TryParse(premisesNew, out i))
 110:                                                                  //{
 111:                                                                  accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(accessNameRow);
 112:   
 113:                                                                  nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 114:   
 115:                                                                  if (nddOnt != null)
 116:                                                                  {
 117:                                                                      if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 118:                                                                      {
 119:                                                                          ontFamilyType = Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyTypeFromString(ontFamilyTypeString);
 120:   
 121:                                                                          if (ontFamilyType != Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType.Undefined)
 122:                                                                          {
 123:                                                                              if (string.IsNullOrEmpty(ip) || ip == nddOnt.Ip)
 124:                                                                              {
 125:                                                                                  note = ontFamilyTypeString + ": " + Ia.Ngn.Cl.Model.Business.Access.NormalizeOntSerialNumberEntry(ontSerialNumber);
 126:   
 127:                                                                                  access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 128:   
 129:                                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 130:                                                                                  stringBuilder.AppendLine(documentValidityResult.Message);
 131:                                                                                  stringBuilder.AppendLine(" ");
 132:                                                                              }
 133:                                                                              else
 134:                                                                              {
 135:                                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 136:                                                                                  stringBuilder.AppendLine(@"Error: Submitted IP: " + ip + " does not match the Network Design Document (NDD) IP: " + nddOnt.Ip + ". ");
 137:                                                                                  stringBuilder.AppendLine(" ");
 138:                                                                              }
 139:                                                                          }
 140:                                                                          else
 141:                                                                          {
 142:                                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 143:                                                                              stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 144:                                                                              stringBuilder.AppendLine(" ");
 145:                                                                          }
 146:                                                                      }
 147:                                                                      else if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 148:                                                                      {
 149:                                                                          emsOntEquipmentType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeFromAccessSubmittalString(ontFamilyTypeString);
 150:   
 151:                                                                          if (emsOntEquipmentType != Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType.Undefined)
 152:                                                                          {
 153:                                                                              note = ontFamilyTypeString + ": " + Ia.Ngn.Cl.Model.Business.Access.NormalizeOntSerialNumberEntry(ontSerialNumber);
 154:   
 155:                                                                              access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 156:   
 157:                                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 158:                                                                              stringBuilder.AppendLine(documentValidityResult.Message);
 159:                                                                              stringBuilder.AppendLine(" ");
 160:                                                                          }
 161:                                                                          else
 162:                                                                          {
 163:                                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 164:                                                                              stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 165:                                                                              stringBuilder.AppendLine(" ");
 166:                                                                          }
 167:                                                                      }
 168:                                                                      else
 169:                                                                      {
 170:                                                                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 171:                                                                          stringBuilder.AppendLine(@"Error: Access vendor is undefined. ");
 172:                                                                          stringBuilder.AppendLine(" ");
 173:                                                                      }
 174:                                                                  }
 175:                                                                  else
 176:                                                                  {
 177:                                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 178:                                                                      stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + accessNameRow + ". Access vendor is undefined. ");
 179:                                                                      stringBuilder.AppendLine(" ");
 180:                                                                  }
 181:                                                              }
 182:                                                              //else
 183:                                                              //{
 184:                                                              //    stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 185:                                                              //    stringBuilder.AppendLine(@"Error: PremisesNew number is undefined or invalid. ");
 186:                                                              //    stringBuilder.AppendLine(" ");
 187:                                                              //}
 188:                                                              //}
 189:                                                              else
 190:                                                              {
 191:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 192:                                                                  stringBuilder.AppendLine(@"Error: PremisesOld (Parcel) number is undefined or invalid. ");
 193:                                                                  stringBuilder.AppendLine(" ");
 194:                                                              }
 195:                                                              //}
 196:                                                              //else
 197:                                                              //{
 198:                                                              //    stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 199:                                                              //    stringBuilder.AppendLine(@"Error: Street number is undefined or invalid. ");
 200:                                                              //    stringBuilder.AppendLine(" ");
 201:                                                              //}
 202:                                                          }
 203:                                                          else
 204:                                                          {
 205:                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 206:                                                              stringBuilder.AppendLine(@"Error: Block number is undefined or invalid. ");
 207:                                                              stringBuilder.AppendLine(" ");
 208:                                                          }
 209:                                                      }
 210:                                                      else
 211:                                                      {
 212:                                                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 213:                                                          stringBuilder.AppendLine(@"Error: PACI is undefined or invalid. ");
 214:                                                          stringBuilder.AppendLine(" ");
 215:                                                      }
 216:                                                  }
 217:                                                  else
 218:                                                  {
 219:                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 220:                                                      stringBuilder.AppendLine(@"Error: ONT serial """ + ontSerialNumber + @""" is not valid. ");
 221:                                                      stringBuilder.AppendLine(" ");
 222:                                                  }
 223:                                              }
 224:                                              else
 225:                                              {
 226:                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 227:                                                  stringBuilder.AppendLine(@"Error: ONT serial is null or zero. ");
 228:                                                  stringBuilder.AppendLine(" ");
 229:                                              }
 230:                                          }
 231:                                          else
 232:                                          {
 233:                                              // ref stringBuilder has a response
 234:                                              //stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 235:                                              //stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 236:                                              //stringBuilder.AppendLine(" ");
 237:                                          }
 238:                                      }
 239:                                  }
 240:                              }
 241:                              else
 242:                              {
 243:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 244:                                  stringBuilder.AppendLine(" ");
 245:                              }
 246:                          }
 247:   
 248:                          responseContent += stringBuilder.ToString();
 249:                          responseContent += "\r\n";
 250:                          //content += "\r\nResult: " + result.Message;
 251:   
 252:                          responseContent += "\r\n";
 253:                          responseContent += "\r\n";
 254:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 255:                          responseContent += "\r\n";
 256:                          responseContent += "\r\n";
 257:                      }
 258:                      else
 259:                      {
 260:                          responseContent += "\r\n";
 261:                          responseContent += "You are not authorized to modify this value. ";
 262:                          responseContent += "\r\n";
 263:                      }
 264:                  }
 265:                  else if (opcode.StartsWith("mail/provision/access/read"))
 266:                  {
 267:                      responseContent += "\r\n";
 268:                      responseContent += "This opcode is not defined yet. ";
 269:                      responseContent += "\r\n";
 270:                  }
 271:                  else if (opcode.StartsWith("mail/provision/access/delete"))
 272:                  {
 273:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Create, staffContact))
 274:                      {
 275:                          responseContent += @"Opcode: """ + opcode + @"""." + "\r\n";
 276:                          //content += @"Operand: """ + operand + @"""." + "\r\n";
 277:                          responseContent += "\r\n";
 278:   
 279:                          stringBuilder = new StringBuilder(10000);
 280:   
 281:                          using (StringReader reader = new StringReader(operand))
 282:                          {
 283:                              if (operand.Length > 0)
 284:                              {
 285:                                  while ((line = reader.ReadLine()) != null)
 286:                                  {
 287:                                      if (!string.IsNullOrEmpty(line)) // skip empty lines
 288:                                      {
 289:                                          accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(line);
 290:   
 291:                                          nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 292:   
 293:                                          if (nddOnt != null)
 294:                                          {
 295:                                              Ia.Ngn.Cl.Model.Business.Access.Delete(nddOnt.Access.Name, staffContact.UserId, out documentValidityResult);
 296:   
 297:                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 298:                                              stringBuilder.AppendLine(documentValidityResult.Message);
 299:                                              stringBuilder.AppendLine(" ");
 300:                                          }
 301:                                          else
 302:                                          {
 303:                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 304:                                              stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + line + ". Access vendor is undefined. ");
 305:                                              stringBuilder.AppendLine(" ");
 306:                                          }
 307:                                      }
 308:                                  }
 309:                              }
 310:                              else
 311:                              {
 312:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 313:                                  stringBuilder.AppendLine(" ");
 314:                              }
 315:                          }
 316:   
 317:                          responseContent += stringBuilder.ToString();
 318:                          responseContent += "\r\n";
 319:                          //content += "\r\nResult: " + result.Message;
 320:   
 321:                          responseContent += "\r\n";
 322:                          responseContent += "\r\n";
 323:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 324:                          responseContent += "\r\n";
 325:                          responseContent += "\r\n";
 326:                      }
 327:                      else
 328:                      {
 329:                          responseContent += "\r\n";
 330:                          responseContent += "You are not authorized to delete this value. ";
 331:                          responseContent += "\r\n";
 332:                      }
 333:                  }
 334:                  else
 335:                  {
 336:                      responseContent += "\r\n";
 337:                      responseContent += "This opcode is not known. ";
 338:                      responseContent += "\r\n";
 339:                  }
 340:              }
 341:          }
 342:   
 343:          /////////////////////////////////////////////////////////////////////////////////
 344:   
 345:          /// <summary>
 346:          ///
 347:          /// </summary>
 348:          private static bool ParseLine(string line, ref StringBuilder stringBuilder, out string accessName, out string kuwaitNgnAreaSymbol, out string block, out string street, out string premisesOld, out string premisesNew, out string ontSerialNumber, out string ip, out string ontFamilyTypeString, out string odf, out string paci)
 349:          {
 350:              bool matchSuccess;
 351:              int slNo, pon, pon2, pon3;
 352:              string accessName2, areaSymbol;
 353:              Match match;
 354:   
 355:              accessName = kuwaitNgnAreaSymbol = block = street = premisesOld = premisesNew = ontSerialNumber = ip = ontFamilyTypeString = odf = paci = string.Empty;
 356:   
 357:              // parse Huawei submittal line
 358:              match = Regex.Match(line, @"(\d+?)\t(\d+?)\t(\w\w\w)\.(\d+?)\.(\d+?)\t(\w\w\w)\.(\d+?)\.(\d+?)\t(.*?)\t(\w\w\w)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)$");
 359:              // [5  1126  SMC.1126.002      SMC.1126.002      SHX011      SMC   1     NA    5      PUBLICSERVICCO    18032043    4857544390755A78  10.150.131.34     NA    66081089      MA5616-96]
 360:              if (match.Success)
 361:              {
 362:                  slNo = int.Parse(match.Groups[1].Value);
 363:                  pon = int.Parse(match.Groups[2].Value);
 364:                  pon2 = int.Parse(match.Groups[4].Value);
 365:                  pon3 = int.Parse(match.Groups[7].Value);
 366:   
 367:                  if (pon == pon2 && pon == pon3 && pon2 == pon3)
 368:                  {
 369:                      accessName = match.Groups[3].Value + "." + match.Groups[4].Value + "." + match.Groups[5].Value;
 370:                      accessName2 = match.Groups[6].Value + "." + match.Groups[7].Value + "." + match.Groups[8].Value;
 371:   
 372:                      kuwaitNgnAreaSymbol = match.Groups[10].Value;
 373:   
 374:                      if (accessName == accessName2 && accessName.StartsWith(kuwaitNgnAreaSymbol))
 375:                      {
 376:                          //mhNo = match.Groups[9].Value;
 377:                          block = match.Groups[11].Value;
 378:                          premisesNew = match.Groups[12].Value;
 379:                          street = match.Groups[13].Value;
 380:                          premisesOld = match.Groups[14].Value;
 381:                          paci = match.Groups[15].Value;
 382:                          ontSerialNumber = match.Groups[16].Value;
 383:                          ip = match.Groups[17].Value;
 384:                          ontFamilyTypeString = match.Groups[20].Value;
 385:                          //odfPort = match.Groups[19].Value;
 386:                          //oltPort = match.Groups[20].Value;
 387:   
 388:                          matchSuccess = true;
 389:                      }
 390:                      else
 391:                      {
 392:                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 393:                          stringBuilder.AppendLine(@"Error: TB.ID, ONT ID, and/or area symbol values don't match in line. ");
 394:                          stringBuilder.AppendLine(" ");
 395:   
 396:                          matchSuccess = false;
 397:                      }
 398:                  }
 399:                  else
 400:                  {
 401:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 402:                      stringBuilder.AppendLine(@"Error: Inconsistent PON, TB.ID and ONT ID values in line. ");
 403:                      stringBuilder.AppendLine(" ");
 404:   
 405:                      matchSuccess = false;
 406:                  }
 407:              }
 408:              else
 409:              {
 410:                  // parse Nokia submittal line
 411:                  match = Regex.Match(line, @"([a-zA-Z]{3})\.(\d{1,4})\.(\d{1,3})\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.+?)$");
 412:   
 413:                  if (match.Success)
 414:                  {
 415:                      areaSymbol = match.Groups[1].Value;
 416:                      kuwaitNgnAreaSymbol = areaSymbol;
 417:   
 418:                      accessName = areaSymbol + "." + match.Groups[2].Value + "." + match.Groups[3].Value;
 419:   
 420:                      premisesOld = match.Groups[6].Value;
 421:                      premisesNew = match.Groups[7].Value;
 422:                      street = match.Groups[5].Value;
 423:                      block = match.Groups[4].Value;
 424:                      paci = match.Groups[8].Value;
 425:   
 426:                      ontSerialNumber = match.Groups[9].Value;
 427:                      ip = string.Empty;
 428:                      ontFamilyTypeString = match.Groups[10].Value;
 429:   
 430:                      matchSuccess = true;
 431:                  }
 432:                  else
 433:                  {
 434:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 435:                      stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 436:                      stringBuilder.AppendLine(" ");
 437:   
 438:                      matchSuccess = false;
 439:                  }
 440:              }
 441:   
 442:              return matchSuccess;
 443:          }
 444:   
 445:          ////////////////////////////////////////////////////////////////////////////
 446:          ////////////////////////////////////////////////////////////////////////////
 447:      }
 448:  }