Exemple #1
0
        }         // constructor

        public virtual void Init()
        {
            PropertyInfo[] propertyInfos = GetType().GetProperties();

            foreach (PropertyInfo pi in propertyInfos)
            {
                SupportedTypes ignored;

                bool bInclude =
                    pi.GetGetMethod().IsVirtual&&
                    pi.GetGetMethod().IsPublic&&
                    (pi.GetSetMethod(true) != null) &&
                    SupportedTypes.TryParse(pi.PropertyType.Name, out ignored);

                if (bInclude)
                {
                    configPropertyInfos.Add(pi.Name, pi);
                    Debug("Configuration property to read from DB: {0}", pi.Name);
                }         // if
            }             // for each property

            Info("Reading configurations");

            try {
                AConnection oDB = DbConnectionGenerator.Get(this);

                oDB.ForEachRow((row, bRowsetStart) => {
                    AddSingleConfiguration(row[KeyFieldName].ToString(), row[ValueFieldName].ToString());
                    return(ActionResult.Continue);
                }, SpName);
            }
            catch (Exception e) {
                throw new ConfigurationBaseException("Error reading configurations.", e);
            }     // try
        }         // Init
Exemple #2
0
        }         // AddSingleConfiguration

        protected virtual void SetProperty(string key, string value)
        {
            SupportedTypes st;

            if (!SupportedTypes.TryParse(configPropertyInfos[key].PropertyType.Name, out st))
            {
                throw new ParseConfigurationBaseException("type is not implemented", key, value);
            }

            switch (st)
            {
            case SupportedTypes.Int32:
                int valueAsInt;

                if (!int.TryParse(value, out valueAsInt))
                {
                    throw new ParseConfigurationBaseException("as int", key, value);
                }

                configPropertyInfos[key].SetValue(this, valueAsInt);
                break;

            case SupportedTypes.Int64:
                long valueAsLong;

                if (!long.TryParse(value, out valueAsLong))
                {
                    throw new ParseConfigurationBaseException("as long", key, value);
                }

                configPropertyInfos[key].SetValue(this, valueAsLong);
                break;

            case SupportedTypes.String:
                configPropertyInfos[key].SetValue(this, value);
                break;

            case SupportedTypes.Boolean:
                Boolean valueAsBool;

                if (!Boolean.TryParse(value, out valueAsBool))
                {
                    throw new ParseConfigurationBaseException("as bool", key, value);
                }

                configPropertyInfos[key].SetValue(this, valueAsBool);
                break;

            default:
                throw new ParseConfigurationBaseException("type is not implemented", key, value);
            } // switch
        }     // SetProperty