)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Default (Ia.Ftn.Cl.Models.Business.Huawei)

Public general use code classes and xml files that we've compiled and used over the years:

Defaul general support class for Huawei's Fixed Telecommunications Network (FTN) business model.

    1: using System.Collections.Generic;
    2: using System.Text.RegularExpressions;
    3: using System.Text;
    4: using System;
    5: using System.IO;
    6: using System.Linq;
    7: using Microsoft.AspNetCore.Identity;
    8:  
    9: namespace Ia.Ftn.Cl.Models.Business.Huawei
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Defaul general support class for Huawei's Fixed Telecommunications Network (FTN) business model.
   15:     /// </summary>
   16:     /// 
   17:     /// <remarks> 
   18:     /// Copyright © 2014-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated 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 class Default
   31:     {
   32:         ////////////////////////////////////////////////////////////////////////////
   33:  
   34:         /// <summary>
   35:         ///
   36:         /// </summary>
   37:         public Default() { }
   38:  
   39:         ////////////////////////////////////////////////////////////////////////////
   40:  
   41:         /// <summary>
   42:         ///
   43:         /// </summary>
   44:         public class FnSnPnPort
   45:         {
   46:             /// <summary/>
   47:             public int Fn { get; set; }
   48:  
   49:             /// <summary/>
   50:             public int Sn { get; set; }
   51:  
   52:             /// <summary/>
   53:             public int Pn { get; set; }
   54:  
   55:             /// <summary/>
   56:             public int Port { get; set; }
   57:  
   58:             ////////////////////////////////////////////////////////////////////////////
   59:  
   60:             /// <summary>
   61:             ///
   62:             /// </summary>
   63:             public FnSnPnPort()
   64:             {
   65:                 this.Fn = 0;
   66:                 this.Sn = 0;
   67:                 this.Pn = 0;
   68:                 this.Port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
   69:             }
   70:  
   71:             ////////////////////////////////////////////////////////////////////////////
   72:  
   73:             /// <summary>
   74:             ///
   75:             /// </summary>
   76:             public FnSnPnPort(int fn, int sn, int pn, int port)
   77:             {
   78:                 this.Fn = fn;
   79:                 this.Sn = sn;
   80:                 this.Pn = pn;
   81:                 this.Port = port;
   82:             }
   83:  
   84:             ////////////////////////////////////////////////////////////////////////////
   85:         }
   86:  
   87:         ////////////////////////////////////////////////////////////////////////////
   88:         ////////////////////////////////////////////////////////////////////////////   
   89:  
   90:         /// <summary>
   91:         ///
   92:         /// </summary>
   93:         public static Ia.Cl.Models.Result InsertLic(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan, string msanDevId, int cabinet, int frame, int card, int port, string service, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
   94:         {
   95:             var result = new Ia.Cl.Models.Result();
   96:  
   97:             if (!string.IsNullOrEmpty(service))
   98:             {
   99:                 if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  100:                 {
  101:                     var lic = Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevLicByNddMsanAndCabinetAndFrameAndFnAndSnAndPn(msan, cabinet, frame, 0, card, port);
  102:  
  103:                     if (lic == null)
  104:                     {
  105:                         if (msan.DomainList.Any(u => service.StartsWith(u.ToString())))
  106:                         {
  107:                             var emsVoipPstnUserList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.ReadByMsanService(service);
  108:  
  109:                             if (emsVoipPstnUserList.Count == 0)
  110:                             {
  111:                                 emsVoipPstnUserList = Ia.Ftn.Cl.Models.Data.Huawei.VoipPstnUser.ReadByService(service);
  112:  
  113:                                 if (emsVoipPstnUserList.Count == 0)
  114:                                 {
  115:                                     var emsOntSipInfoList = Ia.Ftn.Cl.Models.Data.Huawei.OntSipInfo.ReadByService(service);
  116:  
  117:                                     if (emsOntSipInfoList.Count == 0)
  118:                                     {
  119:                                         Ia.Ftn.Cl.Models.Business.Maintenance.Task.ServiceMsanTask(Ia.Ftn.Cl.Models.Business.MessageQueue.Process.CreateReadNceMsanServiceMsanCabinetFrameFnSnPn, msanDevId, cabinet, frame, 0, card, port, service, staff, out result);
  120:                                     }
  121:                                     else result.AddError("The service number " + service + " already exists in the Fiber's EmsOntSipInfo table (الرقم موجود في قاعدة بيانات الشبكة الرقمية (الفايبر))");
  122:                                 }
  123:                                 else result.AddError("The service number " + service + " already exists in the Fiber's MDU EmsVoipPstnUser table (الرقم موجود في قاعدة بيانات الشبكة الرقمية (الفايبر))");
  124:                             }
  125:                             else result.AddError("The service number " + service + " already exists in MSAN's EmsVoipPstnUser table (الرقم موجود في قاعدة بيانات الأمسان)");
  126:                         }
  127:                         else result.AddError("The service number " + service + " does not belong to MSAN " + msan.NameSymbol + " (" + msan.Site.NameArabicName + ") allowed domain list (الرقم لا ينتمي لنطاق الأرقام المسموح بها في الأمسان)");
  128:                     }
  129:                     else result.AddError("LIC " + lic.ToMsanDevDevSnPnTextString() + " already exists in database (الربط موجود في قاعدة البيانات)");
  130:                 }
  131:                 else result.AddError(@"The service """ + service + @""" does not belong to the network (الرقم لا ينتمي للشبكة)");
  132:             }
  133:             else result.AddError("No input was entered for service (لم يتم إدخال رقم)");
  134:  
  135:             return result;
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////   
  139:  
  140:         /// <summary>
  141:         ///
  142:         /// </summary>
  143:         public static Ia.Cl.Models.Result DeleteLic(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan, string emsVoipPstnUserId, Ia.Ftn.Cl.Models.StaffIdentityUser staff, out Ia.Ftn.Cl.Models.Business.Huawei.Dev.MsanDev.Lic msanDevLic)
  144:         {
  145:             var result = new Ia.Cl.Models.Result();
  146:  
  147:             msanDevLic = Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevLicByEmsVoipPstnUserId(emsVoipPstnUserId);
  148:  
  149:             if (msanDevLic != null)
  150:             {
  151:                 var service = msanDevLic.Service;
  152:  
  153:                 if (!string.IsNullOrEmpty(service))
  154:                 {
  155:                     if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(service))
  156:                     {
  157:                         if (msan.DomainList.Any(u => service.StartsWith(u.ToString())))
  158:                         {
  159:                             Ia.Ftn.Cl.Models.Business.Maintenance.Task.ServiceMsanTask(Ia.Ftn.Cl.Models.Business.MessageQueue.Process.DeleteReadNceMsanService, service, staff, out result);
  160:                         }
  161:                         else result.AddError(@"The service """ + service + @""" does not belong to the network (الرقم لا ينتمي للشبكة).");
  162:                     }
  163:                     else result.AddError("No input was entered for service (لم يتم إدخال رقم).");
  164:                 }
  165:                 else result.AddError("The service number " + service + " does not belong to MSAN " + msan.NameSymbol + " (" + msan.Site.NameArabicName + ") allowed domain list (الرقم لا ينتمي لنطاق الأرقام المسموح بها في الأمسان).");
  166:             }
  167:             else result.AddError("LIC could not be deleted because it does not exist in database (لا يمكن مسح الربط لأنه غير موجود في قاعدة البيانات).");
  168:  
  169:             return result;
  170:         }
  171:  
  172:         ////////////////////////////////////////////////////////////////////////////   
  173:  
  174:         /// <summary>
  175:         ///
  176:         /// </summary>
  177:         public static Ia.Cl.Models.Result BulkInsertLic(string content, Ia.Ftn.Cl.Models.StaffIdentityUser staff, out StringBuilder stringBuilder)
  178:         {
  179:             string line;
  180:  
  181:             stringBuilder = new StringBuilder(10000);
  182:  
  183:             var result = new Ia.Cl.Models.Result();
  184:  
  185:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateBulkLicList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Create, staff))
  186:             {
  187:                 using (StringReader stringReader = new StringReader(content))
  188:                 {
  189:                     if (content.Length > 0)
  190:                     {
  191:                         while ((line = stringReader.ReadLine()) != null)
  192:                         {
  193:                             if (!string.IsNullOrEmpty(line)) // skip empty lines
  194:                             {
  195:                                 if (ParseLine(line, ref stringBuilder, out Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan, out int cabinet, out int frame, out int card, out int port, out string service))
  196:                                 {
  197:                                     var msanDevId = (from m in Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevList
  198:                                                      where m.Msan.Site.Id == msan.Site.Id && m.Cabinet == cabinet && m.Frame == frame
  199:                                                      select m.Id).Single();
  200:  
  201:                                     var r0 = Ia.Ftn.Cl.Models.Business.Huawei.Default.InsertLic(msan, msanDevId, cabinet, frame, card, port, service, staff);
  202:  
  203:                                     if (r0.IsSuccessful)
  204:                                     {
  205:                                         result.AddSuccess(@"> [" + line.Trim() + @"]");
  206:                                         result.AddSuccess(r0.MessageWithoutCaption);
  207:  
  208:                                         stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
  209:                                         stringBuilder.AppendLine(@"Success: " + r0.MessageWithoutCaption);
  210:                                         stringBuilder.AppendLine(" ");
  211:                                     }
  212:                                     else
  213:                                     {
  214:                                         result.AddError(@"> [" + line.Trim() + @"]");
  215:                                         result.AddError(r0.MessageWithoutCaption);
  216:  
  217:                                         stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
  218:                                         stringBuilder.AppendLine(@"Error: " + r0.MessageWithoutCaption);
  219:                                         stringBuilder.AppendLine(" ");
  220:                                     }
  221:                                 }
  222:                                 else
  223:                                 {
  224:                                     result.AddError(@"> [" + line.Trim() + @"]");
  225:                                     result.AddError(@"Line format was incorrect and was not matched.");
  226:  
  227:                                     stringBuilder.AppendLine(@"> [" + line.Trim() + @"]");
  228:                                     stringBuilder.AppendLine(@"Error: Line format was incorrect and was not matched.");
  229:                                     stringBuilder.AppendLine(" ");
  230:                                 }
  231:                             }
  232:                         }
  233:                     }
  234:                     else result.AddError("Content is empty.");
  235:                 }
  236:             }
  237:             else result.AddError("You are not authorized to modify this value.");
  238:  
  239:             return result;
  240:         }
  241:  
  242:         /////////////////////////////////////////////////////////////////////////////////
  243:  
  244:         /// <summary>
  245:         ///
  246:         /// </summary>
  247:         private static bool ParseLine(string line, ref StringBuilder stringBuilder, out Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan, out int cabinet, out int frame, out int card, out int port, out string service)
  248:         {
  249:             bool matchSuccess;
  250:  
  251:             var match = Regex.Match(line, @"(\w{3}_MSAN_Cabinet (\d+)_Frame (\d+))\s+0\s+(\d+)\s+(\d+).+(\d{8})");
  252:             // SSB_MSAN_Cabinet 0_Frame 0    0    1    0    A1-0    1    0    23616315    A1-0-1-0
  253:             if (match.Success)
  254:             {
  255:                 var dev = match.Groups[1].Value;
  256:                 cabinet = int.Parse(match.Groups[2].Value);
  257:                 frame = int.Parse(match.Groups[3].Value);
  258:                 card = int.Parse(match.Groups[4].Value);
  259:                 port = int.Parse(match.Groups[5].Value);
  260:  
  261:                 service = match.Groups[6].Value;
  262:  
  263:                 msan = Ia.Ftn.Cl.Models.Business.Default.MsanFromHuaweiEmsDev(dev);
  264:  
  265:                 matchSuccess = true;
  266:             }
  267:             else
  268:             {
  269:                 msan = null;
  270:                 cabinet = frame = card = port = Ia.Ftn.Cl.Models.Business.Default.PortUndefinedOrInvalidOrUnknown;
  271:                 service = string.Empty;
  272:  
  273:                 matchSuccess = false;
  274:             }
  275:  
  276:             return matchSuccess;
  277:         }
  278:  
  279:         ////////////////////////////////////////////////////////////////////////////
  280:         ////////////////////////////////////////////////////////////////////////////   
  281:     }
  282:  
  283:     ////////////////////////////////////////////////////////////////////////////
  284:     ////////////////////////////////////////////////////////////////////////////   
  285: }