public void Save(ApplicationSettings settings)
        {
            string rawSettings = JsonConvert.SerializeObject(settings);

            // Update the database
            Settings dbSettings = _repository.Settings.FirstOrDefault();

            if (dbSettings == null)
            {
                dbSettings = new Settings
                {
                    RawSettings = rawSettings
                };

                _repository.Add(dbSettings);
            }
            else
            {
                dbSettings.RawSettings = rawSettings;
            }

            _repository.CommitChanges();

            // Clear the cache
            _cache.Remove(_jabbrSettingsCacheKey);
        }
        public ApplicationSettings Load()
        {
            var settings = _cache.Get<ApplicationSettings>(_jabbrSettingsCacheKey);

            if (settings == null)
            {
                Settings dbSettings = _repository.Settings.FirstOrDefault();

                if (dbSettings == null)
                {
                    // Create the initial app settings
                    settings = ApplicationSettings.GetDefaultSettings();
                    dbSettings = new Settings
                    {
                        RawSettings = JsonConvert.SerializeObject(settings)
                    };

                    _repository.Add(dbSettings);
                }
                else
                {
                    try
                    {
                        settings = JsonConvert.DeserializeObject<ApplicationSettings>(dbSettings.RawSettings);
                        if (settings.ContentProviders == null)
                        {
                            // this will apply the default for the case where ApplicationSettings exists from prior to
                            // when this property was introduced.
                            settings.ContentProviders = ContentProviderSetting.GetDefaultContentProviders();
                        }
                    }
                    catch
                    {
                        // TODO: Record the exception

                        // We failed to load the settings from the db so go back to using the default
                        settings = ApplicationSettings.GetDefaultSettings();

                        dbSettings.RawSettings = JsonConvert.SerializeObject(settings);
                        _repository.CommitChanges();
                    }
                }

                // Cache the settings forever (until it changes)
                _cache.Set(_jabbrSettingsCacheKey, settings, _settingsCacheTimespan);
            }

            return settings;
        }
Exemple #3
0
        private static void DoMigrations()
        {
            // Get the Jabbr connection string
            var connectionString = ConfigurationManager.ConnectionStrings["Jabbr"];

            if (String.IsNullOrEmpty(connectionString.ProviderName) ||
                !connectionString.ProviderName.Equals(SqlClient, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Only run migrations for SQL server (Sql ce not supported as yet)
            var settings = new Settings();
            var migrator = new DbMigrator(settings);
            migrator.Update();
        }
Exemple #4
0
        public ApplicationSettings Load()
        {
            var settings = _cache.Get<ApplicationSettings>(_jabbrSettingsCacheKey);

            if (settings == null)
            {
                Settings dbSettings = _context.Settings.FirstOrDefault();

                if (dbSettings == null)
                {
                    // Create the initial app settings
                    settings = ApplicationSettings.GetDefaultSettings();
                    dbSettings = new Settings
                    {
                        RawSettings = JsonConvert.SerializeObject(settings)
                    };

                    _context.Settings.Add(dbSettings);
                    _context.SaveChanges();
                }
                else
                {
                    try
                    {
                        settings = JsonConvert.DeserializeObject<ApplicationSettings>(dbSettings.RawSettings);
                    }
                    catch
                    {
                        // TODO: Record the exception

                        // We failed to load the settings from the db so go back to using the default
                        settings = ApplicationSettings.GetDefaultSettings();

                        dbSettings.RawSettings = JsonConvert.SerializeObject(settings);
                        _context.SaveChanges();
                    }
                }

                // Cache the settings forever (until it changes)
                _cache.Set(_jabbrSettingsCacheKey, settings, _settingsCacheTimespan);
            }

            return settings;
        }
 public void Add(Settings settings)
 {
     _settings.Add(settings);
 }
 public void Add(Settings settings)
 {
     _db.Settings.Add(settings);
     _db.SaveChanges();
 }