private List <int> FilterRules(RuleAppliedFilter raf) { IEnumerable <RuleAppliedBase> ruleQuery = _rules.Where(c => c.IsEnabled); if (raf.InType != null) { ruleQuery = ruleQuery.Where(c => c.RuleCodeInTypeId == raf.InType.RuleCodeIOTypeId); } if (raf.OutType != null) { ruleQuery = ruleQuery.Where(c => c.RuleCodeOutTypeId == raf.OutType.RuleCodeIOTypeId); } if (raf.RuleCategory != null) { ruleQuery = ruleQuery.Where(c => c.RuleCategoryId == raf.RuleCategory.RuleCategoryId); } if (raf.RuleSubCategory != null) { ruleQuery = ruleQuery.Where(c => c.RuleSubCategoryId == raf.RuleSubCategory.RuleCategoryId); } return(ruleQuery.Select(c => c.RuleAppliedId).ToList()); }
public RunRulesStatus <Tout> RunRules(RuleAppliedFilter raf, Tin input) { RunRulesParameters <Tin, Tout> param = new RunRulesParameters <Tin, Tout> { CondFuncs = _conditionFuncs, RuleFuncs = _codeFuncs, ContinueRunningAfterException = false, RunUntilFirstRuleHit = false }; return(_rulesBL.RunRules <Tin, Tout> (_rules.Where(c => FilterRules(raf).Contains(c.RuleAppliedId)).ToList(), ref input, param)); }
public RuleAppliedBase GetRuleApplied(RuleAppliedFilter raf) { using (var fs = new StreamReader(System.IO.Path.Combine(_ruleDir, "RuleAppliedBase.xml"))) { var s = fs.ReadToEnd(); return(s.Deserialize <RuleAppliedBase>()); } }
public List <RuleAppliedBase> GetEnabledRules(RuleAppliedFilter raf) { using (var fs = new StreamReader(System.IO.Path.Combine(_ruleDir, "Rules.xml"))) { var s = fs.ReadToEnd(); return(s.Deserialize <List <RuleAppliedBase> >()); } }
public RunRulesStatus <bool> RunRules(RuleAppliedFilter raf, WorkflowState input) { var param = new RunRulesParameters <WorkflowState, bool> { CondFuncs = _conditionFuncs, RuleFuncs = _codeFuncs, ContinueRunningAfterException = false, RunUntilFirstRuleHit = true }; List <RuleAppliedBase> rulesToRun = _rules.Where(c => FilterRules(raf).Contains(c.RuleAppliedId)).ToList(); RunRulesStatus <bool> retVal = _rulesBL.RunRules <WorkflowState, bool>(rulesToRun, ref input, param); return(retVal); }
public RuleAppliedBase GetBaseRuleApplied(int ruleAppliedId, string ruleTable) { RuleAppliedBase ret = null; try { var raf = new RuleAppliedFilter { RuleAppliedId = ruleAppliedId, RuleTableName = ruleTable, }; return(_dal.GetRuleApplied(raf)); } catch (Exception ex) { Console.WriteLine(ex); throw; } return(ret); }
public void TestReferenceDesignRule() { try { BaseRuleEngineDL rulesDL = new BaseRuleEngineDL(ConfigurationManager.AppSettings["RulesEngine"], new TimeSpan(0, 0, 5, 0)); var rulesBL = new ReferenceRuleEngineBL <DyanmicLoadGenericObject, DyanmicLoadGenericObject>(rulesDL); DyanmicLoadGenericObject claim = new DyanmicLoadGenericObject(); RuleAppliedFilter raf = new RuleAppliedFilter { RuleCategoryId = 3, }; var output = rulesBL.RunRules(raf, claim); Assert.IsTrue(output.Result != null); } catch (Exception ex) { Console.WriteLine(ex); } }
public RuleAppliedBase GetRuleApplied(RuleAppliedFilter raf) { if (raf == null) { return(null); } if (raf.RuleAppliedId == null | raf.RuleAppliedId <= 0) { return(null); } if (raf.RuleTableName == null) { return(null); } RuleAppliedBase ret = null; using (var conn = new SqlConnection(_connString)) using (var cmd = new SqlCommand("RulesEngine.spa_GetRuleApplied", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 360; if (raf.RuleAppliedId != null) { cmd.Parameters.Add("@ruleAppliedId", SqlDbType.VarChar).Value = raf.RuleAppliedId; } cmd.Parameters.Add("@ruleAppliedTableName", SqlDbType.VarChar).Value = raf.RuleTableName; conn.Open(); using (var reader = cmd.ExecuteReader()) { if (!reader.Read()) { return(null); } var subCId = reader["RuleSubCategoryId"].ToString(); var applyOrder = reader["ApplyOrder"].ToString(); var condCodeId = reader["ConditionCodeId"].ToString(); var condCodeInputId = reader["ConditionCodeInputTypeId"].ToString(); var condCodeOutputId = reader["ConditionCodeOutputTypeId"].ToString(); ret = new RuleAppliedBase { RuleCategoryId = int.Parse(reader["RuleCategoryId"].ToString()), RuleSubCategoryId = string.IsNullOrWhiteSpace(subCId) ? (int?)null : int.Parse(subCId), ApplyOrder = string.IsNullOrWhiteSpace(applyOrder) ? (int?)null : int.Parse(applyOrder), CodeId = int.Parse(reader["MainCodeId"].ToString()), ConditionCodeId = string.IsNullOrWhiteSpace(condCodeId) ? (int?)null : int.Parse(condCodeId), IsEnabled = bool.Parse(reader["IsEnabled"].ToString()), RuleAppliedId = int.Parse(reader["id"].ToString()), RuleCodeInTypeId = int.Parse(reader["CodeInputTypeId"].ToString()), RuleCodeOutTypeId = int.Parse(reader["CodeOutputTypeId"].ToString()), RuleCodeConditionInTypeId = string.IsNullOrWhiteSpace(condCodeInputId) ? (int?)null : int.Parse(condCodeInputId), RuleCodeConditionOutTypeId = string.IsNullOrWhiteSpace(condCodeOutputId) ? (int?)null : int.Parse(condCodeOutputId) }; } } return(ret); }
private List <RuleAppliedBase> GetEnabledRules(RuleAppliedFilter filter) { return(_rulesDAL.GetEnabledRules(filter)); }