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

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.Linq;
   3:  using System.Text;
   4:  using System.Text.RegularExpressions;
   5:  using System.Data;
   6:  using System.IO;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Ui.Provision
   9:  {
  10:      ////////////////////////////////////////////////////////////////////
  11:      ////////
  12:   
  13:      /// <summary publish="true">
  14:      /// Access support class for Next Generation Network (NGN) ui model.
  15:      /// </summary>
  16:      /// 
  17:      /// <remarks> 
  18:      /// Copyright © 2006-2019 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:          /// <summary/>
  33:          public Access() { }
  34:   
  35:          /////////////////////////////////////////////////////////////////////////////////
  36:   
  37:          /// <summary>
  38:          ///
  39:          /// </summary>
  40:          public static void Manage(Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact, string opcode, string operand, out string responseSubject, out string responseContent)
  41:          {
  42:              string line, accessNameRow, accessName, odf, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, paci, note;
  43:              string ontFamilyTypeString, ontSerialNumber, ip, serviceRequestOntDeleteResult, nullifyEmsOntAccessIdResult;
  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:                                                      accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(accessNameRow);
 101:   
 102:                                                      nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 103:   
 104:                                                      if (nddOnt != null)
 105:                                                      {
 106:                                                          if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 107:                                                          {
 108:                                                              ontFamilyType = Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyTypeFromString(ontFamilyTypeString);
 109:   
 110:                                                              if (ontFamilyType != Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType.Undefined)
 111:                                                              {
 112:                                                                  if (string.IsNullOrEmpty(ip) || ip == nddOnt.Ip)
 113:                                                                  {
 114:                                                                      note = ontFamilyTypeString + ": " + Ia.Ngn.Cl.Model.Business.Access.NormalizeOntSerialNumberEntry(ontSerialNumber);
 115:   
 116:                                                                      access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 117:   
 118:                                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 119:                                                                      stringBuilder.AppendLine(documentValidityResult.Message);
 120:                                                                      stringBuilder.AppendLine(" ");
 121:                                                                  }
 122:                                                                  else
 123:                                                                  {
 124:                                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 125:                                                                      stringBuilder.AppendLine(@"Error: Submitted IP: " + ip + " does not match the Network Design Document (NDD) IP: " + nddOnt.Ip + ". ");
 126:                                                                      stringBuilder.AppendLine(" ");
 127:                                                                  }
 128:                                                              }
 129:                                                              else
 130:                                                              {
 131:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 132:                                                                  stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 133:                                                                  stringBuilder.AppendLine(" ");
 134:                                                              }
 135:                                                          }
 136:                                                          else if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 137:                                                          {
 138:                                                              emsOntEquipmentType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeFromAccessSubmittalString(ontFamilyTypeString);
 139:   
 140:                                                              if (emsOntEquipmentType != Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType.Undefined)
 141:                                                              {
 142:                                                                  note = ontFamilyTypeString + ": " + Ia.Ngn.Cl.Model.Business.Access.NormalizeOntSerialNumberEntry(ontSerialNumber);
 143:   
 144:                                                                  access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 145:   
 146:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 147:                                                                  stringBuilder.AppendLine(documentValidityResult.Message);
 148:                                                                  stringBuilder.AppendLine(" ");
 149:                                                              }
 150:                                                              else
 151:                                                              {
 152:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 153:                                                                  stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 154:                                                                  stringBuilder.AppendLine(" ");
 155:                                                              }
 156:                                                          }
 157:                                                          else
 158:                                                          {
 159:                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 160:                                                              stringBuilder.AppendLine(@"Error: Access vendor is undefined. ");
 161:                                                              stringBuilder.AppendLine(" ");
 162:                                                          }
 163:                                                      }
 164:                                                      else
 165:                                                      {
 166:                                                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 167:                                                          stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + accessNameRow + ". Access vendor is undefined. ");
 168:                                                          stringBuilder.AppendLine(" ");
 169:                                                      }
 170:                                                  }
 171:                                                  else
 172:                                                  {
 173:                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 174:                                                      stringBuilder.AppendLine(@"Error: ONT serial """ + ontSerialNumber + @""" is not valid. ");
 175:                                                      stringBuilder.AppendLine(" ");
 176:                                                  }
 177:                                              }
 178:                                              else
 179:                                              {
 180:                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 181:                                                  stringBuilder.AppendLine(@"Error: ONT serial is null or zero. ");
 182:                                                  stringBuilder.AppendLine(" ");
 183:                                              }
 184:                                          }
 185:                                          else
 186:                                          {
 187:                                              // ref stringBuilder has a response
 188:                                              //stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 189:                                              //stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 190:                                              //stringBuilder.AppendLine(" ");
 191:                                          }
 192:                                      }
 193:                                  }
 194:                              }
 195:                              else
 196:                              {
 197:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 198:                                  stringBuilder.AppendLine(" ");
 199:                              }
 200:                          }
 201:   
 202:                          responseContent += stringBuilder.ToString();
 203:                          responseContent += "\r\n";
 204:                          //content += "\r\nResult: " + result.Message;
 205:   
 206:                          responseContent += "\r\n";
 207:                          responseContent += "\r\n";
 208:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 209:                          responseContent += "\r\n";
 210:                          responseContent += "\r\n";
 211:                      }
 212:                      else
 213:                      {
 214:                          responseContent += "\r\n";
 215:                          responseContent += "You are not authorized to modify this value. ";
 216:                          responseContent += "\r\n";
 217:                      }
 218:                  }
 219:                  else if (opcode.StartsWith("mail/provision/access/read"))
 220:                  {
 221:                      responseContent += "\r\n";
 222:                      responseContent += "This opcode is not defined yet. ";
 223:                      responseContent += "\r\n";
 224:                  }
 225:                  else if (opcode.StartsWith("mail/provision/access/delete"))
 226:                  {
 227:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Create, staffContact))
 228:                      {
 229:                          responseContent += @"Opcode: """ + opcode + @"""." + "\r\n";
 230:                          //content += @"Operand: """ + operand + @"""." + "\r\n";
 231:                          responseContent += "\r\n";
 232:   
 233:                          stringBuilder = new StringBuilder(10000);
 234:   
 235:                          using (StringReader reader = new StringReader(operand))
 236:                          {
 237:                              if (operand.Length > 0)
 238:                              {
 239:                                  while ((line = reader.ReadLine()) != null)
 240:                                  {
 241:                                      if (!string.IsNullOrEmpty(line)) // skip empty lines
 242:                                      {
 243:                                          accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(line);
 244:   
 245:                                          nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 246:   
 247:                                          if (nddOnt != null)
 248:                                          {
 249:                                              /*
 250:  --delete from Accesses where Id = '1110101012517020'
 251:  --delete from EmsOnts where Access_Id = '1110101012517020'
 252:  --delete from ServiceRequestOnts where Access_Id = '1110101012517020'
 253:                                               */
 254:                                              Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.DeleteByAccessId(nddOnt.Access.Id, out serviceRequestOntDeleteResult);
 255:                                              Ia.Ngn.Cl.Model.Data.Huawei.Ont.NullifyAccessIdByAccessId(nddOnt.Access.Id, out nullifyEmsOntAccessIdResult);
 256:                                              Ia.Ngn.Cl.Model.Business.Access.DeleteByAccessId(nddOnt.Access.Id, staffContact.UserId, out documentValidityResult);
 257:   
 258:                                              documentValidityResult.AddSuccess(serviceRequestOntDeleteResult);
 259:                                              documentValidityResult.AddSuccess(nullifyEmsOntAccessIdResult);
 260:   
 261:                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 262:                                              stringBuilder.AppendLine(documentValidityResult.Message);
 263:                                              stringBuilder.AppendLine(" ");
 264:                                          }
 265:                                          else
 266:                                          {
 267:                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 268:                                              stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + line + ". Access vendor is undefined. ");
 269:                                              stringBuilder.AppendLine(" ");
 270:                                          }
 271:                                      }
 272:                                  }
 273:                              }
 274:                              else
 275:                              {
 276:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 277:                                  stringBuilder.AppendLine(" ");
 278:                              }
 279:                          }
 280:   
 281:                          responseContent += stringBuilder.ToString();
 282:                          responseContent += "\r\n";
 283:                          //content += "\r\nResult: " + result.Message;
 284:   
 285:                          responseContent += "\r\n";
 286:                          responseContent += "\r\n";
 287:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 288:                          responseContent += "\r\n";
 289:                          responseContent += "\r\n";
 290:                      }
 291:                      else
 292:                      {
 293:                          responseContent += "\r\n";
 294:                          responseContent += "You are not authorized to delete this value. ";
 295:                          responseContent += "\r\n";
 296:                      }
 297:                  }
 298:                  else
 299:                  {
 300:                      responseContent += "\r\n";
 301:                      responseContent += "This opcode is not known. ";
 302:                      responseContent += "\r\n";
 303:                  }
 304:              }
 305:          }
 306:   
 307:          /////////////////////////////////////////////////////////////////////////////////
 308:   
 309:          /// <summary>
 310:          ///
 311:          /// </summary>
 312:          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)
 313:          {
 314:              bool matchSuccess;
 315:              int slNo, pon, pon2, pon3;
 316:              string accessName2, areaSymbol;
 317:              Match match;
 318:   
 319:              accessName = kuwaitNgnAreaSymbol = block = street = premisesOld = premisesNew = ontSerialNumber = ip = ontFamilyTypeString = odf = paci = string.Empty;
 320:   
 321:              // parse Huawei submittal line
 322:              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(.*?)$");
 323:   
 324:              if (match.Success)
 325:              {
 326:                  slNo = int.Parse(match.Groups[1].Value);
 327:                  pon = int.Parse(match.Groups[2].Value);
 328:                  pon2 = int.Parse(match.Groups[4].Value);
 329:                  pon3 = int.Parse(match.Groups[7].Value);
 330:   
 331:                  if (pon == pon2 && pon == pon3 && pon2 == pon3)
 332:                  {
 333:                      accessName = match.Groups[3].Value + "." + match.Groups[4].Value + "." + match.Groups[5].Value;
 334:                      accessName2 = match.Groups[6].Value + "." + match.Groups[7].Value + "." + match.Groups[8].Value;
 335:   
 336:                      kuwaitNgnAreaSymbol = match.Groups[10].Value;
 337:   
 338:                      if (accessName == accessName2 && accessName.StartsWith(kuwaitNgnAreaSymbol))
 339:                      {
 340:                          //mhNo = match.Groups[9].Value;
 341:                          block = match.Groups[11].Value;
 342:                          premisesNew = match.Groups[12].Value;
 343:                          street = match.Groups[13].Value;
 344:                          premisesOld = match.Groups[14].Value;
 345:                          paci = match.Groups[15].Value;
 346:                          ontSerialNumber = match.Groups[16].Value;
 347:                          ip = match.Groups[17].Value;
 348:                          ontFamilyTypeString = match.Groups[20].Value;
 349:                          //odfPort = match.Groups[19].Value;
 350:                          //oltPort = match.Groups[20].Value;
 351:   
 352:                          matchSuccess = true;
 353:                      }
 354:                      else
 355:                      {
 356:                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 357:                          stringBuilder.AppendLine(@"Error: TB.ID, ONT ID, and/or area symbol values don't match in line. ");
 358:                          stringBuilder.AppendLine(" ");
 359:   
 360:                          matchSuccess = false;
 361:                      }
 362:                  }
 363:                  else
 364:                  {
 365:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 366:                      stringBuilder.AppendLine(@"Error: Inconsistent PON, TB.ID and ONT ID values in line. ");
 367:                      stringBuilder.AppendLine(" ");
 368:   
 369:                      matchSuccess = false;
 370:                  }
 371:              }
 372:              else
 373:              {
 374:                  // parse Nokia submittal line
 375:                  match = Regex.Match(line, @"([a-zA-Z]{3})\.(\d{1,4})\.(\d{1,3})\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.+?)$");
 376:   
 377:                  if (match.Success)
 378:                  {
 379:                      areaSymbol = match.Groups[1].Value;
 380:                      kuwaitNgnAreaSymbol = areaSymbol;
 381:   
 382:                      accessName = areaSymbol + "." + match.Groups[2].Value + "." + match.Groups[3].Value;
 383:   
 384:                      premisesOld = match.Groups[6].Value;
 385:                      premisesNew = match.Groups[7].Value;
 386:                      street = match.Groups[5].Value;
 387:                      block = match.Groups[4].Value;
 388:                      paci = match.Groups[8].Value;
 389:   
 390:                      ontSerialNumber = match.Groups[9].Value;
 391:                      ip = string.Empty;
 392:                      ontFamilyTypeString = match.Groups[10].Value;
 393:   
 394:                      matchSuccess = true;
 395:                  }
 396:                  else
 397:                  {
 398:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 399:                      stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 400:                      stringBuilder.AppendLine(" ");
 401:   
 402:                      matchSuccess = false;
 403:                  }
 404:              }
 405:   
 406:              return matchSuccess;
 407:          }
 408:   
 409:          ////////////////////////////////////////////////////////////////////////////
 410:          ////////////////////////////////////////////////////////////////////////////
 411:      }
 412:  }