예제 #1
0
        public static IEnumerable <GeneralSettings> ParseObjectToSettingDataBase(GeneralSettingsApp settings)
        {
            var result = new List <GeneralSettings>();

            foreach (var prop in settings.GetType().GetProperties())
            {
                var setting = new GeneralSettings {
                    SettingName = prop.Name
                };

                if (prop.PropertyType.Name == typeof(bool).Name)
                {
                    setting.ValueBool = (bool)prop.GetValue(settings);
                }
                else if ((prop.PropertyType.Name == typeof(int).Name) || (prop.PropertyType.IsEnum == true))
                {
                    setting.ValueInt = (int)prop.GetValue(settings);
                }
                else if (prop.PropertyType.Name == typeof(string).Name)
                {
                    setting.ValueString = (string)prop.GetValue(settings);
                }
                else
                {
                    throw new Exception(String.Format("Setting type object is not recognized - Property Name: {0} / Property Type: {1}", prop.Name, prop.PropertyType.Name));
                }

                result.Add(setting);
            }

            return(result);
        }
예제 #2
0
        private static GeneralSettingsApp ParsetDataBaseToSettingsObject(IEnumerable <GeneralSettings> generalSettings)
        {
            var settings = new GeneralSettingsApp();

            foreach (var prop in settings.GetType().GetProperties())
            {
                var item = generalSettings.FirstOrDefault(s => s.SettingName == prop.Name);
                if (item == null)
                {
                    continue;
                }

                object settingsValue;
                if (item.ValueBool != null)
                {
                    settingsValue = item.ValueBool;
                }
                else if (item.ValueInt != null)
                {
                    settingsValue = item.ValueInt;
                }
                else if (item.ValueString != null)
                {
                    settingsValue = item.ValueString;
                }
                else
                {
                    settingsValue = null;
                }
                //    throw new Exception(String.Format("Setting type data base is not recognized {0}", prop.Name));

                prop.SetValue(settings, settingsValue);
            }


            return(settings);
        }
예제 #3
0
        public static void AddInCache(GeneralSettingsApp setting)
        {
            double secondsInOneMinute = 60;

            CacheWrapper.AddToMyCache(CacheKeyName, setting, CachePriority.Default, secondsInOneMinute * CacheExpirationInMinutes);
        }