Merge branch kay.one with markus.

Fixed Conflicts with ConfigProvider.
pull/3113/head
Mark McDowall 13 years ago
commit dcc4410f84

@ -0,0 +1,58 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
[TestFixture]
public class ConfigProviderTest
{
private ConfigProvider GetConfigProvider()
{
var envMoq = new Mock<EnviromentProvider>();
envMoq.SetupGet(c => c.ApplicationPath).Returns(@"C:\NzbDrone\");
return new ConfigProvider(envMoq.Object);
}
[Test]
public void IISExpress_path_test()
{
GetConfigProvider().IISDirectory.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress");
}
[Test]
public void AppDataDirectory_path_test()
{
GetConfigProvider().AppDataDirectory.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\App_Data");
}
[Test]
public void Config_path_test()
{
GetConfigProvider().ConfigFile.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\App_Data\Config.xml");
}
[Test]
public void IISConfig_path_test()
{
GetConfigProvider().IISConfigPath.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\AppServer\applicationhost.config");
}
[Test]
public void IISExe_path_test()
{
GetConfigProvider().IISExePath.Should().BeEquivalentTo(@"C:\NzbDrone\IISExpress\IISExpress.exe");
}
[Test]
public void NlogConfig_path_test()
{
GetConfigProvider().NlogConfigPath.Should().BeEquivalentTo(@"C:\NzbDrone\NzbDrone.Web\log.config");
}
}
}

@ -9,7 +9,7 @@ using NzbDrone.Providers;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test
{ {
[TestFixture] [TestFixture]
public class EnviromentControllerTest public class EnviromentProviderTest
{ {
[Test] [Test]

@ -72,10 +72,11 @@
<Compile Include="AutoMoq\AutoMoqerTest.cs" /> <Compile Include="AutoMoq\AutoMoqerTest.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" /> <Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" /> <Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
<Compile Include="ApplicationTest.cs" /> <Compile Include="MonitoringProviderTest.cs" />
<Compile Include="ConfigProviderTest.cs" />
<Compile Include="IISProviderTest.cs" /> <Compile Include="IISProviderTest.cs" />
<Compile Include="ProcessProviderTests.cs" /> <Compile Include="ProcessProviderTests.cs" />
<Compile Include="EnviromentControllerTest.cs" /> <Compile Include="EnviromentProviderTest.cs" />
<Compile Include="ServiceControllerTests.cs" /> <Compile Include="ServiceControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>

@ -43,6 +43,14 @@ namespace NzbDrone.App.Test
dummyProcess.HasExited.Should().BeTrue(); dummyProcess.HasExited.Should().BeTrue();
} }
[TestCase(0)]
[TestCase(-1)]
[TestCase(9999)]
public void GetProcessById_should_return_null_for_invalid_process(int processId)
{
_processProvider.GetProcessById(processId).Should().BeNull();
}
public Process StartDummyProcess() public Process StartDummyProcess()
{ {

@ -50,5 +50,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.*")] [assembly: AssemblyVersion("0.6.0.*")]
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")] [assembly: InternalsVisibleTo("NzbDrone.Core.Test")]

@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("0.5.0.*")] [assembly: AssemblyVersion("0.6.0.*")]

@ -33,7 +33,7 @@ namespace NzbDrone
_configProvider.ConfigureNlog(); _configProvider.ConfigureNlog();
_configProvider.CreateDefaultConfigFile(); _configProvider.CreateDefaultConfigFile();
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _configProvider.ApplicationRoot); Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", _enviromentProvider.ApplicationPath);
Thread.CurrentThread.Name = "Host"; Thread.CurrentThread.Name = "Host";
} }

@ -1,4 +1,5 @@
using System; using System;
using System.Reflection;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Providers; using NzbDrone.Providers;
@ -25,7 +26,7 @@ namespace NzbDrone
Kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope(); Kernel.Bind<ServiceProvider>().ToSelf().InSingletonScope();
Kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope(); Kernel.Bind<WebClientProvider>().ToSelf().InSingletonScope();
Console.WriteLine("Starting Console."); Console.WriteLine("Starting NzbDrone Console. Version " + Assembly.GetExecutingAssembly().GetName().Version);
Kernel.Get<MonitoringProvider>().Start(); Kernel.Get<MonitoringProvider>().Start();
Kernel.Get<Application>().Start(); Kernel.Get<Application>().Start();
} }

@ -36,4 +36,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.*")] [assembly: AssemblyVersion("0.6.0.*")]

@ -1,36 +1,32 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
using NLog; using NLog;
using NLog.Config; using NLog.Config;
using Ninject;
using NzbDrone.Model; using NzbDrone.Model;
namespace NzbDrone.Providers namespace NzbDrone.Providers
{ {
public class ConfigProvider public class ConfigProvider
{ {
private readonly EnviromentProvider _enviromentProvider;
private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider"); private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider");
public virtual string ApplicationRoot [Inject]
public ConfigProvider(EnviromentProvider enviromentProvider)
{ {
get _enviromentProvider = enviromentProvider;
{ }
var appDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
while (appDir.GetDirectories("iisexpress").Length == 0) public ConfigProvider()
{ {
if (appDir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
appDir = appDir.Parent;
}
return appDir.FullName;
}
} }
public virtual int Port public virtual int PortNumber
{ {
get { return GetValueInt("Port", 8989); } get { return GetValueInt("Port", 8989); }
} }
@ -40,29 +36,34 @@ namespace NzbDrone.Providers
get { return GetValueBoolean("LaunchBrowser", true); } get { return GetValueBoolean("LaunchBrowser", true); }
} }
public virtual string AppDataDirectory public virtual string IISDirectory
{ {
get { return Path.Combine(ApplicationRoot, "NzbDrone.Web", "App_Data"); } get { return Path.Combine(_enviromentProvider.ApplicationPath, "IISExpress"); }
} }
public virtual string ConfigFile public virtual string IISExePath
{ {
get { return Path.Combine(AppDataDirectory, "Config.xml"); } get { return Path.Combine(IISDirectory, "iisexpress.exe"); }
} }
public virtual string IISFolder public virtual string IISConfigPath
{ {
get { return Path.Combine(ApplicationRoot, @"IISExpress\"); } get { return Path.Combine(IISDirectory, "AppServer", "applicationhost.config"); }
} }
public virtual string IISExePath public virtual string AppDataDirectory
{ {
get { return IISFolder + @"iisexpress.exe"; } get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web", "App_Data"); }
} }
public virtual string IISConfigPath public virtual string ConfigFile
{
get { return Path.Combine(AppDataDirectory, "Config.xml"); }
}
public virtual string NlogConfigPath
{ {
get { return Path.Combine(IISFolder, "AppServer", "applicationhost.config"); } get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); }
} }
public virtual AuthenticationType AuthenticationType public virtual AuthenticationType AuthenticationType
@ -73,14 +74,13 @@ namespace NzbDrone.Providers
public virtual void ConfigureNlog() public virtual void ConfigureNlog()
{ {
LogManager.Configuration = new XmlLoggingConfiguration( LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false);
Path.Combine(ApplicationRoot, "NzbDrone.Web\\log.config"), false);
} }
public virtual void UpdateIISConfig(string configPath) public virtual void UpdateIISConfig(string configPath)
{ {
Logger.Info(@"Server configuration file: {0}", configPath); Logger.Info(@"Server configuration file: {0}", configPath);
Logger.Info(@"Configuring server to: [http://localhost:{0}]", Port); Logger.Info(@"Configuring server to: [http://localhost:{0}]", PortNumber);
var configXml = XDocument.Load(configPath); var configXml = XDocument.Load(configPath);
@ -91,13 +91,13 @@ namespace NzbDrone.Providers
bindings.Add( bindings.Add(
new XElement("binding", new XElement("binding",
new XAttribute("protocol", "http"), new XAttribute("protocol", "http"),
new XAttribute("bindingInformation", String.Format("*:{0}:localhost", Port)) new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber))
)); ));
bindings.Add( bindings.Add(
new XElement("binding", new XElement("binding",
new XAttribute("protocol", "http"), new XAttribute("protocol", "http"),
new XAttribute("bindingInformation", String.Format("*:{0}:", Port)) new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber))
)); ));
//Update the authenticationTypes //Update the authenticationTypes
@ -133,7 +133,7 @@ namespace NzbDrone.Providers
} }
} }
public virtual string GetValue(string key, object defaultValue, string parent = null) private string GetValue(string key, object defaultValue, string parent = null)
{ {
var xDoc = XDocument.Load(ConfigFile); var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single(); var config = xDoc.Descendants("Config").Single();

@ -1,4 +1,6 @@
using System; using System;
using System.IO;
using System.Reflection;
namespace NzbDrone.Providers namespace NzbDrone.Providers
{ {
@ -13,5 +15,21 @@ namespace NzbDrone.Providers
{ {
get { return Environment.UserInteractive; } get { return Environment.UserInteractive; }
} }
public virtual string ApplicationPath
{
get
{
var dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
while (dir.GetDirectories("iisexpress").Length == 0)
{
if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
dir = dir.Parent;
}
return dir.FullName;
}
}
} }
} }

@ -12,13 +12,15 @@ namespace NzbDrone.Providers
private static readonly Logger Logger = LogManager.GetLogger("Host.IISProvider"); private static readonly Logger Logger = LogManager.GetLogger("Host.IISProvider");
private readonly ConfigProvider _configProvider; private readonly ConfigProvider _configProvider;
private readonly ProcessProvider _processProvider; private readonly ProcessProvider _processProvider;
private readonly EnviromentProvider _enviromentProvider;
[Inject] [Inject]
public IISProvider(ConfigProvider configProvider, ProcessProvider processProvider) public IISProvider(ConfigProvider configProvider, ProcessProvider processProvider, EnviromentProvider enviromentProvider)
{ {
_configProvider = configProvider; _configProvider = configProvider;
_processProvider = processProvider; _processProvider = processProvider;
_enviromentProvider = enviromentProvider;
} }
public IISProvider() public IISProvider()
@ -27,7 +29,7 @@ namespace NzbDrone.Providers
public string AppUrl public string AppUrl
{ {
get { return string.Format("http://localhost:{0}/", _configProvider.Port); } get { return string.Format("http://localhost:{0}/", _configProvider.PortNumber); }
} }
public int IISProcessId { get; private set; } public int IISProcessId { get; private set; }
@ -42,7 +44,7 @@ namespace NzbDrone.Providers
startInfo.FileName = _configProvider.IISExePath; startInfo.FileName = _configProvider.IISExePath;
startInfo.Arguments = String.Format("/config:\"{0}\" /trace:i", _configProvider.IISConfigPath); startInfo.Arguments = String.Format("/config:\"{0}\" /trace:i", _configProvider.IISConfigPath);
startInfo.WorkingDirectory = _configProvider.ApplicationRoot; startInfo.WorkingDirectory = _enviromentProvider.ApplicationPath;
startInfo.UseShellExecute = false; startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardOutput = true;
@ -50,7 +52,7 @@ namespace NzbDrone.Providers
startInfo.CreateNoWindow = true; startInfo.CreateNoWindow = true;
//Set Variables for the config file. //Set Variables for the config file.
startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _configProvider.ApplicationRoot); startInfo.EnvironmentVariables.Add("NZBDRONE_PATH", _enviromentProvider.ApplicationPath);
startInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString()); startInfo.EnvironmentVariables.Add("NZBDRONE_PID", Process.GetCurrentProcess().Id.ToString());
try try

@ -73,7 +73,7 @@ namespace NzbDrone.Providers
private static ProcessInfo ConvertToProcessInfo(Process process) private static ProcessInfo ConvertToProcessInfo(Process process)
{ {
if (process == null) return null; if (process == null || process.Id <= 0) return null;
return new ProcessInfo return new ProcessInfo
{ {

Loading…
Cancel
Save