2018-02-15 12:39:01 +00:00
|
|
|
using System;
|
2011-04-22 17:09:06 +00:00
|
|
|
using System.Collections.Generic;
|
2018-04-21 04:59:31 +00:00
|
|
|
using System.Globalization;
|
2012-02-12 00:01:52 +00:00
|
|
|
using System.Linq;
|
2010-10-05 06:21:18 +00:00
|
|
|
using NLog;
|
2013-12-03 06:41:40 +00:00
|
|
|
using NzbDrone.Common.EnsureThat;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Common.Http.Proxy;
|
2013-08-06 05:22:58 +00:00
|
|
|
using NzbDrone.Core.Configuration.Events;
|
2014-03-13 05:27:36 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-09-14 06:36:07 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2020-04-03 00:57:36 +00:00
|
|
|
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
2017-06-17 13:02:58 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.Security;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
2013-02-24 06:48:52 +00:00
|
|
|
namespace NzbDrone.Core.Configuration
|
2010-09-23 03:19:47 +00:00
|
|
|
{
|
2013-08-02 07:16:37 +00:00
|
|
|
public enum ConfigKey
|
|
|
|
{
|
2017-03-08 21:07:51 +00:00
|
|
|
DownloadedMoviesFolder
|
2013-08-02 07:16:37 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 06:48:52 +00:00
|
|
|
public class ConfigService : IConfigService
|
2010-09-23 03:19:47 +00:00
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
private readonly IConfigRepository _repository;
|
2013-09-14 06:36:07 +00:00
|
|
|
private readonly IEventAggregator _eventAggregator;
|
2013-02-24 06:48:52 +00:00
|
|
|
private readonly Logger _logger;
|
|
|
|
private static Dictionary<string, string> _cache;
|
2012-02-12 00:01:52 +00:00
|
|
|
|
2013-09-14 06:36:07 +00:00
|
|
|
public ConfigService(IConfigRepository repository, IEventAggregator eventAggregator, Logger logger)
|
2010-09-23 03:19:47 +00:00
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
_repository = repository;
|
2013-09-14 06:36:07 +00:00
|
|
|
_eventAggregator = eventAggregator;
|
2013-02-24 06:48:52 +00:00
|
|
|
_logger = logger;
|
|
|
|
_cache = new Dictionary<string, string>();
|
2010-09-23 03:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 05:57:01 +00:00
|
|
|
private Dictionary<string, object> AllWithDefaults()
|
2013-03-04 01:07:22 +00:00
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
var dict = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
|
2013-03-04 01:07:22 +00:00
|
|
|
|
|
|
|
var type = GetType();
|
|
|
|
var properties = type.GetProperties();
|
|
|
|
|
2013-03-27 00:51:37 +00:00
|
|
|
foreach (var propertyInfo in properties)
|
2013-03-04 01:07:22 +00:00
|
|
|
{
|
|
|
|
var value = propertyInfo.GetValue(this, null);
|
|
|
|
dict.Add(propertyInfo.Name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2014-02-16 09:56:12 +00:00
|
|
|
public void SaveConfigDictionary(Dictionary<string, object> configValues)
|
2013-05-23 05:12:01 +00:00
|
|
|
{
|
|
|
|
var allWithDefaults = AllWithDefaults();
|
|
|
|
|
|
|
|
foreach (var configValue in configValues)
|
|
|
|
{
|
|
|
|
object currentValue;
|
|
|
|
allWithDefaults.TryGetValue(configValue.Key, out currentValue);
|
2019-12-22 22:08:53 +00:00
|
|
|
if (currentValue == null || configValue.Value == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-23 05:12:01 +00:00
|
|
|
|
|
|
|
var equal = configValue.Value.ToString().Equals(currentValue.ToString());
|
|
|
|
|
|
|
|
if (!equal)
|
2015-11-24 05:57:01 +00:00
|
|
|
{
|
2013-05-23 05:12:01 +00:00
|
|
|
SetValue(configValue.Key, configValue.Value.ToString());
|
2015-11-24 05:57:01 +00:00
|
|
|
}
|
2013-05-23 05:12:01 +00:00
|
|
|
}
|
2013-08-06 05:22:58 +00:00
|
|
|
|
2013-09-14 06:36:07 +00:00
|
|
|
_eventAggregator.PublishEvent(new ConfigSavedEvent());
|
2013-05-23 05:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool IsDefined(string key)
|
2014-04-19 15:09:22 +00:00
|
|
|
{
|
|
|
|
return _repository.Get(key.ToLower()) != null;
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
public bool AutoUnmonitorPreviouslyDownloadedMovies
|
2012-11-23 02:56:27 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedMovies"); }
|
|
|
|
set { SetValue("AutoUnmonitorPreviouslyDownloadedMovies", value); }
|
2012-01-16 04:12:47 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 06:50:42 +00:00
|
|
|
public int Retention
|
2012-02-17 09:32:33 +00:00
|
|
|
{
|
|
|
|
get { return GetValueInt("Retention", 0); }
|
|
|
|
set { SetValue("Retention", value); }
|
|
|
|
}
|
|
|
|
|
2013-03-05 06:50:42 +00:00
|
|
|
public string RecycleBin
|
2012-09-04 06:49:04 +00:00
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
get { return GetValue("RecycleBin", string.Empty); }
|
2012-09-04 06:49:04 +00:00
|
|
|
set { SetValue("RecycleBin", value); }
|
|
|
|
}
|
|
|
|
|
2019-08-31 02:50:03 +00:00
|
|
|
public int RecycleBinCleanupDays
|
|
|
|
{
|
|
|
|
get { return GetValueInt("RecycleBinCleanupDays", 7); }
|
|
|
|
set { SetValue("RecycleBinCleanupDays", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public int RssSyncInterval
|
2013-08-06 05:22:58 +00:00
|
|
|
{
|
2017-01-24 20:26:51 +00:00
|
|
|
get { return GetValueInt("RssSyncInterval", 60); }
|
2013-08-06 05:22:58 +00:00
|
|
|
|
|
|
|
set { SetValue("RssSyncInterval", value); }
|
|
|
|
}
|
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
public int AvailabilityDelay
|
|
|
|
{
|
|
|
|
get { return GetValueInt("AvailabilityDelay", 0); }
|
|
|
|
set { SetValue("AvailabilityDelay", value); }
|
|
|
|
}
|
2017-02-23 05:03:48 +00:00
|
|
|
|
2017-01-28 19:59:21 +00:00
|
|
|
public int NetImportSyncInterval
|
|
|
|
{
|
|
|
|
get { return GetValueInt("NetImportSyncInterval", 60); }
|
|
|
|
|
|
|
|
set { SetValue("NetImportSyncInterval", value); }
|
|
|
|
}
|
2018-03-26 07:03:43 +00:00
|
|
|
|
|
|
|
public string ListSyncLevel
|
|
|
|
{
|
|
|
|
get { return GetValue("ListSyncLevel", "disabled"); }
|
|
|
|
set { SetValue("ListSyncLevel", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ImportExclusions
|
|
|
|
{
|
|
|
|
get { return GetValue("ImportExclusions", string.Empty); }
|
|
|
|
set { SetValue("ImportExclusions", value); }
|
|
|
|
}
|
|
|
|
|
2020-04-03 00:57:36 +00:00
|
|
|
public TMDbCountryCode CertificationCountry
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("CertificationCountry", TMDbCountryCode.US); }
|
|
|
|
|
|
|
|
set { SetValue("CertificationCountry", value); }
|
|
|
|
}
|
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
public int MaximumSize
|
|
|
|
{
|
|
|
|
get { return GetValueInt("MaximumSize", 0); }
|
|
|
|
set { SetValue("MaximumSize", value); }
|
|
|
|
}
|
2017-02-25 21:38:52 +00:00
|
|
|
|
2014-12-15 23:40:53 +00:00
|
|
|
public int MinimumAge
|
|
|
|
{
|
|
|
|
get { return GetValueInt("MinimumAge", 0); }
|
|
|
|
|
|
|
|
set { SetValue("MinimumAge", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool AutoDownloadPropers
|
2013-08-12 06:00:40 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("AutoDownloadPropers", true); }
|
|
|
|
|
|
|
|
set { SetValue("AutoDownloadPropers", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool EnableCompletedDownloadHandling
|
2014-04-19 15:09:22 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
get { return GetValueBoolean("EnableCompletedDownloadHandling", true); }
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
set { SetValue("EnableCompletedDownloadHandling", value); }
|
|
|
|
}
|
|
|
|
|
2017-04-17 15:12:09 +00:00
|
|
|
public bool PreferIndexerFlags
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("PreferIndexerFlags", false); }
|
2017-04-10 09:17:31 +00:00
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
set { SetValue("PreferIndexerFlags", value); }
|
2017-04-17 15:12:09 +00:00
|
|
|
}
|
2017-04-10 09:17:31 +00:00
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
public bool AllowHardcodedSubs
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("AllowHardcodedSubs", false); }
|
2017-04-10 09:41:08 +00:00
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
set { SetValue("AllowHardcodedSubs", value); }
|
|
|
|
}
|
2017-04-17 15:12:09 +00:00
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
public string WhitelistedHardcodedSubs
|
|
|
|
{
|
|
|
|
get { return GetValue("WhitelistedHardcodedSubs", ""); }
|
2017-04-17 15:12:09 +00:00
|
|
|
|
2018-03-26 07:03:43 +00:00
|
|
|
set { SetValue("WhitelistedHardcodedSubs", value); }
|
|
|
|
}
|
2017-04-10 09:41:08 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool RemoveCompletedDownloads
|
2014-04-19 15:09:22 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("RemoveCompletedDownloads", false); }
|
|
|
|
|
|
|
|
set { SetValue("RemoveCompletedDownloads", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool AutoRedownloadFailed
|
2013-10-24 22:12:39 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("AutoRedownloadFailed", true); }
|
|
|
|
|
|
|
|
set { SetValue("AutoRedownloadFailed", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool RemoveFailedDownloads
|
2013-10-25 05:55:32 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("RemoveFailedDownloads", true); }
|
|
|
|
|
|
|
|
set { SetValue("RemoveFailedDownloads", value); }
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
public bool CreateEmptyMovieFolders
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("CreateEmptyMovieFolders", false); }
|
|
|
|
|
|
|
|
set { SetValue("CreateEmptyMovieFolders", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DeleteEmptyFolders
|
2013-11-19 06:25:02 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
get { return GetValueBoolean("DeleteEmptyFolders", false); }
|
2013-11-19 06:25:02 +00:00
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
set { SetValue("DeleteEmptyFolders", value); }
|
2013-11-19 06:25:02 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 05:27:36 +00:00
|
|
|
public FileDateType FileDate
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("FileDate", FileDateType.None); }
|
|
|
|
|
|
|
|
set { SetValue("FileDate", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string DownloadClientWorkingFolders
|
2013-08-22 15:34:51 +00:00
|
|
|
{
|
|
|
|
get { return GetValue("DownloadClientWorkingFolders", "_UNPACK_|_FAILED_"); }
|
|
|
|
set { SetValue("DownloadClientWorkingFolders", value); }
|
|
|
|
}
|
|
|
|
|
2019-05-02 10:51:21 +00:00
|
|
|
public int CheckForFinishedDownloadInterval
|
|
|
|
{
|
|
|
|
get { return GetValueInt("CheckForFinishedDownloadInterval", 1); }
|
|
|
|
|
|
|
|
set { SetValue("CheckForFinishedDownloadInterval", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public int DownloadClientHistoryLimit
|
2014-05-27 21:04:13 +00:00
|
|
|
{
|
|
|
|
get { return GetValueInt("DownloadClientHistoryLimit", 30); }
|
|
|
|
|
|
|
|
set { SetValue("DownloadClientHistoryLimit", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool SkipFreeSpaceCheckWhenImporting
|
2014-04-04 16:25:18 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("SkipFreeSpaceCheckWhenImporting", false); }
|
|
|
|
|
|
|
|
set { SetValue("SkipFreeSpaceCheckWhenImporting", value); }
|
|
|
|
}
|
|
|
|
|
2019-08-31 02:50:03 +00:00
|
|
|
public int MinimumFreeSpaceWhenImporting
|
|
|
|
{
|
|
|
|
get { return GetValueInt("MinimumFreeSpaceWhenImporting", 100); }
|
|
|
|
|
|
|
|
set { SetValue("MinimumFreeSpaceWhenImporting", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool CopyUsingHardlinks
|
2014-08-17 18:39:08 +00:00
|
|
|
{
|
2016-02-21 19:26:54 +00:00
|
|
|
get { return GetValueBoolean("CopyUsingHardlinks", true); }
|
2014-08-17 18:39:08 +00:00
|
|
|
|
|
|
|
set { SetValue("CopyUsingHardlinks", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool EnableMediaInfo
|
2014-12-14 18:50:38 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("EnableMediaInfo", true); }
|
|
|
|
|
|
|
|
set { SetValue("EnableMediaInfo", value); }
|
|
|
|
}
|
|
|
|
|
2018-02-15 12:39:01 +00:00
|
|
|
public bool ImportExtraFiles
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ImportExtraFiles", false); }
|
|
|
|
|
|
|
|
set { SetValue("ImportExtraFiles", value); }
|
|
|
|
}
|
|
|
|
|
2015-12-25 09:22:00 +00:00
|
|
|
public string ExtraFileExtensions
|
|
|
|
{
|
2018-02-15 12:39:01 +00:00
|
|
|
get { return GetValue("ExtraFileExtensions", "srt"); }
|
2015-12-25 09:22:00 +00:00
|
|
|
|
|
|
|
set { SetValue("ExtraFileExtensions", value); }
|
|
|
|
}
|
|
|
|
|
2017-04-26 11:31:55 +00:00
|
|
|
public bool AutoRenameFolders
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("AutoRenameFolders", false); }
|
|
|
|
|
|
|
|
set { SetValue("AutoRenameFolders", value); }
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
public RescanAfterRefreshType RescanAfterRefresh
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("RescanAfterRefresh", RescanAfterRefreshType.Always); }
|
|
|
|
|
|
|
|
set { SetValue("RescanAfterRefresh", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool SetPermissionsLinux
|
2014-01-26 08:57:14 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("SetPermissionsLinux", false); }
|
|
|
|
|
|
|
|
set { SetValue("SetPermissionsLinux", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string FileChmod
|
2014-01-14 19:21:20 +00:00
|
|
|
{
|
2014-01-26 08:57:14 +00:00
|
|
|
get { return GetValue("FileChmod", "0644"); }
|
2014-01-14 19:21:20 +00:00
|
|
|
|
|
|
|
set { SetValue("FileChmod", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public int FirstDayOfWeek
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
2018-04-21 04:59:31 +00:00
|
|
|
get { return GetValueInt("FirstDayOfWeek", (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); }
|
2014-08-05 05:44:09 +00:00
|
|
|
|
|
|
|
set { SetValue("FirstDayOfWeek", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string CalendarWeekColumnHeader
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
|
|
|
get { return GetValue("CalendarWeekColumnHeader", "ddd M/D"); }
|
|
|
|
|
|
|
|
set { SetValue("CalendarWeekColumnHeader", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string ShortDateFormat
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
|
|
|
get { return GetValue("ShortDateFormat", "MMM D YYYY"); }
|
|
|
|
|
|
|
|
set { SetValue("ShortDateFormat", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string LongDateFormat
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
|
|
|
get { return GetValue("LongDateFormat", "dddd, MMMM D YYYY"); }
|
|
|
|
|
|
|
|
set { SetValue("LongDateFormat", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public string TimeFormat
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
|
|
|
get { return GetValue("TimeFormat", "h(:mm)a"); }
|
|
|
|
|
|
|
|
set { SetValue("TimeFormat", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool ShowRelativeDates
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ShowRelativeDates", true); }
|
|
|
|
|
|
|
|
set { SetValue("ShowRelativeDates", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public bool EnableColorImpairedMode
|
2015-04-21 22:14:16 +00:00
|
|
|
{
|
|
|
|
get { return GetValueBoolean("EnableColorImpairedMode", false); }
|
|
|
|
|
|
|
|
set { SetValue("EnableColorImpairedMode", value); }
|
|
|
|
}
|
|
|
|
|
2015-01-02 18:57:51 +00:00
|
|
|
public bool CleanupMetadataImages
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("CleanupMetadataImages", true); }
|
|
|
|
|
|
|
|
set { SetValue("CleanupMetadataImages", value); }
|
|
|
|
}
|
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public string PlexClientIdentifier => GetValue("PlexClientIdentifier", Guid.NewGuid().ToString(), true);
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string RijndaelPassphrase => GetValue("RijndaelPassphrase", Guid.NewGuid().ToString(), true);
|
2015-01-26 02:03:21 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string HmacPassphrase => GetValue("HmacPassphrase", Guid.NewGuid().ToString(), true);
|
2015-01-26 02:03:21 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string RijndaelSalt => GetValue("RijndaelSalt", Guid.NewGuid().ToString(), true);
|
2015-01-26 02:03:21 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string HmacSalt => GetValue("HmacSalt", Guid.NewGuid().ToString(), true);
|
2015-01-26 02:03:21 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public bool ProxyEnabled => GetValueBoolean("ProxyEnabled", false);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public ProxyType ProxyType => GetValueEnum<ProxyType>("ProxyType", ProxyType.Http);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string ProxyHostname => GetValue("ProxyHostname", string.Empty);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public int ProxyPort => GetValueInt("ProxyPort", 8080);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string ProxyUsername => GetValue("ProxyUsername", string.Empty);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string ProxyPassword => GetValue("ProxyPassword", string.Empty);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public string ProxyBypassFilter => GetValue("ProxyBypassFilter", string.Empty);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public bool ProxyBypassLocalAddresses => GetValueBoolean("ProxyBypassLocalAddresses", true);
|
2016-02-02 18:42:22 +00:00
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
public string BackupFolder => GetValue("BackupFolder", "Backups");
|
|
|
|
|
|
|
|
public int BackupInterval => GetValueInt("BackupInterval", 7);
|
|
|
|
|
|
|
|
public int BackupRetention => GetValueInt("BackupRetention", 28);
|
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public CertificateValidationType CertificateValidation =>
|
|
|
|
GetValueEnum("CertificateValidation", CertificateValidationType.Enabled);
|
|
|
|
|
2011-03-31 01:42:27 +00:00
|
|
|
private string GetValue(string key)
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
return GetValue(key, string.Empty);
|
2010-09-23 03:19:47 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 06:36:34 +00:00
|
|
|
private bool GetValueBoolean(string key, bool defaultValue = false)
|
|
|
|
{
|
2011-06-17 02:27:10 +00:00
|
|
|
return Convert.ToBoolean(GetValue(key, defaultValue));
|
2011-04-01 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int GetValueInt(string key, int defaultValue = 0)
|
|
|
|
{
|
2012-12-31 21:09:43 +00:00
|
|
|
return Convert.ToInt32(GetValue(key, defaultValue));
|
2011-04-01 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 05:57:01 +00:00
|
|
|
private T GetValueEnum<T>(string key, T defaultValue)
|
2013-05-14 05:22:51 +00:00
|
|
|
{
|
|
|
|
return (T)Enum.Parse(typeof(T), GetValue(key, defaultValue), true);
|
|
|
|
}
|
|
|
|
|
2013-03-05 06:50:42 +00:00
|
|
|
public string GetValue(string key, object defaultValue, bool persist = false)
|
2010-09-23 03:19:47 +00:00
|
|
|
{
|
2013-12-03 06:41:40 +00:00
|
|
|
key = key.ToLowerInvariant();
|
|
|
|
Ensure.That(key, () => key).IsNotNullOrWhiteSpace();
|
|
|
|
|
2012-02-12 00:01:52 +00:00
|
|
|
EnsureCache();
|
|
|
|
|
|
|
|
string dbValue;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !string.IsNullOrEmpty(dbValue))
|
2015-11-24 05:57:01 +00:00
|
|
|
{
|
2012-02-12 00:01:52 +00:00
|
|
|
return dbValue;
|
2015-11-24 05:57:01 +00:00
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
|
2015-03-25 00:39:40 +00:00
|
|
|
_logger.Trace("Using default config value for '{0}' defaultValue:'{1}'", key, defaultValue);
|
2012-01-25 03:09:49 +00:00
|
|
|
|
|
|
|
if (persist)
|
2013-02-24 06:48:52 +00:00
|
|
|
{
|
2012-01-25 03:09:49 +00:00
|
|
|
SetValue(key, defaultValue.ToString());
|
2013-02-24 06:48:52 +00:00
|
|
|
}
|
2015-11-24 05:57:01 +00:00
|
|
|
|
2011-10-23 20:35:16 +00:00
|
|
|
return defaultValue.ToString();
|
2010-09-23 03:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private void SetValue(string key, bool value)
|
2011-04-01 06:36:34 +00:00
|
|
|
{
|
|
|
|
SetValue(key, value.ToString());
|
|
|
|
}
|
|
|
|
|
2011-10-23 20:35:16 +00:00
|
|
|
private void SetValue(string key, int value)
|
2011-04-01 06:36:34 +00:00
|
|
|
{
|
|
|
|
SetValue(key, value.ToString());
|
|
|
|
}
|
|
|
|
|
2015-11-24 05:57:01 +00:00
|
|
|
private void SetValue(string key, Enum value)
|
|
|
|
{
|
|
|
|
SetValue(key, value.ToString().ToLower());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetValue(string key, string value)
|
2010-09-23 03:19:47 +00:00
|
|
|
{
|
2013-03-06 18:41:13 +00:00
|
|
|
key = key.ToLowerInvariant();
|
2010-09-24 05:37:48 +00:00
|
|
|
|
2014-03-13 20:12:42 +00:00
|
|
|
_logger.Trace("Writing Setting to database. Key:'{0}' Value:'{1}'", key, value);
|
2015-11-26 20:05:37 +00:00
|
|
|
_repository.Upsert(key, value);
|
2012-02-12 00:01:52 +00:00
|
|
|
|
|
|
|
ClearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void EnsureCache()
|
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
lock (_cache)
|
2012-02-12 00:01:52 +00:00
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
if (!_cache.Any())
|
2011-06-23 06:56:17 +00:00
|
|
|
{
|
2015-11-24 05:57:01 +00:00
|
|
|
var all = _repository.All();
|
|
|
|
_cache = all.ToDictionary(c => c.Key.ToLower(), c => c.Value);
|
2011-06-23 06:56:17 +00:00
|
|
|
}
|
2010-09-24 06:16:43 +00:00
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
}
|
2012-02-12 00:01:52 +00:00
|
|
|
|
2015-11-24 05:57:01 +00:00
|
|
|
private static void ClearCache()
|
2012-02-12 00:01:52 +00:00
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
lock (_cache)
|
2012-02-12 00:01:52 +00:00
|
|
|
{
|
2013-02-24 06:48:52 +00:00
|
|
|
_cache = new Dictionary<string, string>();
|
2012-02-12 00:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-23 03:19:47 +00:00
|
|
|
}
|
2012-02-05 06:34:36 +00:00
|
|
|
}
|