Ejemplo n.º 1
0
        public static List <RuleInformation> GetDescriptions(Assembly discoverAssembly)
        {
            lock (typeof(RuleDiscoveryProvider)){
                string cacheKey = discoverAssembly.FullName;

                if (!_descriptions.ContainsKey(cacheKey))
                {
                    _descriptions[cacheKey] = new List <RuleInformation>();

                    var rules = DiscoverRules(new Assembly[] { discoverAssembly });

                    foreach (var rulepair in rules)
                    {
                        if (!rulepair.Item2.Enabled)
                        {
                            continue;
                        }

                        RuleInformation info = new RuleInformation();
                        info.Description = rulepair.Item2.Description;
                        info.PsuedoLogic = rulepair.Item2.PsuedoLogic;

                        Rule rule = null;
                        try {
                            rule = RulesEngine <RuleContext> .ConstructRule(rulepair.Item1);
                        } catch { }
                        if (rule != null)
                        {
                            info.Name   = rule.Name;
                            info.Number = rule.Number;
                            info.Scope  = rule.Scope;
                        }
                        else
                        {
                            info.Name   = "RuleLoadingError";
                            info.Number = "0.0";
                            info.Scope  = RuleScope.Global;
                        }

                        _descriptions[cacheKey].Add(info);
                    }


                    _descriptions[cacheKey] = _descriptions[cacheKey].OrderBy(x => x.Number).ToList();
                }
                return(_descriptions[cacheKey]);
            }
        }
Ejemplo n.º 2
0
        public static RuleInformation Map(Tuple <Type, RuleDiscoveryAttribute> discoveredRule)
        {
            RuleInformation info = new RuleInformation();

            if (discoveredRule != null)
            {
                info.Description = discoveredRule.Item2.Description;
                info.PsuedoLogic = discoveredRule.Item2.PsuedoLogic;
                info.Enabled     = discoveredRule.Item2.Enabled;
            }

            Rule rule = RulesEngine <RequestContext> .ConstructRule(discoveredRule.Item1, false);

            info.Rule = rule;
            //if (rule != null)
            //{
            //    info.Name = rule.Name;
            //    info.Number = rule.Number;
            //    info.Scope = rule.Scope;
            //}
            return(info);
        }