2017-08-28 00:32:26 +00:00
|
|
|
using System;
|
2011-04-22 17:09:06 +00:00
|
|
|
using System.Collections.Generic;
|
2017-01-04 02:36:47 +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;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Common.Http.Proxy;
|
2013-08-06 05:22:58 +00:00
|
|
|
using NzbDrone.Core.Configuration.Events;
|
2021-10-02 01:03:57 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
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;
|
2019-05-05 03:50:00 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2019-03-29 02:20:40 +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-08-28 00:32:26 +00:00
|
|
|
DownloadedAlbumsFolder
|
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);
|
2020-01-03 12:49:24 +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;
|
|
|
|
}
|
|
|
|
|
2017-07-25 01:56:40 +00:00
|
|
|
public bool AutoUnmonitorPreviouslyDownloadedTracks
|
2012-01-16 04:12:47 +00:00
|
|
|
{
|
2017-07-25 01:56:40 +00:00
|
|
|
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedTracks"); }
|
|
|
|
set { SetValue("AutoUnmonitorPreviouslyDownloadedTracks", 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-11 07:22:26 +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
|
|
|
{
|
|
|
|
get { return GetValueInt("RssSyncInterval", 15); }
|
|
|
|
|
|
|
|
set { SetValue("RssSyncInterval", value); }
|
|
|
|
}
|
|
|
|
|
2018-01-14 19:47:36 +00:00
|
|
|
public int MaximumSize
|
|
|
|
{
|
2020-01-03 12:49:24 +00:00
|
|
|
get { return GetValueInt("MaximumSize", 0); }
|
2018-01-14 19:47:36 +00:00
|
|
|
|
2020-01-03 12:49:24 +00:00
|
|
|
set { SetValue("MaximumSize", value); }
|
2018-01-14 19:47:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 23:40:53 +00:00
|
|
|
public int MinimumAge
|
|
|
|
{
|
|
|
|
get { return GetValueInt("MinimumAge", 0); }
|
|
|
|
|
|
|
|
set { SetValue("MinimumAge", value); }
|
|
|
|
}
|
|
|
|
|
2019-05-05 03:50:00 +00:00
|
|
|
public ProperDownloadTypes DownloadPropersAndRepacks
|
2013-08-12 06:00:40 +00:00
|
|
|
{
|
2019-05-05 03:50:00 +00:00
|
|
|
get { return GetValueEnum("DownloadPropersAndRepacks", ProperDownloadTypes.PreferAndUpgrade); }
|
2013-08-12 06:00:40 +00:00
|
|
|
|
2019-05-05 03:50:00 +00:00
|
|
|
set { SetValue("DownloadPropersAndRepacks", value); }
|
2013-08-12 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
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); }
|
|
|
|
}
|
|
|
|
|
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); }
|
|
|
|
}
|
|
|
|
|
2017-07-25 01:56:40 +00:00
|
|
|
public bool CreateEmptyArtistFolders
|
2013-11-19 06:25:02 +00:00
|
|
|
{
|
2017-07-25 01:56:40 +00:00
|
|
|
get { return GetValueBoolean("CreateEmptyArtistFolders", false); }
|
2013-11-19 06:25:02 +00:00
|
|
|
|
2017-07-25 01:56:40 +00:00
|
|
|
set { SetValue("CreateEmptyArtistFolders", value); }
|
2013-11-19 06:25:02 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 01:28:46 +00:00
|
|
|
public bool DeleteEmptyFolders
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("DeleteEmptyFolders", false); }
|
|
|
|
|
|
|
|
set { SetValue("DeleteEmptyFolders", value); }
|
|
|
|
}
|
|
|
|
|
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); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public int DownloadClientHistoryLimit
|
2014-05-27 21:04:13 +00:00
|
|
|
{
|
2020-11-13 23:00:29 +00:00
|
|
|
get { return GetValueInt("DownloadClientHistoryLimit", 60); }
|
2014-05-27 21:04:13 +00:00
|
|
|
|
|
|
|
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-09-12 00:50:57 +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); }
|
|
|
|
}
|
|
|
|
|
2023-05-23 03:36:17 +00:00
|
|
|
public bool UseScriptImport
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("UseScriptImport", false); }
|
|
|
|
|
|
|
|
set { SetValue("UseScriptImport", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ScriptImportPath
|
|
|
|
{
|
|
|
|
get { return GetValue("ScriptImportPath"); }
|
|
|
|
|
|
|
|
set { SetValue("ScriptImportPath", value); }
|
|
|
|
}
|
|
|
|
|
2017-03-25 16:13:28 +00:00
|
|
|
public bool ImportExtraFiles
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ImportExtraFiles", false); }
|
|
|
|
|
|
|
|
set { SetValue("ImportExtraFiles", value); }
|
2014-12-14 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-25 09:22:00 +00:00
|
|
|
public string ExtraFileExtensions
|
|
|
|
{
|
2017-03-26 19:22:58 +00:00
|
|
|
get { return GetValue("ExtraFileExtensions", "srt"); }
|
2015-12-25 09:22:00 +00:00
|
|
|
|
|
|
|
set { SetValue("ExtraFileExtensions", value); }
|
|
|
|
}
|
|
|
|
|
2020-02-27 21:27:03 +00:00
|
|
|
public bool WatchLibraryForChanges
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("WatchLibraryForChanges", true); }
|
|
|
|
|
|
|
|
set { SetValue("WatchLibraryForChanges", value); }
|
|
|
|
}
|
|
|
|
|
2018-11-11 04:50:21 +00:00
|
|
|
public RescanAfterRefreshType RescanAfterRefresh
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("RescanAfterRefresh", RescanAfterRefreshType.Always); }
|
|
|
|
|
|
|
|
set { SetValue("RescanAfterRefresh", value); }
|
|
|
|
}
|
|
|
|
|
2019-02-16 14:49:24 +00:00
|
|
|
public AllowFingerprinting AllowFingerprinting
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("AllowFingerprinting", AllowFingerprinting.NewFiles); }
|
|
|
|
|
|
|
|
set { SetValue("AllowFingerprinting", 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); }
|
|
|
|
}
|
|
|
|
|
2020-10-05 23:00:47 +00:00
|
|
|
public string ChmodFolder
|
2014-01-14 19:21:20 +00:00
|
|
|
{
|
2020-10-05 23:00:47 +00:00
|
|
|
get { return GetValue("ChmodFolder", "755"); }
|
2014-01-14 19:21:20 +00:00
|
|
|
|
2020-10-05 23:00:47 +00:00
|
|
|
set { SetValue("ChmodFolder", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ChownGroup
|
|
|
|
{
|
|
|
|
get { return GetValue("ChownGroup", ""); }
|
|
|
|
|
|
|
|
set { SetValue("ChownGroup", value); }
|
2014-01-31 05:24:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 02:13:14 +00:00
|
|
|
public string MetadataSource
|
|
|
|
{
|
|
|
|
get { return GetValue("MetadataSource", ""); }
|
|
|
|
|
|
|
|
set { SetValue("MetadataSource", value); }
|
|
|
|
}
|
|
|
|
|
2019-03-15 12:10:45 +00:00
|
|
|
public WriteAudioTagsType WriteAudioTags
|
|
|
|
{
|
|
|
|
get { return GetValueEnum("WriteAudioTags", WriteAudioTagsType.No); }
|
|
|
|
|
|
|
|
set { SetValue("WriteAudioTags", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ScrubAudioTags
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ScrubAudioTags", false); }
|
|
|
|
|
|
|
|
set { SetValue("ScrubAudioTags", value); }
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public int FirstDayOfWeek
|
2014-08-05 05:44:09 +00:00
|
|
|
{
|
2017-01-04 02:36:47 +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); }
|
|
|
|
}
|
|
|
|
|
2021-10-02 01:03:57 +00:00
|
|
|
public int UILanguage
|
|
|
|
{
|
|
|
|
get { return GetValueInt("UILanguage", (int)Language.English); }
|
|
|
|
|
|
|
|
set { SetValue("UILanguage", value); }
|
|
|
|
}
|
|
|
|
|
2019-03-05 01:16:56 +00:00
|
|
|
public bool ExpandAlbumByDefault
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ExpandAlbumByDefault", false); }
|
|
|
|
|
|
|
|
set { SetValue("ExpandAlbumByDefault", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ExpandEPByDefault
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ExpandEPByDefault", false); }
|
|
|
|
|
|
|
|
set { SetValue("ExpandEPByDefault", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ExpandSingleByDefault
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ExpandSingleByDefault", false); }
|
|
|
|
|
|
|
|
set { SetValue("ExpandSingleByDefault", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ExpandBroadcastByDefault
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ExpandBroadcastByDefault", false); }
|
|
|
|
|
|
|
|
set { SetValue("ExpandBroadcastByDefault", value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ExpandOtherByDefault
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("ExpandOtherByDefault", false); }
|
|
|
|
|
|
|
|
set { SetValue("ExpandOtherByDefault", value); }
|
|
|
|
}
|
|
|
|
|
2015-01-02 18:57:51 +00:00
|
|
|
public bool CleanupMetadataImages
|
|
|
|
{
|
|
|
|
get { return GetValueBoolean("CleanupMetadataImages", true); }
|
|
|
|
|
|
|
|
set { SetValue("CleanupMetadataImages", value); }
|
|
|
|
}
|
|
|
|
|
2018-09-02 04:42:03 +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-01-14 22:11:37 +00:00
|
|
|
public string BackupFolder => GetValue("BackupFolder", "Backups");
|
|
|
|
|
|
|
|
public int BackupInterval => GetValueInt("BackupInterval", 7);
|
|
|
|
|
|
|
|
public int BackupRetention => GetValueInt("BackupRetention", 28);
|
|
|
|
|
2019-03-29 02:20:40 +00:00
|
|
|
public CertificateValidationType CertificateValidation =>
|
|
|
|
GetValueEnum("CertificateValidation", CertificateValidationType.Enabled);
|
|
|
|
|
2022-08-07 18:54:39 +00:00
|
|
|
public string ApplicationUrl => GetValue("ApplicationUrl", string.Empty);
|
|
|
|
|
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
|
|
|
}
|