Esempio n. 1
0
        private void SetListPropertiesFromDataReader <T>(T obj, XapDataReader dr)
        {
            IXapPocoField pocoField;

            try {
                foreach (PropertyInfo prop in PropertyService.Instance.GetInterfaceProperties <T>(obj).GetProperties())
                {
                    pocoField = pocoMap.GetField(prop.ShortName());
                    if (pocoField != null)
                    {
                        string columnName = pocoMap.GetField(prop.ShortName()).DbColumn;
                        if (prop.PropertyType == typeof(string))
                        {
                            if (pocoMap.GetField(prop.ShortName()).DataType == "SmartDate")
                            {
                                prop.SetValue(obj, dr.GetSmartDate(columnName).Text, null);
                            }
                            else
                            {
                                prop.SetValue(obj, dr.GetString(columnName).Trim(), null);
                            }
                        }
                        else if (prop.PropertyType == typeof(SmartDate))
                        {
                            prop.SetValue(obj, dr.GetSmartDate(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(bool))
                        {
                            prop.SetValue(obj, dr.GetBoolean(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(int))
                        {
                            prop.SetValue(obj, dr.GetInt32(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(long))
                        {
                            prop.SetValue(obj, dr.GetInt64(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(short))
                        {
                            prop.SetValue(obj, dr.GetInt16(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(double))
                        {
                            prop.SetValue(obj, dr.GetDouble(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(decimal))
                        {
                            prop.SetValue(obj, dr.GetDecimal(columnName), null);
                        }
                        else if (prop.PropertyType == typeof(float))
                        {
                            prop.SetValue(obj, dr.GetFloat(columnName), null);
                        }
                    }
                }
            } catch (Exception ex) {
                throw new XapException($"Error setting properties for {obj.GetType().FullName}", ex);
            }
        }
Esempio n. 2
0
        IXapEvaluationService IXapValidationProvider.LoadRules <T>(T obj, string ruleType)
        {
            IXapDataProvider db      = null;
            IXapRuleSet      ruleSet = null;
            IXapRule         rule    = null;

            try {
                string dbEnvironment  = string.Empty;
                string lobName        = string.Empty;
                string componentName  = string.Empty;
                string ruleDependents = string.Empty;

                GetDbContext <T>(obj, out dbEnvironment, out lobName, out componentName);

                db = DbFactory.Instance.Db(dbEnvironment, lobName, "CORE.SelectRules");

                XapDataReader dr = db.AddParameter(DbFactory.Instance.DbParameter("RuleType", ruleType))
                                   .AddParameter(DbFactory.Instance.DbParameter("LobName", lobName))
                                   .AddParameter(DbFactory.Instance.DbParameter("ComponentName", componentName))
                                   .AddParameter(DbFactory.Instance.DbParameter("NameSpace", obj.GetType().FullName))
                                   .ExecuteReader();

                while (dr.Read())
                {
                    ruleSet = evaluationService.GetRuleSet(dr.GetString("RuleSet"));
                    evaluationService.AddRuleSet(ruleSet);

                    rule                 = ruleSet.GetRule(dr.GetString("RuleName"));
                    rule.RuleType        = dr.GetString("RuleType");
                    rule.RuleSyntax      = dr.GetString("RuleSyntax");
                    rule.RuleDescription = dr.GetString("RuleDesc");
                    rule.RuleMessage     = dr.GetString("RuleMessage");

                    IXapRuleVariable ruleVariable = EvaluationFactory.Instance.CreateRuleVariable(dr.GetString("PropertyName"));
                    rule.AddRuleVariable(ruleVariable);

                    ruleDependents = dr.GetString("Dependencies");

                    string[] dependents = ruleDependents.Split(',');
                    for (int i = 0; i < dependents.Length; i++)
                    {
                        IXapRuleVariable variableDependent = EvaluationFactory.Instance.CreateRuleVariable(dependents[i]);
                        rule.AddRuleVariable(variableDependent);
                    }
                    ruleSet.AddRule(rule);
                }

                return(evaluationService);
            }catch (XapException ex) {
                throw;
            }catch (Exception ex) {
                throw new XapException($"Error loading validation rules for {obj.GetType().FullName}", ex);
            } finally {
                db.CloseConnection();
            }
        }