|
|
|
@ -1,36 +1,32 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using System.Xml.XPath;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Config;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using NzbDrone.Model;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Providers
|
|
|
|
|
{
|
|
|
|
|
public class ConfigProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly EnviromentProvider _enviromentProvider;
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider");
|
|
|
|
|
|
|
|
|
|
public virtual string ApplicationRoot
|
|
|
|
|
[Inject]
|
|
|
|
|
public ConfigProvider(EnviromentProvider enviromentProvider)
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var appDir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
|
|
|
|
|
_enviromentProvider = enviromentProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (appDir.GetDirectories("iisexpress").Length == 0)
|
|
|
|
|
{
|
|
|
|
|
if (appDir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
|
|
|
|
|
appDir = appDir.Parent;
|
|
|
|
|
}
|
|
|
|
|
public ConfigProvider()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return appDir.FullName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual int Port
|
|
|
|
|
public virtual int PortNumber
|
|
|
|
|
{
|
|
|
|
|
get { return GetValueInt("Port", 8989); }
|
|
|
|
|
}
|
|
|
|
@ -40,29 +36,34 @@ namespace NzbDrone.Providers
|
|
|
|
|
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
|
|
|
|
@ -73,14 +74,13 @@ namespace NzbDrone.Providers
|
|
|
|
|
|
|
|
|
|
public virtual void ConfigureNlog()
|
|
|
|
|
{
|
|
|
|
|
LogManager.Configuration = new XmlLoggingConfiguration(
|
|
|
|
|
Path.Combine(ApplicationRoot, "NzbDrone.Web\\log.config"), false);
|
|
|
|
|
LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void UpdateIISConfig(string 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);
|
|
|
|
|
|
|
|
|
@ -91,13 +91,13 @@ namespace NzbDrone.Providers
|
|
|
|
|
bindings.Add(
|
|
|
|
|
new XElement("binding",
|
|
|
|
|
new XAttribute("protocol", "http"),
|
|
|
|
|
new XAttribute("bindingInformation", String.Format("*:{0}:localhost", Port))
|
|
|
|
|
new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber))
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
bindings.Add(
|
|
|
|
|
new XElement("binding",
|
|
|
|
|
new XAttribute("protocol", "http"),
|
|
|
|
|
new XAttribute("bindingInformation", String.Format("*:{0}:", Port))
|
|
|
|
|
new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber))
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
//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 config = xDoc.Descendants("Config").Single();
|
|
|
|
|