Example #1
0
        private static void LogAllSettings(Entities.Application application)
        {
            List <string> settingsKeys = new List <string>();

            settingsKeys.AddRange(DefaultSettings.Keys);
            settingsKeys.AddRange(System.Configuration.ConfigurationManager.AppSettings.AllKeys.ToList().Where(k => !settingsKeys.Contains(k)));

            Business.Setting            business   = new Business.Setting();
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("Application", application.Id);
            Layers.ModelCollection <Entities.Setting> settings = business.GetModelCollection(parameters);

            System.Configuration.AppSettingsReader settingsReader = new System.Configuration.AppSettingsReader();

            settingsKeys.Remove("AppCode");
            settingsKeys.Remove("AppKey");
            settingsKeys.Remove("AppName");

            foreach (string key in settingsKeys.Where(k => settings.Count(s => s.Key == k) == 0))
            {
                try
                {
                    Commons.Utilities.Logger.Info(key + ": " + settingsReader.GetValue(key, typeof(string)).ToString() + " [App config file setting]");
                }
                catch
                {
                    Commons.Utilities.Logger.Info(key + ": " + DefaultSettings[key] + " [App default settings]");
                }
            }

            foreach (Entities.Setting setting in settings)
            {
                if (setting.Key != "AppCode" && setting.Key != "AppKey" && setting.Key != "AppName")
                {
                    Commons.Utilities.Logger.Info(setting.Key + ": " + setting.Value + " [App settings repository]");
                }
            }
        }
Example #2
0
        public static string GetSettingValue(string key, Entities.Application application = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }
            if (application == null)
            {
                application = RunningApplication;
            }

            if (key != "AppKey" && key != "AppCode")
            {
                Business.Setting business = new Business.Setting();
                Entities.Setting setting  = business.GetSettingByKey(key, application);
                if (setting != null)
                {
                    return(setting.Value);
                }
            }

            System.Configuration.AppSettingsReader settingsReader = new System.Configuration.AppSettingsReader();
            try
            {
                string value = settingsReader.GetValue(key, typeof(string)).ToString();
                return(value);
            }
            catch
            {
                if (DefaultSettings.ContainsKey(key))
                {
                    return(DefaultSettings[key]);
                }
                return(null);
            }
        }