We first need to create a Visual Studio project whose template is a Class Library. For this tutorial we'll be using Visual Studio 2008.
Replace the contents of NameMathRules.cs with the following code.
using System; using System.Collections.Generic; using System.Linq; using ASF.BDS.Rules.Common; using Common.Logging; using ASF.Framework.Service.Parameters; using System.Net; using ASF.Framework.Util; namespace TestRules { public static class NameMathRules { private static readonly ILog Logger = LogManager.GetLogger(typeof(NameMathRules)); public static double MultiplyRule(double x, double y) { return (x * y); } public static RuleResponse Handle(RuleRequest request) { var result = new ParameterCollection(); result.Add(new Parameter("Test_resp_pa") { Value = "11111" }); try { LogHelper.Error(Logger, string.Format("Test", "Success")); foreach (var p in request.Parameters) { result.Add(new Parameter(p.Key) { Value = p.Value }); } if (request.Parameters.ContainsKey("TestParam")) { var myParam = ConvertHelper.SafeObjectToInt(request.Parameters["TestParam"]); ValidationHelper.ValidateNotZeroInt(myParam, "myParam"); //ValidationHelper.ValidateNotNullString(myParam, "myParam"); result.Add(new Parameter("MultiplyValue") { Value = MultiplyRule(myParam, myParam + 1) }); } return new RuleResponse() { ErrorMessage = "", StatusCode = HttpStatusCode.OK, Result = result }; } catch (Exception e) { LogHelper.Error(Logger, string.Format("Error", e.ToString())); return new RuleResponse() { ErrorMessage = e.ToString(), StatusCode = HttpStatusCode.OK }; } } private static Dictionary<string, string>[] __GetMethodParameterMetas(string method) { if (method == "Handle") { var handleParameters = new List<Dictionary<string, string>>(); var handleParameterInfo = new Dictionary<string, string>(); handleParameterInfo["name"] = "TestParam"; handleParameterInfo["behavior"] = "1"; handleParameterInfo["type"] = "Text"; handleParameters.Add(handleParameterInfo); var outputParameterInfo = new Dictionary<string, string>(); outputParameterInfo["name"] = "MultiplyValue"; outputParameterInfo["behavior"] = "2"; outputParameterInfo["type"] = "Number"; handleParameters.Add(outputParameterInfo); return handleParameters.ToArray(); } return null; } } } |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ASF.BDS; using ASF.BDS.Common; using ASF.BDS.Rules.Common; using ASF.Framework; using ASF.Framework.Service; using ASF.Security; using Common.Logging; using Newtonsoft.Json; using ASF.Framework.Service.Parameters; using System.Net; using ASF.Framework.Util; namespace TestRules { public static class ConcatenateRules { private static readonly ILog Logger = LogManager.GetLogger(typeof(NameMathRules)); public static string FullNameRule(string fName, string lName) { return (fName.TrimEnd().TrimStart() + " " + lName.TrimEnd().TrimStart()); } public static RuleResponse Handle(RuleRequest request) { var result = new ParameterCollection(); result.Add(new Parameter("Test_resp_pa") { Value = "11111" }); try { LogHelper.Error(Logger, string.Format("Test", "Success")); foreach (var p in request.Parameters) { result.Add(new Parameter(p.Key) { Value = p.Value }); } if (request.Parameters.ContainsKey("TestParam")) { var myParam = ConvertHelper.SafeObjectToString(request.Parameters["TestParam"]); //ValidationHelper.ValidateNotZeroInt(myParam, "myParam"); ValidationHelper.ValidateNotNullString(myParam, "myParam"); result.Add(new Parameter("ConcatenateValue") { Value = FullNameRule(myParam, myParam + "abc") }); } return new RuleResponse() { ErrorMessage = "", StatusCode = HttpStatusCode.OK, Result = result }; } catch (Exception e) { LogHelper.Error(Logger, string.Format("Error", e.ToString())); return new RuleResponse() { ErrorMessage = e.ToString(), StatusCode = HttpStatusCode.OK }; } } private static Dictionary<string, string>[] __GetMethodParameterMetas(string method) { if (method == "Handle") { var handleParameters = new List<Dictionary<string, string>>(); var handleParameterInfo = new Dictionary<string, string>(); handleParameterInfo["name"] = "TestParam"; handleParameterInfo["behavior"] = "1"; handleParameterInfo["type"] = "Text"; handleParameters.Add(handleParameterInfo); var outputParameterInfo = new Dictionary<string, string>(); outputParameterInfo["name"] = "ConcatenateValue"; outputParameterInfo["behavior"] = "2"; outputParameterInfo["type"] = "Text"; handleParameters.Add(outputParameterInfo); return handleParameters.ToArray(); } return null; } } } |
Enter the specific extension properties as follows:
Property | Value |
---|---|
Extension Name | TestRulesDLL |
Upload DLL | Upload the DLL that the compiled Visual Studio project created. |
Enter the specific extension properties as follows:
Property | Value |
---|---|
Name | TestRulesDLLRule |
Rule Usage | Capture |
Rule Type | Extension |
Extension | TestRuleDLL |
Class Name | NameMathRules |
Method Name | Handle |
Enter the specific extension properties as follows:
Property | Value |
---|---|
Name | TestRulesDLLRule2 |
Rule Usage | Capture |
Rule Type | Extension |
Extension | TestRuleDLL |
Class Name | ConcatenateRules |
Method Name | Handle |