diff --git a/NzbDrone.Api/Authentication/AuthenticationService.cs b/NzbDrone.Api/Authentication/AuthenticationService.cs index 02b525a3b..9148165f5 100644 --- a/NzbDrone.Api/Authentication/AuthenticationService.cs +++ b/NzbDrone.Api/Authentication/AuthenticationService.cs @@ -2,6 +2,7 @@ using Nancy.Security; using NzbDrone.Common; using NzbDrone.Common.Model; +using NzbDrone.Core.Configuration; namespace NzbDrone.Api.Authentication { diff --git a/NzbDrone.Api/Config/SettingsModule.cs b/NzbDrone.Api/Config/SettingsModule.cs index c6fefa8e1..47158667d 100644 --- a/NzbDrone.Api/Config/SettingsModule.cs +++ b/NzbDrone.Api/Config/SettingsModule.cs @@ -55,16 +55,34 @@ namespace NzbDrone.Api.Config public class SettingsModule : NzbDroneApiModule { private readonly IConfigService _configService; + private readonly IConfigFileProvider _configFileProvider; - public SettingsModule(IConfigService configService) + public SettingsModule(IConfigService configService, IConfigFileProvider configFileProvider) : base("/settings") { _configService = configService; - Get["/"] = x => GetAllSettings(); - Post["/"] = x => SaveSettings(); + _configFileProvider = configFileProvider; + Get["/"] = x => GetGeneralSettings(); + Post["/"] = x => SaveGeneralSettings(); + + Get["/host"] = x => GetHostSettings(); + Post["/host"] = x => SaveHostSettings(); + } + + private Response SaveHostSettings() + { + var request = Request.Body.FromJson>(); + _configFileProvider.SaveConfigDictionary(request); + + return GetHostSettings(); + } + + private Response GetHostSettings() + { + return _configFileProvider.GetConfigDictionary().AsResponse(); } - private Response GetAllSettings() + private Response GetGeneralSettings() { var collection = Request.Query.Collection; @@ -74,7 +92,7 @@ namespace NzbDrone.Api.Config return _configService.AllWithDefaults().AsResponse(); } - private Response SaveSettings() + private Response SaveGeneralSettings() { var request = Request.Body.FromJson>(); _configService.SaveValues(request); diff --git a/NzbDrone.Common.Test/CacheTests/CachedFixture.cs b/NzbDrone.Common.Test/CacheTests/CachedFixture.cs index 6396bcc50..08125abc0 100644 --- a/NzbDrone.Common.Test/CacheTests/CachedFixture.cs +++ b/NzbDrone.Common.Test/CacheTests/CachedFixture.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System.Collections.Generic; +using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.Cache; @@ -59,6 +60,21 @@ namespace NzbDrone.Common.Test.CacheTests { _cachedString.Remove("Test"); } + + [Test] + public void get_without_callback_should_throw_on_invalid_key() + { + Assert.Throws(() => _cachedString.Get("InvalidKey")); + } + + [Test] + public void should_be_able_to_update_key() + { + _cachedString.Set("Key", "Old"); + _cachedString.Set("Key", "New"); + + _cachedString.Get("Key").Should().Be("New"); + } } public class Worker diff --git a/NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs b/NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs index 60352d752..57a220d9c 100644 --- a/NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs +++ b/NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs @@ -2,16 +2,17 @@ using System; using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.Cache; +using NzbDrone.Test.Common; namespace NzbDrone.Common.Test.CacheTests { [TestFixture] - public class CachedManagerFixture + public class CachedManagerFixture:TestBase { [Test] public void should_return_proper_type_of_cache() { - var result = CacheManger.GetCache(typeof(string)); + var result = Subject.GetCache(typeof(string)); result.Should().BeOfType>(); } @@ -20,8 +21,8 @@ namespace NzbDrone.Common.Test.CacheTests [Test] public void multiple_calls_should_get_the_same_cache() { - var result1 = CacheManger.GetCache(typeof(string)); - var result2 = CacheManger.GetCache(typeof(string)); + var result1 = Subject.GetCache(typeof(string)); + var result2 = Subject.GetCache(typeof(string)); result1.Should().BeSameAs(result2); } diff --git a/NzbDrone.Common.Test/ConfigFileProviderTest.cs b/NzbDrone.Common.Test/ConfigFileProviderTest.cs index 2312c61be..95232e40f 100644 --- a/NzbDrone.Common.Test/ConfigFileProviderTest.cs +++ b/NzbDrone.Common.Test/ConfigFileProviderTest.cs @@ -2,6 +2,7 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.Model; +using NzbDrone.Core.Configuration; using NzbDrone.Test.Common; namespace NzbDrone.Common.Test @@ -143,15 +144,18 @@ namespace NzbDrone.Common.Test } [Test] - public void Guid_should_return_the_same_every_time() + public void SaveDictionary_should_save_proper_value() { + int port = 20555; - var firstResponse = Subject.Guid; - var secondResponse = Subject.Guid; + var dic = Subject.GetConfigDictionary(); + dic["Port"] = 20555; + Subject.SaveConfigDictionary(dic); - secondResponse.Should().Be(firstResponse); + Subject.Port.Should().Be(port); } + } } \ No newline at end of file diff --git a/NzbDrone.Common/Cache/CacheManger.cs b/NzbDrone.Common/Cache/CacheManger.cs index 97ace151d..98d5846d0 100644 --- a/NzbDrone.Common/Cache/CacheManger.cs +++ b/NzbDrone.Common/Cache/CacheManger.cs @@ -3,20 +3,32 @@ using NzbDrone.Common.EnsureThat; namespace NzbDrone.Common.Cache { - public static class CacheManger + public interface ICacheManger { - private static readonly ICached Cache; + ICached GetCache(Type type); + ICached GetCache(object host); + } + + public class CacheManger : ICacheManger + { + private readonly ICached _cache; - static CacheManger() + public CacheManger() { - Cache = new Cached(); + _cache = new Cached(); + } - public static ICached GetCache(Type type) + public ICached GetCache(Type type) { Ensure.That(() => type).IsNotNull(); - return (ICached)Cache.Get(type.FullName, () => new Cached()); + return (ICached)_cache.Get(type.FullName, () => new Cached()); + } + + public ICached GetCache(object host) + { + return GetCache(host.GetType()); } } } \ No newline at end of file diff --git a/NzbDrone.Common/Cache/Cached.cs b/NzbDrone.Common/Cache/Cached.cs index 9ec11872f..e3ff83210 100644 --- a/NzbDrone.Common/Cache/Cached.cs +++ b/NzbDrone.Common/Cache/Cached.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using NzbDrone.Common.EnsureThat; namespace NzbDrone.Common.Cache @@ -16,7 +17,12 @@ namespace NzbDrone.Common.Cache public void Set(string key, T value) { Ensure.That(() => key).IsNotNullOrWhiteSpace(); - _store.TryAdd(key, value); + _store[key] = value; + } + + public T Get(string key) + { + return Get(key, () => { throw new KeyNotFoundException(key); }); } public T Get(string key, Func function) diff --git a/NzbDrone.Common/Cache/ICached.cs b/NzbDrone.Common/Cache/ICached.cs index ab3142ac4..bc79856b8 100644 --- a/NzbDrone.Common/Cache/ICached.cs +++ b/NzbDrone.Common/Cache/ICached.cs @@ -9,5 +9,6 @@ namespace NzbDrone.Common.Cache bool ContainsKey(string key); void Clear(); void Remove(string key); + T Get(string key); } } \ No newline at end of file diff --git a/NzbDrone.Common/IConfigFileProvider.cs b/NzbDrone.Common/IConfigFileProvider.cs deleted file mode 100644 index 968580ab6..000000000 --- a/NzbDrone.Common/IConfigFileProvider.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Xml.Linq; -using NzbDrone.Common.Model; - -namespace NzbDrone.Common -{ - public interface IConfigFileProvider - { - Guid Guid { get; } - int Port { get; set; } - bool LaunchBrowser { get; set; } - AuthenticationType AuthenticationType { get; set; } - string BasicAuthUsername { get; set; } - string BasicAuthPassword { get; set; } - int GetValueInt(string key, int defaultValue); - bool GetValueBoolean(string key, bool defaultValue); - string GetValue(string key, object defaultValue); - T GetValueEnum(string key, T defaultValue); - void SetValue(string key, object value); - } - - public class ConfigFileProvider : IConfigFileProvider - { - private readonly IEnvironmentProvider _environmentProvider; - - private readonly string _configFile; - - public ConfigFileProvider(IEnvironmentProvider environmentProvider) - { - _environmentProvider = environmentProvider; - _configFile = _environmentProvider.GetConfigPath(); - - CreateDefaultConfigFile(); - } - - public virtual Guid Guid - { - get - { - var key = "Guid"; - if (string.IsNullOrWhiteSpace(GetValue(key, string.Empty))) - { - SetValue(key, Guid.NewGuid().ToString()); - } - - return Guid.Parse(GetValue(key, string.Empty)); - } - } - - public virtual int Port - { - get { return GetValueInt("Port", 8989); } - set { SetValue("Port", value); } - } - - public virtual bool LaunchBrowser - { - get { return GetValueBoolean("LaunchBrowser", true); } - set { SetValue("LaunchBrowser", value); } - } - - public virtual AuthenticationType AuthenticationType - { - get { return GetValueEnum("AuthenticationType", AuthenticationType.Anonymous); } - set { SetValue("AuthenticationType", value); } - } - - public virtual string BasicAuthUsername - { - get { return GetValue("BasicAuthUsername", ""); } - set { SetValue("BasicAuthUsername", value); } - } - - public virtual string BasicAuthPassword - { - get { return GetValue("BasicAuthPassword", ""); } - set { SetValue("BasicAuthPassword", value); } - } - - public virtual int GetValueInt(string key, int defaultValue) - { - return Convert.ToInt32(GetValue(key, defaultValue)); - } - - public virtual bool GetValueBoolean(string key, bool defaultValue) - { - return Convert.ToBoolean(GetValue(key, defaultValue)); - } - - public T GetValueEnum(string key, T defaultValue) - { - return (T)Enum.Parse(typeof(T), GetValue(key, defaultValue), true); - } - - public virtual string GetValue(string key, object defaultValue) - { - var xDoc = XDocument.Load(_configFile); - var config = xDoc.Descendants("Config").Single(); - - var parentContainer = config; - - var valueHolder = parentContainer.Descendants(key).ToList(); - - if (valueHolder.Count() == 1) - return valueHolder.First().Value; - - //Save the value - SetValue(key, defaultValue); - - //return the default value - return defaultValue.ToString(); - } - - public virtual void SetValue(string key, object value) - { - var xDoc = XDocument.Load(_configFile); - var config = xDoc.Descendants("Config").Single(); - - var parentContainer = config; - - var keyHolder = parentContainer.Descendants(key); - - if (keyHolder.Count() != 1) - parentContainer.Add(new XElement(key, value)); - - else - parentContainer.Descendants(key).Single().Value = value.ToString(); - - xDoc.Save(_configFile); - } - - public void SetValue(string key, Enum value) - { - SetValue(key, value.ToString().ToLower()); - } - - private void CreateDefaultConfigFile() - { - if (!File.Exists(_configFile)) - { - var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); - - xDoc.Add(new XElement("Config")); - - xDoc.Save(_configFile); - } - } - } -} diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 942cfac53..a7c516c8f 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -55,10 +55,6 @@ MinimumRecommendedRules.ruleset - - ..\Libraries\Interop.NetFwTypeLib.dll - True - ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll @@ -75,8 +71,6 @@ - - @@ -136,7 +130,6 @@ - @@ -149,12 +142,10 @@ - - diff --git a/NzbDrone.Common/StringExtention.cs b/NzbDrone.Common/StringExtention.cs index f331c0de2..4f209a422 100644 --- a/NzbDrone.Common/StringExtention.cs +++ b/NzbDrone.Common/StringExtention.cs @@ -1,4 +1,7 @@ -namespace NzbDrone.Common +using System; +using System.Linq; + +namespace NzbDrone.Common { public static class StringExtension { @@ -13,5 +16,10 @@ { return ((object)target).NullSafe().ToString(); } + + public static string FirstCharToUpper(this string input) + { + return input.First().ToString().ToUpper() + String.Join("", input.Skip(1)); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index b69107dd1..fd010347c 100644 --- a/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -32,7 +32,6 @@ namespace NzbDrone.Core.Test.UpdateTests public void Setup() { Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(TempFolder); - Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); Mocker.GetMock().Setup(c => c.GetLatestUpdate()).Returns(_updatePackage); Mocker.GetMock().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 }); diff --git a/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/NzbDrone.Core/Configuration/ConfigFileProvider.cs new file mode 100644 index 000000000..882e7e5e6 --- /dev/null +++ b/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -0,0 +1,189 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using NzbDrone.Common; +using NzbDrone.Common.Cache; +using NzbDrone.Common.Model; + +namespace NzbDrone.Core.Configuration +{ + public interface IConfigFileProvider + { + Dictionary GetConfigDictionary(); + void SaveConfigDictionary(Dictionary configValues); + + int Port { get; set; } + bool LaunchBrowser { get; set; } + AuthenticationType AuthenticationType { get; set; } + string BasicAuthUsername { get; set; } + string BasicAuthPassword { get; set; } + } + + public class ConfigFileProvider : IConfigFileProvider + { + private readonly IEnvironmentProvider _environmentProvider; + private readonly ICached _cache; + + private readonly string _configFile; + + public ConfigFileProvider(IEnvironmentProvider environmentProvider, ICacheManger cacheManger) + { + _environmentProvider = environmentProvider; + _cache = cacheManger.GetCache(this); + _configFile = _environmentProvider.GetConfigPath(); + } + + public Dictionary GetConfigDictionary() + { + var dict = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + + var type = GetType(); + var properties = type.GetProperties(); + + foreach (var propertyInfo in properties) + { + var value = propertyInfo.GetValue(this, null); + + dict.Add(propertyInfo.Name, value); + } + + return dict; + } + + public void SaveConfigDictionary(Dictionary configValues) + { + _cache.Clear(); + + var allWithDefaults = GetConfigDictionary(); + + foreach (var configValue in configValues) + { + object currentValue; + allWithDefaults.TryGetValue(configValue.Key, out currentValue); + if (currentValue == null) continue; + + var equal = configValue.Value.ToString().Equals(currentValue.ToString()); + + if (!equal) + { + SetValue(configValue.Key.FirstCharToUpper(), configValue.Value.ToString()); + } + } + + + } + + public int Port + { + get { return GetValueInt("Port", 8989); } + set { SetValue("Port", value); } + } + + public bool LaunchBrowser + { + get { return GetValueBoolean("LaunchBrowser", true); } + set { SetValue("LaunchBrowser", value); } + } + + public AuthenticationType AuthenticationType + { + get { return GetValueEnum("AuthenticationType", AuthenticationType.Anonymous); } + set { SetValue("AuthenticationType", value); } + } + + public string BasicAuthUsername + { + get { return GetValue("BasicAuthUsername", ""); } + set { SetValue("BasicAuthUsername", value); } + } + + public string BasicAuthPassword + { + get { return GetValue("BasicAuthPassword", ""); } + set { SetValue("BasicAuthPassword", value); } + } + + public int GetValueInt(string key, int defaultValue) + { + return Convert.ToInt32(GetValue(key, defaultValue)); + } + + public bool GetValueBoolean(string key, bool defaultValue) + { + return Convert.ToBoolean(GetValue(key, defaultValue)); + } + + public T GetValueEnum(string key, T defaultValue) + { + return (T)Enum.Parse(typeof(T), GetValue(key, defaultValue), true); + } + + public string GetValue(string key, object defaultValue) + { + return _cache.Get(key, () => + { + EnsureDefaultConfigFile(); + + var xDoc = XDocument.Load(_configFile); + var config = xDoc.Descendants("Config").Single(); + + var parentContainer = config; + + var valueHolder = parentContainer.Descendants(key).ToList(); + + if (valueHolder.Count() == 1) + return valueHolder.First().Value; + + //Save the value + SetValue(key, defaultValue); + + //return the default value + return defaultValue.ToString(); + }); + } + + public void SetValue(string key, object value) + { + EnsureDefaultConfigFile(); + + var xDoc = XDocument.Load(_configFile); + var config = xDoc.Descendants("Config").Single(); + + var parentContainer = config; + + var keyHolder = parentContainer.Descendants(key); + + if (keyHolder.Count() != 1) + { + parentContainer.Add(new XElement(key, value)); + } + + else + { + parentContainer.Descendants(key).Single().Value = value.ToString(); + } + + _cache.Set(key, value.ToString()); + + xDoc.Save(_configFile); + } + + public void SetValue(string key, Enum value) + { + SetValue(key, value.ToString().ToLower()); + } + + private void EnsureDefaultConfigFile() + { + if (!File.Exists(_configFile)) + { + var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); + xDoc.Add(new XElement("Config")); + xDoc.Save(_configFile); + } + } + } +} diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 381782444..0f3a55e3e 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -43,6 +43,23 @@ namespace NzbDrone.Core.Configuration return dict; } + public void SaveValues(Dictionary configValues) + { + var allWithDefaults = AllWithDefaults(); + + foreach (var configValue in configValues) + { + object currentValue; + allWithDefaults.TryGetValue(configValue.Key, out currentValue); + if (currentValue == null) continue; + + var equal = configValue.Value.ToString().Equals(currentValue.ToString()); + + if (!equal) + SetValue(configValue.Key, configValue.Value.ToString()); + } + } + public String SabHost { get { return GetValue("SabHost", "localhost"); } @@ -132,18 +149,6 @@ namespace NzbDrone.Core.Configuration set { SetValue("UpdateUrl", value); } } - public string TwitterAccessToken - { - get { return GetValue("TwitterAccessToken", String.Empty); } - set { SetValue("TwitterAccessToken", value); } - } - - public string TwitterAccessTokenSecret - { - get { return GetValue("TwitterAccessTokenSecret", String.Empty); } - set { SetValue("TwitterAccessTokenSecret", value); } - } - public bool EnableBacklogSearching { get { return GetValueBoolean("EnableBacklogSearching"); } @@ -365,22 +370,7 @@ namespace NzbDrone.Core.Configuration SetValue(key, value.ToString().ToLower()); } - public void SaveValues(Dictionary configValues) - { - var allWithDefaults = AllWithDefaults(); - foreach (var configValue in configValues) - { - object currentValue; - allWithDefaults.TryGetValue(configValue.Key, out currentValue); - if (currentValue == null) continue; - - var equal = configValue.Value.ToString().Equals(currentValue.ToString()); - - if (!equal) - SetValue(configValue.Key, configValue.Value.ToString()); - } - } private void EnsureCache() { diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index 4570a7d14..bf51b3da0 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -23,8 +23,6 @@ namespace NzbDrone.Core.Configuration bool UseSeasonFolder { get; set; } string SortingSeasonFolderFormat { get; set; } int DefaultQualityProfile { get; set; } - string TwitterAccessToken { get; set; } - string TwitterAccessTokenSecret { get; set; } bool EnableBacklogSearching { get; set; } bool AutoIgnorePreviouslyDownloadedEpisodes { get; set; } int Retention { get; set; } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 8e5115589..07ca1d9d8 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -178,6 +178,7 @@ + diff --git a/NzbDrone.Core/Update/UpdateService.cs b/NzbDrone.Core/Update/UpdateService.cs index bfde1c213..8c924a600 100644 --- a/NzbDrone.Core/Update/UpdateService.cs +++ b/NzbDrone.Core/Update/UpdateService.cs @@ -7,6 +7,7 @@ using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Update.Commands; namespace NzbDrone.Core.Update @@ -75,7 +76,7 @@ namespace NzbDrone.Core.Update var startInfo = new ProcessStartInfo { FileName = _environmentProvider.GetUpdateClientExePath(), - Arguments = string.Format("{0} {1}", _processProvider.GetCurrentProcess().Id, _configFileProvider.Guid) + Arguments = string.Format("{0} {1}", _processProvider.GetCurrentProcess().Id) }; var process = _processProvider.Start(startInfo); diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index da30ff7a2..0b1223c18 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -11,6 +11,7 @@ using NzbDrone.Api.Commands; using NzbDrone.Api.RootFolders; using NzbDrone.Common; using NzbDrone.Common.Composition; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Integration.Test.Client; using NzbDrone.Owin; diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 94793c4aa..da36b0584 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -5,6 +5,7 @@ using Moq; using NLog; using NUnit.Framework; using NzbDrone.Common; +using NzbDrone.Common.Cache; using NzbDrone.Common.Messaging; using NzbDrone.Common.Serializer; using NzbDrone.Test.Common.AutoMoq; @@ -20,6 +21,8 @@ namespace NzbDrone.Test.Common public void CoreTestSetup() { _subject = null; + + Mocker.SetConstant(new CacheManger()); } protected TSubject Subject diff --git a/NzbDrone/ApplicationServer.cs b/NzbDrone/ApplicationServer.cs index 63b67109a..fdd34727d 100644 --- a/NzbDrone/ApplicationServer.cs +++ b/NzbDrone/ApplicationServer.cs @@ -2,6 +2,8 @@ using System.ServiceProcess; using NLog; using NzbDrone.Common; +using NzbDrone.Core.Configuration; +using NzbDrone.Host; using NzbDrone.Owin; namespace NzbDrone diff --git a/NzbDrone.Common/FirewallAdapter.cs b/NzbDrone/Host/FirewallAdapter.cs similarity index 98% rename from NzbDrone.Common/FirewallAdapter.cs rename to NzbDrone/Host/FirewallAdapter.cs index 26627d3f5..8d04068cb 100644 --- a/NzbDrone.Common/FirewallAdapter.cs +++ b/NzbDrone/Host/FirewallAdapter.cs @@ -1,8 +1,9 @@ -using System; +using System; using NLog; using NetFwTypeLib; +using NzbDrone.Core.Configuration; -namespace NzbDrone.Common +namespace NzbDrone.Host { public interface IFirewallAdapter { diff --git a/NzbDrone.Common/UrlAclAdapter.cs b/NzbDrone/Host/UrlAclAdapter.cs similarity index 95% rename from NzbDrone.Common/UrlAclAdapter.cs rename to NzbDrone/Host/UrlAclAdapter.cs index 63be66c09..101217355 100644 --- a/NzbDrone.Common/UrlAclAdapter.cs +++ b/NzbDrone/Host/UrlAclAdapter.cs @@ -1,8 +1,10 @@ -using System; +using System; using System.Diagnostics; using NLog; +using NzbDrone.Common; +using NzbDrone.Core.Configuration; -namespace NzbDrone.Common +namespace NzbDrone.Host { public interface IUrlAclAdapter { diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 22ca1b196..353b6c2f0 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -89,6 +89,10 @@ False ..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll + + ..\Libraries\Interop.NetFwTypeLib.dll + True + False ..\packages\Microsoft.AspNet.SignalR.Core.1.0.1\lib\net40\Microsoft.AspNet.SignalR.Core.dll @@ -137,6 +141,8 @@ Component + + diff --git a/NzbDrone/Owin/OwinHostController.cs b/NzbDrone/Owin/OwinHostController.cs index 9307e478f..b3d1ae7d4 100644 --- a/NzbDrone/Owin/OwinHostController.cs +++ b/NzbDrone/Owin/OwinHostController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.Owin.Hosting; using NLog; using NzbDrone.Common; +using NzbDrone.Core.Configuration; using NzbDrone.Owin.MiddleWare; using Owin; using System.Linq; diff --git a/UI/Settings/General/GeneralSettingsModel.js b/UI/Settings/General/GeneralSettingsModel.js new file mode 100644 index 000000000..3ea5f52c2 --- /dev/null +++ b/UI/Settings/General/GeneralSettingsModel.js @@ -0,0 +1,16 @@ +"use strict"; +define(['app'], function () { + NzbDrone.Settings.General.GeneralSettingsModel = Backbone.Model.extend({ + url: NzbDrone.Constants.ApiRoot + '/settings/host', + + initialize: function () { + this.on('change', function () { + this.isSaved = false; + }, this); + + this.on('sync', function () { + this.isSaved = true; + }, this); + } + }); +}); diff --git a/UI/Settings/General/GeneralTemplate.html b/UI/Settings/General/GeneralTemplate.html new file mode 100644 index 000000000..2a959f841 --- /dev/null +++ b/UI/Settings/General/GeneralTemplate.html @@ -0,0 +1,70 @@ +
+
+ Start-Up + +
+ + +
+ + + + +
+ +
+ +
+ + +
+ + + + + +
+
+
+ +
+ Security + + +
+ + +
+ +
+
+
+ + +
+ +
+
+
+ + +
+ +
+
+ + +
+
\ No newline at end of file diff --git a/UI/Settings/General/GeneralView.js b/UI/Settings/General/GeneralView.js new file mode 100644 index 000000000..82a50b5c4 --- /dev/null +++ b/UI/Settings/General/GeneralView.js @@ -0,0 +1,31 @@ +'use strict'; +define(['app', 'Settings/SettingsModel', 'Shared/Messenger'], function () { + + NzbDrone.Settings.General.GeneralView = Backbone.Marionette.ItemView.extend({ + template: 'Settings/General/GeneralTemplate', + + initialize: function () { + + NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this); + }, + + saveSettings: function () { + if (!this.model.isSaved) { + this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings")); + } + }, + + syncNotification: function (success, error) { + return { + success: function () { + NzbDrone.Shared.Messenger.show({message: 'General Settings Saved'}); + }, + error : function () { + NzbDrone.Shared.Messenger.show({message: "Couldn't Save General Settings", type: 'error'}); + } + }; + } + } + ); +}); + diff --git a/UI/Settings/Naming/NamingTemplate.html b/UI/Settings/Naming/NamingTemplate.html index e5a2b8cb0..d3cf73484 100644 --- a/UI/Settings/Naming/NamingTemplate.html +++ b/UI/Settings/Naming/NamingTemplate.html @@ -1,191 +1,198 @@ -
- Episode Naming +
+
+ Episode Naming -
- +
+ -
-
-
-
- +
+ + +
+
-
-
- +
+ + +
+
-
-
- +
+ -
-
-
-
- +
+ + +
+
-
-
- +
+ -
- +
+ +
-
-
- +
+ -
- +
+ +
-
- -
- - -
- + +
+ + +
+ +
-
- -
- - -
- + +
+ + +
+ +
-
-
+
-
- Metadata +
+ Metadata -
- +
+ -
-
- -
+
+
+ +
+
-
-
- +
+ -
-
- -
+
+
+ +
+
-
-
+
+ \ No newline at end of file diff --git a/UI/Settings/Naming/NamingView.js b/UI/Settings/Naming/NamingView.js index 090f2be71..9c7bcde94 100644 --- a/UI/Settings/Naming/NamingView.js +++ b/UI/Settings/Naming/NamingView.js @@ -3,7 +3,6 @@ define(['app', 'Settings/Naming/NamingModel'], function () { NzbDrone.Settings.Naming.NamingView = Backbone.Marionette.ItemView.extend({ template : 'Settings/Naming/NamingTemplate', - className: 'form-horizontal', ui: { tooltip: '[class^="help-inline"] i' diff --git a/UI/Settings/SettingsLayout.js b/UI/Settings/SettingsLayout.js index f0c4d5fff..5479d931e 100644 --- a/UI/Settings/SettingsLayout.js +++ b/UI/Settings/SettingsLayout.js @@ -6,7 +6,8 @@ define([ 'Settings/Indexers/CollectionView', 'Settings/DownloadClient/DownloadClientView', 'Settings/Notifications/CollectionView', - 'Settings/System/SystemView', + 'Settings/General/GeneralView', + 'Settings/General/GeneralSettingsModel', 'Settings/Misc/MiscView' ], function () { @@ -19,7 +20,7 @@ define([ indexers : '#indexers', downloadClient: '#download-client', notifications : '#notifications', - system : '#system', + general : '#general', misc : '#misc' }, @@ -29,7 +30,7 @@ define([ indexersTab : '.x-indexers-tab', downloadClientTab: '.x-download-client-tab', notificationsTab : '.x-notifications-tab', - systemTab : '.x-system-tab', + generalTab : '.x-general-tab', miscTab : '.x-misc-tab' }, @@ -39,7 +40,7 @@ define([ 'click .x-indexers-tab' : 'showIndexers', 'click .x-download-client-tab': 'showDownloadClient', 'click .x-notifications-tab' : 'showNotifications', - 'click .x-system-tab' : 'showSystem', + 'click .x-general-tab' : 'showGeneral', 'click .x-misc-tab' : 'showMisc', 'click .x-save-settings' : 'save' }, @@ -89,13 +90,13 @@ define([ NzbDrone.Router.navigate('settings/notifications'); }, - showSystem: function (e) { + showGeneral: function (e) { if (e) { e.preventDefault(); } - this.ui.systemTab.tab('show'); - NzbDrone.Router.navigate('settings/system'); + this.ui.generalTab.tab('show'); + NzbDrone.Router.navigate('settings/general'); }, showMisc: function (e) { @@ -111,6 +112,9 @@ define([ this.settings = new NzbDrone.Settings.SettingsModel(); this.settings.fetch(); + this.generalSettings = new NzbDrone.Settings.General.GeneralSettingsModel(); + this.generalSettings.fetch(); + this.namingSettings = new NzbDrone.Settings.Naming.NamingModel(); this.namingSettings.fetch(); @@ -131,7 +135,7 @@ define([ this.indexers.show(new NzbDrone.Settings.Indexers.CollectionView({collection: this.indexerSettings})); this.downloadClient.show(new NzbDrone.Settings.DownloadClient.DownloadClientView({model: this.settings})); this.notifications.show(new NzbDrone.Settings.Notifications.CollectionView({collection: this.notificationSettings})); - this.system.show(new NzbDrone.Settings.System.SystemView({model: this.settings})); + this.general.show(new NzbDrone.Settings.General.GeneralView({model: this.generalSettings})); this.misc.show(new NzbDrone.Settings.Misc.MiscView({model: this.settings})); }, @@ -149,8 +153,8 @@ define([ case 'notifications': this.showNotifications(); break; - case 'system': - this.showSystem(); + case 'general': + this.showGeneral(); break; case 'misc': this.showMisc(); diff --git a/UI/Settings/SettingsLayoutTemplate.html b/UI/Settings/SettingsLayoutTemplate.html index 0a7c58ab5..adbbfa740 100644 --- a/UI/Settings/SettingsLayoutTemplate.html +++ b/UI/Settings/SettingsLayoutTemplate.html @@ -4,7 +4,7 @@
  • Indexers
  • Download Client
  • Notifications
  • -
  • System
  • +
  • general
  • Misc
  • @@ -14,7 +14,7 @@
    Indexer Settings
    Download Client Settings
    Notification Settings
    -
    System Settings
    +
    general Settings
    Misc Settings
    diff --git a/UI/Settings/System/SystemTemplate.html b/UI/Settings/System/SystemTemplate.html deleted file mode 100644 index 8edf2eb4b..000000000 --- a/UI/Settings/System/SystemTemplate.html +++ /dev/null @@ -1,3 +0,0 @@ -
    - System settings will go here -
    \ No newline at end of file diff --git a/UI/Settings/System/SystemView.js b/UI/Settings/System/SystemView.js deleted file mode 100644 index 516cf25c8..000000000 --- a/UI/Settings/System/SystemView.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -define([ - 'app', 'Settings/SettingsModel' - -], function () { - - NzbDrone.Settings.System.SystemView = Backbone.Marionette.ItemView.extend({ - template: 'Settings/System/SystemTemplate' - }); -}); diff --git a/UI/app.js b/UI/app.js index c14cb9c2d..15248cc9a 100644 --- a/UI/app.js +++ b/UI/app.js @@ -76,7 +76,7 @@ define('app', ['shared/modal/region'], function (ModalRegion) { Indexers : {}, DownloadClient: {}, Notifications : {}, - System : {}, + General : {}, Misc : {} };