コード例 #1
0
        static RuleSet CreateRuleset(string rulesetName)
        {
            // create a simple rule
            // IF MySampleBusinessObject.MyValue != XMLdocument.ID
            // THEN MySampleBusinessObject.MySampleMethod1(5)

            //Creating the XML bindings on the SampleSchema XSD

            //Document Binding that binds to the schema name and specifies the selector
            XPathPair          xp_root = new XPathPair("/*[local-name()='Root']", "Root");
            XMLDocumentBinding xdb     = new XMLDocumentBinding("SampleSchema", xp_root);

            //DocumentField Bindings that bind to the fields in the schema that need to be used in rule defintion
            XPathPair xp_ID = new XPathPair("/*[local-name()='Root']/*[local-name()='ID']", "ID");
            XMLDocumentFieldBinding xfb1 = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_ID, xdb);

            //Creating .NET class (property and member) bindings

            // Class Bindings to bind to the class defintions whose properties and memebers will be used in rule defintion
            ClassBinding cb = new ClassBinding(typeof(Microsoft.Samples.BizTalk.BusinessRulesHelloWorld2.HelloWorld2Library.HelloWorld2LibraryObject));

            // Member Bindings to bind to the properties and members in the MySampleBusinessObject class that need to be used in rule definition
            ClassMemberBinding myValue = new ClassMemberBinding("MyValue", cb);

            ArgumentCollection argList = new ArgumentCollection();

            argList.Add(new Constant(5));
            ClassMemberBinding method1 = new ClassMemberBinding("MySampleMethod", cb, argList);


            // create IF part
            LogicalExpression condition = new NotEqual(new UserFunction(myValue), new UserFunction(xfb1));

            // create then part
            ActionCollection actions = new ActionCollection();

            actions.Add(new UserFunction(method1));

            // create the rule
            Rule rule1 = new Rule("rule1", 0, condition, actions);

            //create the verion information and ruleset description

            DateTime    time  = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
            VersionInfo vinf1 = new VersionInfo("Sample RuleSet to demonstrate the use of the Policy object", time, "BizRules", 1, 0);

            // create the ruleset
            RuleSet rs1 = new RuleSet(rulesetName, vinf1);

            rs1.Rules.Add(rule1);
            return(rs1);
        }
コード例 #2
0
        public void CreatePolicy()
        {
            //Creating XML document bindings on the Case XSD schema

            //Document Binding that binds to the schema name and specifies the selector

            XPathPair          xp_root = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']", "Root");
            XMLDocumentBinding xmlCase = new XMLDocumentBinding("Microsoft.Samples.BizTalk.LoansProcessor.Case", xp_root);

            //DocumentField Bindings that bind to the fields int the schema that are used in the defintion of "Income Rule" and the associated negation rule (the ELSE part)

            XPathPair xp_basicSalary = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='Income']/*[local-name()='BasicSalary']", "Income/BasicSalary");
            XMLDocumentFieldBinding xmlCase_basicSalary = new XMLDocumentFieldBinding((Type.GetType("System.Int32")), xp_basicSalary, xmlCase);

            XPathPair xp_otherIncome = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='Income']/*[local-name()='OtherIncome']", "Income/OtherIncome");
            XMLDocumentFieldBinding xmlCase_otherIncome = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_otherIncome, xmlCase);

            Constant c1 = new Constant("Income status is valid");

            XPathPair xp_incomeStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='IncomeStatus']", "IncomeStatus");
            XMLDocumentFieldBinding xmlCase_incomeStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_incomeStatus, xmlCase, c1);

            Constant c1_1 = new Constant("Income status is not valid");
            XMLDocumentFieldBinding xmlCase_incomeStatusNegation = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_incomeStatus, xmlCase, c1_1);

            // Wrapping the XML bindings as User Functions

            UserFunction uf_basicSalary          = new UserFunction(xmlCase_basicSalary);
            UserFunction uf_otherIncome          = new UserFunction(xmlCase_otherIncome);
            UserFunction uf_incomeStatus         = new UserFunction(xmlCase_incomeStatus);
            UserFunction uf_incomeStatusNegation = new UserFunction(xmlCase_incomeStatusNegation);

            // Condition 1: IF Basic Salary and Other Income > 0

            Constant    zero = new Constant(0);
            GreaterThan ge1  = new GreaterThan(uf_basicSalary, zero);
            GreaterThan ge2  = new GreaterThan(uf_otherIncome, zero);

            LogicalExpressionCollection andList4 = new LogicalExpressionCollection();

            andList4.Add(ge1);
            andList4.Add(ge2);
            LogicalAnd la4 = new LogicalAnd(andList4);

            //Action 1 - THEN set Income Status in the incoming Case document to be Valid

            ActionCollection actionList1 = new ActionCollection();

            actionList1.Add(uf_incomeStatus);

            /*  Name: Income Rule
             *
             *      Description:
             *      IF Basic Salary and Other Income > 0
             *      THEN set Income Status in the incoming Case document to be Valid
             *
             */

            Microsoft.RuleEngine.Rule r1 = new Microsoft.RuleEngine.Rule("Income Status Rule", la4, actionList1);

            //Negation of Income Rule

            LogicalNot ln1 = new LogicalNot(la4);

            ActionCollection actionList1_1 = new ActionCollection();

            actionList1_1.Add(uf_incomeStatusNegation);

            Microsoft.RuleEngine.Rule r1_1 = new Microsoft.RuleEngine.Rule("Negation of Income Status Rule", ln1, actionList1_1);

            //Creating DB bindings on the NorthWind DB -> CustInfo table

            // DataRow Binding to bind to the Data Table, and provide the Data Set name (defaulting here to the DB name)

            DataConnectionBinding drb_CustInfo = new DataConnectionBinding("CustInfo", "Northwind");

            // Column bindings to bind to the columns in the Data Table that need to be used in the Commitments Status Rule

            DatabaseColumnBinding col_ID = new DatabaseColumnBinding(Type.GetType("System.String"), "ID", drb_CustInfo);
            DatabaseColumnBinding col_creditCardBalance = new DatabaseColumnBinding(Type.GetType("System.Int32"), "CreditCardBalance", drb_CustInfo);

            // Creating the XML Document Field Bindings required in rule defintion

            XPathPair xp_ID = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='ID']", "ID");
            XMLDocumentFieldBinding xmlCase_ID = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_ID, xmlCase);

            Constant c3 = new Constant("Compute Commitments");

            XPathPair xp_commitmentsStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='CommitmentsStatus']", "CommitmentsStatus");
            XMLDocumentFieldBinding xmlCase_commitmentsStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_commitmentsStatus, xmlCase, c3);

            // Wrapping the DB and XML bindings as User Functions

            UserFunction uf_xmlID             = new UserFunction(xmlCase_ID);
            UserFunction uf_commitmentsStatus = new UserFunction(xmlCase_commitmentsStatus);
            UserFunction uf_dbID    = new UserFunction(col_ID);
            UserFunction uf_balance = new UserFunction(col_creditCardBalance);

            //Condition 2 : IF the ID in the XML document is equal to the ID in the DB record, and the Credit Card Balance for that record is > 500

            Equal       eq2         = new Equal(uf_dbID, uf_xmlID);
            Constant    c2          = new Constant(500);
            GreaterThan greaterThan = new GreaterThan(uf_balance, c2);

            LogicalExpressionCollection andList2 = new LogicalExpressionCollection();

            andList2.Add(eq2);
            andList2.Add(greaterThan);
            LogicalAnd la2 = new LogicalAnd(andList2);

            //Action 2 Set the Commitments Status field to "Compute Commitments"

            ActionCollection actionList2 = new ActionCollection();

            actionList2.Add(uf_commitmentsStatus);

            /* Rule 2 -
             *                              Name: Commitments Rule
             *
             *                               IF the ID in the Document is = to the ID column in the DB
             *
             *                               AND
             *
             *                               IF Credit Card Balance > 500
             *
             *                               Set Commitments Status in the XML document to be equal to "Compute Commitments"
             */

            Microsoft.RuleEngine.Rule r2 = new Microsoft.RuleEngine.Rule("Commitments Status Rule", la2, actionList2);

            //Negation of Commitments Status Rule (the ELSE part)

            LogicalNot ln2 = new LogicalNot(greaterThan);

            LogicalExpressionCollection andList2negation = new LogicalExpressionCollection();

            andList2negation.Add(eq2);
            andList2negation.Add(ln2);
            LogicalAnd la2negation = new LogicalAnd(andList2negation);

            // Creating the XML Document Field Bindings required in rule defintion

            Constant ignore_string = new Constant("Ignore Commitments");
            XMLDocumentFieldBinding xmlCase_commitmentsStatusNegation = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_commitmentsStatus, xmlCase, ignore_string);
            UserFunction            uf_commitmentsStatusNegation      = new UserFunction(xmlCase_commitmentsStatusNegation);

            ActionCollection actionList2_1 = new ActionCollection();

            actionList2_1.Add(uf_commitmentsStatusNegation);

            Microsoft.RuleEngine.Rule r2_1 = new Microsoft.RuleEngine.Rule("Negation of Commitments Rule", la2negation, actionList2_1);

            // Creating the XML Document Field Bindings required in the Employment Status rule

            XPathPair xp_employmentTime = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='EmploymentType']/*[local-name()='TimeInMonths']", "EmploymentType/TimeInMonths");
            XMLDocumentFieldBinding xmlCase_employmentTime = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_employmentTime, xmlCase);

            UserFunction uf_employmentTime = new UserFunction(xmlCase_employmentTime);
            Constant     action3           = new Constant("Employment Status is valid");

            XPathPair xp_employmentStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='EmploymentStatus']", "EmploymentStatus");
            XMLDocumentFieldBinding xmlCase_employmentStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_employmentStatus, xmlCase, action3);

            UserFunction uf_employmentStatus = new UserFunction(xmlCase_employmentStatus);

            // Condition 3: IF Employment Time > 18 months

            Constant         lengthOfEmployment = new Constant(18);
            GreaterThanEqual greaterThanEqual1  = new GreaterThanEqual(uf_employmentTime, lengthOfEmployment);

            //Action 3 - THEN set Employment Status in the incoming Case document to be Valid

            ActionCollection actionList3 = new ActionCollection();

            actionList3.Add(uf_employmentStatus);

            /*  Name: Employment Status Rule
             *
             *      Description:
             *      IF Time of Employment > 18 months
             *      THEN set Employment Status in the incoming Case document to be Valid
             *
             */

            Microsoft.RuleEngine.Rule r3 = new Microsoft.RuleEngine.Rule("Employment Status Rule", greaterThanEqual1, actionList3);

            // Negation of EmploymentStatus Rule (the ELSE part)

            LogicalNot ln3 = new LogicalNot(greaterThanEqual1);

            Constant empStatus_invalid = new Constant("Employment Status is Invalid");
            XMLDocumentFieldBinding xmlCase_employmentStatusInvalid = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_employmentStatus, xmlCase, empStatus_invalid);
            UserFunction            uf_employmentStatusInvalid      = new UserFunction(xmlCase_employmentStatusInvalid);

            ActionCollection actionList3_1 = new ActionCollection();

            actionList3_1.Add(uf_employmentStatusInvalid);

            Microsoft.RuleEngine.Rule r3_1 = new Microsoft.RuleEngine.Rule("Negation of Employment Status Rule", ln3, actionList3_1);

            // Creating the XML Document Field Bindings required in the Residence Status rule

            XPathPair xp_timeinResidence = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='PlaceOfResidence']/*[local-name()='TimeInMonths']", "PlaceOfResidence/TimeInMonths");
            XMLDocumentFieldBinding xmlCase_timeinResidence = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), xp_timeinResidence, xmlCase);

            UserFunction uf_timeinResidence = new UserFunction(xmlCase_timeinResidence);
            Constant     lengthOfResidence  = new Constant(3);

            Constant residencyStatus_valid = new Constant("Residency Status is valid");

            XPathPair xp_residencyStatus = new XPathPair("/*[local-name()='Root' and namespace-uri()='http://LoansProcessor.Case']/*[local-name()='ResidencyStatus']", "ResidencyStatus");
            XMLDocumentFieldBinding xmlCase_residencyStatus = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_residencyStatus, xmlCase, residencyStatus_valid);
            UserFunction            uf_residencyStatus      = new UserFunction(xmlCase_residencyStatus);

            // Condition 4: IF Time of residence >= 3 years

            GreaterThanEqual greaterThanEqual2 = new GreaterThanEqual(uf_timeinResidence, lengthOfResidence);

            //Action 3 - THEN set Resdiency Status in the incoming Case document to be Valid

            ActionCollection actionList4 = new ActionCollection();

            actionList4.Add(uf_residencyStatus);

            /*  Name: Residency Status Rule
             *
             *      Description:
             *      IF Time of Residency > 3 years
             *      THEN set Residency Status in the incoming Case document to be Valid
             *
             */

            Microsoft.RuleEngine.Rule r4 = new Microsoft.RuleEngine.Rule("Residency Status Rule", greaterThanEqual2, actionList4);

            // Negation of Residency Status Rule

            LogicalNot ln4 = new LogicalNot(greaterThanEqual2);

            Constant residencyStatus_Invalid = new Constant("Residency Status is Invalid");
            XMLDocumentFieldBinding xmlCase_residencyStatusInvalid = new XMLDocumentFieldBinding(Type.GetType("System.String"), xp_residencyStatus, xmlCase, residencyStatus_Invalid);
            UserFunction            uf_residencyStatusInvalid      = new UserFunction(xmlCase_residencyStatusInvalid);

            ActionCollection actionList4_1 = new ActionCollection();

            actionList4_1.Add(uf_residencyStatusInvalid);

            Microsoft.RuleEngine.Rule r4_1 = new Microsoft.RuleEngine.Rule("Negation of Residency Status Rule", ln4, actionList4_1);

            // Creation of the rule-set (policy) and saving it into the file rulestore

            // Creating configuration information (date, version, description, creator, policy name, and fact retriever used to retrieve the required datasets at runtime)

            DateTime    time  = new DateTime(System.DateTime.Today.Year, System.DateTime.Today.Month, System.DateTime.Today.Day);
            VersionInfo vinf1 = new VersionInfo("Rules to process Loan applications", time, "BizRules", 1, 0);
            RuleSet     rs1   = new RuleSet("LoanProcessing", vinf1);
            RuleSetExecutionConfiguration rec1 = new RuleSetExecutionConfiguration();

            Type factRetriever = typeof(myFactRetriever.DbFactRetriever);
            RuleEngineComponentConfiguration recc1 = new RuleEngineComponentConfiguration(factRetriever.Assembly.FullName, factRetriever.FullName);

            rec1.FactRetriever         = recc1;
            rs1.ExecutionConfiguration = rec1;

            // Adding rules to the rule-set

            rs1.Rules.Add(r1);
            rs1.Rules.Add(r1_1);
            rs1.Rules.Add(r2);
            rs1.Rules.Add(r2_1);
            rs1.Rules.Add(r3);
            rs1.Rules.Add(r3_1);
            rs1.Rules.Add(r4);
            rs1.Rules.Add(r4_1);

            // Saving the rule-set (policy) to an XML file in the current directory

            FileRuleStore frs1 = new FileRuleStore("LoanProcessing.xml");

            frs1.Add(rs1);

            // Publish and deploy the ruleset to rulestore
            DeployRuleSet(rs1);
        }
コード例 #3
0
        private string WriteTerm(Term term)
        {
            string             displayString = "";
            ArgumentCollection args          = null;

            if (term is Constant)
            {
                if (((Constant)term).Value != null)
                {
                    if (((Constant)term).Value.ToString() == string.Empty)
                    {
                        displayString = "<empty string>";
                    }
                    else
                    {
                        displayString = ((Constant)term).Value.ToString();
                    }
                }
                else
                {
                    displayString = "<null>";
                }
            }

            else if (term is UserFunction || term is ObjectReference)
            {
                Binding termBinding = null;

                if (term is UserFunction)
                {
                    termBinding = ((UserFunction)term).Binding;
                }
                else
                {
                    termBinding = ((ObjectReference)term).Binding;
                }

                if (termBinding is XMLDocumentBinding)
                {
                    XMLDocumentBinding binding = termBinding as XMLDocumentBinding;
                    displayString = binding.DocumentType;
                }
                else if (termBinding is DatabaseBinding)
                {
                    DatabaseBinding binding = termBinding as DatabaseBinding;
                    displayString = binding.DatasetName;
                }
                else if (termBinding is ClassBinding)
                {
                    ClassBinding binding = termBinding as ClassBinding;
                    displayString = binding.TypeName;
                }
                else if (termBinding is XMLDocumentFieldBinding)
                {
                    XMLDocumentFieldBinding binding = termBinding as XMLDocumentFieldBinding;
                    displayString = binding.DocumentBinding.DocumentType + ":" + binding.DocumentBinding.Selector.Alias + "/" + binding.Field.Alias;

                    if (binding.Argument != null)
                    {
                        if (binding.MemberName.ToLower() == "setstring")
                        {
                            displayString += " = {0}";
                        }

                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DatabaseColumnBinding)
                {
                    DatabaseColumnBinding binding = termBinding as DatabaseColumnBinding;
                    displayString = binding.DatabaseBinding.DatasetName + "." + binding.DatabaseBinding.TableName + "." + binding.ColumnName;

                    if (binding.Argument != null)
                    {
                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DataRowBinding)
                {
                    DataRowBinding binding = termBinding as DataRowBinding;
                    displayString = binding.DisplayName;
                }
                else if (termBinding is ClassMemberBinding)
                {
                    ClassMemberBinding binding = termBinding as ClassMemberBinding;
                    displayString = binding.ClassBinding.ImplementingType.FullName + "." + binding.MemberName;
                    args          = binding.Arguments;
                }
            }
            else if (term is ArithmeticFunction)
            {
                ArithmeticFunction f = term as ArithmeticFunction;
                args = new ArgumentCollection();
                args.Add(f.LeftArgument);
                args.Add(f.RightArgument);
            }
            else if (term is Assert)
            {
                args = new ArgumentCollection();
                args.Add(((Assert)term).Facts);
            }
            else if (term is Retract)
            {
                args = new ArgumentCollection();
                args.Add(((Retract)term).Facts);
            }
            else if (term is Update)
            {
                args = new ArgumentCollection();
                args.Add(((Update)term).Facts);
            }
            else if (term is Halt)
            {
                args = new ArgumentCollection();
                args.Add(((Halt)term).ClearAgenda);
            }

            ArrayList argsToDisplay = new ArrayList();

            if (args != null)
            {
                foreach (Term t in args)
                {
                    argsToDisplay.Add(WriteTerm(t));
                }
            }

            string format = "";

            if (term.VocabularyLink != null)
            {
                VocabularyDefinition vd = vdefs[term.VocabularyLink.DefinitionId] as VocabularyDefinition;
                format = vd.GetFormatString().Format;

                // Added to fix halt documentation CD 20140328
                if (format == "halt choices")
                {
                    format = "{0}";
                    if (displayString == "True")
                    {
                        argsToDisplay.Add("clear all rules firings");
                    }
                    else
                    {
                        argsToDisplay.Add("do not clear");
                    }
                }
            }
            else
            {
                format = displayString;
            }

            displayString = TryStringFormat(format, argsToDisplay.ToArray());

            return("<span class='TableData'>" + displayString + "</span>");
        }
コード例 #4
0
        // Method to create the rule-set or policy
        public void CreateRuleSet()
        {
            //Creating XML document bindings on the Medical claims XSD schema

            //Document Binding that binds to the schema name and specifies the selector
            XMLDocumentBinding xmlClaim = new XMLDocumentBinding("MedicalClaims", "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']");

            //DocumentField Bindings that bind to the fields in the schema that need to be used in rule defintion

            XMLDocumentFieldBinding xmlClaim_Name   = new XMLDocumentFieldBinding(Type.GetType("System.String"), "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']/*[local-name()='Name']", xmlClaim);
            XMLDocumentFieldBinding xmlClaim_ID     = new XMLDocumentFieldBinding(Type.GetType("System.String"), "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']/*[local-name()='ID']", xmlClaim);
            XMLDocumentFieldBinding xmlClaim_Amount = new XMLDocumentFieldBinding(Type.GetType("System.Double"), "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']/*[local-name()='Amount']", xmlClaim);
            XMLDocumentFieldBinding xmlClaim_Nights = new XMLDocumentFieldBinding(Type.GetType("System.Int32"), "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']/*[local-name()='Nights']", xmlClaim);
            XMLDocumentFieldBinding xmlClaim_Date   = new XMLDocumentFieldBinding(Type.GetType("System.DateTime"), "/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_Project1.MedicalClaims']/*[local-name()='Date']", xmlClaim);

            //Creating DB bindings on the NorthWind DB -> PolicyValidity table

            // DataRow Binding to bind to the Data Table, and provide the Data Set name (defaulting here to the DB name)

            DataConnectionBinding policyvalidityTable = new DataConnectionBinding("PolicyValidity", "Northwind");

            // Column bindings to bind to the columns in the Data Table that need to be used in rule definition

            DatabaseColumnBinding policyvalidityTable_IDColumn           = new DatabaseColumnBinding(Type.GetType("System.String"), "ID", policyvalidityTable);
            DatabaseColumnBinding policyvalidityTable_PolicyStatusColumn = new DatabaseColumnBinding(Type.GetType("System.String"), "PolicyStatus", policyvalidityTable);

            //Creating .NET class (property and member) bindings

            // Class Bindings to bind to the class defintions whose properties and members will be used in rule definition

            ClassBinding dateClass    = new ClassBinding(typeof(TimeStamp));
            ClassBinding resultsClass = new ClassBinding(new Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults().GetType());


            // Member Bindings to bind to the properties and members in the TimeStamp class that need to be used in rule definition

            ClassMemberBinding today = new ClassMemberBinding("Value", dateClass);

            // Member bindings for ClaimResults.Status and ClaimResults.Reason properties

            ClassMemberBinding reason = new ClassMemberBinding("Reason", resultsClass);
            ClassMemberBinding status = new ClassMemberBinding("Status", resultsClass);


            // Member bindings for ClaimResults.Status and ClaimResults.Reason properties with different arguments

            // Creation of constant strings that are required as arguments for rule actions

            Constant           c1  = new Constant(" REJECTED!");
            ArgumentCollection al1 = new ArgumentCollection();

            al1.Add(c1);

            Constant           c2  = new Constant("Amount of claim has exceeded Policy limit");
            ArgumentCollection al2 = new ArgumentCollection();

            al2.Add(c2);

            Constant           c3  = new Constant(" Claim Accepted!");
            ArgumentCollection al3 = new ArgumentCollection();

            al3.Add(c3);

            Constant           c4  = new Constant(" Amount of Nights has exceeded Policy limit");
            ArgumentCollection al4 = new ArgumentCollection();

            al4.Add(c4);

            Constant           c5  = new Constant(" Cannot submit claims for future dates!");
            ArgumentCollection al5 = new ArgumentCollection();

            al5.Add(c5);

            Constant           c6  = new Constant("Policy ID is invalid");
            ArgumentCollection al6 = new ArgumentCollection();

            al6.Add(c6);

            ClassMemberBinding status_Rejected      = new ClassMemberBinding("Status", resultsClass, al1);
            ClassMemberBinding reason_invalidAmount = new ClassMemberBinding("Reason", resultsClass, al2);
            ClassMemberBinding status_Accepted      = new ClassMemberBinding("Status", resultsClass, al3);
            ClassMemberBinding reason_invalidNights = new ClassMemberBinding("Reason", resultsClass, al4);
            ClassMemberBinding reason_invalidDate   = new ClassMemberBinding("Reason", resultsClass, al5);
            ClassMemberBinding reason_invalidID     = new ClassMemberBinding("Reason", resultsClass, al6);


            // MemberBinding for the SendLead method in the ClaimResults class with the name and ID from the incoming XML document as arguments

            Term arg1 = new UserFunction(xmlClaim_Name);
            Term arg2 = new UserFunction(xmlClaim_ID);
            ArgumentCollection args1 = new ArgumentCollection();

            args1.Add(arg1);
            args1.Add(arg2);
            ClassMemberBinding sendLead = new ClassMemberBinding("SendLead", resultsClass, args1);

            // Object reference binding to the ClaimResults object that is to be asserted back in to the initial fact base as part of the rule actions

            ObjectReference resultsObject = new ObjectReference(resultsClass);


            // Wrapping the XML bindings as User Functions

            UserFunction uf_xmlName   = new UserFunction(xmlClaim_Name);
            UserFunction uf_xmlID     = new UserFunction(xmlClaim_ID);
            UserFunction uf_xmlAmount = new UserFunction(xmlClaim_Amount);
            UserFunction uf_xmlNights = new UserFunction(xmlClaim_Nights);
            UserFunction uf_xmlDate   = new UserFunction(xmlClaim_Date);

            // Wrapping the DB bindings as User Functions

            UserFunction uf_IDColumn           = new UserFunction(policyvalidityTable_IDColumn);
            UserFunction uf_PolicyStatusColumn = new UserFunction(policyvalidityTable_PolicyStatusColumn);


            // Wrapping the .NET bindings as User Functions

            UserFunction uf_today         = new UserFunction(today);
            UserFunction uf_reason        = new UserFunction(reason);
            UserFunction uf_status        = new UserFunction(status);
            UserFunction uf_rejected      = new UserFunction(status_Rejected);
            UserFunction uf_invalidAmount = new UserFunction(reason_invalidAmount);
            UserFunction uf_accepted      = new UserFunction(status_Accepted);
            UserFunction uf_invalidNights = new UserFunction(reason_invalidNights);
            UserFunction uf_invalidDate   = new UserFunction(reason_invalidDate);
            UserFunction uf_invalidID     = new UserFunction(reason_invalidID);
            UserFunction uf_sendLead      = new UserFunction(sendLead);


            // Rule 1: Amount Check (check to see if claim amount has exceeded the allowable limit)

            // Condition 1: IF the Amount in the XML document element is > 1000 AND IF the Claims.ClaimResults object has not been modified i.e if STATUS = null

            GreaterThan ge1 = new GreaterThan(uf_xmlAmount, new Constant(1000));
            Equal       eq1 = new Equal(uf_status, new Constant(uf_status.Type, null as string));

            LogicalExpressionCollection conditionAnd1 = new LogicalExpressionCollection();

            conditionAnd1.Add(ge1);
            conditionAnd1.Add(eq1);

            LogicalAnd la1 = new LogicalAnd(conditionAnd1);

            //Action 1 - THEN Claims.ClaimResults.Status = "REJECTED" and Claims.ClaimResults.Reason = "Amount of claim has exceeded limit" && Assert this object back into working memory

            ActionCollection actionList1 = new ActionCollection();

            actionList1.Add(uf_rejected);
            actionList1.Add(uf_invalidAmount);
            actionList1.Add(new Assert(resultsObject));

            // Amount Check Rule defintion
            Microsoft.RuleEngine.Rule r1 = new Microsoft.RuleEngine.Rule("Amount Check", la1, actionList1);

            // Rule 2: Nights Spent (check to see if no of nights has exceeded the allowable limit)

            // Condition 2: IF the number of nights in the XML document element is > 10 AND IF the Claims.ClaimResults object has not been modified i.e if STATUS = null

            GreaterThan ge2 = new GreaterThan(uf_xmlNights, new Constant(10));

            Equal eq2 = new Equal(uf_status, new Constant(uf_status.Type, null as string));

            LogicalExpressionCollection conditionAnd2 = new LogicalExpressionCollection();

            conditionAnd2.Add(ge2);
            conditionAnd2.Add(eq2);

            LogicalAnd la2 = new LogicalAnd(conditionAnd2);

            //Action 2 - THEN Claims.ClaimResults.Status = "REJECTED" and Claims.ClaimResults.Reason = "No of Nights has exceeded limit" && Assert this object back into working memory

            ActionCollection actionList2 = new ActionCollection();

            actionList2.Add(uf_rejected);
            actionList2.Add(uf_invalidNights);
            actionList2.Add(new Assert(resultsObject));

            //Nights Spent Rule Definition
            Microsoft.RuleEngine.Rule r2 = new Microsoft.RuleEngine.Rule("Nights Spent", la2, actionList2);

            // Rule 3: Date Validity (check to see if the date on the claim is greater than today's date)

            // Condition 3: IF date on the incoming XML claim is greater than Today than reject the claim AND IF the Claims.ClaimResults object has not been modified i.e if RESULT = null

            GreaterThan ge3 = new GreaterThan(uf_xmlDate, uf_today);

            Equal eq3 = new Equal(uf_status, new Constant(uf_status.Type, null as string));

            LogicalExpressionCollection conditionAnd3 = new LogicalExpressionCollection();

            conditionAnd3.Add(ge3);
            conditionAnd3.Add(eq3);

            LogicalAnd la3 = new LogicalAnd(conditionAnd3);

            //Action 3 - THEN Claims.ClaimResults.Status = "REJECTED" and Claims.ClaimResults.Reason = "Cannot submit claims in the future!" && Assert this object back into working memory

            ActionCollection actionList3 = new ActionCollection();

            actionList3.Add(uf_rejected);
            actionList3.Add(uf_invalidDate);
            actionList3.Add(new Assert(resultsObject));

            // Date Validity Rule defintion

            Microsoft.RuleEngine.Rule r3 = new Microsoft.RuleEngine.Rule("Date Validity Check", la3, actionList3);

            // Rule 4: Policy Validity (check to see if the policy ID is valid by inspecting the database)

            // Condition 4: IF the Policy is Invalid for the ID in the XML claim (where the validity record is stored in the DB) AND IF the Claims.ClaimResults object has not been modified i.e if RESULT = null

            Equal    ceq1           = new Equal(uf_IDColumn, uf_xmlID);
            Constant invalid_string = new Constant("INVALID");
            Equal    ceq2           = new Equal(uf_PolicyStatusColumn, invalid_string);

            LogicalExpressionCollection andList1 = new LogicalExpressionCollection();

            andList1.Add(ceq1);
            andList1.Add(ceq2);
            LogicalAnd cla1 = new LogicalAnd(andList1);

            Equal eq4 = new Equal(uf_status, new Constant(uf_status.Type, null as string));

            LogicalExpressionCollection conditionAnd4 = new LogicalExpressionCollection();

            conditionAnd4.Add(cla1);
            conditionAnd4.Add(eq4);

            LogicalAnd la4 = new LogicalAnd(conditionAnd4);


            //Action 4 - THEN Claims.ClaimResults.Status = "REJECTED" and Claims.ClaimResults.Reason = "Policy Invalid" && Assert this object back into working memory

            ActionCollection actionList4 = new ActionCollection();

            actionList4.Add(uf_rejected);
            actionList4.Add(uf_invalidID);
            actionList4.Add(new Assert(resultsObject));

            // Policy Validity Rule defintion

            Microsoft.RuleEngine.Rule r4 = new Microsoft.RuleEngine.Rule("Policy Validity Check", la4, actionList4);

            // Rule 5: (Send a Lead To Policy Department (by executing the SendLead Method) if the user's policy has expired and is invalid)

            // Condition 5: IF Claim.ClaimResults.Reason = "Policy invalid"

            Constant Reason_String = new Constant("Policy ID is invalid");
            Equal    eq5           = new Equal(uf_reason, Reason_String);

            //Action 5 - THEN Send a Lead to the Policy Department by invoking the function Claim.ClaimResults.SendLead wirh customer ID and Name

            ActionCollection actionList5 = new ActionCollection();

            actionList5.Add(uf_sendLead);

            Microsoft.RuleEngine.Rule r5 = new Microsoft.RuleEngine.Rule("Send Lead", eq5, actionList5);

            // Rule 6:  Set the Claim Status to be Valid if it the Status has not been set to Invalid

            // Condition 6: IF Claim.ClaimResults.Status = null

            Equal eq6 = new Equal(uf_status, new Constant(uf_status.Type, null as string));

            //Action 6 - THEN Send a Set the Claim status to be Valid

            ActionCollection actionList6 = new ActionCollection();

            actionList6.Add(uf_accepted);

            //Claim Accepted Rule definition

            Microsoft.RuleEngine.Rule r6 = new Microsoft.RuleEngine.Rule("Claim Accepted", eq6, actionList6);

            // Since initially the condition is TRUE (the claim has not been rejected or accepted),
            // we need to make this rule a lower priority so that the rejection rules run first.
            // That way, if the claim is rejected, this rule will not execute.
            r6.Priority = -1;

            // Creation of the rule-set (policy) and saving it into the file rulestore

            // Creating configuration information (date, version, description, creator, policy name, and fact retriever used to retrieve the required datasets at runtime)

            DateTime    time  = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
            VersionInfo vinf1 = new VersionInfo("Rules to Process medical Insurance Claims", time, "BizRules", 0, 0);
            RuleSet     rs1   = new RuleSet("MedicalInsurancePolicy", vinf1);
            RuleSetExecutionConfiguration    rec1  = new RuleSetExecutionConfiguration();
            RuleEngineComponentConfiguration recc1 = new RuleEngineComponentConfiguration("FactRetrieverForClaimsProcessing", "Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.FactRetrieverForClaimsProcessing.DbFactRetriever");

            rec1.FactRetriever         = recc1;
            rs1.ExecutionConfiguration = rec1;

            // Adding rules to the rule-set

            rs1.Rules.Add(r1);
            rs1.Rules.Add(r2);
            rs1.Rules.Add(r3);
            rs1.Rules.Add(r4);
            rs1.Rules.Add(r5);
            rs1.Rules.Add(r6);

            // Saving the rule-set (policy) to an XML file in the current directory

            FileRuleStore frs1 = new FileRuleStore("MedicalInsurancePolicy.xml");

            frs1.Add(rs1);
        }