Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public void Add(ChatRoom room)
 {
     _db.Rooms.Add(room);
     _db.SaveChanges();
 }
Exemplo n.º 3
0
 public void Add(Settings settings)
 {
     _db.Settings.Add(settings);
     _db.SaveChanges();
 }