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.

Create the DLL

  1. Start Visual Studio
  2. Go to File -> New -> Project
  3. In the Template Categories, expand Visual C# and select the Windows
  4. Then select the Class Library template.
  5. Type a name for your project in the Name field - we will use "TestRules" for this example.
  6. Click OK. The new project appears in Solution Explorer.
  7. If Program.cs is not open in the Code Editor, right-click Program.cs in Solution Explorer and then click View Code.
  8. Renamed Program.cs to NameMathRules.cs.
  9. 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;
            }
        }
    }
  10. Add another class called ConcatenateRules.cs
  11. Replace the contents of  ConcatenateRules.cs with the following code. 

     

    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;
            }
    
        }
    }
  12. Now build the solution (Ctrl+Shift+B).
  13. Find the entire Visual Studio project here: TestRules.zip
Use the DLL in AppBase
Next we need to write a upload the compiled DLL to AppBase.
  1. Open Application Studio of your solution.
  2. From the left menu, select Business Rules -> DLL Extensions
  3. Click the New Extension button. The New Extension page is displayed.
  4. Enter the specific extension properties as follows:

    PropertyValue
    Extension NameTestRulesDLL
    Upload DLLUpload the DLL that the compiled Visual Studio project created.
  5. Click Save.
  6. Now deploy your solution.
  7. From the left menu, select Business Rules -> Rules
  8. Click the New Rule button. The New Rule page is displayed.
  9. Enter the specific extension properties as follows:

    PropertyValue
    NameTestRulesDLLRule
    Rule UsageCapture
    Rule TypeExtension
    ExtensionTestRuleDLL
    Class NameNameMathRules
    Method NameHandle
  10. Click Save. You will be redirected to the Rule detail page.
  11. Click Debug.
  12. Type any number into the TestParam value and click Run.
  13. Inspect the Rule Result text area that displays the correct output of the rule.
  14. Rule the class ConcatenateRules by adding a new rule.
  15. From the left menu, select Business Rules -> Rules
  16. Click the New Rule button. The New Rule page is displayed.
  17. Enter the specific extension properties as follows:

    PropertyValue
    NameTestRulesDLLRule2
    Rule UsageCapture
    Rule TypeExtension
    ExtensionTestRuleDLL
    Class NameConcatenateRules
    Method NameHandle
  18. Click Save. You will be redirected to the Rule detail page.
  19. Click Debug.
  20. Type any word into the TestParam value and click Run.
  21. Inspect the Rule Result text area that displays the correct output of the rule.