Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public static ApplicationSettings GetDefaultSettings()
 {
     return(new ApplicationSettings
     {
         EncryptionKey = CryptoHelper.ToHex(GenerateRandomBytes()),
         VerificationKey = CryptoHelper.ToHex(GenerateRandomBytes()),
         MaxFileUploadBytes = 5242880,
         MaxMessageLength = 0,
         AllowUserRegistration = true,
         AllowRoomCreation = true,
         AllowUserResetPassword = false,
         RequestResetPasswordValidThroughInHours = 6,
         EmailSender = String.Empty,
         ContentProviders = ContentProviderSetting.GetDefaultContentProviders()
     });
 }