예제 #1
0
 public Biz_RuleSet(string ruleSetName)
 {
     using (var context = new MyRuleEngineEntities())
     {
         var ruleSet = context.RuleSet.Where(x => x.Name == ruleSetName).FirstOrDefault();
         if (ruleSet != null)
         {
             dbRulesSet = ruleSet;
             if (dbRulesSet.RuleSet_Rule.Count == 0)
             {
                 throw (new Exception("There in no rule defined in RuleSet!"));
             }
             GenerateBizRuleSetFromDBRuleset();
         }
         else
         {
             throw (new Exception("RuleSet '" + ruleSetName + "' in not defined!"));
         }
     }
 }
        public static T GetVocabulary <T>(string vocabularyName, params object[] objects)
        {
            using (var context = new MyRuleEngineEntities())
            {
                var dbVocabulary = context.Vocabulary.Where(x => x.Name == vocabularyName).FirstOrDefault();
                if (dbVocabulary != null)
                {
                    var vocabularyInstance = ReflectionHelper.GetClassInstance(dbVocabulary.AssemblyInfo.Name, dbVocabulary.AssemblyInfo.Path, dbVocabulary.ClassName);
                    if (vocabularyInstance != null)
                    {
                        if (ReflectionHelper.ImplementsInterface(vocabularyInstance, typeof(IVocabulary)))
                        {
                            var result = ((IVocabulary)vocabularyInstance).GetVocabulary(objects);
                            if (result.GetType() == typeof(T))
                            {
                                return((T)result);
                            }
                        }
                        else
                        {
                            throw (new Exception("Vocabulary class '" + dbVocabulary.ClassName + "' is not of type IVocabulary"));
                        }
                    }
                    else
                    {
                        throw (new Exception("Vocabulary class '" + dbVocabulary.ClassName + "' colud not be found in assembly '" + dbVocabulary.AssemblyInfo.Name + "'"));
                    }
                }
                else
                {
                    throw (new Exception("Vocabulary in not defined!"));
                }
            }

            return(default(T));
        }