private static void InitLoggerFromXml()
        {
            try
            {
                string directory = string.Empty;

                try
                {
                    directory = Environment.GetEnvironmentVariable("BMCConfigPath", EnvironmentVariableTarget.Machine);
                }
                catch { }

                if (!directory.IsEmpty() &&
                    Directory.Exists(directory))
                {
                    string fileName = Path.Combine(directory, "BMCApp.xml");
                    if (File.Exists(fileName) &&
                        new FileInfo(fileName).Length > 0)
                    {
                        XmlDocument xDoc = new XmlDocument();
                        xDoc.Load(fileName);

                        if (xDoc.DocumentElement != null)
                        {
                            XmlNode valueNode = xDoc.DocumentElement.SelectSingleNode("Section[@id='Honeyframe']/KeyValue[@key='DisableLogging']/@value");
                            if (valueNode != null)
                            {
                                _disableLogging = TypeSystem.GetValueBoolSimple(valueNode.InnerText);
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }
        public T GetSettingValue <T>(string settingName, T defaultValue)
        {
            ModuleProc PROC   = new ModuleProc(this.DYN_MODULE_NAME, "GetSettingValue");
            object     result = defaultValue;

            try
            {
                using (Database db = DbFactory.OpenDB(_connectionString))
                {
                    DbParameter[] parameters = db.CreateParameters(1);
                    parameters[0] = db.CreateParameter("@SettingName", settingName);
                    DataRow dr = db.ExecuteDataset("dbo.rsp_EBS_GetSettingValue", parameters).GetDataRow(0, 0);
                    if (dr != null)
                    {
                        string settingValue = dr.Field <string>("Setting_Value");

                        if (typeof(T) == typeof(int))
                        {
                            result = TypeSystem.GetValueInt(settingValue);
                        }
                        else if (typeof(T) == typeof(long))
                        {
                            result = TypeSystem.GetValueInt64(settingValue);
                        }
                        else if (typeof(T) == typeof(bool))
                        {
                            result = TypeSystem.GetValueBoolSimple(settingValue);
                        }
                        else
                        {
                            result = settingValue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return((T)result);
        }
        /// <summary>
        /// Gets the RegValue bool.
        /// </summary>
        /// <param name="subKey">The sub key.</param>
        /// <param name="keyName">Name of the key.</param>
        /// <param name="defaultValue">if set to <c>true</c> [default value].</param>
        /// <returns>Value from the key.</returns>
        public static bool GetValueBool(this RegistryKey regKey, string subKey, string keyName, bool defaultValue)
        {
            string sValue = GetValueString(regKey, subKey, keyName, string.Empty);

            return(TypeSystem.GetValueBoolSimple(sValue));
        }
 public bool GetSettingValueBool(string settingName, bool defaultValue)
 {
     return(TypeSystem.GetValueBoolSimple(this.GetSettingValue(settingName, defaultValue.ToString())));
 }
Example #5
0
        private static object GetFormattedValue(Type keyType, string appValue)
        {
            object value = null;

            switch (keyType.FullName)
            {
            case "System.Char":
            {
                if (appValue.Length > 0)
                {
                    value = appValue[0];
                }
                else
                {
                    value = '\0';
                }
            }
            break;

            case "System.Boolean":
                value = TypeSystem.GetValueBoolSimple(appValue);
                break;

            case "System.SByte":
                value = TypeSystem.GetValueSByte(appValue);
                break;

            case "System.Byte":
                value = TypeSystem.GetValueByte(appValue);
                break;

            case "System.Int16":
                value = TypeSystem.GetValueShort(appValue);
                break;

            case "System.UInt16":
                value = TypeSystem.GetValueUShort(appValue);
                break;

            case "System.Int32":
                value = TypeSystem.GetValueInt(appValue);
                break;

            case "System.UInt32":
                value = TypeSystem.GetValueUInt(appValue);
                break;

            case "System.Int64":
                value = TypeSystem.GetValueInt64(appValue);
                break;

            case "System.UInt64":
                value = TypeSystem.GetValueUInt64(appValue);
                break;

            case "System.Double":
                value = TypeSystem.GetValueDouble(appValue);
                break;

            default:
            {
                if (keyType.BaseType != null &&
                    keyType.BaseType == typeof(Enum))
                {
                    if (Enum.IsDefined(keyType, appValue))
                    {
                        value = TypeSystem.GetValueEnum(keyType, appValue);
                    }
                    else
                    {
                        string sValue = Enum.GetName(keyType, TypeSystem.GetValueInt(appValue));
                        value = TypeSystem.GetValueEnum(keyType, sValue);
                    }
                }
                else
                {
                    value = TypeSystem.GetValueString(appValue);
                }
            }
            break;
            }

            return(value);
        }