示例#1
0
        private void SetPropertyValueToStore(PropertyInfo property, object value, bool skipUpdate)
        {
            ModuleProc PROC    = new ModuleProc("ConfigStoreManager", "Initialize");
            Type       typeOfT = this.Store.GetType();

            try
            {
                if (skipUpdate)
                {
                    property.SetValue(this.Store, value, null);
                }

                var configAttribute = (from a in property.GetCustomAttributes(typeof(ConfigSettingAttribute), true)
                                       select a).OfType <ConfigSettingAttribute>().FirstOrDefault();
                if (configAttribute != null)
                {
                    Type attrType = configAttribute.GetType();
                    if (attrType == typeof(ConfigAppSettingAttribute))
                    {
                    }
                    else if (attrType == typeof(ConfigRegistrySettingAttribute))
                    {
                        ConfigRegistrySettingAttribute configAttributeReg = configAttribute as ConfigRegistrySettingAttribute;
                        if (value.GetType() == typeof(bool))
                        {
                            if (configAttributeReg.RegKeyType == RegKeyType.REG_KT_DWORD)
                            {
                                value = ((bool)value ? 1 : 0);
                            }
                        }
                        RegistryHelper.SetRegValue(configAttributeReg.RegistryKey,
                                                   configAttributeReg.SubKey,
                                                   configAttributeReg.KeyName,
                                                   value);
                    }
                    OnPropertyChanged(property.Name, value);
                    try
                    {
                        Log.InfoV(PROC, "Property : {0}, Value : {1}", property.Name, value.ToString());
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
示例#2
0
        private static void GetPropertyValueFromStore(IConfigStore store, PropertyInfo property)
        {
            ModuleProc PROC    = new ModuleProc("ConfigStoreManager", "Initialize");
            Type       typeOfT = store.GetType();
            object     value   = null;

            try
            {
                var configAttribute = (from a in property.GetCustomAttributes(typeof(ConfigSettingAttribute), true)
                                       select a).OfType <ConfigSettingAttribute>().FirstOrDefault();
                if (configAttribute != null)
                {
                    Type attrType = configAttribute.GetType();
                    Type keyType  = configAttribute.KeyType;

                    if (attrType == typeof(ConfigAppSettingAttribute))
                    {
                        ConfigAppSettingAttribute configAttributeApp = configAttribute as ConfigAppSettingAttribute;
                        string appValue = Extensions.GetAppSettingValue(configAttributeApp.KeyName, configAttributeApp.DefaultValue.ToStringSafe());

                        if (configAttributeApp.CustomAction)
                        {
                            ExecuteCustomAction(store, string.Empty, configAttributeApp.KeyName, appValue);
                        }
                        else
                        {
                            value = GetFormattedValue(keyType, appValue);
                        }
                    }
                    else if (attrType == typeof(ConfigRegistrySettingAttribute))
                    {
                        ConfigRegistrySettingAttribute configAttributeReg = configAttribute as ConfigRegistrySettingAttribute;
                        switch (configAttribute.KeyType.FullName)
                        {
                        case "System.Boolean":
                            value = RegistryHelper.GetValueBool(configAttributeReg.RegistryKey,
                                                                configAttributeReg.SubKey,
                                                                configAttributeReg.KeyName,
                                                                false);
                            break;

                        case "System.SByte":
                            value = RegistryHelper.GetValueSByte(configAttributeReg.RegistryKey,
                                                                 configAttributeReg.SubKey,
                                                                 configAttributeReg.KeyName,
                                                                 0);
                            break;

                        case "System.Byte":
                            value = RegistryHelper.GetValueByte(configAttributeReg.RegistryKey,
                                                                configAttributeReg.SubKey,
                                                                configAttributeReg.KeyName,
                                                                0);
                            break;

                        case "System.Int16":
                            value = RegistryHelper.GetValueInt16(configAttributeReg.RegistryKey,
                                                                 configAttributeReg.SubKey,
                                                                 configAttributeReg.KeyName,
                                                                 0);
                            break;

                        case "System.UInt16":
                            value = RegistryHelper.GetValueUInt16(configAttributeReg.RegistryKey,
                                                                  configAttributeReg.SubKey,
                                                                  configAttributeReg.KeyName,
                                                                  0);
                            break;

                        case "System.Int32":
                            value = RegistryHelper.GetValueInt32(configAttributeReg.RegistryKey,
                                                                 configAttributeReg.SubKey,
                                                                 configAttributeReg.KeyName,
                                                                 0);
                            break;

                        case "System.UInt32":
                            value = RegistryHelper.GetValueUInt32(configAttributeReg.RegistryKey,
                                                                  configAttributeReg.SubKey,
                                                                  configAttributeReg.KeyName,
                                                                  0);
                            break;

                        case "System.Int64":
                            value = RegistryHelper.GetValueInt64(configAttributeReg.RegistryKey,
                                                                 configAttributeReg.SubKey,
                                                                 configAttributeReg.KeyName,
                                                                 0);
                            break;

                        case "System.UInt64":
                            value = RegistryHelper.GetValueUInt64(configAttributeReg.RegistryKey,
                                                                  configAttributeReg.SubKey,
                                                                  configAttributeReg.KeyName,
                                                                  0);
                            break;

                        case "System.Double":
                            value = RegistryHelper.GetValueDouble(configAttributeReg.RegistryKey,
                                                                  configAttributeReg.SubKey,
                                                                  configAttributeReg.KeyName,
                                                                  0);
                            break;

                        default:
                            value = RegistryHelper.GetValueString(configAttributeReg.RegistryKey,
                                                                  configAttributeReg.SubKey,
                                                                  configAttributeReg.KeyName,
                                                                  string.Empty);
                            break;
                        }
                    }
                    else if (attrType == typeof(ConfigApplicationSettingAttribute))
                    {
#if REF_BMC_COMMON
                        ConfigApplicationSettingAttribute configAttributeApp = configAttribute as ConfigApplicationSettingAttribute;
                        string appValue = BMC.Common.Utilities.BMCRegistryHelper.GetRegKeyValue(configAttributeApp.SubKey, configAttributeApp.KeyName);

                        if (configAttributeApp.CustomAction)
                        {
                            ExecuteCustomAction(store, configAttributeApp.SubKey, configAttributeApp.KeyName, appValue);
                        }
                        else
                        {
                            value = GetFormattedValue(keyType, appValue);
                        }
#endif
                    }
                    else if (attrType == typeof(ConfigDatabaseSettingAttribute))
                    {
                        ConfigDatabaseSettingAttribute configAttributeApp = configAttribute as ConfigDatabaseSettingAttribute;
                        if (configAttributeApp.CustomAction)
                        {
                            value = GetFormattedValue(keyType, ExecuteCustomActionDB(store, configAttributeApp.SubKey, configAttributeApp.KeyName, configAttributeApp.DefaultValue.ToStringSafe()));
                        }
                    }

                    if (property.CanWrite)
                    {
                        property.SetValue(store, value, null);
                    }
                    try
                    {
                        Log.InfoV(PROC, "Property : {0}, Value : {1}", property.Name, value.ToStringSafe());
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }