Merge branch 'markus' into kay.one

Conflicts:
	NzbDrone/NzbDrone.csproj
	NzbDrone/Providers/ConfigProvider.cs
pull/7/merge
kay.one 13 years ago
commit 012fa88301

@ -694,4 +694,14 @@
</handlers>
</system.webServer>
</location>
<location path="NZBDrone">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
</configuration>

@ -8,6 +8,7 @@ using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone.App.Test

@ -1,6 +1,7 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone.App.Test

@ -2,6 +2,7 @@
using AutoMoq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
@ -32,7 +33,7 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key);
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
@ -47,7 +48,7 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key);
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key, value);
//Assert
result.Should().Be(value);
@ -57,11 +58,12 @@ namespace NzbDrone.Core.Test
public void GetBool_Success()
{
const string key = "LaunchBrowser";
const bool value = true;
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key);
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key, value);
//Assert
result.Should().BeTrue();
@ -124,5 +126,60 @@ namespace NzbDrone.Core.Test
var result = mocker.Resolve<ConfigFileProvider>().Port;
result.Should().Be(value);
}
[Test]
public void GetValue_New_Key()
{
const string key = "Hello";
const string value = "World";
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value);
//Assert
result.Should().Be(value);
}
[Test]
public void GetValue_New_Key_with_new_parent()
{
const string key = "Hello";
const string value = "World";
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key, value, "Universe");
//Assert
result.Should().Be(value);
}
[Test]
public void GetAuthenticationType_No_Existing_Value()
{
var mocker = new AutoMoqer();
//Act
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Anonymous);
}
[Test]
public void GetAuthenticationType_Windows()
{
var mocker = new AutoMoqer();
mocker.Resolve<ConfigFileProvider>().SetValue("AuthenticationType", 1);
//Act
var result = mocker.Resolve<ConfigFileProvider>().AuthenticationType;
//Assert
result.Should().Be(AuthenticationType.Windows);
}
}
}

@ -113,6 +113,7 @@ namespace NzbDrone.Core
_kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
_kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
_kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30);

@ -0,0 +1,9 @@
namespace NzbDrone.Core.Model
{
public enum AtomicParsleyTitleType
{
None = 0,
EpisodeNumber = 1,
Both = 2
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Model
{
public enum AuthenticationType
{
Anonymous = 0,
Windows = 1
}
}

@ -189,6 +189,8 @@
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
<Compile Include="Instrumentation\NlogWriter.cs" />
<Compile Include="Datastore\PetaPoco\PetaPoco.cs" />
<Compile Include="Model\AtomicParsleyTitleType.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="Model\ConnectionInfoModel.cs" />
<Compile Include="Model\ExternalNotificationType.cs" />
<Compile Include="Model\JobQueueItem.cs" />
@ -203,10 +205,13 @@
<Compile Include="Model\Xbmc\ActivePlayersResult.cs" />
<Compile Include="Model\Xbmc\ErrorResult.cs" />
<Compile Include="Model\Xbmc\IconType.cs" />
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
<Compile Include="Providers\Core\ConfigFileProvider.cs" />
<Compile Include="Providers\Core\UdpProvider.cs" />
<Compile Include="Providers\Jobs\BacklogSearchJob.cs" />
<Compile Include="Providers\Jobs\BannerDownloadJob.cs" />
<Compile Include="Providers\Jobs\ConvertEpisodeJob.cs" />
<Compile Include="Providers\Jobs\RenameSeriesJob.cs" />
<Compile Include="Providers\Jobs\SeriesSearchJob.cs" />
<Compile Include="Providers\Jobs\RenameSeasonJob.cs" />

@ -0,0 +1,74 @@
using System;
using System.Diagnostics;
using System.IO;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.Converting
{
public class AtomicParsleyProvider
{
private readonly ConfigProvider _configProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public AtomicParsleyProvider(ConfigProvider configProvider)
{
_configProvider = configProvider;
}
public AtomicParsleyProvider()
{
}
public virtual bool RunAtomicParsley(Episode episode, string outputFile)
{
throw new NotImplementedException();
var atomicParsleyLocation = _configProvider.GetValue("AtomicParsleyLocation", "");
var atomicParsleyTitleType = (AtomicParsleyTitleType) System.Convert.ToInt32(_configProvider.GetValue("AtomicParsley", 0));
var atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
//If Episode Number + Name should be in Episode Title (Number - Title)
if (atomicParsleyTitleType == AtomicParsleyTitleType.EpisodeNumber)
{
atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{3} - {1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
}
//If Season/Episode Number + Name should be in Episode Title (SeasonNumber'x'EpisodeNumber - Title)
else if (atomicParsleyTitleType == AtomicParsleyTitleType.Both)
{
atomicParsleyCommand = String.Format("\"{0}\" --overWrite --title \"{4}x{3:00} - {1}\" --genre \"TV Shows\" --stik \"TV Show\" --TVShowName \"{2}\" --TVEpisodeNum \"{3}\" --TVSeason \"{4}\"",
outputFile, episode.Title, episode.Series.Title, episode.EpisodeNumber, episode.SeasonNumber);
}
try
{
var process = new Process();
process.StartInfo.FileName = Path.Combine(atomicParsleyLocation, "AtomicParsley.exe");
process.StartInfo.Arguments = atomicParsleyCommand;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
//process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
process.Start();
//process.BeginOutputReadLine();
process.WaitForExit();
}
catch (Exception ex)
{
Logger.DebugException(ex.Message, ex);
return false;
}
return true;
}
}
}

@ -0,0 +1,105 @@
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers.Converting
{
public class HandbrakeProvider
{
//Interacts with Handbrake
private readonly ConfigProvider _configProvider;
private ProgressNotification _notification;
private Episode _currentEpisode;
private Regex _processingRegex =
new Regex(@"^(?:Encoding).+?(?:\,\s(?<percent>\d{1,3}\.\d{2})\s\%)(?:.+?ETA\s(?<hours>\d{2})h(?<minutes>\d{2})m(?<seconds>\d{2})s)?",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public HandbrakeProvider(ConfigProvider configProvider)
{
_configProvider = configProvider;
}
public HandbrakeProvider()
{
}
public virtual string ConvertFile(Episode episode, ProgressNotification notification)
{
_notification = notification;
_currentEpisode = episode;
var outputFile = _configProvider.GetValue("iPodConvertDir", "");
var handBrakePreset = _configProvider.GetValue("HandBrakePreset", "iPhone & iPod Touch");
var handBrakeCommand = String.Format("-i \"{0}\" -o \"{1}\" --preset=\"{2}\"", episode.EpisodeFile.Path, outputFile, handBrakePreset);
var handBrakeFile = @"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe";
try
{
var process = new Process();
process.StartInfo.FileName = handBrakeFile;
process.StartInfo.Arguments = handBrakeCommand;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
}
catch (Exception ex)
{
Logger.DebugException(ex.Message, ex);
return String.Empty;
}
return outputFile;
}
private void HandBrakeOutputDataReceived(object obj, DataReceivedEventArgs args)
{
throw new NotImplementedException();
//args.Data contains the line writen
var match = _processingRegex.Matches(args.Data);
if (match.Count != 1)
return;
var episodeString = String.Format("{0} - {1}x{2:00}",
_currentEpisode.Series.Title,
_currentEpisode.SeasonNumber,
_currentEpisode.EpisodeNumber);
var percent = System.Convert.ToDecimal(match[0].Groups["percent"].Value);
int hours;
int minutes;
int seconds;
Int32.TryParse(match[0].Groups["hours"].Value, out hours);
Int32.TryParse(match[0].Groups["minutes"].Value, out minutes);
Int32.TryParse(match[0].Groups["seconds"].Value, out seconds);
if (seconds > 0 || minutes > 0 || hours > 0)
{
var eta = DateTime.Now.Add(new TimeSpan(0, hours, minutes, seconds));
_notification.CurrentMessage = String.Format("Converting: {0}, {1}%. ETA: {2}", episodeString, percent, eta);
}
else
_notification.CurrentMessage = String.Format("Converting: {0}, {1}%.", episodeString, percent);
Console.WriteLine(args.Data);
}
}
}

@ -5,29 +5,39 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;
using NzbDrone.Core.Model;
namespace NzbDrone.Core.Providers.Core
{
public class ConfigFileProvider
{
private string _configFile = Path.Combine(CentralDispatch.AppPath, "App_Data", "Config.xml");
public string ConfigFile
{
get { return Path.Combine(CentralDispatch.AppPath, "App_Data", "Config.xml"); }
get { return _configFile; }
set { _configFile = value; }
}
public virtual int Port
{
get { return GetValueInt("Port"); }
get { return GetValueInt("Port", 8989); }
set { SetValue("Port", value); }
}
public virtual bool LaunchBrowser
{
get { return GetValueBoolean("LaunchBrowser"); }
get { return GetValueBoolean("LaunchBrowser", true); }
set { SetValue("LaunchBrowser", value); }
}
public virtual string GetValue(string key, string parent = null)
public virtual AuthenticationType AuthenticationType
{
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
set { SetValue("AuthenticationType", (int)value); }
}
public virtual string GetValue(string key, object defaultValue, string parent = null)
{
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
@ -35,21 +45,40 @@ namespace NzbDrone.Core.Providers.Core
var parentContainer = config;
if (!String.IsNullOrEmpty(parent))
{
//Add the parent
if (config.Descendants(parent).Count() != 1)
{
SetValue(key, defaultValue, parent);
//Reload the configFile
xDoc = XDocument.Load(ConfigFile);
config = xDoc.Descendants("Config").Single();
}
parentContainer = config.Descendants(parent).Single();
}
var valueHolder = parentContainer.Descendants(key).ToList();
if (valueHolder.Count() == 1)
return valueHolder.First().Value;
var value = parentContainer.Descendants(key).Single().Value;
//Save the value
SetValue(key, defaultValue, parent);
return value;
//return the default value
return defaultValue.ToString();
}
public virtual int GetValueInt(string key, string parent = null)
public virtual int GetValueInt(string key, int defaultValue, string parent = null)
{
return Convert.ToInt32(GetValue(key, parent));
return Convert.ToInt32(GetValue(key, defaultValue, parent));
}
public virtual bool GetValueBoolean(string key, string parent = null)
public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null)
{
return Convert.ToBoolean(GetValue(key, parent));
return Convert.ToBoolean(GetValue(key, defaultValue, parent));
}
public virtual void SetValue(string key, object value, string parent = null)
@ -60,9 +89,23 @@ namespace NzbDrone.Core.Providers.Core
var parentContainer = config;
if (!String.IsNullOrEmpty(parent))
{
//Add the parent container if it doesn't already exist
if (config.Descendants(parent).Count() != 1)
{
config.Add(new XElement(parent));
}
parentContainer = config.Descendants(parent).Single();
}
var keyHolder = parentContainer.Descendants(key);
if (keyHolder.Count() != 1)
parentContainer.Add(new XElement(key, value));
parentContainer.Descendants(key).Single().Value = value.ToString();
else
parentContainer.Descendants(key).Single().Value = value.ToString();
xDoc.Save(ConfigFile);
}
@ -82,11 +125,7 @@ namespace NzbDrone.Core.Providers.Core
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config",
new XElement("Port", 8989),
new XElement("LaunchBrowser", true)
)
);
xDoc.Add(new XElement("Config"));
xDoc.Save(ConfigFile);
}

@ -0,0 +1,53 @@
using System;
using Ninject;
using NLog;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Converting;
namespace NzbDrone.Core.Providers.Jobs
{
public class ConvertEpisodeJob : IJob
{
private readonly HandbrakeProvider _handbrakeProvider;
private readonly AtomicParsleyProvider _atomicParsleyProvider;
private readonly EpisodeProvider _episodeProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider,
EpisodeProvider episodeProvider)
{
_handbrakeProvider = handbrakeProvider;
_atomicParsleyProvider = atomicParsleyProvider;
_episodeProvider = episodeProvider;
}
public string Name
{
get { return "Convert Episode"; }
}
public int DefaultInterval
{
get { return 0; }
}
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
{
if (targetId <= 0)
throw new ArgumentOutOfRangeException("targetId");
var episode = _episodeProvider.GetEpisode(targetId);
notification.CurrentMessage = String.Format("Starting Conversion for {0}", episode);
var outputFile = _handbrakeProvider.ConvertFile(episode, notification);
if (String.IsNullOrEmpty(outputFile))
notification.CurrentMessage = String.Format("Conversion failed for {0}", episode);
_atomicParsleyProvider.RunAtomicParsley(episode, outputFile);
notification.CurrentMessage = String.Format("Conversion completed for {0}", episode);
}
}
}

@ -189,9 +189,21 @@ namespace NzbDrone.Web.Controllers
public ActionResult System()
{
var selectedAuthenticationType = _configFileProvider.AuthenticationType;
var authenticationTypes = new List<AuthenticationType>();
foreach (AuthenticationType authenticationType in Enum.GetValues(typeof(AuthenticationType)))
{
authenticationTypes.Add(authenticationType);
}
var authTypeSelectList = new SelectList(authenticationTypes, selectedAuthenticationType);
var model = new SystemSettingsModel();
model.Port = _configFileProvider.Port;
model.LaunchBrowser = _configFileProvider.LaunchBrowser;
model.AuthenticationType = selectedAuthenticationType;
model.AuthTypeSelectList = authTypeSelectList;
return View(model);
}
@ -455,6 +467,7 @@ namespace NzbDrone.Web.Controllers
{
_configFileProvider.Port = data.Port;
_configFileProvider.LaunchBrowser = data.LaunchBrowser;
_configFileProvider.AuthenticationType = data.AuthenticationType;
return GetSuccessResult();
}

@ -4,6 +4,8 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Model;
namespace NzbDrone.Web.Models
{
@ -17,5 +19,11 @@ namespace NzbDrone.Web.Models
[DisplayName("Launch Browser")]
[Description("Start default webrowser when NzbDrone starts?")]
public bool LaunchBrowser { get; set; }
[DisplayName("Authentication")]
[Description("Secure the webserver with Authentication?")]
public AuthenticationType AuthenticationType { get; set; }
public SelectList AuthTypeSelectList { get; set; }
}
}

@ -31,6 +31,11 @@
<span class="small">@Html.DescriptionFor(m => m.Port)</span>
</label>
@Html.TextBoxFor(m => m.Port, new { @class = "inputClass" })
<label class="labelClass">@Html.LabelFor(m => m.AuthenticationType)
<span class="small">@Html.DescriptionFor(m => m.AuthenticationType)</span>
</label>
@Html.DropDownListFor(m => m.AuthenticationType, Model.AuthTypeSelectList, new { @class = "inputClass" })
<button type="submit" id="save_button" disabled="disabled">Save</button>
}

@ -3,6 +3,7 @@ using System.Linq;
using System.Reflection;
using NLog;
using Ninject;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone
namespace NzbDrone.Model
{
public enum ApplicationMode
{

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Model
{
public enum AuthenticationType
{
Anonymous = 0,
Windows = 1
}
}

@ -1,6 +1,6 @@
using System.Diagnostics;
namespace NzbDrone
namespace NzbDrone.Model
{
public class ProcessInfo
{

@ -86,8 +86,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="ApplicationMode.cs" />
<Compile Include="ProcessInfo.cs" />
<Compile Include="Model\ApplicationMode.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="Model\ProcessInfo.cs" />
<Compile Include="Providers\ConsoleProvider.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
@ -134,6 +135,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>

@ -0,0 +1,154 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone</RootNamespace>
<AssemblyName>NzbDrone</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<CodeAnalysisRuleSet>BasicCorrectnessRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Exceptioneer.WindowsFormsClient, Version=1.0.0.812, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Exceptioneer.WindowsFormsClient.dll</HintPath>
</Reference>
<Reference Include="Ninject">
<HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<<<<<<< HEAD
<Compile Include="ApplicationMode.cs" />
=======
<Compile Include="Model\AuthenticationType.cs" />
>>>>>>> markus
<Compile Include="ProcessInfo.cs" />
<Compile Include="Providers\ConsoleProvider.cs" />
<Compile Include="Providers\DebuggerProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
<Compile Include="NzbDroneService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ProcessAttacher.cs" />
<Compile Include="Providers\ConfigProvider.cs" />
<Compile Include="Providers\IISProvider.cs" />
<Compile Include="Console.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\MonitoringProvider.cs" />
<Compile Include="Providers\ProcessProvider.cs" />
<Compile Include="Providers\ServiceProvider.cs" />
<Compile Include="Providers\WebClientProvider.cs" />
<Compile Include="Router.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="NzbDrone.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -6,6 +6,7 @@ using System.Xml.XPath;
using NLog;
using NLog.Config;
using Ninject;
using NzbDrone.Model;
namespace NzbDrone.Providers
{
@ -27,12 +28,12 @@ namespace NzbDrone.Providers
public virtual int PortNumber
{
get { return GetValueInt("Port"); }
get { return GetValueInt("Port", 8989); }
}
public virtual bool LaunchBrowser
{
get { return GetValueBoolean("LaunchBrowser"); }
get { return GetValueBoolean("LaunchBrowser", true); }
}
public virtual string IISDirectory
@ -65,6 +66,10 @@ namespace NzbDrone.Providers
get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); }
}
public virtual AuthenticationType AuthenticationType
{
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
}
public virtual void ConfigureNlog()
{
@ -94,6 +99,25 @@ namespace NzbDrone.Providers
new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber))
));
//Update the authenticationTypes
var location = configXml.XPathSelectElement("configuration").Elements("location").Where(
d => d.Attribute("path").Value.ToLowerInvariant() == "nzbdrone").First();
var authenticationTypes = location.XPathSelectElements("system.webServer/security/authentication").First().Descendants();
//Set all authentication types enabled to false
foreach (var child in authenticationTypes)
{
child.Attribute("enabled").Value = "false";
}
var configuredAuthType = String.Format("{0}Authentication", AuthenticationType.ToString()).ToLowerInvariant();
//Set the users authenticationType to true
authenticationTypes.Where(t => t.Name.ToString().ToLowerInvariant() == configuredAuthType).Single().Attribute("enabled").Value = "true";
configXml.Save(configPath);
}
@ -108,42 +132,86 @@ namespace NzbDrone.Providers
}
}
private void WriteDefaultConfig()
public virtual string GetValue(string key, object defaultValue, string parent = null)
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
xDoc.Add(new XElement("Config",
new XElement("Port", 8989),
new XElement("LaunchBrowser", true)
)
);
var parentContainer = config;
xDoc.Save(ConfigFile);
if (!String.IsNullOrEmpty(parent))
{
//Add the parent
if (config.Descendants(parent).Count() != 1)
{
SetValue(key, defaultValue, parent);
//Reload the configFile
xDoc = XDocument.Load(ConfigFile);
config = xDoc.Descendants("Config").Single();
}
parentContainer = config.Descendants(parent).Single();
}
var valueHolder = parentContainer.Descendants(key).ToList();
if (valueHolder.Count() == 1)
return valueHolder.First().Value;
//Save the value
SetValue(key, defaultValue, parent);
//return the default value
return defaultValue.ToString();
}
private string GetValue(string key, string parent = null)
public virtual int GetValueInt(string key, int defaultValue, string parent = null)
{
return Convert.ToInt32(GetValue(key, defaultValue, parent));
}
public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null)
{
return Convert.ToBoolean(GetValue(key, defaultValue, parent));
}
public virtual void SetValue(string key, object value, string parent = null)
{
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
var parentContainer = config;
if (parent != null)
if (!String.IsNullOrEmpty(parent))
{
//Add the parent container if it doesn't already exist
if (config.Descendants(parent).Count() != 1)
{
config.Add(new XElement(parent));
}
parentContainer = config.Descendants(parent).Single();
}
string value = parentContainer.Descendants(key).Single().Value;
var keyHolder = parentContainer.Descendants(key);
return value;
}
if (keyHolder.Count() != 1)
parentContainer.Add(new XElement(key, value));
private int GetValueInt(string key, string parent = null)
{
return Convert.ToInt32(GetValue(key, parent));
else
parentContainer.Descendants(key).Single().Value = value.ToString();
xDoc.Save(ConfigFile);
}
private bool GetValueBoolean(string key, string parent = null)
public virtual void WriteDefaultConfig()
{
return Convert.ToBoolean(GetValue(key, parent));
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config"));
xDoc.Save(ConfigFile);
}
}
}

@ -0,0 +1,228 @@
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using NLog;
using NLog.Config;
<<<<<<< HEAD
using Ninject;
=======
using NzbDrone.Model;
>>>>>>> markus
namespace NzbDrone.Providers
{
public class ConfigProvider
{
private readonly EnviromentProvider _enviromentProvider;
private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider");
[Inject]
public ConfigProvider(EnviromentProvider enviromentProvider)
{
_enviromentProvider = enviromentProvider;
}
public ConfigProvider()
{
}
public virtual int PortNumber
{
get { return GetValueInt("Port", 8989); }
}
public virtual bool LaunchBrowser
{
get { return GetValueBoolean("LaunchBrowser", true); }
}
public virtual string IISDirectory
{
get { return Path.Combine(_enviromentProvider.ApplicationPath, "IISExpress"); }
}
public virtual string IISExePath
{
get { return Path.Combine(IISDirectory, "iisexpress.exe"); }
}
public virtual string IISConfigPath
{
get { return Path.Combine(IISDirectory, "AppServer", "applicationhost.config"); }
}
public virtual string AppDataDirectory
{
get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web", "App_Data"); }
}
public virtual string ConfigFile
{
get { return Path.Combine(AppDataDirectory, "Config.xml"); }
}
public virtual string NlogConfigPath
{
get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); }
}
<<<<<<< HEAD
=======
public virtual AuthenticationType AuthenticationType
{
get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); }
set { SetValue("AuthenticationType", (int)value); }
}
>>>>>>> markus
public virtual void ConfigureNlog()
{
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}]", PortNumber);
var configXml = XDocument.Load(configPath);
var bindings =
configXml.XPathSelectElement("configuration/system.applicationHost/sites").Elements("site").Where(
d => d.Attribute("name").Value.ToLowerInvariant() == "nzbdrone").First().Element("bindings");
bindings.Descendants().Remove();
bindings.Add(
new XElement("binding",
new XAttribute("protocol", "http"),
new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber))
));
bindings.Add(
new XElement("binding",
new XAttribute("protocol", "http"),
new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber))
));
//Update the authenticationTypes
var location = configXml.XPathSelectElement("configuration").Elements("location").Where(
d => d.Attribute("path").Value.ToLowerInvariant() == "nzbdrone").First();
var authenticationTypes = location.XPathSelectElements("system.webServer/security/authentication").First().Descendants();
//Set all authentication types enabled to false
foreach (var child in authenticationTypes)
{
child.Attribute("enabled").Value = "false";
}
var configuredAuthType = String.Format("{0}Authentication", AuthenticationType.ToString()).ToLowerInvariant();
//Set the users authenticationType to true
authenticationTypes.Where(t => t.Name.ToString().ToLowerInvariant() == configuredAuthType).Single().Attribute("enabled").Value = "true";
configXml.Save(configPath);
}
public virtual void CreateDefaultConfigFile()
{
//Create the config file here
Directory.CreateDirectory(AppDataDirectory);
if (!File.Exists(ConfigFile))
{
WriteDefaultConfig();
}
}
<<<<<<< HEAD
private void WriteDefaultConfig()
=======
public virtual string GetValue(string key, object defaultValue, string parent = null)
>>>>>>> markus
{
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
var parentContainer = config;
if (!String.IsNullOrEmpty(parent))
{
//Add the parent
if (config.Descendants(parent).Count() != 1)
{
SetValue(key, defaultValue, parent);
//Reload the configFile
xDoc = XDocument.Load(ConfigFile);
config = xDoc.Descendants("Config").Single();
}
parentContainer = config.Descendants(parent).Single();
}
var valueHolder = parentContainer.Descendants(key).ToList();
if (valueHolder.Count() == 1)
return valueHolder.First().Value;
//Save the value
SetValue(key, defaultValue, parent);
//return the default value
return defaultValue.ToString();
}
public virtual int GetValueInt(string key, int defaultValue, string parent = null)
{
return Convert.ToInt32(GetValue(key, defaultValue, parent));
}
public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null)
{
return Convert.ToBoolean(GetValue(key, defaultValue, parent));
}
public virtual void SetValue(string key, object value, string parent = null)
{
var xDoc = XDocument.Load(ConfigFile);
var config = xDoc.Descendants("Config").Single();
var parentContainer = config;
if (!String.IsNullOrEmpty(parent))
{
//Add the parent container if it doesn't already exist
if (config.Descendants(parent).Count() != 1)
{
config.Add(new XElement(parent));
}
parentContainer = config.Descendants(parent).Single();
}
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 virtual void WriteDefaultConfig()
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config"));
xDoc.Save(ConfigFile);
}
}
}

@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Linq;
using NLog;
using NzbDrone.Model;
namespace NzbDrone.Providers
{

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Model;
using NzbDrone.Providers;
namespace NzbDrone

Loading…
Cancel
Save