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) 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-2018 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 s, block, line, accessName, accessName2, odf, kuwaitNgnAreaSymbol, street, premisesOld, premisesNew, paci, note;
  43:              string ontFamilyTypeString, ontSerialNumber, onuDeleteResult, serviceRequestOntDeleteResult;
  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:              Ia.Ngn.Cl.Model.Huawei.Onu onu;
  52:   
  53:              documentValidityResult = new Ia.Cl.Model.Result();
  54:   
  55:              opcode = opcode.ToLower();
  56:   
  57:              now = DateTime.UtcNow.AddHours(3);
  58:   
  59:              // subject can't have \r\n
  60:              responseSubject = "Optical Fiber Network (OFN) Access Manager (" + now.ToString("yyyy-MM-dd HH:mm") + ")";
  61:              responseContent = "Optical Fiber Network (OFN) Access Manager: " + now.ToString("yyyy-MM-dd HH:mm") + "\r\n";
  62:   
  63:              if (opcode.Contains("help"))
  64:              {
  65:                  responseContent += Ia.Ngn.Cl.Model.Data.Help.Text("mail/provision/access");
  66:                  responseContent += "\r\n";
  67:              }
  68:              else
  69:              {
  70:                  if (opcode.StartsWith("mail/provision/access/create"))
  71:                  {
  72:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Create, staffContact))
  73:                      {
  74:                          responseContent += @"Opcode: """ + opcode + @"""." + "\r\n";
  75:                          //content += @"Operand: """ + operand + @"""." + "\r\n";
  76:                          responseContent += "\r\n";
  77:   
  78:                          stringBuilder = new StringBuilder(10000);
  79:   
  80:                          using (StringReader reader = new StringReader(operand))
  81:                          {
  82:                              if (operand.Length > 0)
  83:                              {
  84:                                  while ((line = reader.ReadLine()) != null)
  85:                                  {
  86:                                      if (!string.IsNullOrEmpty(line)) // skip empty lines
  87:                                      {
  88:                                          if (ParseLine(line, ref stringBuilder, out accessName, out kuwaitNgnAreaSymbol, out block, out street, out premisesOld, out premisesNew, out ontSerialNumber, out ontFamilyTypeString, out odf, out paci))
  89:                                          {
  90:                                              if (ontSerialNumber != "0" && !string.IsNullOrEmpty(ontSerialNumber))
  91:                                              {
  92:                                                  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
  93:                                                  {
  94:                                                      block = Ia.Ngn.Cl.Model.Business.Access.NormalizeBlockEntry(block);
  95:                                                      street = Ia.Ngn.Cl.Model.Business.Access.NormalizeStreetEntry(street);
  96:                                                      premisesOld = Ia.Ngn.Cl.Model.Business.Access.NormalizePremisesEntry(premisesOld);
  97:                                                      premisesNew = Ia.Ngn.Cl.Model.Business.Access.NormalizePremisesEntry(premisesNew);
  98:                                                      paci = Ia.Ngn.Cl.Model.Business.Access.NormalizePaciEntry(paci);
  99:                                                      odf = string.Empty; // odfPort;
 100:                                                      note = Ia.Ngn.Cl.Model.Business.Access.NormalizeOntSerialNumberEntry(ontSerialNumber);
 101:   
 102:                                                      accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(accessName);
 103:   
 104:                                                      nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 105:   
 106:                                                      if (nddOnt != null)
 107:                                                      {
 108:                                                          if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Nokia)
 109:                                                          {
 110:                                                              ontFamilyType = Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyTypeFromString(ontFamilyTypeString);
 111:   
 112:                                                              //if (ontFamilyType != Ia.Ngn.Cl.Model.Business.Nokia.Ont.FamilyType.Undefined)
 113:                                                              //{
 114:                                                              access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 115:   
 116:                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 117:                                                              stringBuilder.AppendLine(documentValidityResult.Message);
 118:                                                              stringBuilder.AppendLine(" ");
 119:                                                              /*}
 120:                                                              else
 121:                                                              {
 122:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 123:                                                                  stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 124:                                                                  stringBuilder.AppendLine(" ");
 125:                                                              }*/
 126:                                                          }
 127:                                                          else if (nddOnt.Pon.PonGroup.Olt.Odf.Vendor == Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor.Huawei)
 128:                                                          {
 129:                                                              emsOntEquipmentType = Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeFromString(ontFamilyTypeString);
 130:   
 131:                                                              if (emsOntEquipmentType != Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentType.Undefined)
 132:                                                              {
 133:                                                                  access = Ia.Ngn.Cl.Model.Business.Access.Create(accessName, kuwaitNgnAreaSymbol, block, street, premisesOld, premisesNew, odf, paci, note, staffContact.UserId, out documentValidityResult);
 134:   
 135:                                                                  if (documentValidityResult.IsSuccessful)
 136:                                                                  {
 137:                                                                      onu = new Ia.Ngn.Cl.Model.Huawei.Onu
 138:                                                                      {
 139:                                                                          Id = Ia.Ngn.Cl.Model.Business.Huawei.Onu.OnuId(nddOnt.Id),
 140:                                                                          Access = access,
 141:                                                                          FamilyTypeId = (int)emsOntEquipmentType,
 142:                                                                          Serial = ontSerialNumber
 143:                                                                      };
 144:   
 145:                                                                      Ia.Ngn.Cl.Model.Data.Huawei.Onu.Create(onu, out s);
 146:                                                                  }
 147:                                                                  else
 148:                                                                  {
 149:                                                                  }
 150:   
 151:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 152:                                                                  stringBuilder.AppendLine(documentValidityResult.Message);
 153:                                                                  stringBuilder.AppendLine(" ");
 154:                                                              }
 155:                                                              else
 156:                                                              {
 157:                                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 158:                                                                  stringBuilder.AppendLine(@"Error: ONT family type is undefined. ");
 159:                                                                  stringBuilder.AppendLine(" ");
 160:                                                              }
 161:                                                          }
 162:                                                          else
 163:                                                          {
 164:                                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 165:                                                              stringBuilder.AppendLine(@"Error: Access vendor is undefined. ");
 166:                                                              stringBuilder.AppendLine(" ");
 167:                                                          }
 168:                                                      }
 169:                                                      else
 170:                                                      {
 171:                                                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 172:                                                          stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + accessName + ". Access vendor is undefined. ");
 173:                                                          stringBuilder.AppendLine(" ");
 174:                                                      }
 175:                                                  }
 176:                                                  else
 177:                                                  {
 178:                                                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 179:                                                      stringBuilder.AppendLine(@"Error: ONT serial """ + ontSerialNumber + @""" is not valid. ");
 180:                                                      stringBuilder.AppendLine(" ");
 181:                                                  }
 182:                                              }
 183:                                              else
 184:                                              {
 185:                                                  stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 186:                                                  stringBuilder.AppendLine(@"Error: ONT serial is null or zero. ");
 187:                                                  stringBuilder.AppendLine(" ");
 188:                                              }
 189:                                          }
 190:                                          else
 191:                                          {
 192:                                              // ref stringBuilder has a response
 193:                                              //stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 194:                                              //stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 195:                                              //stringBuilder.AppendLine(" ");
 196:                                          }
 197:                                      }
 198:                                  }
 199:                              }
 200:                              else
 201:                              {
 202:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 203:                                  stringBuilder.AppendLine(" ");
 204:                              }
 205:                          }
 206:   
 207:                          responseContent += stringBuilder.ToString();
 208:                          responseContent += "\r\n";
 209:                          //content += "\r\nResult: " + result.Message;
 210:   
 211:                          responseContent += "\r\n";
 212:                          responseContent += "\r\n";
 213:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 214:                          responseContent += "\r\n";
 215:                          responseContent += "\r\n";
 216:                      }
 217:                      else
 218:                      {
 219:                          responseContent += "\r\n";
 220:                          responseContent += "You are not authorized to modify this value. ";
 221:                          responseContent += "\r\n";
 222:                      }
 223:                  }
 224:                  else if (opcode.StartsWith("mail/provision/access/read"))
 225:                  {
 226:                      responseContent += "\r\n";
 227:                      responseContent += "This opcode is not defined yet. ";
 228:                      responseContent += "\r\n";
 229:                  }
 230:                  else if (opcode.StartsWith("mail/provision/access/delete"))
 231:                  {
 232:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Create, staffContact))
 233:                      {
 234:                          responseContent += @"Opcode: """ + opcode + @"""." + "\r\n";
 235:                          //content += @"Operand: """ + operand + @"""." + "\r\n";
 236:                          responseContent += "\r\n";
 237:   
 238:                          stringBuilder = new StringBuilder(10000);
 239:   
 240:                          using (StringReader reader = new StringReader(operand))
 241:                          {
 242:                              if (operand.Length > 0)
 243:                              {
 244:                                  while ((line = reader.ReadLine()) != null)
 245:                                  {
 246:                                      if (!string.IsNullOrEmpty(line)) // skip empty lines
 247:                                      {
 248:                                          accessName = Ia.Ngn.Cl.Model.Business.Default.ExtractAccessNameWithValidSymbolAndLegalFormatForPonAndOntFromValue(line);
 249:   
 250:                                          nddOnt = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Name == accessName select o).SingleOrDefault();
 251:   
 252:                                          if (nddOnt != null)
 253:                                          {
 254:                                              Ia.Ngn.Cl.Model.Data.Huawei.Onu.DeleteByAccessId(nddOnt.Access.Id, out onuDeleteResult);
 255:                                              Ia.Ngn.Cl.Model.Data.ServiceRequestOnt.DeleteByAccessId(accessName, out serviceRequestOntDeleteResult);
 256:                                              Ia.Ngn.Cl.Model.Business.Access.Delete(accessName, staffContact.UserId, out documentValidityResult);
 257:   
 258:                                              documentValidityResult.AddSuccess(onuDeleteResult);
 259:                                              documentValidityResult.AddSuccess(serviceRequestOntDeleteResult);
 260:                                          }
 261:                                          else
 262:                                          {
 263:                                              stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 264:                                              stringBuilder.AppendLine(@"Error: Network design document does not recognize the access name " + accessName + ". Access vendor is undefined. ");
 265:                                              stringBuilder.AppendLine(" ");
 266:                                          }
 267:                                      }
 268:                                  }
 269:                              }
 270:                              else
 271:                              {
 272:                                  stringBuilder.AppendLine("Error: Operand is empty. ");
 273:                                  stringBuilder.AppendLine(" ");
 274:                              }
 275:                          }
 276:   
 277:                          responseContent += stringBuilder.ToString();
 278:                          responseContent += "\r\n";
 279:                          //content += "\r\nResult: " + result.Message;
 280:   
 281:                          responseContent += "\r\n";
 282:                          responseContent += "\r\n";
 283:                          responseContent += @"Help? Send email with subject ""mail/provision/access/help"". ";
 284:                          responseContent += "\r\n";
 285:                          responseContent += "\r\n";
 286:                      }
 287:                      else
 288:                      {
 289:                          responseContent += "\r\n";
 290:                          responseContent += "You are not authorized to delete this value. ";
 291:                          responseContent += "\r\n";
 292:                      }
 293:                  }
 294:                  else
 295:                  {
 296:                      responseContent += "\r\n";
 297:                      responseContent += "This opcode is not known. ";
 298:                      responseContent += "\r\n";
 299:                  }
 300:              }
 301:          }
 302:   
 303:          /////////////////////////////////////////////////////////////////////////////////
 304:   
 305:          /// <summary>
 306:          ///
 307:          /// </summary>
 308:          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 ontFamilyTypeString, out string odf, out string paci)
 309:          {
 310:              bool matchSuccess;
 311:              int slNo, pon, pon2, pon3;
 312:              string accessName2, areaSymbol; //, ipAddress, odfPort, oltPort;
 313:              Match match;
 314:   
 315:              accessName = kuwaitNgnAreaSymbol = block = street = premisesOld = premisesNew = ontSerialNumber = ontFamilyTypeString = odf = paci = string.Empty;
 316:   
 317:              // parse Huawei submittal line
 318:              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(.*?)$");
 319:   
 320:              if (match.Success)
 321:              {
 322:                  slNo = int.Parse(match.Groups[1].Value);
 323:                  pon = int.Parse(match.Groups[2].Value);
 324:                  pon2 = int.Parse(match.Groups[4].Value);
 325:                  pon3 = int.Parse(match.Groups[7].Value);
 326:   
 327:                  if (pon == pon2 && pon == pon3 && pon2 == pon3)
 328:                  {
 329:                      accessName = match.Groups[3].Value + "." + match.Groups[4].Value + "." + match.Groups[5].Value;
 330:                      accessName2 = match.Groups[6].Value + "." + match.Groups[7].Value + "." + match.Groups[8].Value;
 331:   
 332:                      if (accessName == accessName2)
 333:                      {
 334:                          //mhNo = match.Groups[9].Value;
 335:                          kuwaitNgnAreaSymbol = match.Groups[10].Value;
 336:                          block = match.Groups[11].Value;
 337:                          premisesNew = match.Groups[12].Value;
 338:                          street = match.Groups[13].Value;
 339:                          premisesOld = match.Groups[14].Value;
 340:                          paci = match.Groups[15].Value;
 341:                          ontSerialNumber = match.Groups[16].Value;
 342:                          ontFamilyTypeString = match.Groups[20].Value;
 343:                          //ipAddress = match.Groups[18].Value;
 344:                          //odfPort = match.Groups[19].Value;
 345:                          //oltPort = match.Groups[20].Value;
 346:   
 347:                          matchSuccess = true;
 348:                      }
 349:                      else
 350:                      {
 351:                          stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 352:                          stringBuilder.AppendLine(@"Error: TB.ID and ONT ID values don't match in line. ");
 353:                          stringBuilder.AppendLine(" ");
 354:   
 355:                          matchSuccess = false;
 356:                      }
 357:                  }
 358:                  else
 359:                  {
 360:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 361:                      stringBuilder.AppendLine(@"Error: Inconsistent PON, TB.ID and ONT ID values in line. ");
 362:                      stringBuilder.AppendLine(" ");
 363:   
 364:                      matchSuccess = false;
 365:                  }
 366:              }
 367:              else
 368:              {
 369:                  // parse Nokia submittal line
 370:                  match = Regex.Match(line, @"([a-zA-Z]{3})\.(\d{1,4})\.(\d{1,3})\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.+?)$");
 371:   
 372:                  if (match.Success)
 373:                  {
 374:                      areaSymbol = match.Groups[1].Value;
 375:                      kuwaitNgnAreaSymbol = areaSymbol;
 376:   
 377:                      accessName = areaSymbol + "." + match.Groups[2].Value + "." + match.Groups[3].Value;
 378:   
 379:                      premisesOld = match.Groups[6].Value;
 380:                      premisesNew = match.Groups[7].Value;
 381:                      street = match.Groups[5].Value;
 382:                      block = match.Groups[4].Value;
 383:                      paci = match.Groups[8].Value;
 384:   
 385:                      ontSerialNumber = match.Groups[9].Value;
 386:                      ontFamilyTypeString = match.Groups[10].Value;
 387:   
 388:                      matchSuccess = true;
 389:                  }
 390:                  else
 391:                  {
 392:                      stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
 393:                      stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched. ");
 394:                      stringBuilder.AppendLine(" ");
 395:   
 396:                      matchSuccess = false;
 397:                  }
 398:              }
 399:   
 400:              return matchSuccess;
 401:          }
 402:   
 403:          ////////////////////////////////////////////////////////////////////////////
 404:          ////////////////////////////////////////////////////////////////////////////
 405:      }
 406:  }