예제 #1
0
 public ChatService(ICache cache, IRecentMessageCache recentMessageCache, IJabbrRepository repository)
     : this(cache,
            recentMessageCache,
            repository,  
            ApplicationSettings.GetDefaultSettings())
 {
 }
예제 #2
0
        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);
        }
예제 #3
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);
        }
예제 #4
0
        public ApplicationSettings Load()
        {
            ApplicationSettings appSettings = null;

            var settings = _settings.FirstOrDefault();

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

                _settings.Add(settings);
                SaveCollectionToStorage(_settings, _settingsFileName);
            }
            else
            {
                try
                {
                    appSettings = JsonConvert.DeserializeObject <ApplicationSettings>(settings.RawSettings);
                }
                catch
                {
                    // TODO: Record the exception

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

                    settings.RawSettings = JsonConvert.SerializeObject(appSettings);
                    SaveCollectionToStorage(_settings, _settingsFileName);
                }
            }

            return(appSettings);
        }