)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation Links

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