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

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

Signaling Service Processing System (SPS) support class for Huawei's Fixed Telecommunications Network (FTN) data model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Linq;
    5: using System.Text.RegularExpressions;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Data.Huawei
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Signaling Service Processing System (SPS) support class for Huawei's Fixed Telecommunications Network (FTN) data model.
   13:     /// </summary>
   14:  
   15:     /// <remarks> 
   16:     /// Copyright © 2018-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     /// </remarks> 
   18:     public class Sps
   19:     {
   20:         ////////////////////////////////////////////////////////////////////////////
   21:  
   22:         /// <summary>
   23:         ///
   24:         /// </summary>
   25:         public static bool UpdateDatabaseWithSpsCommandOutput(string rowData, ref Ia.Ftn.Cl.Models.Client.Huawei.Sps sps, out Ia.Cl.Models.Result result)
   26:         {
   27:             bool b;
   28:             Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response response;
   29:  
   30:             b = false;
   31:             result = new Ia.Cl.Models.Result();
   32:  
   33:             // below: remove all '\' characters from rowData and reset NULL comments to ""
   34:             //rowData = rowData.Replace(@"\", "");
   35:             //rowData = rowData.Replace(@"NULL", "");
   36:  
   37:             response = Ia.Ftn.Cl.Models.Data.Huawei.Sps.ParseResponse(rowData);
   38:  
   39:             if (response != null)
   40:             {
   41:                 if (response.ReturnCode == Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode.OperationIsSuccessful)
   42:                 {
   43:                     if (response.CommandString.Contains("LST SERUATTR:"))
   44:                     {
   45:                         if (response.QueryDictionary != null)
   46:                         {
   47:                             b = Ia.Ftn.Cl.Models.Data.Huawei.Seruattr.Update(response, out result);
   48:                         }
   49:                         else result.AddWarning(response.CodeExplanation);
   50:                     }
   51:                     else if (response.CommandString.StartsWith("MOD SERUATTR:"))
   52:                     {
   53:                         result.AddSuccess(response.CodeExplanation);
   54:                     }
   55:                     else if (response.CommandString.StartsWith("SHK HND:"))
   56:                     {
   57:                         result.AddSuccess(response.CodeExplanation);
   58:                     }
   59:                     else if (response.CommandString.StartsWith("LGI:"))
   60:                     {
   61:                         sps.IsLoggedIn = true;
   62:  
   63:                         result.AddSuccess(response.CodeExplanation);
   64:                     }
   65:                     else if (response.CommandString.StartsWith("LGO:"))
   66:                     {
   67:                         sps.IsLoggedIn = false;
   68:  
   69:                         result.AddSuccess(response.CodeExplanation);
   70:                     }
   71:                     else
   72:                     {
   73:                         result.AddWarning("No designated opcode to process");
   74:  
   75:                         b = false;
   76:                     }
   77:                 }
   78:                 else if (response.ReturnCode == Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode.InvalidCommand)
   79:                 {
   80:                     /*
   81:     +++    USCDB        2020-09-21 12:40:52
   82:     PGW    #003580
   83:     %%;%%
   84:     RETCODE = 1001 Invalid command <">
   85: 
   86:     There is together 1 report
   87: 
   88:     ---    END
   89:                      */
   90:  
   91:                     // just ignore for now
   92:  
   93:                     b = false;
   94:                 }
   95:                 else
   96:                 {
   97:                     result.AddWarning(response.CodeExplanation);
   98:  
   99:                     b = false;
  100:                 }
  101:             }
  102:             else
  103:             {
  104:                 result.AddError("Response is null");
  105:  
  106:                 b = false;
  107:             }
  108:  
  109:             return b;
  110:         }
  111:  
  112:         ////////////////////////////////////////////////////////////////////////////
  113:  
  114:         /// <summary>
  115:         /// Parse response according to HUAWEI SPS Signaling Service Processing System V300R008C10 SPS V300R008C10 PGW MML Command Protocol(NP)
  116:         /// </summary>
  117:         private static Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response ParseResponse(string rowData)
  118:         {
  119:             int reportSerialNumber, c;
  120:             string header, body, endTag, sourceIdentifier, serviceReportIdentifier, commandString, resultBody, key, value, codeExplanation;
  121:             DateTime reportOutputDateTime;
  122:             Dictionary<string, string> dictionary, dictionary2;
  123:             Match match;
  124:             MatchCollection matchCollection;
  125:             Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode returnCode;
  126:             Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response response;
  127:             List<string> attributeList;
  128:             List<List<string>> valueListList;
  129:  
  130:             response = new Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response();
  131:  
  132:             attributeList = new List<string>(100);
  133:             valueListList = new List<List<string>>(100);
  134:  
  135:             // header: <Start identifier><4SP><Source identifier'M32><8SP><Report output date'M10><1SP><Report output time'M8>\r\n<Service report identifier'M10><4SP><#Report serial number'M10>\r\n
  136:             // body: 
  137:             // end tag: <---><4SP><END>\r\n
  138:             match = Regex.Match(rowData, @"(\+\+\+    (.+?)        (\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2})\r\n(.+?)    #(\d+))
  139: (%%(.+?)%%\r\nRETCODE = (\d+) (.+?)\r\n(.+?))\r\n
  140: (---    END)\r\n", RegexOptions.Singleline);
  141:  
  142:             if (match.Success)
  143:             {
  144:                 // header:
  145:                 header = match.Groups[1].Value;
  146:                 sourceIdentifier = match.Groups[2].Value;
  147:                 reportOutputDateTime = DateTime.Parse(match.Groups[3].Value);
  148:                 serviceReportIdentifier = match.Groups[4].Value;
  149:                 reportSerialNumber = int.Parse(match.Groups[5].Value);
  150:  
  151:                 // body:
  152:                 body = match.Groups[6].Value;
  153:                 commandString = match.Groups[7].Value.Trim();
  154:                 returnCode = (Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode)int.Parse(match.Groups[8].Value);
  155:                 codeExplanation = match.Groups[9].Value;
  156:                 resultBody = match.Groups[10].Value;
  157:  
  158:                 dictionary = new Dictionary<string, string>();
  159:                 dictionary2 = new Dictionary<string, string>();
  160:  
  161:                 // end tag:
  162:                 endTag = match.Groups[3].Value;
  163:  
  164:                 if (!string.IsNullOrEmpty(resultBody))
  165:                 {
  166:                     matchCollection = Regex.Matches(resultBody, @"(.+?)\s+?=\s+?(.+)\r\n", RegexOptions.Multiline);
  167:  
  168:                     if (matchCollection.Count > 0)
  169:                     {
  170:                         foreach (Match m in matchCollection)
  171:                         {
  172:                             key = m.Groups[1].Value.Trim();
  173:                             value = m.Groups[2].Value.Trim();
  174:  
  175:                             if (!string.IsNullOrEmpty(key))
  176:                             {
  177:                                 dictionary[key] = value;
  178:                             }
  179:                         }
  180:                     }
  181:                 }
  182:  
  183:                 if (dictionary.ContainsKey("Total count"))
  184:                 {
  185:                     if (int.TryParse(dictionary["Total count"], out c)) response.Count = c;
  186:  
  187:                     dictionary.Remove("Total count");
  188:                 }
  189:  
  190:                 // convert field discriptions to field names, and enumerated values to actual values
  191:                 foreach (KeyValuePair<string, string> kvp in dictionary)
  192:                 {
  193:                     key = (from p in Ia.Ftn.Cl.Models.Business.Huawei.Sps.ParameterFieldNameExplanationList where p.FieldExplanation == kvp.Key select p.FieldName).SingleOrDefault();
  194:  
  195:                     if (key == "NUMTYPE") value = (from n in Ia.Ftn.Cl.Models.Business.Huawei.Sps.NumTypeFieldIdExplanationList where n.FieldExplanation == kvp.Value select n.Id).SingleOrDefault().ToString();
  196:                     else if (key == "RNIDXTYPE") value = (from r in Ia.Ftn.Cl.Models.Business.Huawei.Sps.RnidxTypeFieldIdExplanationList where r.FieldExplanation == kvp.Value select r.Id).SingleOrDefault().ToString();
  197:                     else if (key == "SERVATTR") value = "0";
  198:                     else value = kvp.Value;
  199:  
  200:                     dictionary2[key] = value;
  201:                 }
  202:  
  203:                 response.CommandString = commandString;
  204:                 response.ReturnCode = returnCode;
  205:                 response.CodeExplanation = codeExplanation;
  206:                 response.QueryDictionary = dictionary2;
  207:             }
  208:             else response = null;
  209:  
  210:             return response;
  211:         }
  212:  
  213:         ////////////////////////////////////////////////////////////////////////////
  214:         ////////////////////////////////////////////////////////////////////////////   
  215:     }
  216:  
  217:     ////////////////////////////////////////////////////////////////////////////
  218:     ////////////////////////////////////////////////////////////////////////////   
  219: }