)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
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:     ///
   18:     /// 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
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class Sps
   29:     {
   30:         ////////////////////////////////////////////////////////////////////////////
   31:  
   32:         /// <summary>
   33:         ///
   34:         /// </summary>
   35:         public static bool UpdateDatabaseWithSpsCommandOutput(string rowData, ref Ia.Ftn.Cl.Models.Client.Huawei.Sps sps, out Ia.Cl.Models.Result result)
   36:         {
   37:             bool b;
   38:             Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response response;
   39:  
   40:             b = false;
   41:             result = new Ia.Cl.Models.Result();
   42:  
   43:             // below: remove all '\' characters from rowData and reset NULL comments to ""
   44:             //rowData = rowData.Replace(@"\", "");
   45:             //rowData = rowData.Replace(@"NULL", "");
   46:  
   47:             response = Ia.Ftn.Cl.Models.Data.Huawei.Sps.ParseResponse(rowData);
   48:  
   49:             if (response != null)
   50:             {
   51:                 if (response.ReturnCode == Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode.OperationIsSuccessful)
   52:                 {
   53:                     if (response.CommandString.Contains("LST SERUATTR:"))
   54:                     {
   55:                         if (response.QueryDictionary != null)
   56:                         {
   57:                             b = Ia.Ftn.Cl.Models.Data.Huawei.Seruattr.Update(response, out result);
   58:                         }
   59:                         else result.AddWarning(response.CodeExplanation);
   60:                     }
   61:                     else if (response.CommandString.StartsWith("MOD SERUATTR:"))
   62:                     {
   63:                         result.AddSuccess(response.CodeExplanation);
   64:                     }
   65:                     else if (response.CommandString.StartsWith("SHK HND:"))
   66:                     {
   67:                         result.AddSuccess(response.CodeExplanation);
   68:                     }
   69:                     else if (response.CommandString.StartsWith("LGI:"))
   70:                     {
   71:                         sps.IsLoggedIn = true;
   72:  
   73:                         result.AddSuccess(response.CodeExplanation);
   74:                     }
   75:                     else if (response.CommandString.StartsWith("LGO:"))
   76:                     {
   77:                         sps.IsLoggedIn = false;
   78:  
   79:                         result.AddSuccess(response.CodeExplanation);
   80:                     }
   81:                     else
   82:                     {
   83:                         result.AddWarning("No designated opcode to process");
   84:  
   85:                         b = false;
   86:                     }
   87:                 }
   88:                 else if (response.ReturnCode == Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode.InvalidCommand)
   89:                 {
   90:                     /*
   91:     +++    USCDB        2020-09-21 12:40:52
   92:     PGW    #003580
   93:     %%;%%
   94:     RETCODE = 1001 Invalid command <">
   95: 
   96:     There is together 1 report
   97: 
   98:     ---    END
   99:                      */
  100:  
  101:                     // just ignore for now
  102:  
  103:                     b = false;
  104:                 }
  105:                 else
  106:                 {
  107:                     result.AddWarning(response.CodeExplanation);
  108:  
  109:                     b = false;
  110:                 }
  111:             }
  112:             else
  113:             {
  114:                 result.AddError("Response is null");
  115:  
  116:                 b = false;
  117:             }
  118:  
  119:             return b;
  120:         }
  121:  
  122:         ////////////////////////////////////////////////////////////////////////////
  123:  
  124:         /// <summary>
  125:         /// Parse response according to HUAWEI SPS Signaling Service Processing System V300R008C10 SPS V300R008C10 PGW MML Command Protocol(NP)
  126:         /// </summary>
  127:         private static Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response ParseResponse(string rowData)
  128:         {
  129:             int reportSerialNumber, c;
  130:             string header, body, endTag, sourceIdentifier, serviceReportIdentifier, commandString, resultBody, key, value, codeExplanation;
  131:             DateTime reportOutputDateTime;
  132:             Dictionary<string, string> dictionary, dictionary2;
  133:             Match match;
  134:             MatchCollection matchCollection;
  135:             Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode returnCode;
  136:             Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response response;
  137:             List<string> attributeList;
  138:             List<List<string>> valueListList;
  139:  
  140:             response = new Ia.Ftn.Cl.Models.Business.Huawei.Sps.Response();
  141:  
  142:             attributeList = new List<string>(100);
  143:             valueListList = new List<List<string>>(100);
  144:  
  145:             // 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
  146:             // body: 
  147:             // end tag: <---><4SP><END>\r\n
  148:             match = Regex.Match(rowData, @"(\+\+\+    (.+?)        (\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2})\r\n(.+?)    #(\d+))
  149: (%%(.+?)%%\r\nRETCODE = (\d+) (.+?)\r\n(.+?))\r\n
  150: (---    END)\r\n", RegexOptions.Singleline);
  151:  
  152:             if (match.Success)
  153:             {
  154:                 // header:
  155:                 header = match.Groups[1].Value;
  156:                 sourceIdentifier = match.Groups[2].Value;
  157:                 reportOutputDateTime = DateTime.Parse(match.Groups[3].Value);
  158:                 serviceReportIdentifier = match.Groups[4].Value;
  159:                 reportSerialNumber = int.Parse(match.Groups[5].Value);
  160:  
  161:                 // body:
  162:                 body = match.Groups[6].Value;
  163:                 commandString = match.Groups[7].Value.Trim();
  164:                 returnCode = (Ia.Ftn.Cl.Models.Client.Huawei.Sps.ResultCode)int.Parse(match.Groups[8].Value);
  165:                 codeExplanation = match.Groups[9].Value;
  166:                 resultBody = match.Groups[10].Value;
  167:  
  168:                 dictionary = new Dictionary<string, string>();
  169:                 dictionary2 = new Dictionary<string, string>();
  170:  
  171:                 // end tag:
  172:                 endTag = match.Groups[3].Value;
  173:  
  174:                 if (!string.IsNullOrEmpty(resultBody))
  175:                 {
  176:                     matchCollection = Regex.Matches(resultBody, @"(.+?)\s+?=\s+?(.+)\r\n", RegexOptions.Multiline);
  177:  
  178:                     if (matchCollection.Count > 0)
  179:                     {
  180:                         foreach (Match m in matchCollection)
  181:                         {
  182:                             key = m.Groups[1].Value.Trim();
  183:                             value = m.Groups[2].Value.Trim();
  184:  
  185:                             if (!string.IsNullOrEmpty(key))
  186:                             {
  187:                                 dictionary[key] = value;
  188:                             }
  189:                         }
  190:                     }
  191:                 }
  192:  
  193:                 if (dictionary.ContainsKey("Total count"))
  194:                 {
  195:                     if (int.TryParse(dictionary["Total count"], out c)) response.Count = c;
  196:  
  197:                     dictionary.Remove("Total count");
  198:                 }
  199:  
  200:                 // convert field discriptions to field names, and enumerated values to actual values
  201:                 foreach (KeyValuePair<string, string> kvp in dictionary)
  202:                 {
  203:                     key = (from p in Ia.Ftn.Cl.Models.Business.Huawei.Sps.ParameterFieldNameExplanationList where p.FieldExplanation == kvp.Key select p.FieldName).SingleOrDefault();
  204:  
  205:                     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();
  206:                     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();
  207:                     else if (key == "SERVATTR") value = "0";
  208:                     else value = kvp.Value;
  209:  
  210:                     dictionary2[key] = value;
  211:                 }
  212:  
  213:                 response.CommandString = commandString;
  214:                 response.ReturnCode = returnCode;
  215:                 response.CodeExplanation = codeExplanation;
  216:                 response.QueryDictionary = dictionary2;
  217:             }
  218:             else response = null;
  219:  
  220:             return response;
  221:         }
  222:  
  223:         ////////////////////////////////////////////////////////////////////////////
  224:         ////////////////////////////////////////////////////////////////////////////   
  225:     }
  226:  
  227:     ////////////////////////////////////////////////////////////////////////////
  228:     ////////////////////////////////////////////////////////////////////////////   
  229: }