Ejemplo n.º 1
0
        public RuleBookTraceInformation[] Execute(DateTime effectiveDate, string ruleBookName, Dictionary<string, object> inputs)
        {
            //MoreApplicationFactory.GetCompiler(effectiveDate);
            var rulesEngine = new RulesEngine();
            var assemblyEffectiveDate = MoreApplicationFactory.GetAssemblyEffectiveDate(effectiveDate);
            var factory = rulesEngine.GetFactory(MoreApplicationFactory.GetAssemblyName(assemblyEffectiveDate),
                MoreApplicationFactory.GetLookupRepository(effectiveDate)
                );
            if (factory == null)
            {
                throw new Exception(
                    "Either the assembly was not found.  Or it was compiled incorrectly. Recompile and try again.");
            }
            var ruleBook = factory.GetRuleBook(ruleBookName);

            if (ruleBook == null)
            {
                throw new Exception("Rule book not found.");
            }
            var result = ruleBook.Execute(inputs);
            if (result.Errors.Any())
            {
                var error = result.Errors.First();
                throw new FaultException(string.Format("{0} - {1}", error.Message, error.RuleDescription));
            }
            return result.TraceInformation.ToArray();
        }
Ejemplo n.º 2
0
        public InputRequirement[] GetInputRequirements(DateTime effectiveDate, string ruleBookName)
        {
            var rulesEngine = new RulesEngine();
            var assemblyEffectiveDate = MoreApplicationFactory.GetAssemblyEffectiveDate(effectiveDate);
            var factory = rulesEngine.GetFactory(
                MoreApplicationFactory.GetAssemblyName(assemblyEffectiveDate),
                MoreApplicationFactory.GetLookupRepository(effectiveDate));
            if (factory == null)
            {
                throw new Exception(
                    "Either the assembly was not found.  Or it was compiled incorrectly. Recompile and try again.");
            }
            var ruleBook = factory.GetRuleBook(ruleBookName);

            return ruleBook.GetInputRequirements().ToArray();
        }
Ejemplo n.º 3
0
        //public ActionResult TestForm(string ruleBookName)
        //{
        //    ViewBag.RuleBookName = ruleBookName;
        //    MoreApplicationFactory.GetCompiler(MissionControlDate);
        //    var rulesEngine = new RulesEngine();
        //    var factory = rulesEngine.GetFactory(MoreApplicationFactory.GetAssemblyName(MissionControlDate), TableStrategy);
        //    var ruleBook = factory.GetRuleBook(ruleBookName);
        //    if (ruleBook == null)
        //    {
        //        return View("ErrorMessage", (object)"Rule book not found");
        //    }
        //    return View(ruleBook.GetInputRequirements());
        //}
        public ActionResult TestRuleBook(string ruleBookName)
        {
            ViewBag.RuleBookName = ruleBookName;
            MoreApplicationFactory.GetCompiler(MissionControlDate);
            var rulesEngine = new RulesEngine();
            var factory = rulesEngine.GetFactory(MoreApplicationFactory.GetAssemblyName(MissionControlDate), TableStrategy);
            var ruleBook = factory.GetRuleBook(ruleBookName);

            var ruleBookRequirements = ruleBook.GetInputRequirements();
            var inputs = new Dictionary<string, object>();

            foreach (var ruleBookRequirement in ruleBookRequirements)
            {
                inputs.Add(ruleBookRequirement.Name, Request[ruleBookRequirement.Name]);
            }

            return Json(ruleBook.Execute(inputs), JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 4
0
        // POST api/values
        public object Post(RulesExecuteModel model)
        {
            // MoreApplicationFactory.GetCompiler(model.EffectiveDate);
            try
            {
                var inputs = JsonHelper.FromJson(model.Data);
                var rulesEngine = new RulesEngine();
                var assemblyEffectiveDate = MoreApplicationFactory.GetAssemblyEffectiveDate(model.EffectiveDate);
                var factory = rulesEngine.GetFactory(
                    MoreApplicationFactory.GetAssemblyName(assemblyEffectiveDate),
                    MoreApplicationFactory.GetLookupRepository(assemblyEffectiveDate)
                    );
                if (factory == null)
                {
                    return
                        "Either the assembly was not found.  Or it was compiled incorrectly. Recompile and try again.";
                }
                var ruleBook = factory.GetRuleBook(model.RuleBook);

                if (ruleBook == null)
                {
                    return "Rule book not found.";
                }
                var result = ruleBook.Execute(inputs);
                if (result.Errors.Any())
                {
                    var error = result.Errors.First();
                    return string.Format("{0} - {1}", error.Message, error.RuleDescription);
                }
                if (model.Items != null && model.Items.Length > 0 && model.Items.First() != "null")
                {
                    return model.Items.ToDictionary(item => item, result.Find);
                }
                return JsonHelper.GetJsonTrace(result.Results);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }