mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-03-11 15:19:56 -04:00
Compare commits
133 Commits
stats
...
v2.0.0.414
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
229986033c | ||
|
|
c249ad5dbe | ||
|
|
e2d6d374ab | ||
|
|
d3adb7ac40 | ||
|
|
0f1afd416b | ||
|
|
2f3bc61af7 | ||
|
|
319b4f13b7 | ||
|
|
54fda3d648 | ||
|
|
2f6fded7c3 | ||
|
|
7934003b5e | ||
|
|
8773d38ddd | ||
|
|
f16f097b3e | ||
|
|
7284ef50eb | ||
|
|
e9248e284e | ||
|
|
aff6af1806 | ||
|
|
c0c35a0eba | ||
|
|
072ca459bd | ||
|
|
0865306064 | ||
|
|
ac14444d34 | ||
|
|
8a6d1ef373 | ||
|
|
dc694b0f34 | ||
|
|
76f8cc81da | ||
|
|
14f737bd60 | ||
|
|
5942ddf9f1 | ||
|
|
ab7b427241 | ||
|
|
15120270b4 | ||
|
|
cc0406653a | ||
|
|
9f34127565 | ||
|
|
71ecc96c70 | ||
|
|
2fa3873503 | ||
|
|
96b7bd3b2b | ||
|
|
e1ea17cabf | ||
|
|
3a162be265 | ||
|
|
502298aab9 | ||
|
|
edea488dbe | ||
|
|
2fabe2d198 | ||
|
|
f2c8156c00 | ||
|
|
942be364dc | ||
|
|
44e09e2220 | ||
|
|
0fcd20ec4a | ||
|
|
4c5707bba8 | ||
|
|
947f494e72 | ||
|
|
3f74a87b45 | ||
|
|
da0bdc5750 | ||
|
|
3ea59cd91b | ||
|
|
9b42dc7082 | ||
|
|
8b1c022244 | ||
|
|
e5cb8bb0bd | ||
|
|
d37343bb7d | ||
|
|
9c91f11cdc | ||
|
|
444fcf5ae5 | ||
|
|
31f8e0a47a | ||
|
|
1e0fcc877b | ||
|
|
1293bab868 | ||
|
|
9de92d18e1 | ||
|
|
5a877cbd62 | ||
|
|
99aa25bf83 | ||
|
|
5f66c15b91 | ||
|
|
af220c7f7b | ||
|
|
59e71a4cd9 | ||
|
|
6b1a4c4198 | ||
|
|
1072c5247c | ||
|
|
6508e920fe | ||
|
|
1154e0eeb3 | ||
|
|
2d96914bfa | ||
|
|
70494c3674 | ||
|
|
d68ad98176 | ||
|
|
eb70a6419c | ||
|
|
22aa759abc | ||
|
|
19b8fb6d8b | ||
|
|
d4bc835b1c | ||
|
|
b99d82cccc | ||
|
|
25d481d5d9 | ||
|
|
23871503a2 | ||
|
|
7c54fa70d7 | ||
|
|
2ffbbb0e71 | ||
|
|
7818f0c59b | ||
|
|
03e2adc332 | ||
|
|
e6ab4196de | ||
|
|
f2784d3ec2 | ||
|
|
ef3d508b31 | ||
|
|
9ffc0ec521 | ||
|
|
b598add64e | ||
|
|
47446515d1 | ||
|
|
e5de7fb8cf | ||
|
|
55e870f295 | ||
|
|
1485c83ab6 | ||
|
|
e8d1623e96 | ||
|
|
3bc6bf9e99 | ||
|
|
949d8bf49b | ||
|
|
c29e49da95 | ||
|
|
79c565911c | ||
|
|
bb9a0371c5 | ||
|
|
e945231ab3 | ||
|
|
c1298d162e | ||
|
|
f005edfcf0 | ||
|
|
59c68ec6cc | ||
|
|
a5077b0b1b | ||
|
|
a22c0499d5 | ||
|
|
c38608e3cf | ||
|
|
3b57194d47 | ||
|
|
21c901eab4 | ||
|
|
9ad8311dd6 | ||
|
|
df84028c90 | ||
|
|
7cb1e91ba1 | ||
|
|
974a7276c3 | ||
|
|
f0ca2bc11e | ||
|
|
cb43888496 | ||
|
|
34d5fb1aa0 | ||
|
|
72f0085ef7 | ||
|
|
f25f5abced | ||
|
|
94323f79e7 | ||
|
|
bdb1076100 | ||
|
|
8818e39c63 | ||
|
|
6a90035a4c | ||
|
|
e01b2ef25c | ||
|
|
91d91bc673 | ||
|
|
1c92ea58da | ||
|
|
bd6a38173e | ||
|
|
5d05a85411 | ||
|
|
1a5eafd2b1 | ||
|
|
1603b06431 | ||
|
|
2396af4589 | ||
|
|
262b8daec1 | ||
|
|
d33efe59fc | ||
|
|
5550565d6a | ||
|
|
68540cb479 | ||
|
|
4038fa6907 | ||
|
|
f96f997506 | ||
|
|
4e84d1a17c | ||
|
|
97cdb6a4a5 | ||
|
|
f5b3d70641 | ||
|
|
db66d3da9e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -128,3 +128,4 @@ output/*
|
||||
._*
|
||||
|
||||
_start
|
||||
_temp_*/**/*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# How to Contribute #
|
||||
|
||||
We're always looking for people to help make Sonarr even better, there are a number of ways to contribute. To get started, <a href="http://www.clahub.com/agreements/NzbDrone/NzbDrone">sign the Contributor License Agreement</a>.
|
||||
We're always looking for people to help make Sonarr even better, there are a number of ways to contribute.
|
||||
|
||||
## Documentation ##
|
||||
Setup guides, FAQ, the more information we have on the wiki the better.
|
||||
@@ -18,7 +18,9 @@ Setup guides, FAQ, the more information we have on the wiki the better.
|
||||
1. Fork Sonarr
|
||||
2. Clone (develop branch) *you may need pull in submodules separately if you client doesn't clone them automatically (CurlSharp)*
|
||||
3. Run `npm install`
|
||||
4. Run `gulp watch` - Used to compile the UI components and copy them (leave this window open)
|
||||
4. Run `npm start` - Used to compile the UI components and copy them.
|
||||
Leave this window open.
|
||||
If you have gulp globally installed you can use `gulp watch` instead
|
||||
5. Compile in Visual Studio
|
||||
|
||||
### Contributing Code ###
|
||||
|
||||
14
build.sh
14
build.sh
@@ -1,5 +1,5 @@
|
||||
#! /bin/bash
|
||||
msBuild='/c/Windows/Microsoft.NET/Framework64/v4.0.30319/'
|
||||
msBuild='/c/Program Files (x86)/MSBuild/14.0/Bin'
|
||||
outputFolder='./_output'
|
||||
outputFolderMono='./_output_mono'
|
||||
outputFolderOsx='./_output_osx'
|
||||
@@ -102,12 +102,12 @@ Build()
|
||||
RunGulp()
|
||||
{
|
||||
echo "##teamcity[progressStart 'npm install']"
|
||||
CheckExitCode npm install
|
||||
npm-cache install npm || CheckExitCode npm install
|
||||
echo "##teamcity[progressFinish 'npm install']"
|
||||
|
||||
echo "##teamcity[progressStart 'Running Gulp']"
|
||||
CheckExitCode gulp build
|
||||
echo "##teamcity[progressFinish 'Running Gulp']"
|
||||
echo "##teamcity[progressStart 'Running gulp']"
|
||||
CheckExitCode npm run build
|
||||
echo "##teamcity[progressFinish 'Running gulp']"
|
||||
}
|
||||
|
||||
CreateMdbs()
|
||||
@@ -208,9 +208,9 @@ PackageTests()
|
||||
find $sourceFolder -path $testSearchPattern -exec cp -r -u -T "{}" $testPackageFolder \;
|
||||
|
||||
if [ $runtime = "dotnet" ] ; then
|
||||
$nuget install NUnit.Runners -Version 2.6.1 -Output $testPackageFolder
|
||||
$nuget install NUnit.ConsoleRunner -Version 3.2.0 -Output $testPackageFolder
|
||||
else
|
||||
mono $nuget install NUnit.Runners -Version 2.6.1 -Output $testPackageFolder
|
||||
mono $nuget install NUnit.ConsoleRunner -Version 3.2.0 -Output $testPackageFolder
|
||||
fi
|
||||
|
||||
cp $outputFolder/*.dll $testPackageFolder
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
EXCLUDE="-exclude:Windows -include:IntegrationTest"
|
||||
TESTDIR="."
|
||||
NUNIT="$TESTDIR/NUnit.Runners.2.6.1/tools/nunit-console-x86.exe"
|
||||
|
||||
mono --debug --runtime=v4.0 $NUNIT $EXCLUDE -xml:NzbDrone.Api.Result.xml $TESTDIR/NzbDrone.Api.Test.dll
|
||||
mono --debug --runtime=v4.0 $NUNIT $EXCLUDE -xml:NzbDrone.Core.Result.xml $TESTDIR/NzbDrone.Core.Test.dll
|
||||
mono --debug --runtime=v4.0 $NUNIT $EXCLUDE -xml:NzbDrone.Integration.Result.xml $TESTDIR/NzbDrone.Integration.Test.dll
|
||||
mono --debug --runtime=v4.0 $NUNIT $EXCLUDE -xml:NzbDrone.Common.Result.xml $TESTDIR/NzbDrone.Common.Test.dll
|
||||
29
osx/Sonarr
29
osx/Sonarr
@@ -1,17 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
#get the bundle's MacOS directory full path
|
||||
DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
|
||||
#change these values to match your app
|
||||
EXE_PATH="$DIR/NzbDrone.exe"
|
||||
APPNAME="Sonarr"
|
||||
|
||||
#set up environment
|
||||
MONO_FRAMEWORK_PATH=/Library/Frameworks/Mono.framework/Versions/Current
|
||||
export DYLD_FALLBACK_LIBRARY_PATH="$DIR:$MONO_FRAMEWORK_PATH/lib:/lib:/usr/lib"
|
||||
export PATH="$MONO_FRAMEWORK_PATH/bin:$PATH"
|
||||
|
||||
if [[ -x '/opt/local/bin/mono' ]]; then
|
||||
export PATH="/opt/local/bin:$PATH"
|
||||
fi
|
||||
|
||||
export DYLD_FALLBACK_LIBRARY_PATH="$DIR"
|
||||
|
||||
if [ -e /Library/Frameworks/Mono.framework ]; then
|
||||
MONO_FRAMEWORK_PATH=/Library/Frameworks/Mono.framework/Versions/Current
|
||||
export PATH="$MONO_FRAMEWORK_PATH/bin:$PATH"
|
||||
export DYLD_FALLBACK_LIBRARY_PATH="$DYLD_FALLBACK_LIBRARY_PATH:$MONO_FRAMEWORK_PATH/lib"
|
||||
fi
|
||||
|
||||
if [[ -f '/opt/local/lib/libsqlite3.0.dylib' ]]; then
|
||||
export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib:$DYLD_FALLBACK_LIBRARY_PATH"
|
||||
fi
|
||||
|
||||
export DYLD_FALLBACK_LIBRARY_PATH="$DYLD_FALLBACK_LIBRARY_PATH:$HOME/lib:/usr/local/lib:/lib:/usr/lib"
|
||||
|
||||
#mono version check
|
||||
REQUIRED_MAJOR=3
|
||||
REQUIRED_MINOR=10
|
||||
@@ -21,6 +35,9 @@ VERSION_MSG="$APPNAME requires Mono Runtime Environment(MRE) $REQUIRED_MAJOR.$RE
|
||||
DOWNLOAD_URL="http://www.mono-project.com/download/#download-mac"
|
||||
|
||||
MONO_VERSION="$(mono --version | grep 'Mono JIT compiler version ' | cut -f5 -d\ )"
|
||||
# if [[ -o DEBUG ]]; then osascript -e "display dialog \"MONO_VERSION: $MONO_VERSION\""; fi
|
||||
|
||||
|
||||
MONO_VERSION_MAJOR="$(echo $MONO_VERSION | cut -f1 -d.)"
|
||||
MONO_VERSION_MINOR="$(echo $MONO_VERSION | cut -f2 -d.)"
|
||||
if [ -z "$MONO_VERSION" ] \
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
"description": "Sonarr",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"preinstall": ""
|
||||
"build": "gulp build",
|
||||
"start": "gulp watch"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Sonarr/Sonarr.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "BSD",
|
||||
"license": "GPL-3.0",
|
||||
"gitHead": "9ff7aa1bf7fe38c4c5bdb92f56c8ad556916ed67",
|
||||
"readmeFilename": "readme.md",
|
||||
"dependencies": {
|
||||
|
||||
@@ -24,7 +24,6 @@ Sonarr is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS fee
|
||||
- Visual Studio 2015 [Free Community Edition](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx)
|
||||
- [Git](http://git-scm.com/downloads)
|
||||
- [NodeJS](http://nodejs.org/download/)
|
||||
- [Gulp](http://gulpjs.com)
|
||||
|
||||
### Setup ###
|
||||
|
||||
@@ -32,8 +31,7 @@ Sonarr is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS fee
|
||||
- Clone the repository into your development machine. [*info*](https://help.github.com/articles/working-with-repositories)
|
||||
- Grab the submodules `git submodule init && git submodule update`
|
||||
- install the required Node Packages `npm install`
|
||||
- install gulp `npm install gulp -g`
|
||||
- start gulp to monitor your dev environment for any changes that need post processing using `gulp watch` command.
|
||||
- start gulp to monitor your dev environment for any changes that need post processing using `npm start` command.
|
||||
|
||||
*Please note gulp must be running at all times while you are working with Sonarr client source files.*
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ namespace LogentriesCore
|
||||
WriteDebugMessages("HostName parameter is not defined - trying to get it from System.Environment.MachineName");
|
||||
m_HostName = "HostName=" + System.Environment.MachineName + " ";
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Cannot get host name automatically, so assume that HostName is not used
|
||||
// and log message is sent without it.
|
||||
|
||||
@@ -51,8 +51,9 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -79,6 +80,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="fastJSON\license.txt" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
</packages>
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -774,7 +774,8 @@ namespace MonoTorrent
|
||||
break;
|
||||
|
||||
case ("nodes"):
|
||||
this.nodes = (BEncodedList)keypair.Value;
|
||||
if (keypair.Value.ToString().Length != 0)
|
||||
this.nodes = (BEncodedList)keypair.Value;
|
||||
break;
|
||||
|
||||
case ("comment.utf-8"):
|
||||
|
||||
@@ -46,9 +46,9 @@
|
||||
<HintPath>..\packages\FluentAssertions.4.2.1\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -111,4 +111,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1.1" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
||||
<package id="ValueInjecter" version="2.3.3" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -26,7 +26,7 @@ namespace NzbDrone.Api.ErrorManagement
|
||||
|
||||
if (apiException != null)
|
||||
{
|
||||
_logger.WarnException("API Error", apiException);
|
||||
_logger.Warn(apiException, "API Error");
|
||||
return apiException.ToErrorResponse();
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ namespace NzbDrone.Api.ErrorManagement
|
||||
|
||||
var sqlErrorMessage = string.Format("[{0} {1}]", context.Request.Method, context.Request.Path);
|
||||
|
||||
_logger.ErrorException(sqlErrorMessage, sqLiteException);
|
||||
_logger.Error(sqLiteException, sqlErrorMessage);
|
||||
}
|
||||
|
||||
_logger.FatalException("Request Failed", exception);
|
||||
_logger.Fatal(exception, "Request Failed");
|
||||
|
||||
return new ErrorModel
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace NzbDrone.Api.Extensions.Pipelines
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Unable to gzip response", ex);
|
||||
_logger.Error(ex, "Unable to gzip response");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Api.Extensions.Pipelines
|
||||
{
|
||||
public class RequestLoggingPipeline : IRegisterNancyPipeline
|
||||
{
|
||||
private static readonly Logger _loggerHttp = LogManager.GetLogger("Http");
|
||||
private static readonly Logger _loggerApi = LogManager.GetLogger("Api");
|
||||
|
||||
private static int _requestSequenceID;
|
||||
|
||||
public void Register(IPipelines pipelines)
|
||||
{
|
||||
pipelines.BeforeRequest.AddItemToStartOfPipeline(LogStart);
|
||||
pipelines.AfterRequest.AddItemToEndOfPipeline(LogEnd);
|
||||
}
|
||||
|
||||
private Response LogStart(NancyContext context)
|
||||
{
|
||||
var id = Interlocked.Increment(ref _requestSequenceID);
|
||||
|
||||
context.Items["ApiRequestSequenceID"] = id;
|
||||
context.Items["ApiRequestStartTime"] = DateTime.UtcNow;
|
||||
|
||||
var reqPath = GetRequestPathAndQuery(context.Request);
|
||||
|
||||
_loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void LogEnd(NancyContext context)
|
||||
{
|
||||
var id = (int)context.Items["ApiRequestSequenceID"];
|
||||
var startTime = (DateTime)context.Items["ApiRequestStartTime"];
|
||||
|
||||
var endTime = DateTime.UtcNow;
|
||||
var duration = endTime - startTime;
|
||||
|
||||
var reqPath = GetRequestPathAndQuery(context.Request);
|
||||
|
||||
_loggerHttp.Trace("Res: {0} [{1}] {2}: {3}.{4} ({5} ms)", id, context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds);
|
||||
|
||||
if (context.Request.IsApiRequest())
|
||||
{
|
||||
_loggerApi.Debug("[{0}] {1}: {2}.{3} ({4} ms)", context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetRequestPathAndQuery(Request request)
|
||||
{
|
||||
if (request.Url.Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return string.Concat(request.Url.Path, "?", request.Url.Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
return request.Url.Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.HealthCheck;
|
||||
|
||||
namespace NzbDrone.Api.Health
|
||||
@@ -8,6 +9,6 @@ namespace NzbDrone.Api.Health
|
||||
{
|
||||
public HealthCheckResult Type { get; set; }
|
||||
public string Message { get; set; }
|
||||
public Uri WikiUrl { get; set; }
|
||||
public HttpUri WikiUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace NzbDrone.Api.Indexers
|
||||
}
|
||||
catch (ReleaseDownloadException ex)
|
||||
{
|
||||
_logger.ErrorException(ex.Message, ex);
|
||||
_logger.Error(ex, ex.Message);
|
||||
throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed");
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace NzbDrone.Api.Indexers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Episode search failed: " + ex.Message, ex);
|
||||
_logger.Error(ex, "Episode search failed: " + ex.Message);
|
||||
}
|
||||
|
||||
return new List<ReleaseResource>();
|
||||
|
||||
@@ -9,6 +9,7 @@ using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Api.Indexers
|
||||
{
|
||||
@@ -30,7 +31,7 @@ namespace NzbDrone.Api.Indexers
|
||||
|
||||
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.DownloadUrl).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.DownloadProtocol).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.Protocol).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.PublishDate).NotEmpty();
|
||||
}
|
||||
|
||||
@@ -38,11 +39,14 @@ namespace NzbDrone.Api.Indexers
|
||||
{
|
||||
_logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl);
|
||||
|
||||
var info = release.InjectTo<ReleaseInfo>();
|
||||
var info = release.Protocol == DownloadProtocol.Usenet ?
|
||||
release.InjectTo<ReleaseInfo>() :
|
||||
release.InjectTo<TorrentInfo>();
|
||||
|
||||
info.Guid = "PUSH-" + info.DownloadUrl;
|
||||
|
||||
var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
|
||||
var processed = _downloadDecisionProcessor.ProcessDecisions(decisions);
|
||||
_downloadDecisionProcessor.ProcessDecisions(decisions);
|
||||
|
||||
return MapDecisions(decisions).First().AsResponse();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Qualities;
|
||||
@@ -48,8 +49,25 @@ namespace NzbDrone.Api.Indexers
|
||||
public int? Leechers { get; set; }
|
||||
public DownloadProtocol Protocol { get; set; }
|
||||
|
||||
//TODO: besides a test I don't think this is used...
|
||||
public DownloadProtocol DownloadProtocol { get; set; }
|
||||
|
||||
// TODO: Remove in v3
|
||||
// Used to support the original Release Push implementation
|
||||
// JsonIgnore so we don't serialize it, but can still parse it
|
||||
[JsonIgnore]
|
||||
public DownloadProtocol DownloadProtocol
|
||||
{
|
||||
get
|
||||
{
|
||||
return Protocol;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 0 && Protocol == 0)
|
||||
{
|
||||
Protocol = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDaily { get; set; }
|
||||
public bool IsAbsoluteNumbering { get; set; }
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentValidation, Version=6.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentValidation.6.0.2.0\lib\portable-net40+sl50+wp80+win8+wpa81\FluentValidation.dll</HintPath>
|
||||
<Reference Include="FluentValidation, Version=6.2.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentValidation.6.2.1.0\lib\portable-net40+sl50+wp80+win8+wpa81\FluentValidation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Nancy, Version=0.23.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
@@ -59,6 +59,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
@@ -66,9 +70,6 @@
|
||||
<Reference Include="DDay.iCal">
|
||||
<HintPath>..\packages\DDay.iCal.1.0.2.575\lib\DDay.iCal.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Omu.ValueInjecter">
|
||||
<HintPath>..\packages\ValueInjecter.2.3.3\lib\net35\Omu.ValueInjecter.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -99,6 +100,7 @@
|
||||
<Compile Include="Commands\CommandResource.cs" />
|
||||
<Compile Include="Extensions\AccessControlHeaders.cs" />
|
||||
<Compile Include="Extensions\Pipelines\CorsPipeline.cs" />
|
||||
<Compile Include="Extensions\Pipelines\RequestLoggingPipeline.cs" />
|
||||
<Compile Include="Frontend\Mappers\LoginHtmlMapper.cs" />
|
||||
<Compile Include="Frontend\Mappers\RobotsTxtMapper.cs" />
|
||||
<Compile Include="Indexers\ReleaseModuleBase.cs" />
|
||||
@@ -278,4 +280,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -92,11 +92,6 @@ namespace NzbDrone.Api
|
||||
{
|
||||
var providerDefinition = GetDefinition(providerResource, false);
|
||||
|
||||
if (providerDefinition.Enable)
|
||||
{
|
||||
Test(providerDefinition, false);
|
||||
}
|
||||
|
||||
_providerFactory.Update(providerDefinition);
|
||||
}
|
||||
|
||||
@@ -160,8 +155,10 @@ namespace NzbDrone.Api
|
||||
|
||||
private Response Test(TProviderResource providerResource)
|
||||
{
|
||||
var providerDefinition = GetDefinition(providerResource, true);
|
||||
// Don't validate when getting the definition so we can validate afterwards (avoids validation being skipped because the provider is disabled)
|
||||
var providerDefinition = GetDefinition(providerResource, true, false);
|
||||
|
||||
Validate(providerDefinition, true);
|
||||
Test(providerDefinition, true);
|
||||
|
||||
return "{}";
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace NzbDrone.Api.RootFolders
|
||||
RootFolderValidator rootFolderValidator,
|
||||
PathExistsValidator pathExistsValidator,
|
||||
DroneFactoryValidator droneFactoryValidator,
|
||||
MappedNetworkDriveValidator mappedNetworkDriveValidator)
|
||||
MappedNetworkDriveValidator mappedNetworkDriveValidator,
|
||||
StartupFolderValidator startupFolderValidator)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_rootFolderService = rootFolderService;
|
||||
@@ -32,6 +33,7 @@ namespace NzbDrone.Api.RootFolders
|
||||
.SetValidator(rootFolderValidator)
|
||||
.SetValidator(droneFactoryValidator)
|
||||
.SetValidator(mappedNetworkDriveValidator)
|
||||
.SetValidator(startupFolderValidator)
|
||||
.SetValidator(pathExistsValidator);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@ namespace NzbDrone.Api.Series
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public int SceneSeasonNumber { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,6 @@ namespace NzbDrone.Api
|
||||
break;
|
||||
case Lifetime.PerRequest:
|
||||
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -120,7 +119,6 @@ namespace NzbDrone.Api
|
||||
break;
|
||||
case Lifetime.PerRequest:
|
||||
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DDay.iCal" version="1.0.2.575" targetFramework="net40" />
|
||||
<package id="FluentValidation" version="6.0.2.0" targetFramework="net40" />
|
||||
<package id="FluentValidation" version="6.2.1.0" targetFramework="net40" />
|
||||
<package id="Nancy" version="0.23.2" targetFramework="net40" />
|
||||
<package id="Nancy.Authentication.Basic" version="0.23.2" targetFramework="net40" />
|
||||
<package id="Nancy.Authentication.Forms" version="0.23.2" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net40" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
<package id="ValueInjecter" version="2.3.3" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -45,9 +45,13 @@
|
||||
<HintPath>..\packages\FluentAssertions.4.2.1\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -60,9 +64,6 @@
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ContainerFixture.cs" />
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1.1" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -46,9 +46,13 @@
|
||||
<HintPath>..\packages\FluentAssertions.4.2.1\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -58,9 +62,6 @@
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebDriver, Version=2.48.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Selenium.WebDriver.2.48.0\lib\net40\WebDriver.dll</HintPath>
|
||||
@@ -102,4 +103,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
||||
<package id="Selenium.Support" version="2.48.0" targetFramework="net40" />
|
||||
<package id="Selenium.WebDriver" version="2.48.0" targetFramework="net40" />
|
||||
</packages>
|
||||
102
src/NzbDrone.Common.Test/CacheTests/CachedDictionaryFixture.cs
Normal file
102
src/NzbDrone.Common.Test/CacheTests/CachedDictionaryFixture.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
||||
namespace NzbDrone.Common.Test.CacheTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CachedDictionaryFixture
|
||||
{
|
||||
private CachedDictionary<string> _cachedString;
|
||||
private DictionaryWorker _worker;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_worker = new DictionaryWorker();
|
||||
_cachedString = new CachedDictionary<string>(_worker.GetDict, TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_fetch_on_create()
|
||||
{
|
||||
_worker.HitCount.Should().Be(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fetch_on_first_call()
|
||||
{
|
||||
var result = _cachedString.Get("Hi");
|
||||
|
||||
_worker.HitCount.Should().Be(1);
|
||||
|
||||
result.Should().Be("Value");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fetch_once()
|
||||
{
|
||||
var result1 = _cachedString.Get("Hi");
|
||||
var result2 = _cachedString.Get("HitCount");
|
||||
|
||||
_worker.HitCount.Should().Be(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_auto_refresh_after_lifetime()
|
||||
{
|
||||
var result1 = _cachedString.Get("Hi");
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
var result2 = _cachedString.Get("Hi");
|
||||
|
||||
_worker.HitCount.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_refresh_early_if_requested()
|
||||
{
|
||||
var result1 = _cachedString.Get("Hi");
|
||||
|
||||
Thread.Sleep(10);
|
||||
|
||||
_cachedString.RefreshIfExpired(TimeSpan.FromMilliseconds(1));
|
||||
|
||||
var result2 = _cachedString.Get("Hi");
|
||||
|
||||
_worker.HitCount.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_refresh_early_if_not_expired()
|
||||
{
|
||||
var result1 = _cachedString.Get("Hi");
|
||||
|
||||
_cachedString.RefreshIfExpired(TimeSpan.FromMilliseconds(50));
|
||||
|
||||
var result2 = _cachedString.Get("Hi");
|
||||
|
||||
_worker.HitCount.Should().Be(1);
|
||||
}
|
||||
}
|
||||
|
||||
public class DictionaryWorker
|
||||
{
|
||||
public int HitCount { get; private set; }
|
||||
|
||||
public Dictionary<string, string> GetDict()
|
||||
{
|
||||
HitCount++;
|
||||
|
||||
var result = new Dictionary<string, string>();
|
||||
result["Hi"] = "Value";
|
||||
result["HitCount"] = "Hit count is " + HitCount;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace NzbDrone.Common.Test.CacheTests
|
||||
int hitCount = 0;
|
||||
_cachedString = new Cached<string>();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
_cachedString.Get("key", () =>
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace NzbDrone.Common.Test.CacheTests
|
||||
return null;
|
||||
}, TimeSpan.FromMilliseconds(300));
|
||||
|
||||
Thread.Sleep(10);
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
hitCount.Should().BeInRange(3, 6);
|
||||
|
||||
@@ -24,6 +24,10 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>(MockBehavior.Strict);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetMount(It.IsAny<string>()))
|
||||
.Returns((IMount)null);
|
||||
|
||||
WithEmulatedDiskProvider();
|
||||
|
||||
WithExistingFile(_sourcePath);
|
||||
|
||||
@@ -58,18 +58,20 @@ namespace NzbDrone.Common.Test.Http
|
||||
|
||||
var response = Subject.Get<HttpBinResource>(request);
|
||||
|
||||
response.Resource.Url.Should().Be(request.Url.ToString());
|
||||
response.Resource.Url.Should().Be(request.Url.FullUri);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_execute_simple_post()
|
||||
{
|
||||
var message = "{ my: 1 }";
|
||||
|
||||
var request = new HttpRequest("http://eu.httpbin.org/post");
|
||||
request.Body = "{ my: 1 }";
|
||||
request.SetContent(message);
|
||||
|
||||
var response = Subject.Post<HttpBinResource>(request);
|
||||
|
||||
response.Resource.Data.Should().Be(request.Body);
|
||||
response.Resource.Data.Should().Be(message);
|
||||
}
|
||||
|
||||
[TestCase("gzip")]
|
||||
@@ -162,7 +164,7 @@ namespace NzbDrone.Common.Test.Http
|
||||
public void should_send_cookie()
|
||||
{
|
||||
var request = new HttpRequest("http://eu.httpbin.org/get");
|
||||
request.AddCookie("my", "cookie");
|
||||
request.Cookies["my"] = "cookie";
|
||||
|
||||
var response = Subject.Get<HttpBinResource>(request);
|
||||
|
||||
@@ -176,7 +178,7 @@ namespace NzbDrone.Common.Test.Http
|
||||
public void GivenOldCookie()
|
||||
{
|
||||
var oldRequest = new HttpRequest("http://eu.httpbin.org/get");
|
||||
oldRequest.AddCookie("my", "cookie");
|
||||
oldRequest.Cookies["my"] = "cookie";
|
||||
|
||||
var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<Logger>());
|
||||
|
||||
@@ -260,7 +262,7 @@ namespace NzbDrone.Common.Test.Http
|
||||
var requestSet = new HttpRequest("http://eu.httpbin.org/cookies/set?my=cookie");
|
||||
requestSet.AllowAutoRedirect = false;
|
||||
requestSet.StoreResponseCookie = true;
|
||||
requestSet.AddCookie("my", "oldcookie");
|
||||
requestSet.Cookies["my"] = "oldcookie";
|
||||
|
||||
var responseSet = Subject.Get(requestSet);
|
||||
|
||||
@@ -322,10 +324,10 @@ namespace NzbDrone.Common.Test.Http
|
||||
{
|
||||
// the date is bad in the below - should be 13-Jul-2016
|
||||
string malformedCookie = @"__cfduid=d29e686a9d65800021c66faca0a29b4261436890790; expires=Wed, 13-Jul-16 16:19:50 GMT; path=/; HttpOnly";
|
||||
string url = "http://eu.httpbin.org/response-headers?Set-Cookie=" +
|
||||
System.Uri.EscapeUriString(malformedCookie);
|
||||
var requestSet = new HttpRequestBuilder("http://eu.httpbin.org/response-headers")
|
||||
.AddQueryParam("Set-Cookie", malformedCookie)
|
||||
.Build();
|
||||
|
||||
var requestSet = new HttpRequest(url);
|
||||
requestSet.AllowAutoRedirect = false;
|
||||
requestSet.StoreResponseCookie = true;
|
||||
|
||||
@@ -376,6 +378,21 @@ namespace NzbDrone.Common.Test.Http
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void should_submit_formparameters_in_body()
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
public void should_submit_attachments_as_multipart()
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
public void should_submit_formparameters_as_multipart_if_attachments_exist()
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpBinResource
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Test.Common;
|
||||
@@ -8,14 +9,32 @@ namespace NzbDrone.Common.Test.Http
|
||||
[TestFixture]
|
||||
public class HttpRequestBuilderFixture : TestBase
|
||||
{
|
||||
[TestCase("http://host/{seg}/some", "http://host/dir/some")]
|
||||
[TestCase("http://host/some/{seg}", "http://host/some/dir")]
|
||||
public void should_add_single_segment_url_segments(string url, string result)
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder(url);
|
||||
|
||||
requestBuilder.SetSegment("seg", "dir");
|
||||
|
||||
requestBuilder.Build().Url.Should().Be(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void shouldnt_add_value_for_nonexisting_segment()
|
||||
{
|
||||
var requestBuilder = new HttpRequestBuilder("http://host/{seg}/some");
|
||||
Assert.Throws<InvalidOperationException>(() => requestBuilder.SetSegment("seg2", "dir"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_duplicated_slashes()
|
||||
{
|
||||
var builder = new HttpRequestBuilder("http://domain/");
|
||||
|
||||
var request = builder.Build("/v1/");
|
||||
var request = builder.Resource("/v1/").Build();
|
||||
|
||||
request.Url.ToString().Should().Be("http://domain/v1/");
|
||||
request.Url.FullUri.Should().Be("http://domain/v1/");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,5 @@ namespace NzbDrone.Common.Test.Http
|
||||
[TestFixture]
|
||||
public class HttpRequestFixture
|
||||
{
|
||||
[TestCase("http://host/{seg}/some", "http://host/dir/some")]
|
||||
[TestCase("http://host/some/{seg}", "http://host/some/dir")]
|
||||
public void should_add_single_segment_url_segments(string url, string result)
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
|
||||
request.AddSegment("seg", "dir");
|
||||
|
||||
request.Url.Should().Be(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void shouldnt_add_value_for_nonexisting_segment()
|
||||
{
|
||||
var request = new HttpRequest("http://host/{seg}/some");
|
||||
Assert.Throws<InvalidOperationException>(() => request.AddSegment("seg2", "dir"));
|
||||
}
|
||||
}
|
||||
}
|
||||
84
src/NzbDrone.Common.Test/Http/HttpUriFixture.cs
Normal file
84
src/NzbDrone.Common.Test/Http/HttpUriFixture.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.Http
|
||||
{
|
||||
public class HttpUriFixture : TestBase
|
||||
{
|
||||
[TestCase("", "", "")]
|
||||
[TestCase("/", "", "/")]
|
||||
[TestCase("base", "", "base")]
|
||||
[TestCase("/base", "", "/base")]
|
||||
[TestCase("/base/", "", "/base/")]
|
||||
[TestCase("", "relative", "relative")]
|
||||
[TestCase("", "/relative", "/relative")]
|
||||
[TestCase("/", "relative", "/relative")]
|
||||
[TestCase("/", "/relative", "/relative")]
|
||||
[TestCase("base", "relative", "relative")]
|
||||
[TestCase("base", "/relative", "/relative")]
|
||||
[TestCase("/base", "relative", "/relative")]
|
||||
[TestCase("/base", "/relative", "/relative")]
|
||||
[TestCase("/base/", "relative", "/base/relative")]
|
||||
[TestCase("/base/", "/relative", "/relative")]
|
||||
[TestCase("base/sub", "relative", "base/relative")]
|
||||
[TestCase("base/sub", "/relative", "/relative")]
|
||||
[TestCase("/base/sub", "relative", "/base/relative")]
|
||||
[TestCase("/base/sub", "/relative", "/relative")]
|
||||
[TestCase("/base/sub/", "relative", "/base/sub/relative")]
|
||||
[TestCase("/base/sub/", "/relative", "/relative")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api", "relative/path", "abc://host.com:8080/root/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "/relative/path", "abc://host.com:8080/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "//otherhost.com/path", "abc://otherhost.com/path")]
|
||||
public void should_combine_uri(string basePath, string relativePath, string expected)
|
||||
{
|
||||
var newUri = new HttpUri(basePath) + new HttpUri(relativePath);
|
||||
newUri.FullUri.Should().Be(expected);
|
||||
}
|
||||
|
||||
[TestCase("", "", "")]
|
||||
[TestCase("/", "", "/")]
|
||||
[TestCase("base", "", "base")]
|
||||
[TestCase("/base", "", "/base")]
|
||||
[TestCase("/base/", "", "/base/")]
|
||||
[TestCase("", "relative", "relative")]
|
||||
[TestCase("", "/relative", "/relative")]
|
||||
[TestCase("/", "relative", "/relative")]
|
||||
[TestCase("/", "/relative", "/relative")]
|
||||
[TestCase("base", "relative", "base/relative")]
|
||||
[TestCase("base", "/relative", "base/relative")]
|
||||
[TestCase("/base", "relative", "/base/relative")]
|
||||
[TestCase("/base", "/relative", "/base/relative")]
|
||||
[TestCase("/base/", "relative", "/base/relative")]
|
||||
[TestCase("/base/", "/relative", "/base/relative")]
|
||||
[TestCase("base/sub", "relative", "base/sub/relative")]
|
||||
[TestCase("base/sub", "/relative", "base/sub/relative")]
|
||||
[TestCase("/base/sub", "relative", "/base/sub/relative")]
|
||||
[TestCase("/base/sub", "/relative", "/base/sub/relative")]
|
||||
[TestCase("/base/sub/", "relative", "/base/sub/relative")]
|
||||
[TestCase("/base/sub/", "/relative", "/base/sub/relative")]
|
||||
[TestCase("/base/sub/", "relative/", "/base/sub/relative/")]
|
||||
[TestCase("/base/sub/", "/relative/", "/base/sub/relative/")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "relative/path", "abc://host.com:8080/root/file.xml/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml", "/relative/path", "abc://host.com:8080/root/file.xml/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "relative/path", "abc://host.com:8080/root/file.xml/relative/path?query=1#fragment")]
|
||||
[TestCase("abc://host.com:8080/root/file.xml?query=1#fragment", "/relative/path", "abc://host.com:8080/root/file.xml/relative/path?query=1#fragment")]
|
||||
[TestCase("abc://host.com:8080/root/api", "relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api", "/relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
[TestCase("abc://host.com:8080/root/api/", "/relative/path", "abc://host.com:8080/root/api/relative/path")]
|
||||
public void should_combine_relative_path(string basePath, string relativePath, string expected)
|
||||
{
|
||||
var newUri = new HttpUri(basePath).CombinePath(relativePath);
|
||||
|
||||
newUri.FullUri.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,13 @@
|
||||
<HintPath>..\packages\FluentAssertions.4.2.1\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -60,11 +64,9 @@
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheTests\CachedDictionaryFixture.cs" />
|
||||
<Compile Include="CacheTests\CachedFixture.cs" />
|
||||
<Compile Include="CacheTests\CachedManagerFixture.cs" />
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
@@ -81,6 +83,7 @@
|
||||
<Compile Include="Http\HttpClientFixture.cs" />
|
||||
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
||||
<Compile Include="Http\HttpRequestFixture.cs" />
|
||||
<Compile Include="Http\HttpUriFixture.cs" />
|
||||
<Compile Include="InstrumentationTests\CleanseLogMessageFixture.cs" />
|
||||
<Compile Include="LevenshteinDistanceFixture.cs" />
|
||||
<Compile Include="OsPathFixture.cs" />
|
||||
@@ -151,4 +154,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -6,6 +6,7 @@ using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
@@ -153,7 +154,7 @@ namespace NzbDrone.Common.Test
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
[Ignore("Parent, not Grandparent")]
|
||||
public void should_not_be_parent_when_it_is_grandparent()
|
||||
{
|
||||
var path = Path.Combine(_parent, "parent", "child");
|
||||
@@ -205,7 +206,7 @@ namespace NzbDrone.Common.Test
|
||||
public void get_actual_casing_should_return_actual_casing_for_local_dir_in_windows()
|
||||
{
|
||||
WindowsOnly();
|
||||
var path = Directory.GetCurrentDirectory().Replace("c:\\","C:\\");
|
||||
var path = Directory.GetCurrentDirectory().Replace("c:\\","C:\\").Replace("system32", "System32");
|
||||
|
||||
path.ToUpper().GetActualCasing().Should().Be(path);
|
||||
path.ToLower().GetActualCasing().Should().Be(path);
|
||||
@@ -222,6 +223,7 @@ namespace NzbDrone.Common.Test
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
[ManualTest]
|
||||
public void get_actual_casing_should_return_original_casing_for_shares()
|
||||
{
|
||||
var path = @"\\server\Pool\Apps";
|
||||
|
||||
@@ -31,10 +31,20 @@ namespace NzbDrone.Common.Test
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c =>
|
||||
{
|
||||
try
|
||||
{
|
||||
c.Kill();
|
||||
}
|
||||
catch (Win32Exception ex)
|
||||
{
|
||||
TestLogger.Warn(ex, "{0} when killing process", ex.Message);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetById_should_return_null_if_process_doesnt_exist()
|
||||
{
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.ServiceProcess;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
@@ -13,7 +15,6 @@ namespace NzbDrone.Common.Test
|
||||
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
|
||||
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -24,8 +25,10 @@ namespace NzbDrone.Common.Test
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
WindowsOnly();
|
||||
CleanupService();
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
CleanupService();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +73,7 @@ namespace NzbDrone.Common.Test
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
[ManualTest]
|
||||
public void UnInstallService()
|
||||
{
|
||||
Subject.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
@@ -78,6 +82,7 @@ namespace NzbDrone.Common.Test
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
[ManualTest]
|
||||
public void Should_be_able_to_start_and_stop_service()
|
||||
{
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
|
||||
|
||||
[Test]
|
||||
[Retry(3)]
|
||||
public void should_hold_the_call_for_debounce_duration()
|
||||
{
|
||||
var counter = new Counter();
|
||||
@@ -40,6 +41,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Retry(3)]
|
||||
public void should_throttle_calls()
|
||||
{
|
||||
var counter = new Counter();
|
||||
@@ -65,6 +67,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Retry(3)]
|
||||
public void should_hold_the_call_while_paused()
|
||||
{
|
||||
var counter = new Counter();
|
||||
@@ -98,6 +101,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Retry(3)]
|
||||
public void should_handle_pause_reentrancy()
|
||||
{
|
||||
var counter = new Counter();
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Retry(3)]
|
||||
public void should_wait_for_existing()
|
||||
{
|
||||
GivenExisting("me", _epoch + TimeSpan.FromMilliseconds(200));
|
||||
@@ -70,7 +71,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
||||
Subject.WaitAndPulse("me", TimeSpan.FromMilliseconds(400));
|
||||
watch.Stop();
|
||||
|
||||
watch.ElapsedMilliseconds.Should().BeInRange(195, 250);
|
||||
watch.ElapsedMilliseconds.Should().BeInRange(175, 250);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -6,8 +6,9 @@ namespace NzbDrone.Common.Cache
|
||||
{
|
||||
public interface ICacheManager
|
||||
{
|
||||
ICached<T> GetCache<T>(Type host, string name);
|
||||
ICached<T> GetCache<T>(Type host);
|
||||
ICached<T> GetCache<T>(Type host, string name);
|
||||
ICachedDictionary<T> GetCacheDictionary<T>(Type host, string name, Func<IDictionary<string, T>> fetchFunc = null, TimeSpan? lifeTime = null);
|
||||
void Clear();
|
||||
ICollection<ICached> Caches { get; }
|
||||
}
|
||||
@@ -22,12 +23,6 @@ namespace NzbDrone.Common.Cache
|
||||
|
||||
}
|
||||
|
||||
public ICached<T> GetCache<T>(Type host)
|
||||
{
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
return GetCache<T>(host, host.FullName);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_cache.Clear();
|
||||
@@ -35,6 +30,12 @@ namespace NzbDrone.Common.Cache
|
||||
|
||||
public ICollection<ICached> Caches { get { return _cache.Values; } }
|
||||
|
||||
public ICached<T> GetCache<T>(Type host)
|
||||
{
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
return GetCache<T>(host, host.FullName);
|
||||
}
|
||||
|
||||
public ICached<T> GetCache<T>(Type host, string name)
|
||||
{
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
@@ -42,5 +43,13 @@ namespace NzbDrone.Common.Cache
|
||||
|
||||
return (ICached<T>)_cache.Get(host.FullName + "_" + name, () => new Cached<T>());
|
||||
}
|
||||
|
||||
public ICachedDictionary<T> GetCacheDictionary<T>(Type host, string name, Func<IDictionary<string, T>> fetchFunc = null, TimeSpan? lifeTime = null)
|
||||
{
|
||||
Ensure.That(host, () => host).IsNotNull();
|
||||
Ensure.That(name, () => name).IsNotNullOrWhiteSpace();
|
||||
|
||||
return (ICachedDictionary<T>)_cache.Get("dict_" + host.FullName + "_" + name, () => new CachedDictionary<T>(fetchFunc, lifeTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
137
src/NzbDrone.Common/Cache/CachedDictionary.cs
Normal file
137
src/NzbDrone.Common/Cache/CachedDictionary.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Cache
|
||||
{
|
||||
|
||||
public class CachedDictionary<TValue> : ICachedDictionary<TValue>
|
||||
{
|
||||
private readonly Func<IDictionary<string, TValue>> _fetchFunc;
|
||||
private readonly TimeSpan? _ttl;
|
||||
|
||||
private DateTime _lastRefreshed = DateTime.MinValue;
|
||||
private ConcurrentDictionary<string, TValue> _items = new ConcurrentDictionary<string, TValue>();
|
||||
|
||||
public CachedDictionary(Func<IDictionary<string, TValue>> fetchFunc = null, TimeSpan? ttl = null)
|
||||
{
|
||||
_fetchFunc = fetchFunc;
|
||||
_ttl = ttl;
|
||||
}
|
||||
|
||||
public bool IsExpired(TimeSpan ttl)
|
||||
{
|
||||
return _lastRefreshed.Add(ttl) < DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void RefreshIfExpired()
|
||||
{
|
||||
if (_ttl.HasValue && _fetchFunc != null)
|
||||
{
|
||||
RefreshIfExpired(_ttl.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshIfExpired(TimeSpan ttl)
|
||||
{
|
||||
if (IsExpired(ttl))
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (_fetchFunc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot update cache without data source.");
|
||||
}
|
||||
|
||||
Update(_fetchFunc());
|
||||
ExtendTTL();
|
||||
}
|
||||
|
||||
public void Update(IDictionary<string, TValue> items)
|
||||
{
|
||||
_items = new ConcurrentDictionary<string, TValue>(items);
|
||||
ExtendTTL();
|
||||
}
|
||||
|
||||
public void ExtendTTL()
|
||||
{
|
||||
_lastRefreshed = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public ICollection<TValue> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
RefreshIfExpired();
|
||||
return _items.Values;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
RefreshIfExpired();
|
||||
return _items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public TValue Get(string key)
|
||||
{
|
||||
RefreshIfExpired();
|
||||
|
||||
TValue result;
|
||||
|
||||
if (!_items.TryGetValue(key, out result))
|
||||
{
|
||||
throw new KeyNotFoundException(string.Format("Item {0} not found in cache.", key));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public TValue Find(string key)
|
||||
{
|
||||
RefreshIfExpired();
|
||||
|
||||
TValue result;
|
||||
|
||||
_items.TryGetValue(key, out result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_items.Clear();
|
||||
_lastRefreshed = DateTime.MinValue;
|
||||
}
|
||||
|
||||
public void ClearExpired()
|
||||
{
|
||||
if (!_ttl.HasValue)
|
||||
{
|
||||
throw new InvalidOperationException("Checking expiry without ttl not possible.");
|
||||
}
|
||||
|
||||
if (IsExpired(_ttl.Value))
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
TValue item;
|
||||
_items.TryRemove(key, out item);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/NzbDrone.Common/Cache/ICachedDictionary.cs
Normal file
18
src/NzbDrone.Common/Cache/ICachedDictionary.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Cache
|
||||
{
|
||||
public interface ICachedDictionary<TValue> : ICached
|
||||
{
|
||||
void RefreshIfExpired();
|
||||
void RefreshIfExpired(TimeSpan ttl);
|
||||
void Refresh();
|
||||
void Update(IDictionary<string, TValue> items);
|
||||
void ExtendTTL();
|
||||
TValue Get(string key);
|
||||
TValue Find(string key);
|
||||
bool IsExpired(TimeSpan ttl);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Common.Cloud
|
||||
{
|
||||
public interface IDroneServicesRequestBuilder
|
||||
{
|
||||
HttpRequest Build(string path);
|
||||
}
|
||||
|
||||
public class DroneServicesHttpRequestBuilder : HttpRequestBuilder, IDroneServicesRequestBuilder
|
||||
{
|
||||
private const string ROOT_URL = "http://services.sonarr.tv/v1/";
|
||||
|
||||
public DroneServicesHttpRequestBuilder()
|
||||
: base(ROOT_URL)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs
Normal file
28
src/NzbDrone.Common/Cloud/SonarrCloudRequestBuilder.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Common.Cloud
|
||||
{
|
||||
public interface ISonarrCloudRequestBuilder
|
||||
{
|
||||
IHttpRequestBuilderFactory Services { get; }
|
||||
IHttpRequestBuilderFactory SkyHookTvdb { get; }
|
||||
}
|
||||
|
||||
public class SonarrCloudRequestBuilder : ISonarrCloudRequestBuilder
|
||||
{
|
||||
public SonarrCloudRequestBuilder()
|
||||
{
|
||||
Services = new HttpRequestBuilder("http://services.sonarr.tv/v1/")
|
||||
.CreateFactory();
|
||||
|
||||
SkyHookTvdb = new HttpRequestBuilder("http://skyhook.sonarr.tv/v1/tvdb/{route}/{language}/")
|
||||
.SetSegment("language", "en")
|
||||
.CreateFactory();
|
||||
}
|
||||
|
||||
public IHttpRequestBuilderFactory Services { get; private set; }
|
||||
|
||||
public IHttpRequestBuilderFactory SkyHookTvdb { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,16 @@ namespace NzbDrone.Common.Crypto
|
||||
|
||||
public static int GetHashInt31(string target)
|
||||
{
|
||||
byte[] hash;
|
||||
var hash = GetHash(target);
|
||||
return BitConverter.ToInt32(hash, 0) & 0x7fffffff;
|
||||
}
|
||||
|
||||
public static byte[] GetHash(string target)
|
||||
{
|
||||
lock (Sha1)
|
||||
{
|
||||
hash = Sha1.ComputeHash(Encoding.Default.GetBytes(target));
|
||||
return Sha1.ComputeHash(Encoding.Default.GetBytes(target));
|
||||
}
|
||||
return BitConverter.ToInt32(hash, 0) & 0x7fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,18 +293,30 @@ namespace NzbDrone.Common.Disk
|
||||
var sid = new SecurityIdentifier(accountSid, null);
|
||||
|
||||
var directoryInfo = new DirectoryInfo(filename);
|
||||
var directorySecurity = directoryInfo.GetAccessControl();
|
||||
var directorySecurity = directoryInfo.GetAccessControl(AccessControlSections.Access);
|
||||
|
||||
var rules = directorySecurity.GetAccessRules(true, false, typeof(SecurityIdentifier));
|
||||
|
||||
if (rules.OfType<FileSystemAccessRule>().Any(acl => acl.AccessControlType == controlType && (acl.FileSystemRights & rights) == rights && acl.IdentityReference.Equals(sid)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var accessRule = new FileSystemAccessRule(sid, rights,
|
||||
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
|
||||
PropagationFlags.None, controlType);
|
||||
PropagationFlags.InheritOnly, controlType);
|
||||
|
||||
directorySecurity.AddAccessRule(accessRule);
|
||||
directoryInfo.SetAccessControl(directorySecurity);
|
||||
bool modified;
|
||||
directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out modified);
|
||||
|
||||
if (modified)
|
||||
{
|
||||
directoryInfo.SetAccessControl(directorySecurity);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType), e);
|
||||
Logger.Warn(e, "Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType);
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -346,12 +358,12 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
public string[] GetFixedDrives()
|
||||
{
|
||||
return (DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Fixed).Select(x => x.Name)).ToArray();
|
||||
return GetMounts().Where(x => x.DriveType == DriveType.Fixed).Select(x => x.RootDirectory).ToArray();
|
||||
}
|
||||
|
||||
public string GetVolumeLabel(string path)
|
||||
{
|
||||
var driveInfo = DriveInfo.GetDrives().SingleOrDefault(d => d.Name == path);
|
||||
var driveInfo = GetMounts().SingleOrDefault(d => d.RootDirectory.PathEquals(path));
|
||||
|
||||
if (driveInfo == null)
|
||||
{
|
||||
@@ -376,11 +388,36 @@ namespace NzbDrone.Common.Disk
|
||||
return new FileStream(path, FileMode.Create);
|
||||
}
|
||||
|
||||
public List<DriveInfo> GetDrives()
|
||||
public virtual List<IMount> GetMounts()
|
||||
{
|
||||
return GetDriveInfoMounts();
|
||||
}
|
||||
|
||||
public virtual IMount GetMount(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var mounts = GetMounts();
|
||||
|
||||
return mounts.Where(drive => drive.RootDirectory.PathEquals(path) ||
|
||||
drive.RootDirectory.IsParentPath(path))
|
||||
.OrderByDescending(drive => drive.RootDirectory.Length)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Debug(ex, string.Format("Failed to get mount for path {0}", path));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<IMount> GetDriveInfoMounts()
|
||||
{
|
||||
return DriveInfo.GetDrives()
|
||||
.Where(d => d.DriveType == DriveType.Fixed || d.DriveType == DriveType.Network)
|
||||
.Where(d => d.DriveType == DriveType.Fixed || d.DriveType == DriveType.Network || d.DriveType == DriveType.Removable)
|
||||
.Where(d => d.IsReady)
|
||||
.Select(d => new DriveInfoMount(d))
|
||||
.Cast<IMount>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -401,5 +438,19 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
return di.GetFiles().ToList();
|
||||
}
|
||||
|
||||
public void RemoveEmptySubfolders(string path)
|
||||
{
|
||||
var subfolders = GetDirectories(path);
|
||||
var files = GetFiles(path, SearchOption.AllDirectories);
|
||||
|
||||
foreach (var subfolder in subfolders)
|
||||
{
|
||||
if (files.None(f => subfolder.IsParentPath(f)))
|
||||
{
|
||||
DeleteFolder(subfolder, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,13 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
|
||||
public TransferMode TransferFolder(string sourcePath, string targetPath, TransferMode mode, bool verified = true)
|
||||
{
|
||||
var verificationMode = verified ? VerificationMode : DiskTransferVerificationMode.VerifyOnly;
|
||||
|
||||
return TransferFolder(sourcePath, targetPath, mode, verificationMode);
|
||||
}
|
||||
|
||||
public TransferMode TransferFolder(string sourcePath, string targetPath, TransferMode mode, DiskTransferVerificationMode verificationMode)
|
||||
{
|
||||
Ensure.That(sourcePath, () => sourcePath).IsValidPath();
|
||||
Ensure.That(targetPath, () => targetPath).IsValidPath();
|
||||
@@ -58,14 +65,14 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
foreach (var subDir in _diskProvider.GetDirectoryInfos(sourcePath))
|
||||
{
|
||||
result &= TransferFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name), mode, verified);
|
||||
result &= TransferFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name), mode, verificationMode);
|
||||
}
|
||||
|
||||
foreach (var sourceFile in _diskProvider.GetFileInfos(sourcePath))
|
||||
{
|
||||
var destFile = Path.Combine(targetPath, sourceFile.Name);
|
||||
|
||||
result &= TransferFile(sourceFile.FullName, destFile, mode, true, verified);
|
||||
result &= TransferFile(sourceFile.FullName, destFile, mode, true, verificationMode);
|
||||
}
|
||||
|
||||
if (mode.HasFlag(TransferMode.Move))
|
||||
@@ -77,15 +84,17 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
|
||||
public TransferMode TransferFile(string sourcePath, string targetPath, TransferMode mode, bool overwrite = false, bool verified = true)
|
||||
{
|
||||
var verificationMode = verified ? VerificationMode : DiskTransferVerificationMode.None;
|
||||
|
||||
return TransferFile(sourcePath, targetPath, mode, overwrite, verificationMode);
|
||||
}
|
||||
|
||||
public TransferMode TransferFile(string sourcePath, string targetPath, TransferMode mode, bool overwrite, DiskTransferVerificationMode verificationMode)
|
||||
{
|
||||
Ensure.That(sourcePath, () => sourcePath).IsValidPath();
|
||||
Ensure.That(targetPath, () => targetPath).IsValidPath();
|
||||
|
||||
if (VerificationMode != DiskTransferVerificationMode.Transactional && VerificationMode != DiskTransferVerificationMode.TryTransactional)
|
||||
{
|
||||
verified = false;
|
||||
}
|
||||
|
||||
_logger.Debug("{0} [{1}] > [{2}]", mode, sourcePath, targetPath);
|
||||
|
||||
var originalSize = _diskProvider.GetFileSize(sourcePath);
|
||||
@@ -154,49 +163,59 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
}
|
||||
|
||||
if (verified)
|
||||
// We force a transactional transfer if the transfer occurs between mounts and one of the mounts is cifs, it would be a copy anyway.
|
||||
if (verificationMode == DiskTransferVerificationMode.TryTransactional && OsInfo.IsNotWindows)
|
||||
{
|
||||
if (mode.HasFlag(TransferMode.Copy))
|
||||
var sourceMount = _diskProvider.GetMount(sourcePath);
|
||||
var targetMount = _diskProvider.GetMount(targetPath);
|
||||
|
||||
if (sourceMount != null && targetMount != null && sourceMount.RootDirectory != targetMount.RootDirectory &&
|
||||
(sourceMount.DriveFormat == "cifs" || targetMount.DriveFormat == "cifs"))
|
||||
{
|
||||
verificationMode = DiskTransferVerificationMode.Transactional;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode.HasFlag(TransferMode.Copy))
|
||||
{
|
||||
if (verificationMode == DiskTransferVerificationMode.Transactional || verificationMode == DiskTransferVerificationMode.TryTransactional)
|
||||
{
|
||||
if (TryCopyFileTransactional(sourcePath, targetPath, originalSize))
|
||||
{
|
||||
return TransferMode.Copy;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode.HasFlag(TransferMode.Move))
|
||||
{
|
||||
if (TryMoveFileTransactional(sourcePath, targetPath, originalSize))
|
||||
{
|
||||
return TransferMode.Move;
|
||||
}
|
||||
throw new IOException(string.Format("Failed to completely transfer [{0}] to [{1}], aborting.", sourcePath, targetPath));
|
||||
}
|
||||
|
||||
throw new IOException(string.Format("Failed to completely transfer [{0}] to [{1}], aborting.", sourcePath, targetPath));
|
||||
}
|
||||
else if (VerificationMode != DiskTransferVerificationMode.None)
|
||||
{
|
||||
if (mode.HasFlag(TransferMode.Copy))
|
||||
else if (verificationMode == DiskTransferVerificationMode.VerifyOnly)
|
||||
{
|
||||
TryCopyFileVerified(sourcePath, targetPath, originalSize);
|
||||
return TransferMode.Copy;
|
||||
}
|
||||
|
||||
if (mode.HasFlag(TransferMode.Move))
|
||||
{
|
||||
TryMoveFileVerified(sourcePath, targetPath, originalSize);
|
||||
return TransferMode.Move;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mode.HasFlag(TransferMode.Copy))
|
||||
else
|
||||
{
|
||||
_diskProvider.CopyFile(sourcePath, targetPath);
|
||||
return TransferMode.Copy;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode.HasFlag(TransferMode.Move))
|
||||
if (mode.HasFlag(TransferMode.Move))
|
||||
{
|
||||
if (verificationMode == DiskTransferVerificationMode.Transactional || verificationMode == DiskTransferVerificationMode.TryTransactional)
|
||||
{
|
||||
if (TryMoveFileTransactional(sourcePath, targetPath, originalSize, verificationMode))
|
||||
{
|
||||
return TransferMode.Move;
|
||||
}
|
||||
|
||||
throw new IOException(string.Format("Failed to completely transfer [{0}] to [{1}], aborting.", sourcePath, targetPath));
|
||||
}
|
||||
else if (verificationMode == DiskTransferVerificationMode.VerifyOnly)
|
||||
{
|
||||
TryMoveFileVerified(sourcePath, targetPath, originalSize);
|
||||
return TransferMode.Move;
|
||||
}
|
||||
else
|
||||
{
|
||||
_diskProvider.MoveFile(sourcePath, targetPath);
|
||||
return TransferMode.Move;
|
||||
@@ -240,7 +259,7 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException(string.Format("Failed to properly rollback the file move [{0}] to [{1}], incomplete file may be left in target path.", sourcePath, targetPath), ex);
|
||||
_logger.Error(ex, string.Format("Failed to properly rollback the file move [{0}] to [{1}], incomplete file may be left in target path.", sourcePath, targetPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +275,7 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException(string.Format("Failed to properly rollback the file move [{0}] to [{1}], file may be left in target path.", sourcePath, targetPath), ex);
|
||||
_logger.Error(ex, string.Format("Failed to properly rollback the file move [{0}] to [{1}], file may be left in target path.", sourcePath, targetPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +294,7 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException(string.Format("Failed to properly rollback the file copy [{0}] to [{1}], file may be left in target path.", sourcePath, targetPath), ex);
|
||||
_logger.Error(ex, string.Format("Failed to properly rollback the file copy [{0}] to [{1}], file may be left in target path.", sourcePath, targetPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +359,7 @@ namespace NzbDrone.Common.Disk
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryMoveFileTransactional(string sourcePath, string targetPath, long originalSize)
|
||||
private bool TryMoveFileTransactional(string sourcePath, string targetPath, long originalSize, DiskTransferVerificationMode verificationMode)
|
||||
{
|
||||
var backupPath = sourcePath + ".backup~";
|
||||
var tempTargetPath = targetPath + ".partial~";
|
||||
@@ -394,7 +413,7 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
}
|
||||
|
||||
if (VerificationMode == DiskTransferVerificationMode.Transactional)
|
||||
if (verificationMode == DiskTransferVerificationMode.Transactional)
|
||||
{
|
||||
_logger.Trace("Hardlink move failed, reverting to copy.");
|
||||
if (TryCopyFileTransactional(sourcePath, targetPath, originalSize))
|
||||
|
||||
76
src/NzbDrone.Common/Disk/DriveInfoMount.cs
Normal file
76
src/NzbDrone.Common/Disk/DriveInfoMount.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
{
|
||||
public class DriveInfoMount : IMount
|
||||
{
|
||||
private readonly DriveInfo _driveInfo;
|
||||
|
||||
public DriveInfoMount(DriveInfo driveInfo)
|
||||
{
|
||||
_driveInfo = driveInfo;
|
||||
}
|
||||
|
||||
public long AvailableFreeSpace
|
||||
{
|
||||
get { return _driveInfo.AvailableFreeSpace; }
|
||||
}
|
||||
|
||||
public string DriveFormat
|
||||
{
|
||||
get { return _driveInfo.DriveFormat; }
|
||||
}
|
||||
|
||||
public DriveType DriveType
|
||||
{
|
||||
get { return _driveInfo.DriveType; }
|
||||
}
|
||||
|
||||
public bool IsReady
|
||||
{
|
||||
get { return _driveInfo.IsReady; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _driveInfo.Name; }
|
||||
}
|
||||
|
||||
public string RootDirectory
|
||||
{
|
||||
get { return _driveInfo.RootDirectory.FullName; }
|
||||
}
|
||||
|
||||
public long TotalFreeSpace
|
||||
{
|
||||
get { return _driveInfo.TotalFreeSpace; }
|
||||
}
|
||||
|
||||
public long TotalSize
|
||||
{
|
||||
get { return _driveInfo.TotalSize; }
|
||||
}
|
||||
|
||||
public string VolumeLabel
|
||||
{
|
||||
get { return _driveInfo.VolumeLabel; }
|
||||
}
|
||||
|
||||
public string VolumeName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (VolumeLabel.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
return string.Format("{0} ({1})", Name, VolumeLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,12 +103,12 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
private List<FileSystemModel> GetDrives()
|
||||
{
|
||||
return _diskProvider.GetDrives()
|
||||
return _diskProvider.GetMounts()
|
||||
.Select(d => new FileSystemModel
|
||||
{
|
||||
Type = FileSystemEntityType.Drive,
|
||||
Name = GetVolumeName(d),
|
||||
Path = d.Name,
|
||||
Name = d.VolumeLabel,
|
||||
Path = d.RootDirectory,
|
||||
LastModified = null
|
||||
})
|
||||
.ToList();
|
||||
@@ -157,16 +157,6 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private string GetVolumeName(DriveInfo driveInfo)
|
||||
{
|
||||
if (driveInfo.VolumeLabel.IsNullOrWhiteSpace())
|
||||
{
|
||||
return driveInfo.Name;
|
||||
}
|
||||
|
||||
return string.Format("{0} ({1})", driveInfo.Name, driveInfo.VolumeLabel);
|
||||
}
|
||||
|
||||
private string GetParent(string path)
|
||||
{
|
||||
|
||||
@@ -40,12 +40,13 @@ namespace NzbDrone.Common.Disk
|
||||
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
|
||||
FileAttributes GetFileAttributes(string path);
|
||||
void EmptyFolder(string path);
|
||||
string[] GetFixedDrives();
|
||||
string GetVolumeLabel(string path);
|
||||
FileStream OpenReadStream(string path);
|
||||
FileStream OpenWriteStream(string path);
|
||||
List<DriveInfo> GetDrives();
|
||||
List<IMount> GetMounts();
|
||||
IMount GetMount(string path);
|
||||
List<DirectoryInfo> GetDirectoryInfos(string path);
|
||||
List<FileInfo> GetFileInfos(string path);
|
||||
void RemoveEmptySubfolders(string path);
|
||||
}
|
||||
}
|
||||
|
||||
21
src/NzbDrone.Common/Disk/IMount.cs
Normal file
21
src/NzbDrone.Common/Disk/IMount.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
{
|
||||
public interface IMount
|
||||
{
|
||||
long AvailableFreeSpace { get; }
|
||||
string DriveFormat { get; }
|
||||
DriveType DriveType { get; }
|
||||
bool IsReady { get; }
|
||||
string Name { get; }
|
||||
string RootDirectory { get; }
|
||||
long TotalFreeSpace { get; }
|
||||
long TotalSize { get; }
|
||||
string VolumeLabel { get; }
|
||||
}
|
||||
}
|
||||
@@ -39,11 +39,11 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
try
|
||||
{
|
||||
_diskProvider.SetPermissions(_appFolderInfo.AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.FullControl, AccessControlType.Allow);
|
||||
_diskProvider.SetPermissions(_appFolderInfo.AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.Modify, AccessControlType.Allow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Coudn't set app folder permission", ex);
|
||||
_logger.Warn(ex, "Coudn't set app folder permission");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error checking if the current user is an administrator.", ex);
|
||||
_logger.Warn(ex, "Error checking if the current user is an administrator.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace NzbDrone.Common.Extensions
|
||||
|
||||
public static void Add<TKey, TValue>(this ICollection<KeyValuePair<TKey, TValue>> collection, TKey key, TValue value)
|
||||
{
|
||||
collection.Add(key, value);
|
||||
collection.Add(new KeyValuePair<TKey, TValue>(key, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,14 @@ namespace NzbDrone.Common.Extensions
|
||||
|
||||
public static bool IsParentPath(this string parentPath, string childPath)
|
||||
{
|
||||
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
childPath = childPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
if (parentPath != "/")
|
||||
{
|
||||
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
}
|
||||
if (childPath != "/")
|
||||
{
|
||||
childPath = childPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
var parent = new DirectoryInfo(parentPath);
|
||||
var child = new DirectoryInfo(childPath);
|
||||
|
||||
@@ -100,5 +100,10 @@ namespace NzbDrone.Common.Extensions
|
||||
.Select(x => Convert.ToByte(input.Substring(x, 2), 16))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static string ToHexString(this byte[] input)
|
||||
{
|
||||
return string.Concat(Array.ConvertAll(input, x => x.ToString("X2")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NzbDrone.Common.Http.Dispatchers
|
||||
{
|
||||
@@ -21,6 +22,21 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
|
||||
private static readonly Logger _logger = NzbDroneLogger.GetLogger(typeof(CurlHttpDispatcher));
|
||||
|
||||
private const string _caBundleFileName = "curl-ca-bundle.crt";
|
||||
private static readonly string _caBundleFilePath;
|
||||
|
||||
static CurlHttpDispatcher()
|
||||
{
|
||||
if (Assembly.GetExecutingAssembly().Location.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
_caBundleFilePath = Path.Combine(Assembly.GetExecutingAssembly().Location, "..", _caBundleFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_caBundleFilePath = _caBundleFileName;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckAvailability()
|
||||
{
|
||||
try
|
||||
@@ -29,7 +45,7 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.TraceException("Initializing curl failed", ex);
|
||||
_logger.Trace(ex, "Initializing curl failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -41,11 +57,6 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
throw new ApplicationException("Curl failed to initialize.");
|
||||
}
|
||||
|
||||
if (request.NetworkCredential != null)
|
||||
{
|
||||
throw new NotImplementedException("Credentials not supported for curl dispatcher.");
|
||||
}
|
||||
|
||||
lock (CurlGlobalHandle.Instance)
|
||||
{
|
||||
Stream responseStream = new MemoryStream();
|
||||
@@ -64,8 +75,8 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
headerStream.Write(b, 0, s * n);
|
||||
return s * n;
|
||||
};
|
||||
|
||||
curlEasy.Url = request.Url.AbsoluteUri;
|
||||
|
||||
curlEasy.Url = request.Url.FullUri;
|
||||
switch (request.Method)
|
||||
{
|
||||
case HttpMethod.GET:
|
||||
@@ -86,21 +97,25 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
curlEasy.UserAgent = UserAgentBuilder.UserAgent;
|
||||
curlEasy.FollowLocation = request.AllowAutoRedirect;
|
||||
|
||||
if (request.RequestTimeout != TimeSpan.Zero)
|
||||
{
|
||||
curlEasy.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalSeconds);
|
||||
}
|
||||
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
curlEasy.CaInfo = "curl-ca-bundle.crt";
|
||||
curlEasy.CaInfo = _caBundleFilePath;
|
||||
}
|
||||
|
||||
if (cookies != null)
|
||||
{
|
||||
curlEasy.Cookie = cookies.GetCookieHeader(request.Url);
|
||||
curlEasy.Cookie = cookies.GetCookieHeader((Uri)request.Url);
|
||||
}
|
||||
|
||||
if (!request.Body.IsNullOrWhiteSpace())
|
||||
if (request.ContentData != null)
|
||||
{
|
||||
// TODO: This might not go well with encoding.
|
||||
curlEasy.PostFieldSize = request.Body.Length;
|
||||
curlEasy.SetOpt(CurlOption.CopyPostFields, request.Body);
|
||||
curlEasy.PostFieldSize = request.ContentData.Length;
|
||||
curlEasy.SetOpt(CurlOption.CopyPostFields, new string(Array.ConvertAll(request.ContentData, v => (char)v)));
|
||||
}
|
||||
|
||||
// Yes, we have to keep a ref to the object to prevent corrupting the unmanaged state
|
||||
@@ -112,7 +127,15 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
|
||||
if (result != CurlCode.Ok)
|
||||
{
|
||||
throw new WebException(string.Format("Curl Error {0} for Url {1}", result, curlEasy.Url));
|
||||
switch (result)
|
||||
{
|
||||
case CurlCode.SslCaCert:
|
||||
case (CurlCode)77:
|
||||
throw new WebException(string.Format("Curl Error {0} for Url {1}, issues with your operating system SSL Root Certificate Bundle (ca-bundle).", result, curlEasy.Url));
|
||||
default:
|
||||
throw new WebException(string.Format("Curl Error {0} for Url {1}", result, curlEasy.Url));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +190,7 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
{
|
||||
try
|
||||
{
|
||||
cookies.SetCookies(request.Url, FixSetCookieHeader(setCookie));
|
||||
cookies.SetCookies((Uri)request.Url, FixSetCookieHeader(setCookie));
|
||||
}
|
||||
catch (CookieException ex)
|
||||
{
|
||||
|
||||
@@ -8,34 +8,35 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
{
|
||||
public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
|
||||
{
|
||||
var webRequest = (HttpWebRequest)WebRequest.Create(request.Url);
|
||||
var webRequest = (HttpWebRequest)WebRequest.Create((Uri)request.Url);
|
||||
|
||||
// Deflate is not a standard and could break depending on implementation.
|
||||
// we should just stick with the more compatible Gzip
|
||||
//http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net
|
||||
webRequest.AutomaticDecompression = DecompressionMethods.GZip;
|
||||
|
||||
webRequest.Credentials = request.NetworkCredential;
|
||||
webRequest.Method = request.Method.ToString();
|
||||
webRequest.UserAgent = UserAgentBuilder.UserAgent;
|
||||
webRequest.KeepAlive = false;
|
||||
webRequest.KeepAlive = request.ConnectionKeepAlive;
|
||||
webRequest.AllowAutoRedirect = request.AllowAutoRedirect;
|
||||
webRequest.ContentLength = 0;
|
||||
webRequest.CookieContainer = cookies;
|
||||
|
||||
if (request.RequestTimeout != TimeSpan.Zero)
|
||||
{
|
||||
webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds);
|
||||
}
|
||||
|
||||
if (request.Headers != null)
|
||||
{
|
||||
AddRequestHeaders(webRequest, request.Headers);
|
||||
}
|
||||
|
||||
if (!request.Body.IsNullOrWhiteSpace())
|
||||
if (request.ContentData != null)
|
||||
{
|
||||
var bytes = request.Headers.GetEncodingFromContentType().GetBytes(request.Body.ToCharArray());
|
||||
|
||||
webRequest.ContentLength = bytes.Length;
|
||||
webRequest.ContentLength = request.ContentData.Length;
|
||||
using (var writeStream = webRequest.GetRequestStream())
|
||||
{
|
||||
writeStream.Write(bytes, 0, bytes.Length);
|
||||
writeStream.Write(request.ContentData, 0, request.ContentData.Length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,45 +76,43 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
switch (header.Key)
|
||||
{
|
||||
case "Accept":
|
||||
webRequest.Accept = header.Value.ToString();
|
||||
webRequest.Accept = header.Value;
|
||||
break;
|
||||
case "Connection":
|
||||
webRequest.Connection = header.Value.ToString();
|
||||
webRequest.Connection = header.Value;
|
||||
break;
|
||||
case "Content-Length":
|
||||
webRequest.ContentLength = Convert.ToInt64(header.Value);
|
||||
break;
|
||||
case "Content-Type":
|
||||
webRequest.ContentType = header.Value.ToString();
|
||||
webRequest.ContentType = header.Value;
|
||||
break;
|
||||
case "Date":
|
||||
webRequest.Date = (DateTime)header.Value;
|
||||
webRequest.Date = HttpHeader.ParseDateTime(header.Value);
|
||||
break;
|
||||
case "Expect":
|
||||
webRequest.Expect = header.Value.ToString();
|
||||
webRequest.Expect = header.Value;
|
||||
break;
|
||||
case "Host":
|
||||
webRequest.Host = header.Value.ToString();
|
||||
webRequest.Host = header.Value;
|
||||
break;
|
||||
case "If-Modified-Since":
|
||||
webRequest.IfModifiedSince = (DateTime)header.Value;
|
||||
webRequest.IfModifiedSince = HttpHeader.ParseDateTime(header.Value);
|
||||
break;
|
||||
case "Range":
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case "Referer":
|
||||
webRequest.Referer = header.Value.ToString();
|
||||
webRequest.Referer = header.Value;
|
||||
break;
|
||||
case "Transfer-Encoding":
|
||||
webRequest.TransferEncoding = header.Value.ToString();
|
||||
webRequest.TransferEncoding = header.Value;
|
||||
break;
|
||||
case "User-Agent":
|
||||
throw new NotSupportedException("User-Agent other than Sonarr not allowed.");
|
||||
case "Proxy-Connection":
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
default:
|
||||
webRequest.Headers.Add(header.Key, header.Value.ToString());
|
||||
webRequest.Headers.Add(header.Key, header.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace NzbDrone.Common.Http
|
||||
{
|
||||
public sealed class HttpAccept
|
||||
{
|
||||
public static readonly HttpAccept Rss = new HttpAccept("application/rss+xml, text/rss+xml, text/xml");
|
||||
public static readonly HttpAccept Rss = new HttpAccept("application/rss+xml, text/rss+xml, application/xml, text/xml");
|
||||
public static readonly HttpAccept Json = new HttpAccept("application/json");
|
||||
public static readonly HttpAccept Html = new HttpAccept("text/html");
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http.Dispatchers;
|
||||
using NzbDrone.Common.TPL;
|
||||
|
||||
@@ -28,7 +30,6 @@ namespace NzbDrone.Common.Http
|
||||
private readonly Logger _logger;
|
||||
private readonly IRateLimitService _rateLimitService;
|
||||
private readonly ICached<CookieContainer> _cookieContainerCache;
|
||||
private readonly ICached<bool> _curlTLSFallbackCache;
|
||||
private readonly List<IHttpRequestInterceptor> _requestInterceptors;
|
||||
private readonly IHttpDispatcher _httpDispatcher;
|
||||
|
||||
@@ -73,13 +74,18 @@ namespace NzbDrone.Common.Http
|
||||
|
||||
stopWatch.Stop();
|
||||
|
||||
_logger.Trace("{0} ({1:n0} ms)", response, stopWatch.ElapsedMilliseconds);
|
||||
_logger.Trace("{0} ({1} ms)", response, stopWatch.ElapsedMilliseconds);
|
||||
|
||||
foreach (var interceptor in _requestInterceptors)
|
||||
{
|
||||
response = interceptor.PostResponse(response);
|
||||
}
|
||||
|
||||
if (request.LogResponseContent)
|
||||
{
|
||||
_logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
|
||||
}
|
||||
|
||||
if (!RuntimeInfoBase.IsProduction &&
|
||||
(response.StatusCode == HttpStatusCode.Moved ||
|
||||
response.StatusCode == HttpStatusCode.MovedPermanently ||
|
||||
@@ -124,7 +130,7 @@ namespace NzbDrone.Common.Http
|
||||
}
|
||||
}
|
||||
|
||||
var requestCookies = persistentCookieContainer.GetCookies(request.Url);
|
||||
var requestCookies = persistentCookieContainer.GetCookies((Uri)request.Url);
|
||||
|
||||
var cookieContainer = new CookieContainer();
|
||||
|
||||
@@ -145,7 +151,7 @@ namespace NzbDrone.Common.Http
|
||||
{
|
||||
var persistentCookieContainer = _cookieContainerCache.Get("container", () => new CookieContainer());
|
||||
|
||||
var cookies = cookieContainer.GetCookies(request.Url);
|
||||
var cookies = cookieContainer.GetCookies((Uri)request.Url);
|
||||
|
||||
persistentCookieContainer.Add(cookies);
|
||||
}
|
||||
@@ -177,7 +183,7 @@ namespace NzbDrone.Common.Http
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.WarnException("Failed to get response from: " + url, e);
|
||||
_logger.Warn(e, "Failed to get response from: " + url);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NzbDrone.Common.Http
|
||||
public HttpResponse Response { get; private set; }
|
||||
|
||||
public HttpException(HttpRequest request, HttpResponse response)
|
||||
: base(string.Format("HTTP request failed: [{0}:{1}] [{2}] at [{3}]", (int)response.StatusCode, response.StatusCode, request.Method, request.Url.ToString()))
|
||||
: base(string.Format("HTTP request failed: [{0}:{1}] [{2}] at [{3}]", (int)response.StatusCode, response.StatusCode, request.Method, request.Url))
|
||||
{
|
||||
Request = request;
|
||||
Response = response;
|
||||
|
||||
14
src/NzbDrone.Common/Http/HttpFormData.cs
Normal file
14
src/NzbDrone.Common/Http/HttpFormData.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpFormData
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public byte[] ContentData { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,37 +4,92 @@ using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpHeader : Dictionary<string, object>
|
||||
public class HttpHeader : NameValueCollection, IEnumerable<KeyValuePair<string, string>>, IEnumerable
|
||||
{
|
||||
public HttpHeader(NameValueCollection headers) : base(StringComparer.OrdinalIgnoreCase)
|
||||
public HttpHeader(NameValueCollection headers)
|
||||
: base(headers)
|
||||
{
|
||||
foreach (var key in headers.AllKeys)
|
||||
|
||||
}
|
||||
|
||||
public HttpHeader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
key = key.ToLowerInvariant();
|
||||
return AllKeys.Any(v => v.ToLowerInvariant() == key);
|
||||
}
|
||||
|
||||
public string GetSingleValue(string key)
|
||||
{
|
||||
var values = GetValues(key);
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
this[key] = headers[key];
|
||||
return null;
|
||||
}
|
||||
if (values.Length > 1)
|
||||
{
|
||||
throw new ApplicationException(string.Format("Expected {0} to occur only once.", key));
|
||||
}
|
||||
|
||||
return values[0];
|
||||
}
|
||||
|
||||
protected T? GetSingleValue<T>(string key, Func<string, T> converter) where T : struct
|
||||
{
|
||||
var value = GetSingleValue(key);
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return converter(value);
|
||||
}
|
||||
protected void SetSingleValue(string key, string value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeader() : base(StringComparer.OrdinalIgnoreCase)
|
||||
protected void SetSingleValue<T>(string key, T? value, Func<T, string> converter = null) where T : struct
|
||||
{
|
||||
|
||||
if (!value.HasValue)
|
||||
{
|
||||
Remove(key);
|
||||
}
|
||||
else if (converter != null)
|
||||
{
|
||||
Set(key, converter(value.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
Set(key, value.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public long? ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!ContainsKey("Content-Length"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Convert.ToInt64(this["Content-Length"]);
|
||||
return GetSingleValue("Content-Length", Convert.ToInt64);
|
||||
}
|
||||
set
|
||||
{
|
||||
this["Content-Length"] = value;
|
||||
SetSingleValue("Content-Length", value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,15 +97,11 @@ namespace NzbDrone.Common.Http
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!ContainsKey("Content-Type"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this["Content-Type"].ToString();
|
||||
return GetSingleValue("Content-Type");
|
||||
}
|
||||
set
|
||||
{
|
||||
this["Content-Type"] = value;
|
||||
SetSingleValue("Content-Type", value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,25 +109,36 @@ namespace NzbDrone.Common.Http
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!ContainsKey("Accept"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this["Accept"].ToString();
|
||||
return GetSingleValue("Accept");
|
||||
}
|
||||
set
|
||||
{
|
||||
this["Accept"] = value;
|
||||
SetSingleValue("Accept", value);
|
||||
}
|
||||
}
|
||||
|
||||
public new IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||
{
|
||||
return AllKeys.SelectMany(GetValues, (k, c) => new KeyValuePair<string, string>(k, c)).ToList().GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return base.GetEnumerator();
|
||||
}
|
||||
|
||||
public Encoding GetEncodingFromContentType()
|
||||
{
|
||||
return GetEncodingFromContentType(ContentType ?? string.Empty);
|
||||
}
|
||||
|
||||
public static Encoding GetEncodingFromContentType(string contentType)
|
||||
{
|
||||
Encoding encoding = null;
|
||||
|
||||
if (ContentType.IsNotNullOrWhiteSpace())
|
||||
if (contentType.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var charset = ContentType.ToLowerInvariant()
|
||||
var charset = contentType.ToLowerInvariant()
|
||||
.Split(';', '=', ' ')
|
||||
.SkipWhile(v => v != "charset")
|
||||
.Skip(1).FirstOrDefault();
|
||||
@@ -99,5 +161,18 @@ namespace NzbDrone.Common.Http
|
||||
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public static DateTime ParseDateTime(string value)
|
||||
{
|
||||
return DateTime.ParseExact(value, "R", CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal);
|
||||
}
|
||||
|
||||
public static List<KeyValuePair<string, string>> ParseCookies(string cookies)
|
||||
{
|
||||
return cookies.Split(';')
|
||||
.Select(v => v.Trim().Split('='))
|
||||
.Select(v => new KeyValuePair<string, string>(v[0], v[1]))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ namespace NzbDrone.Common.Http
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.WarnException("Failed to get response from: " + url, e);
|
||||
_logger.Warn(e, "Failed to get response from: " + url);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpRequest
|
||||
{
|
||||
private readonly Dictionary<string, string> _segments;
|
||||
|
||||
public HttpRequest(string url, HttpAccept httpAccept = null)
|
||||
{
|
||||
UriBuilder = new UriBuilder(url);
|
||||
Url = new HttpUri(url);
|
||||
Headers = new HttpHeader();
|
||||
_segments = new Dictionary<string, string>();
|
||||
AllowAutoRedirect = true;
|
||||
Cookies = new Dictionary<string, string>();
|
||||
|
||||
@@ -28,73 +28,54 @@ namespace NzbDrone.Common.Http
|
||||
}
|
||||
}
|
||||
|
||||
public UriBuilder UriBuilder { get; private set; }
|
||||
|
||||
public Uri Url
|
||||
{
|
||||
get
|
||||
{
|
||||
var uri = UriBuilder.Uri.ToString();
|
||||
|
||||
foreach (var segment in _segments)
|
||||
{
|
||||
uri = uri.Replace(segment.Key, segment.Value);
|
||||
}
|
||||
|
||||
return new Uri(uri);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpUri Url { get; set; }
|
||||
public HttpMethod Method { get; set; }
|
||||
public HttpHeader Headers { get; set; }
|
||||
public string Body { get; set; }
|
||||
public NetworkCredential NetworkCredential { get; set; }
|
||||
public byte[] ContentData { get; set; }
|
||||
public string ContentSummary { get; set; }
|
||||
public bool SuppressHttpError { get; set; }
|
||||
public bool AllowAutoRedirect { get; set; }
|
||||
public bool ConnectionKeepAlive { get; set; }
|
||||
public bool LogResponseContent { get; set; }
|
||||
public Dictionary<string, string> Cookies { get; private set; }
|
||||
public bool StoreResponseCookie { get; set; }
|
||||
public TimeSpan RequestTimeout { get; set; }
|
||||
public TimeSpan RateLimit { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Body == null)
|
||||
return ToString();
|
||||
}
|
||||
|
||||
public string ToString(bool includeMethod = true, bool includeSummary = true)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
if (includeMethod)
|
||||
{
|
||||
return string.Format("Req: [{0}] {1}", Method, Url);
|
||||
builder.AppendFormat("Req: [{0}] ", Method);
|
||||
}
|
||||
|
||||
return string.Format("Req: [{0}] {1} {2} {3}", Method, Url, Environment.NewLine, Body);
|
||||
}
|
||||
builder.Append(Url);
|
||||
|
||||
public void AddSegment(string segment, string value)
|
||||
{
|
||||
var key = "{" + segment + "}";
|
||||
|
||||
if (!UriBuilder.Uri.ToString().Contains(key))
|
||||
if (includeSummary && ContentSummary.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
throw new InvalidOperationException("Segment " + key +" is not defined in Uri");
|
||||
builder.Append(": ");
|
||||
builder.Append(ContentSummary);
|
||||
}
|
||||
|
||||
_segments.Add(key, value);
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public void AddQueryParam(string segment, string value)
|
||||
public void SetContent(byte[] data)
|
||||
{
|
||||
UriBuilder.SetQueryParam(segment, value);
|
||||
ContentData = data;
|
||||
}
|
||||
|
||||
public void AddCookie(string key, string value)
|
||||
public void SetContent(string data)
|
||||
{
|
||||
Cookies[key] = value;
|
||||
}
|
||||
|
||||
public void AddCookie(string cookies)
|
||||
{
|
||||
foreach (var pair in cookies.Split(';'))
|
||||
{
|
||||
var split = pair.Split('=');
|
||||
|
||||
Cookies[split[0].Trim()] = split[1].Trim();
|
||||
}
|
||||
var encoding = HttpHeader.GetEncodingFromContentType(Headers.ContentType);
|
||||
ContentData = encoding.GetBytes(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpRequestBuilder
|
||||
{
|
||||
public Uri BaseUri { get; private set; }
|
||||
public bool SupressHttpError { get; set; }
|
||||
public HttpMethod Method { get; set; }
|
||||
public HttpAccept HttpAccept { get; set; }
|
||||
public HttpUri BaseUrl { get; private set; }
|
||||
public string ResourceUrl { get; set; }
|
||||
public List<KeyValuePair<string, string>> QueryParams { get; private set; }
|
||||
public List<KeyValuePair<string, string>> SuffixQueryParams { get; private set; }
|
||||
public Dictionary<string, string> Segments { get; private set; }
|
||||
public HttpHeader Headers { get; private set; }
|
||||
public bool SuppressHttpError { get; set; }
|
||||
public bool AllowAutoRedirect { get; set; }
|
||||
public bool ConnectionKeepAlive { get; set; }
|
||||
public bool LogResponseContent { get; set; }
|
||||
public NetworkCredential NetworkCredential { get; set; }
|
||||
public Dictionary<string, string> Cookies { get; private set; }
|
||||
public List<HttpFormData> FormData { get; private set; }
|
||||
|
||||
public Action<HttpRequest> PostProcess { get; set; }
|
||||
|
||||
public HttpRequestBuilder(string baseUri)
|
||||
public HttpRequestBuilder(string baseUrl)
|
||||
{
|
||||
BaseUri = new Uri(baseUri);
|
||||
BaseUrl = new HttpUri(baseUrl);
|
||||
ResourceUrl = string.Empty;
|
||||
Method = HttpMethod.GET;
|
||||
QueryParams = new List<KeyValuePair<string, string>>();
|
||||
SuffixQueryParams = new List<KeyValuePair<string, string>>();
|
||||
Segments = new Dictionary<string, string>();
|
||||
Headers = new HttpHeader();
|
||||
Cookies = new Dictionary<string, string>();
|
||||
FormData = new List<HttpFormData>();
|
||||
}
|
||||
|
||||
public virtual HttpRequest Build(string path)
|
||||
public HttpRequestBuilder(bool useHttps, string host, int port, string urlBase = null)
|
||||
: this(BuildBaseUrl(useHttps, host, port, urlBase))
|
||||
{
|
||||
if (BaseUri.ToString().EndsWith("/"))
|
||||
|
||||
}
|
||||
|
||||
public static string BuildBaseUrl(bool useHttps, string host, int port, string urlBase = null)
|
||||
{
|
||||
var protocol = useHttps ? "https" : "http";
|
||||
|
||||
if (urlBase.IsNotNullOrWhiteSpace() && !urlBase.StartsWith("/"))
|
||||
{
|
||||
path = path.TrimStart('/');
|
||||
urlBase = "/" + urlBase;
|
||||
}
|
||||
|
||||
var request = new HttpRequest(BaseUri + path)
|
||||
return string.Format("{0}://{1}:{2}{3}", protocol, host, port, urlBase);
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder Clone()
|
||||
{
|
||||
var clone = MemberwiseClone() as HttpRequestBuilder;
|
||||
clone.QueryParams = new List<KeyValuePair<string, string>>(clone.QueryParams);
|
||||
clone.SuffixQueryParams = new List<KeyValuePair<string, string>>(clone.SuffixQueryParams);
|
||||
clone.Segments = new Dictionary<string, string>(clone.Segments);
|
||||
clone.Headers = new HttpHeader(clone.Headers);
|
||||
clone.Cookies = new Dictionary<string, string>(clone.Cookies);
|
||||
clone.FormData = new List<HttpFormData>(clone.FormData);
|
||||
return clone;
|
||||
}
|
||||
|
||||
protected virtual HttpUri CreateUri()
|
||||
{
|
||||
var url = BaseUrl.CombinePath(ResourceUrl).AddQueryParams(QueryParams.Concat(SuffixQueryParams));
|
||||
|
||||
if (Segments.Any())
|
||||
{
|
||||
SuppressHttpError = SupressHttpError,
|
||||
NetworkCredential = NetworkCredential
|
||||
};
|
||||
var fullUri = url.FullUri;
|
||||
|
||||
foreach (var segment in Segments)
|
||||
{
|
||||
fullUri = fullUri.Replace(segment.Key, segment.Value);
|
||||
}
|
||||
|
||||
url = new HttpUri(fullUri);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
protected virtual HttpRequest CreateRequest()
|
||||
{
|
||||
return new HttpRequest(CreateUri().FullUri, HttpAccept);
|
||||
}
|
||||
|
||||
protected virtual void Apply(HttpRequest request)
|
||||
{
|
||||
request.Method = Method;
|
||||
request.SuppressHttpError = SuppressHttpError;
|
||||
request.AllowAutoRedirect = AllowAutoRedirect;
|
||||
request.ConnectionKeepAlive = ConnectionKeepAlive;
|
||||
request.LogResponseContent = LogResponseContent;
|
||||
|
||||
if (NetworkCredential != null)
|
||||
{
|
||||
var authInfo = NetworkCredential.UserName + ":" + NetworkCredential.Password;
|
||||
authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(authInfo));
|
||||
request.Headers.Set("Authorization", "Basic " + authInfo);
|
||||
}
|
||||
|
||||
foreach (var header in Headers)
|
||||
{
|
||||
request.Headers.Set(header.Key, header.Value);
|
||||
}
|
||||
|
||||
foreach (var cookie in Cookies)
|
||||
{
|
||||
request.Cookies[cookie.Key] = cookie.Value;
|
||||
}
|
||||
|
||||
ApplyFormData(request);
|
||||
}
|
||||
|
||||
public virtual HttpRequest Build()
|
||||
{
|
||||
var request = CreateRequest();
|
||||
|
||||
Apply(request);
|
||||
|
||||
if (PostProcess != null)
|
||||
{
|
||||
@@ -36,5 +136,237 @@ namespace NzbDrone.Common.Http
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
public IHttpRequestBuilderFactory CreateFactory()
|
||||
{
|
||||
return new HttpRequestBuilderFactory(this);
|
||||
}
|
||||
|
||||
protected virtual void ApplyFormData(HttpRequest request)
|
||||
{
|
||||
if (FormData.Empty()) return;
|
||||
|
||||
if (request.ContentData != null)
|
||||
{
|
||||
throw new ApplicationException("Cannot send HttpRequest Body and FormData simultaneously.");
|
||||
}
|
||||
|
||||
var shouldSendAsMultipart = FormData.Any(v => v.ContentType != null || v.FileName != null || v.ContentData.Length > 1024);
|
||||
|
||||
if (shouldSendAsMultipart)
|
||||
{
|
||||
var boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x14");
|
||||
var partBoundary = string.Format("--{0}\r\n", boundary);
|
||||
var endBoundary = string.Format("--{0}--\r\n", boundary);
|
||||
|
||||
var bodyStream = new MemoryStream();
|
||||
var summary = new StringBuilder();
|
||||
|
||||
using (var writer = new StreamWriter(bodyStream, new UTF8Encoding(false)))
|
||||
{
|
||||
foreach (var formData in FormData)
|
||||
{
|
||||
writer.Write(partBoundary);
|
||||
|
||||
writer.Write("Content-Disposition: form-data");
|
||||
if (formData.Name.IsNotNullOrWhiteSpace()) writer.Write("; name=\"{0}\"", formData.Name);
|
||||
if (formData.FileName.IsNotNullOrWhiteSpace()) writer.Write("; filename=\"{0}\"", formData.FileName);
|
||||
writer.Write("\r\n");
|
||||
|
||||
if (formData.ContentType.IsNotNullOrWhiteSpace()) writer.Write("Content-Type: {0}\r\n", formData.ContentType);
|
||||
|
||||
writer.Write("\r\n");
|
||||
writer.Flush();
|
||||
|
||||
bodyStream.Write(formData.ContentData, 0, formData.ContentData.Length);
|
||||
writer.Write("\r\n");
|
||||
|
||||
if (formData.FileName.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
summary.AppendFormat("\r\n{0}={1} ({2} bytes)", formData.Name, formData.FileName, formData.ContentData.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
summary.AppendFormat("\r\n{0}={1}", formData.Name, Encoding.UTF8.GetString(formData.ContentData));
|
||||
}
|
||||
}
|
||||
|
||||
writer.Write(endBoundary);
|
||||
}
|
||||
|
||||
var body = bodyStream.ToArray();
|
||||
|
||||
// TODO: Scan through body to see if we have a boundary collision?
|
||||
|
||||
request.Headers.ContentType = "multipart/form-data; boundary=" + boundary;
|
||||
request.SetContent(body);
|
||||
|
||||
if (request.ContentSummary == null)
|
||||
{
|
||||
request.ContentSummary = summary.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var parameters = FormData.Select(v => string.Format("{0}={1}", v.Name, Uri.EscapeDataString(Encoding.UTF8.GetString(v.ContentData))));
|
||||
var urlencoded = string.Join("&", parameters);
|
||||
var body = Encoding.UTF8.GetBytes(urlencoded);
|
||||
|
||||
request.Headers.ContentType = "application/x-www-form-urlencoded";
|
||||
request.SetContent(body);
|
||||
|
||||
if (request.ContentSummary == null)
|
||||
{
|
||||
request.ContentSummary = urlencoded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder Resource(string resourceUrl)
|
||||
{
|
||||
if (!ResourceUrl.IsNotNullOrWhiteSpace() || resourceUrl.StartsWith("/"))
|
||||
{
|
||||
ResourceUrl = resourceUrl.TrimStart('/');
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceUrl = string.Format("{0}/{1}", ResourceUrl.TrimEnd('/'), resourceUrl);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder KeepAlive(bool keepAlive = true)
|
||||
{
|
||||
ConnectionKeepAlive = keepAlive;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder Post()
|
||||
{
|
||||
Method = HttpMethod.POST;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder Accept(HttpAccept accept)
|
||||
{
|
||||
HttpAccept = accept;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder SetHeader(string name, string value)
|
||||
{
|
||||
Headers.Set(name, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder AddPrefixQueryParam(string key, object value, bool replace = false)
|
||||
{
|
||||
if (replace)
|
||||
{
|
||||
QueryParams.RemoveAll(v => v.Key == key);
|
||||
SuffixQueryParams.RemoveAll(v => v.Key == key);
|
||||
}
|
||||
|
||||
QueryParams.Insert(0, new KeyValuePair<string, string>(key, value.ToString()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder AddQueryParam(string key, object value, bool replace = false)
|
||||
{
|
||||
if (replace)
|
||||
{
|
||||
QueryParams.RemoveAll(v => v.Key == key);
|
||||
SuffixQueryParams.RemoveAll(v => v.Key == key);
|
||||
}
|
||||
|
||||
QueryParams.Add(key, value.ToString());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder AddSuffixQueryParam(string key, object value, bool replace = false)
|
||||
{
|
||||
if (replace)
|
||||
{
|
||||
QueryParams.RemoveAll(v => v.Key == key);
|
||||
SuffixQueryParams.RemoveAll(v => v.Key == key);
|
||||
}
|
||||
|
||||
SuffixQueryParams.Add(new KeyValuePair<string, string>(key, value.ToString()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder SetSegment(string segment, string value, bool dontCheck = false)
|
||||
{
|
||||
var key = string.Concat("{", segment, "}");
|
||||
|
||||
if (!dontCheck && !CreateUri().ToString().Contains(key))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format("Segment {0} is not defined in Uri", segment));
|
||||
}
|
||||
|
||||
Segments[key] = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder SetCookies(IEnumerable<KeyValuePair<string, string>> cookies)
|
||||
{
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
Cookies[cookie.Key] = cookie.Value;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder SetCookie(string key, string value)
|
||||
{
|
||||
Cookies[key] = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder AddFormParameter(string key, object value)
|
||||
{
|
||||
if (Method != HttpMethod.POST)
|
||||
{
|
||||
throw new NotSupportedException("HttpRequest Method must be POST to add FormParameter.");
|
||||
}
|
||||
|
||||
FormData.Add(new HttpFormData
|
||||
{
|
||||
Name = key,
|
||||
ContentData = Encoding.UTF8.GetBytes(value.ToString())
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual HttpRequestBuilder AddFormUpload(string name, string fileName, byte[] data, string contentType = "application/octet-stream")
|
||||
{
|
||||
if (Method != HttpMethod.POST)
|
||||
{
|
||||
throw new NotSupportedException("HttpRequest Method must be POST to add FormUpload.");
|
||||
}
|
||||
|
||||
FormData.Add(new HttpFormData
|
||||
{
|
||||
Name = name,
|
||||
FileName = fileName,
|
||||
ContentData = data,
|
||||
ContentType = contentType
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
src/NzbDrone.Common/Http/HttpRequestBuilderFactory.cs
Normal file
36
src/NzbDrone.Common/Http/HttpRequestBuilderFactory.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public interface IHttpRequestBuilderFactory
|
||||
{
|
||||
HttpRequestBuilder Create();
|
||||
}
|
||||
|
||||
public class HttpRequestBuilderFactory : IHttpRequestBuilderFactory
|
||||
{
|
||||
private HttpRequestBuilder _rootBuilder;
|
||||
|
||||
public HttpRequestBuilderFactory(HttpRequestBuilder rootBuilder)
|
||||
{
|
||||
SetRootBuilder(rootBuilder);
|
||||
}
|
||||
|
||||
protected HttpRequestBuilderFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void SetRootBuilder(HttpRequestBuilder rootBuilder)
|
||||
{
|
||||
_rootBuilder = rootBuilder.Clone();
|
||||
}
|
||||
|
||||
public HttpRequestBuilder Create()
|
||||
{
|
||||
return _rootBuilder.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Serializer;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpResponse
|
||||
{
|
||||
private static readonly Regex RegexSetCookie = new Regex("^(.*?)=(.*?)(?:;|$)", RegexOptions.Compiled);
|
||||
|
||||
public HttpResponse(HttpRequest request, HttpHeader headers, byte[] binaryData, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
Request = request;
|
||||
@@ -52,11 +57,31 @@ namespace NzbDrone.Common.Http
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetCookies()
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
|
||||
var setCookieHeaders = Headers.GetValues("Set-Cookie");
|
||||
if (setCookieHeaders != null)
|
||||
{
|
||||
foreach (var cookie in setCookieHeaders)
|
||||
{
|
||||
var match = RegexSetCookie.Match(cookie);
|
||||
if (match.Success)
|
||||
{
|
||||
result[match.Groups[1].Value] = match.Groups[2].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var result = string.Format("Res: [{0}] {1} : {2}.{3}", Request.Method, Request.Url, (int)StatusCode, StatusCode);
|
||||
var result = string.Format("Res: [{0}] {1}: {2}.{3}", Request.Method, Request.Url, (int)StatusCode, StatusCode);
|
||||
|
||||
if (HasHttpError && !Headers.ContentType.Equals("text/html", StringComparison.InvariantCultureIgnoreCase))
|
||||
if (HasHttpError && Headers.ContentType.IsNotNullOrWhiteSpace() && !Headers.ContentType.Equals("text/html", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
result += Environment.NewLine + Content;
|
||||
}
|
||||
|
||||
272
src/NzbDrone.Common/Http/HttpUri.cs
Normal file
272
src/NzbDrone.Common/Http/HttpUri.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class HttpUri : IEquatable<HttpUri>
|
||||
{
|
||||
private static readonly Regex RegexUri = new Regex(@"^(?:(?<scheme>[a-z]+):)?(?://(?<host>[-A-Z0-9.]+)(?::(?<port>[0-9]{1,5}))?)?(?<path>(?:(?:(?<=^)|/)[^/?#\r\n]+)+/?|/)?(?:\?(?<query>[^#\r\n]*))?(?:\#(?<fragment>.*))?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private readonly string _uri;
|
||||
public string FullUri { get { return _uri; } }
|
||||
|
||||
public HttpUri(string uri)
|
||||
{
|
||||
_uri = uri ?? string.Empty;
|
||||
|
||||
Parse();
|
||||
}
|
||||
|
||||
public HttpUri(string scheme, string host, int? port, string path, string query, string fragment)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (scheme.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.Append(scheme);
|
||||
builder.Append(":");
|
||||
}
|
||||
|
||||
if (host.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.Append("//");
|
||||
builder.Append(host);
|
||||
if (port.HasValue)
|
||||
{
|
||||
builder.Append(":");
|
||||
builder.Append(port);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
if (host.IsNotNullOrWhiteSpace() || path.StartsWith("/"))
|
||||
{
|
||||
builder.Append('/');
|
||||
}
|
||||
builder.Append(path.TrimStart('/'));
|
||||
}
|
||||
|
||||
if (query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.Append('?');
|
||||
builder.Append(query);
|
||||
}
|
||||
|
||||
if (fragment.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
builder.Append('#');
|
||||
builder.Append(fragment);
|
||||
}
|
||||
|
||||
_uri = builder.ToString();
|
||||
|
||||
Parse();
|
||||
}
|
||||
|
||||
private void Parse()
|
||||
{
|
||||
var match = RegexUri.Match(_uri);
|
||||
|
||||
var scheme = match.Groups["scheme"];
|
||||
var host = match.Groups["host"];
|
||||
var port = match.Groups["port"];
|
||||
var path = match.Groups["path"];
|
||||
var query = match.Groups["query"];
|
||||
var fragment = match.Groups["fragment"];
|
||||
|
||||
if (!match.Success || scheme.Success && !host.Success && path.Success)
|
||||
{
|
||||
throw new ArgumentException("Uri didn't match expected pattern: " + _uri);
|
||||
}
|
||||
|
||||
Scheme = scheme.Value;
|
||||
Host = host.Value;
|
||||
Port = port.Success ? (int?)int.Parse(port.Value) : null;
|
||||
Path = path.Value;
|
||||
Query = query.Value;
|
||||
Fragment = fragment.Value;
|
||||
}
|
||||
|
||||
public string Scheme { get; private set; }
|
||||
public string Host { get; private set; }
|
||||
public int? Port { get; private set; }
|
||||
public string Path { get; private set; }
|
||||
public string Query { get; private set; }
|
||||
public string Fragment { get; private set; }
|
||||
|
||||
private IList<KeyValuePair<string, string>> _queryParams;
|
||||
private IList<KeyValuePair<string, string>> QueryParams
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_queryParams == null)
|
||||
{
|
||||
var dict = new List<KeyValuePair<string, string>>();
|
||||
|
||||
if (Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
foreach (var pair in Query.Split('&'))
|
||||
{
|
||||
var split = pair.Split(new[] { '=' }, 2);
|
||||
|
||||
if (split.Length == 1)
|
||||
{
|
||||
dict.Add(new KeyValuePair<string, string>(Uri.UnescapeDataString(split[0]), null));
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.Add(new KeyValuePair<string, string>(Uri.UnescapeDataString(split[0]), Uri.UnescapeDataString(split[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_queryParams = dict.AsReadOnly();
|
||||
}
|
||||
return _queryParams;
|
||||
}
|
||||
}
|
||||
|
||||
public HttpUri CombinePath(string path)
|
||||
{
|
||||
return new HttpUri(Scheme, Host, Port, CombinePath(Path, path), Query, Fragment);
|
||||
}
|
||||
|
||||
private static string CombinePath(string basePath, string relativePath)
|
||||
{
|
||||
if (relativePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
|
||||
if (basePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
return basePath.TrimEnd('/') + "/" + relativePath.TrimStart('/');
|
||||
}
|
||||
|
||||
private static string CombineRelativePath(string basePath, string relativePath)
|
||||
{
|
||||
if (relativePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
|
||||
if (relativePath.StartsWith("/"))
|
||||
{
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
var baseSlashIndex = basePath.LastIndexOf('/');
|
||||
|
||||
if (baseSlashIndex >= 0)
|
||||
{
|
||||
return basePath.Substring(0, baseSlashIndex) + "/" + relativePath;
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
public HttpUri SetQuery(string query)
|
||||
{
|
||||
return new HttpUri(Scheme, Host, Port, Path, query, Fragment);
|
||||
}
|
||||
|
||||
public HttpUri AddQueryParam(string key, object value)
|
||||
{
|
||||
var newQuery = string.Concat(Uri.EscapeDataString(key), "=", Uri.EscapeDataString(value.ToString()));
|
||||
|
||||
if (Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
newQuery = string.Concat(Query, "&", newQuery);
|
||||
}
|
||||
|
||||
return SetQuery(newQuery);
|
||||
}
|
||||
|
||||
public HttpUri AddQueryParams(IEnumerable<KeyValuePair<string, string>> queryParams)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.Append(Query);
|
||||
|
||||
foreach (var pair in queryParams)
|
||||
{
|
||||
if (builder.Length != 0)
|
||||
{
|
||||
builder.Append("&");
|
||||
}
|
||||
builder.Append(Uri.EscapeDataString(pair.Key));
|
||||
builder.Append("=");
|
||||
builder.Append(Uri.EscapeDataString(pair.Value));
|
||||
}
|
||||
|
||||
return SetQuery(builder.ToString());
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _uri.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _uri;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is string)
|
||||
{
|
||||
return _uri.Equals((string)obj);
|
||||
}
|
||||
else if (obj is Uri)
|
||||
{
|
||||
return _uri.Equals(((Uri)obj).OriginalString);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Equals(obj as HttpUri);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(HttpUri other)
|
||||
{
|
||||
if (object.ReferenceEquals(other, null)) return false;
|
||||
|
||||
return _uri.Equals(other._uri);
|
||||
}
|
||||
|
||||
public static explicit operator Uri(HttpUri url)
|
||||
{
|
||||
return new Uri(url.FullUri);
|
||||
}
|
||||
|
||||
public static HttpUri operator +(HttpUri baseUrl, HttpUri relativeUrl)
|
||||
{
|
||||
if (relativeUrl.Scheme.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return relativeUrl;
|
||||
}
|
||||
|
||||
if (relativeUrl.Host.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return new HttpUri(baseUrl.Scheme, relativeUrl.Host, relativeUrl.Port, relativeUrl.Path, relativeUrl.Query, relativeUrl.Fragment);
|
||||
}
|
||||
|
||||
if (relativeUrl.Path.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return new HttpUri(baseUrl.Scheme, baseUrl.Host, baseUrl.Port, CombineRelativePath(baseUrl.Path, relativeUrl.Path), relativeUrl.Query, relativeUrl.Fragment);
|
||||
}
|
||||
|
||||
return new HttpUri(baseUrl.Scheme, baseUrl.Host, baseUrl.Port, baseUrl.Path, relativeUrl.Query, relativeUrl.Fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Serializer;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public class JsonRpcRequestBuilder : HttpRequestBuilder
|
||||
{
|
||||
public string Method { get; private set; }
|
||||
public List<object> Parameters { get; private set; }
|
||||
public static HttpAccept JsonRpcHttpAccept = new HttpAccept("application/json-rpc, application/json");
|
||||
public static string JsonRpcContentType = "application/json-rpc";
|
||||
|
||||
public JsonRpcRequestBuilder(string baseUri, string method, IEnumerable<object> parameters)
|
||||
: base (baseUri)
|
||||
public string JsonMethod { get; private set; }
|
||||
public List<object> JsonParameters { get; private set; }
|
||||
|
||||
public JsonRpcRequestBuilder(string baseUrl)
|
||||
: base(baseUrl)
|
||||
{
|
||||
Method = method;
|
||||
Parameters = parameters.ToList();
|
||||
Method = HttpMethod.POST;
|
||||
JsonParameters = new List<object>();
|
||||
}
|
||||
|
||||
public override HttpRequest Build(string path)
|
||||
public JsonRpcRequestBuilder(string baseUrl, string method, IEnumerable<object> parameters)
|
||||
: base (baseUrl)
|
||||
{
|
||||
var request = base.Build(path);
|
||||
request.Method = HttpMethod.POST;
|
||||
request.Headers.Accept = "application/json-rpc, application/json";
|
||||
request.Headers.ContentType = "application/json-rpc";
|
||||
Method = HttpMethod.POST;
|
||||
JsonMethod = method;
|
||||
JsonParameters = parameters.ToList();
|
||||
}
|
||||
|
||||
public override HttpRequestBuilder Clone()
|
||||
{
|
||||
var clone = base.Clone() as JsonRpcRequestBuilder;
|
||||
clone.JsonParameters = new List<object>(JsonParameters);
|
||||
return clone;
|
||||
}
|
||||
|
||||
public JsonRpcRequestBuilder Call(string method, params object[] parameters)
|
||||
{
|
||||
var clone = Clone() as JsonRpcRequestBuilder;
|
||||
clone.JsonMethod = method;
|
||||
clone.JsonParameters = parameters.ToList();
|
||||
return clone;
|
||||
}
|
||||
|
||||
protected override void Apply(HttpRequest request)
|
||||
{
|
||||
base.Apply(request);
|
||||
|
||||
request.Headers.ContentType = JsonRpcContentType;
|
||||
|
||||
var parameterData = new object[JsonParameters.Count];
|
||||
var parameterSummary = new string[JsonParameters.Count];
|
||||
|
||||
for (var i = 0; i < JsonParameters.Count; i++)
|
||||
{
|
||||
ConvertParameter(JsonParameters[i], out parameterData[i], out parameterSummary[i]);
|
||||
}
|
||||
|
||||
var message = new Dictionary<string, object>();
|
||||
message["jsonrpc"] = "2.0";
|
||||
message["method"] = Method;
|
||||
message["params"] = Parameters;
|
||||
message["method"] = JsonMethod;
|
||||
message["params"] = parameterData;
|
||||
message["id"] = CreateNextId();
|
||||
|
||||
request.Body = message.ToJson();
|
||||
request.SetContent(message.ToJson());
|
||||
|
||||
return request;
|
||||
if (request.ContentSummary == null)
|
||||
{
|
||||
request.ContentSummary = string.Format("{0}({1})", JsonMethod, string.Join(", ", parameterSummary));
|
||||
}
|
||||
}
|
||||
|
||||
private void ConvertParameter(object value, out object data, out string summary)
|
||||
{
|
||||
if (value is byte[])
|
||||
{
|
||||
data = Convert.ToBase64String(value as byte[]);
|
||||
summary = string.Format("[blob {0} bytes]", (value as byte[]).Length);
|
||||
}
|
||||
else if (value is Array && ((Array)value).Length > 0)
|
||||
{
|
||||
data = value;
|
||||
summary = "[...]";
|
||||
}
|
||||
else
|
||||
{
|
||||
data = value;
|
||||
summary = JsonConvert.SerializeObject(data);
|
||||
}
|
||||
}
|
||||
|
||||
public string CreateNextId()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
@@ -6,6 +7,6 @@ namespace NzbDrone.Common.Http
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public T Result { get; set; }
|
||||
public object Error { get; set; }
|
||||
public JToken Error { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public static class UriExtensions
|
||||
{
|
||||
public static void SetQueryParam(this UriBuilder uriBuilder, string key, object value)
|
||||
{
|
||||
var query = uriBuilder.Query;
|
||||
|
||||
if (query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
query += "&";
|
||||
}
|
||||
|
||||
uriBuilder.Query = query.Trim('?') + key + "=" + Uri.EscapeDataString(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace NzbDrone.Common.Instrumentation
|
||||
var value = m.Value;
|
||||
foreach (var capture in m.Groups["secret"].Captures.OfType<Capture>().Reverse())
|
||||
{
|
||||
value = value.Replace(capture.Index - m.Index, capture.Length, "<removed>");
|
||||
value = value.Replace(capture.Index - m.Index, capture.Length, "(removed)");
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace NzbDrone.Common.Instrumentation
|
||||
var exception = e.Exception;
|
||||
|
||||
Console.WriteLine("Task Error: {0}", exception);
|
||||
Logger.Error("Task Error: " + exception.Message, exception);
|
||||
Logger.Error(exception, "Task Error: " + exception.Message);
|
||||
}
|
||||
|
||||
private static void HandleAppDomainException(object sender, UnhandledExceptionEventArgs e)
|
||||
@@ -40,13 +40,13 @@ namespace NzbDrone.Common.Instrumentation
|
||||
if (exception is TypeInitializationException && exception.InnerException is DllNotFoundException ||
|
||||
exception is DllNotFoundException)
|
||||
{
|
||||
Logger.DebugException("Minor Fail: " + exception.Message, exception);
|
||||
Logger.Debug(exception, "Minor Fail: " + exception.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("EPIC FAIL: {0}", exception);
|
||||
Logger.FatalException("EPIC FAIL: " + exception.Message, exception);
|
||||
Logger.Fatal(exception, "EPIC FAIL: " + exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
DebuggerTarget target = new DebuggerTarget();
|
||||
target.Name = "debuggerLogger";
|
||||
target.Layout = "[${level}] [${threadid}] ${logger}: ${message} ${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}";
|
||||
target.Layout = "[${level}] [${threadid}] ${logger}: ${message} ${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}}";
|
||||
|
||||
var loggingRule = new LoggingRule("*", LogLevel.Trace, target);
|
||||
LogManager.Configuration.AddTarget("debugger", target);
|
||||
@@ -91,7 +91,7 @@ namespace NzbDrone.Common.Instrumentation
|
||||
var coloredConsoleTarget = new ColoredConsoleTarget();
|
||||
|
||||
coloredConsoleTarget.Name = "consoleLogger";
|
||||
coloredConsoleTarget.Layout = "[${level}] ${logger}: ${message} ${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}";
|
||||
coloredConsoleTarget.Layout = "[${level}] ${logger}: ${message} ${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}}";
|
||||
|
||||
var loggingRule = new LoggingRule("*", level, coloredConsoleTarget);
|
||||
|
||||
@@ -99,29 +99,38 @@ namespace NzbDrone.Common.Instrumentation
|
||||
LogManager.Configuration.LoggingRules.Add(loggingRule);
|
||||
}
|
||||
|
||||
const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}";
|
||||
const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}}";
|
||||
|
||||
private static void RegisterAppFile(IAppFolderInfo appFolderInfo)
|
||||
{
|
||||
RegisterAppFile(appFolderInfo, "appFileInfo", "sonarr.txt", 5);
|
||||
RegisterAppFile(appFolderInfo, "appFileDebug", "sonarr.debug.txt", 50);
|
||||
RegisterAppFile(appFolderInfo, "appFileTrace", "sonarr.trace.txt", 50);
|
||||
}
|
||||
|
||||
private static LoggingRule RegisterAppFile(IAppFolderInfo appFolderInfo, string name, string fileName, int maxArchiveFiles)
|
||||
{
|
||||
var fileTarget = new NzbDroneFileTarget();
|
||||
|
||||
fileTarget.Name = "rollingFileLogger";
|
||||
fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), "nzbdrone.txt");
|
||||
fileTarget.Name = name;
|
||||
fileTarget.FileName = Path.Combine(appFolderInfo.GetLogFolder(), fileName);
|
||||
fileTarget.AutoFlush = true;
|
||||
fileTarget.KeepFileOpen = false;
|
||||
fileTarget.ConcurrentWrites = false;
|
||||
fileTarget.ConcurrentWriteAttemptDelay = 50;
|
||||
fileTarget.ConcurrentWriteAttempts = 10;
|
||||
fileTarget.ArchiveAboveSize = 1024000;
|
||||
fileTarget.MaxArchiveFiles = 5;
|
||||
fileTarget.MaxArchiveFiles = maxArchiveFiles;
|
||||
fileTarget.EnableFileDelete = true;
|
||||
fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling;
|
||||
fileTarget.Layout = FILE_LOG_LAYOUT;
|
||||
|
||||
var loggingRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
|
||||
|
||||
LogManager.Configuration.AddTarget("appfile", fileTarget);
|
||||
LogManager.Configuration.AddTarget(name, fileTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(loggingRule);
|
||||
|
||||
return loggingRule;
|
||||
}
|
||||
|
||||
private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo)
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
@@ -53,9 +57,6 @@
|
||||
<Reference Include="ICSharpCode.SharpZipLib">
|
||||
<HintPath>..\packages\ICSharpCode.SharpZipLib.Patched.0.86.5\lib\net20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
@@ -63,8 +64,10 @@
|
||||
<Compile Include="ArchiveService.cs" />
|
||||
<Compile Include="Cache\Cached.cs" />
|
||||
<Compile Include="Cache\CacheManager.cs" />
|
||||
<Compile Include="Cache\CachedDictionary.cs" />
|
||||
<Compile Include="Cache\ICached.cs" />
|
||||
<Compile Include="Cloud\CloudClient.cs" />
|
||||
<Compile Include="Cache\ICachedDictionary.cs" />
|
||||
<Compile Include="Cloud\SonarrCloudRequestBuilder.cs" />
|
||||
<Compile Include="Composition\Container.cs" />
|
||||
<Compile Include="Composition\ContainerBuilderBase.cs" />
|
||||
<Compile Include="Composition\IContainer.cs" />
|
||||
@@ -72,6 +75,8 @@
|
||||
<Compile Include="ConvertBase32.cs" />
|
||||
<Compile Include="Crypto\HashProvider.cs" />
|
||||
<Compile Include="Disk\FileSystemLookupService.cs" />
|
||||
<Compile Include="Disk\DriveInfoMount.cs" />
|
||||
<Compile Include="Disk\IMount.cs" />
|
||||
<Compile Include="Disk\RelativeFileSystemModel.cs" />
|
||||
<Compile Include="Disk\FileSystemModel.cs" />
|
||||
<Compile Include="Disk\FileSystemResult.cs" />
|
||||
@@ -151,11 +156,13 @@
|
||||
<Compile Include="Http\HttpAccept.cs" />
|
||||
<Compile Include="Http\HttpClient.cs" />
|
||||
<Compile Include="Http\HttpException.cs" />
|
||||
<Compile Include="Http\HttpFormData.cs" />
|
||||
<Compile Include="Http\HttpHeader.cs" />
|
||||
<Compile Include="Http\HttpMethod.cs" />
|
||||
<Compile Include="Http\HttpProvider.cs" />
|
||||
<Compile Include="Http\HttpRequest.cs" />
|
||||
<Compile Include="Http\HttpResponse.cs" />
|
||||
<Compile Include="Http\HttpUri.cs" />
|
||||
<Compile Include="Http\IHttpRequestInterceptor.cs" />
|
||||
<Compile Include="Http\JsonRpcRequestBuilder.cs" />
|
||||
<Compile Include="Http\JsonRpcResponse.cs" />
|
||||
@@ -163,8 +170,8 @@
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Http\HttpRequestBuilder.cs" />
|
||||
<Compile Include="Http\HttpRequestBuilderFactory.cs" />
|
||||
<Compile Include="Http\TooManyRequestsException.cs" />
|
||||
<Compile Include="Http\UriExtensions.cs" />
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Http\UserAgentBuilder.cs" />
|
||||
<Compile Include="Instrumentation\CleanseLogMessage.cs" />
|
||||
@@ -190,6 +197,7 @@
|
||||
<Compile Include="Reflection\ReflectionExtensions.cs" />
|
||||
<Compile Include="Extensions\ResourceExtensions.cs" />
|
||||
<Compile Include="Security\X509CertificateValidationPolicy.cs" />
|
||||
<Compile Include="Serializer\HttpUriConverter.cs" />
|
||||
<Compile Include="Serializer\IntConverter.cs" />
|
||||
<Compile Include="Serializer\Json.cs" />
|
||||
<Compile Include="ServiceFactory.cs" />
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace NzbDrone.Common.Processes
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error("Unable to write PID file: " + filename, ex);
|
||||
_logger.Error(ex, "Unable to write PID file: " + filename);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ namespace NzbDrone.Common.Processes
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
_logger.WarnException("Couldn't get process info for " + process.ProcessName, e);
|
||||
_logger.Warn(e, "Couldn't get process info for " + process.ProcessName);
|
||||
}
|
||||
|
||||
return processInfo;
|
||||
|
||||
31
src/NzbDrone.Common/Serializer/HttpUriConverter.cs
Normal file
31
src/NzbDrone.Common/Serializer/HttpUriConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Common.Serializer
|
||||
{
|
||||
public class HttpUriConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNull();
|
||||
}
|
||||
else if (value is HttpUri)
|
||||
{
|
||||
writer.WriteValue((value as HttpUri).FullUri);
|
||||
}
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
return new HttpUri(reader.ReadAsString());
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(HttpUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ namespace NzbDrone.Common.Serializer
|
||||
SerializerSetting.Converters.Add(new StringEnumConverter { CamelCaseText = true });
|
||||
//SerializerSetting.Converters.Add(new IntConverter());
|
||||
SerializerSetting.Converters.Add(new VersionConverter());
|
||||
SerializerSetting.Converters.Add(new HttpUriConverter());
|
||||
|
||||
Serializer = JsonSerializer.Create(SerializerSetting);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace NzbDrone.Common.TPL
|
||||
var aggregateException = t.Exception.Flatten();
|
||||
foreach (var exception in aggregateException.InnerExceptions)
|
||||
{
|
||||
Logger.ErrorException("Task Error", exception);
|
||||
Logger.Error(exception, "Task Error");
|
||||
}
|
||||
}
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net40" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="ICSharpCode.SharpZipLib.Patched" version="0.86.5" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -32,7 +32,7 @@ namespace NzbDrone.Console
|
||||
{
|
||||
System.Console.WriteLine("");
|
||||
System.Console.WriteLine("");
|
||||
Logger.FatalException("EPIC FAIL!", e);
|
||||
Logger.Fatal(e, "EPIC FAIL!");
|
||||
System.Console.WriteLine("Press any key to exit...");
|
||||
System.Console.ReadLine();
|
||||
Environment.Exit(1);
|
||||
|
||||
@@ -75,11 +75,12 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.3.0-rc1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.1.0\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin">
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -150,4 +151,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Hosting" version="2.1.0" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net40" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.3.0-rc1" targetFramework="net40" />
|
||||
<package id="Owin" version="1.0" targetFramework="net40" />
|
||||
</packages>
|
||||
</packages>
|
||||
@@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
.Returns(Builder<SceneMapping>.CreateListOfSize(1).Build());
|
||||
|
||||
|
||||
Subject.HandleAsync(new ApplicationStartedEvent());
|
||||
Subject.Execute(new UpdateSceneMappingCommand());
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>()
|
||||
.Verify(v => v.All(), Times.Once());
|
||||
@@ -187,16 +187,15 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
{
|
||||
var mappings = new List<SceneMapping>
|
||||
{
|
||||
new SceneMapping { Title = "Working!!", ParseTerm = "working", SearchTerm = "Working!!", TvdbId = 100, SeasonNumber = -1 },
|
||||
new SceneMapping { Title = "Working!!", ParseTerm = "working", SearchTerm = "Working!!", TvdbId = 100, SeasonNumber = 1 },
|
||||
new SceneMapping { Title = "Working`!!", ParseTerm = "working", SearchTerm = "Working`!!", TvdbId = 100, SeasonNumber = 2 },
|
||||
new SceneMapping { Title = "Working!!!", ParseTerm = "working", SearchTerm = "Working!!!", TvdbId = 100, SeasonNumber = 3 },
|
||||
new SceneMapping { Title = "Working!!", ParseTerm = "working", SearchTerm = "Working!!", TvdbId = 100, SceneSeasonNumber = 1 },
|
||||
new SceneMapping { Title = "Working`!!", ParseTerm = "working", SearchTerm = "Working`!!", TvdbId = 100, SceneSeasonNumber = 2 },
|
||||
new SceneMapping { Title = "Working!!!", ParseTerm = "working", SearchTerm = "Working!!!", TvdbId = 100, SceneSeasonNumber = 3 },
|
||||
};
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
||||
|
||||
var tvdbId = Subject.FindTvdbId(parseTitle);
|
||||
var seasonNumber = Subject.GetSeasonNumber(parseTitle);
|
||||
var seasonNumber = Subject.GetSceneSeasonNumber(parseTitle);
|
||||
|
||||
tvdbId.Should().Be(100);
|
||||
seasonNumber.Should().Be(expectedSeasonNumber);
|
||||
@@ -217,7 +216,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
|
||||
foreach (var sceneMapping in _fakeMappings)
|
||||
{
|
||||
Subject.GetSceneNames(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber)).Should().Contain(sceneMapping.SearchTerm);
|
||||
Subject.GetSceneNamesBySeasonNumbers(sceneMapping.TvdbId, _fakeMappings.Select(m => m.SeasonNumber.Value)).Should().Contain(sceneMapping.SearchTerm);
|
||||
Subject.FindTvdbId(sceneMapping.ParseTerm).Should().Be(sceneMapping.TvdbId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using NzbDrone.Core.DataAugmentation.Xem.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
|
||||
{
|
||||
@@ -144,6 +145,25 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
|
||||
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Verify(v => v.UpdateSeries(It.IsAny<Series>()), Times.Never());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_clear_scenenumbering_if_thexem_throws()
|
||||
{
|
||||
GivenExistingMapping();
|
||||
|
||||
Mocker.GetMock<IXemProxy>()
|
||||
.Setup(v => v.GetXemSeriesIds())
|
||||
.Throws(new InvalidOperationException());
|
||||
|
||||
Subject.Handle(new SeriesUpdatedEvent(_series));
|
||||
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Verify(v => v.UpdateSeries(It.IsAny<Series>()), Times.Never());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Profiles.Delay;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
@@ -16,7 +12,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
[Test]
|
||||
public void should_migrate_old_delays()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Profiles").Row(new
|
||||
{
|
||||
@@ -35,10 +31,10 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var allProfiles = Mocker.Resolve<DelayProfileRepository>().All().ToList();
|
||||
var allProfiles = db.Query<DelayProfile70>("SELECT * FROM DelayProfiles");
|
||||
|
||||
allProfiles.Should().HaveCount(3);
|
||||
allProfiles.Should().OnlyContain(c => c.PreferredProtocol == DownloadProtocol.Usenet);
|
||||
allProfiles.Should().OnlyContain(c => c.PreferredProtocol == 1);
|
||||
allProfiles.Should().OnlyContain(c => c.TorrentDelay == 0);
|
||||
allProfiles.Should().Contain(c => c.UsenetDelay == 60);
|
||||
allProfiles.Should().Contain(c => c.UsenetDelay == 120);
|
||||
@@ -47,17 +43,18 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
[Test]
|
||||
public void should_create_tag_for_delay_profile()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Profiles").Row(new
|
||||
{
|
||||
GrabDelay = 1,
|
||||
Name = "OneHour",
|
||||
Cutoff = 0,
|
||||
Items = "[]"
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
var tags = Mocker.Resolve<TagRepository>().All().ToList();
|
||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
||||
|
||||
tags.Should().HaveCount(1);
|
||||
tags.First().Label.Should().Be("delay-60");
|
||||
@@ -66,7 +63,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
[Test]
|
||||
public void should_add_tag_to_series_that_had_a_profile_with_delay_attached()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Profiles").Row(new
|
||||
{
|
||||
@@ -95,12 +92,11 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var tag = Mocker.Resolve<TagRepository>().All().ToList().First();
|
||||
var series = Mocker.Resolve<SeriesRepository>().All().ToList();
|
||||
var tag = db.Query<Tag69>("SELECT Id, Label FROM Tags").Single();
|
||||
var series = db.Query<Series69>("SELECT Tags FROM Series");
|
||||
|
||||
series.Should().HaveCount(1);
|
||||
series.First().Tags.Should().HaveCount(1);
|
||||
series.First().Tags.First().Should().Be(tag.Id);
|
||||
series.First().Tags.Should().BeEquivalentTo(tag.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Profiles.Delay;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
@@ -17,10 +12,11 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
[Test]
|
||||
public void should_add_unknown_to_old_profile()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Profiles").Row(new
|
||||
{
|
||||
Id = 0,
|
||||
Name = "SDTV",
|
||||
Cutoff = 1,
|
||||
Items = "[ { \"quality\": 1, \"allowed\": true } ]",
|
||||
@@ -28,11 +24,12 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var allProfiles = Mocker.Resolve<ProfileRepository>().All().ToList();
|
||||
var profiles = db.Query<Profile70>("SELECT Items FROM Profiles LIMIT 1");
|
||||
|
||||
allProfiles.Should().HaveCount(1);
|
||||
allProfiles.First().Items.Should().HaveCount(2);
|
||||
allProfiles.First().Items.Should().Contain(i => i.Quality.Id == 0 && i.Allowed == false);
|
||||
var items = profiles.First().Items;
|
||||
items.Should().HaveCount(2);
|
||||
items.First().Quality.Should().Be(0);
|
||||
items.First().Allowed.Should().Be(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using FluentMigrator;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
@@ -17,7 +16,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
[Test]
|
||||
public void should_move_grab_id_from_date_to_columns()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
InsertHistory(c, new Dictionary<string, string>
|
||||
{
|
||||
@@ -33,19 +32,19 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
|
||||
});
|
||||
|
||||
var allProfiles = Mocker.Resolve<HistoryRepository>().All().ToList();
|
||||
var history = db.Query<History72>("SELECT DownloadId, Data FROM History");
|
||||
|
||||
allProfiles.Should().HaveCount(2);
|
||||
allProfiles.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
|
||||
allProfiles.Should().Contain(c => c.DownloadId == "123");
|
||||
allProfiles.Should().Contain(c => c.DownloadId == "abc");
|
||||
history.Should().HaveCount(2);
|
||||
history.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
|
||||
history.Should().Contain(c => c.DownloadId == "123");
|
||||
history.Should().Contain(c => c.DownloadId == "abc");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_leave_items_with_no_grabid()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
InsertHistory(c, new Dictionary<string, string>
|
||||
{
|
||||
@@ -60,18 +59,18 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
|
||||
});
|
||||
|
||||
var allProfiles = Mocker.Resolve<HistoryRepository>().All().ToList();
|
||||
var history = db.Query<History72>("SELECT DownloadId, Data FROM History");
|
||||
|
||||
allProfiles.Should().HaveCount(2);
|
||||
allProfiles.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
|
||||
allProfiles.Should().Contain(c => c.DownloadId == "123");
|
||||
allProfiles.Should().Contain(c => c.DownloadId == null);
|
||||
history.Should().HaveCount(2);
|
||||
history.Should().NotContain(c => c.Data.ContainsKey("downloadClientId"));
|
||||
history.Should().Contain(c => c.DownloadId == "123");
|
||||
history.Should().Contain(c => c.DownloadId == null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_leave_other_data()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
InsertHistory(c, new Dictionary<string, string>
|
||||
{
|
||||
@@ -81,16 +80,15 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var allProfiles = Mocker.Resolve<HistoryRepository>().All().Single();
|
||||
var history = db.Query<History72>("SELECT DownloadId, Data FROM History").Single();
|
||||
|
||||
allProfiles.Data.Should().NotContainKey("downloadClientId");
|
||||
allProfiles.Data.Should().Contain(new KeyValuePair<string, string>("indexer", "test"));
|
||||
allProfiles.Data.Should().Contain(new KeyValuePair<string, string>("group", "test2"));
|
||||
history.Data.Should().NotContainKey("downloadClientId");
|
||||
history.Data.Should().Contain(new KeyValuePair<string, string>("indexer", "test"));
|
||||
history.Data.Should().Contain(new KeyValuePair<string, string>("group", "test2"));
|
||||
|
||||
allProfiles.DownloadId.Should().Be("123");
|
||||
history.DownloadId.Should().Be("123");
|
||||
}
|
||||
|
||||
|
||||
private void InsertHistory(MigrationBase migrationBase, Dictionary<string, string> data)
|
||||
{
|
||||
migrationBase.Insert.IntoTable("History").Row(new
|
||||
@@ -1,29 +1,28 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class force_lib_updateFixture : MigrationTest<Core.Datastore.Migration.force_lib_update>
|
||||
public class force_lib_updateFixture : MigrationTest<force_lib_update>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_fail_on_empty_db()
|
||||
{
|
||||
WithTestDb(c => { });
|
||||
var db = WithMigrationTestDb();
|
||||
|
||||
Mocker.Resolve<ScheduledTaskRepository>().All().Should().BeEmpty();
|
||||
Mocker.Resolve<SeriesRepository>().All().Should().BeEmpty();
|
||||
db.Query("SELECT * FROM ScheduledTasks").Should().BeEmpty();
|
||||
db.Query("SELECT * FROM Series").Should().BeEmpty();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_reset_job_last_execution_time()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("ScheduledTasks").Row(new
|
||||
{
|
||||
@@ -40,7 +39,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var jobs = Mocker.Resolve<ScheduledTaskRepository>().All().ToList();
|
||||
var jobs = db.Query<ScheduledTasks75>("SELECT TypeName, LastExecution FROM ScheduledTasks");
|
||||
|
||||
jobs.Single(c => c.TypeName == "NzbDrone.Core.Tv.Commands.RefreshSeriesCommand")
|
||||
.LastExecution.Year.Should()
|
||||
@@ -51,11 +50,10 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
.Be(2000);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_reset_series_last_sync_time()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Series").Row(new
|
||||
{
|
||||
@@ -92,9 +90,9 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var jobs = Mocker.Resolve<SeriesRepository>().All().ToList();
|
||||
var series = db.Query<Series69>("SELECT LastInfoSync FROM Series");
|
||||
|
||||
jobs.Should().OnlyContain(c => c.LastInfoSync.Value.Year == 2014);
|
||||
series.Should().OnlyContain(c => c.LastInfoSync.Value.Year == 2014);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,18 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class dedupe_tagsFixture : MigrationTest<Core.Datastore.Migration.dedupe_tags>
|
||||
public class dedupe_tagsFixture : MigrationTest<dedupe_tags>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_fail_if_series_tags_are_null()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Series").Row(new
|
||||
{
|
||||
@@ -40,13 +37,14 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Mocker.Resolve<TagRepository>().All().Should().HaveCount(1);
|
||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
||||
tags.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_fail_if_series_tags_are_empty()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Series").Row(new
|
||||
{
|
||||
@@ -72,13 +70,14 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Mocker.Resolve<TagRepository>().All().Should().HaveCount(1);
|
||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
||||
tags.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_duplicate_labels_from_tags()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Tags").Row(new
|
||||
{
|
||||
@@ -91,13 +90,14 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Mocker.Resolve<TagRepository>().All().Should().HaveCount(1);
|
||||
var tags = db.Query<Tag69>("SELECT * FROM Tags");
|
||||
tags.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_allow_duplicate_tag_to_be_inserted()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Tags").Row(new
|
||||
{
|
||||
@@ -105,13 +105,13 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Assert.That(() => Mocker.Resolve<TagRepository>().Insert(new Tag { Label = "test" }), Throws.Exception);
|
||||
Assert.That(() => db.Query("INSERT INTO Tags (Label) VALUES ('test')"), Throws.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_replace_duplicated_tag_with_proper_tag()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Series").Row(new
|
||||
{
|
||||
@@ -142,13 +142,14 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Mocker.Resolve<SeriesRepository>().Get(1).Tags.First().Should().Be(1);
|
||||
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 1").Single();
|
||||
series.Tags.First().Should().Be(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_update_affected_series()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Series").Row(new
|
||||
{
|
||||
@@ -197,7 +198,8 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
Mocker.Resolve<SeriesRepository>().Get(2).Tags.Should().BeEmpty();
|
||||
var series = db.Query<Series69>("SELECT Tags FROM Series WHERE Id = 2").Single();
|
||||
series.Tags.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,25 @@ using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Sabnzbd;
|
||||
using NzbDrone.Core.Download.Clients.Transmission;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class move_dot_prefix_to_transmission_categoryFixture : MigrationTest<Core.Datastore.Migration.move_dot_prefix_to_transmission_category>
|
||||
public class move_dot_prefix_to_transmission_categoryFixture : MigrationTest<move_dot_prefix_to_transmission_category>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_fail_if_no_transmission()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Sab",
|
||||
Implementation = "Sabnzbd",
|
||||
Settings = new SabnzbdSettings
|
||||
Settings = new
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc"
|
||||
@@ -32,24 +30,23 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<SabnzbdSettings>().TvCategory.Should().Be("abc");
|
||||
downloadClients.Should().HaveCount(1);
|
||||
downloadClients.First().Settings.ToObject<SabnzbdSettings81>().TvCategory.Should().Be("abc");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_updated_for_transmission()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Trans",
|
||||
Implementation = "Transmission",
|
||||
Settings = new TransmissionSettings
|
||||
Settings = new
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc"
|
||||
@@ -58,24 +55,23 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<TransmissionSettings>().TvCategory.Should().Be(".abc");
|
||||
downloadClients.Should().HaveCount(1);
|
||||
downloadClients.First().Settings.ToObject<TransmissionSettings81>().TvCategory.Should().Be(".abc");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_leave_empty_category_untouched()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Trans",
|
||||
Implementation = "Transmission",
|
||||
Settings = new TransmissionSettings
|
||||
Settings = new
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = ""
|
||||
@@ -84,11 +80,10 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var downloadClients = db.Query<DownloadClientDefinition81>("SELECT Settings FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<TransmissionSettings>().TvCategory.Should().Be("");
|
||||
downloadClients.Should().HaveCount(1);
|
||||
downloadClients.First().Settings.ToObject<TransmissionSettings81>().TvCategory.Should().Be("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,28 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class update_quality_minmax_sizeFixture : MigrationTest<Core.Datastore.Migration.update_quality_minmax_size>
|
||||
public class update_quality_minmax_sizeFixture : MigrationTest<update_quality_minmax_size>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_fail_if_empty()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
{
|
||||
var db = WithMigrationTestDb();
|
||||
|
||||
});
|
||||
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
|
||||
|
||||
var items = Mocker.Resolve<QualityDefinitionRepository>().All();
|
||||
|
||||
items.Should().HaveCount(0);
|
||||
qualityDefinitions.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_rawhd_to_null()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("QualityDefinitions").Row(new
|
||||
{
|
||||
@@ -44,17 +40,16 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<QualityDefinitionRepository>().All();
|
||||
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
|
||||
|
||||
items.Should().HaveCount(2);
|
||||
|
||||
items.First(v => v.Quality.Id == 10).MaxSize.Should().NotHaveValue();
|
||||
qualityDefinitions.Should().HaveCount(2);
|
||||
qualityDefinitions.First(v => v.Quality == 10).MaxSize.Should().NotHaveValue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_zero_maxsize_to_null()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("QualityDefinitions").Row(new
|
||||
{
|
||||
@@ -65,17 +60,16 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<QualityDefinitionRepository>().All();
|
||||
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First(v => v.Quality.Id == 1).MaxSize.Should().NotHaveValue();
|
||||
qualityDefinitions.Should().HaveCount(1);
|
||||
qualityDefinitions.First(v => v.Quality == 1).MaxSize.Should().NotHaveValue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_preserve_values()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("QualityDefinitions").Row(new
|
||||
{
|
||||
@@ -93,11 +87,10 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<QualityDefinitionRepository>().All();
|
||||
var qualityDefinitions = db.Query<QualityDefinition84>("SELECT * FROM QualityDefinitions");
|
||||
|
||||
items.Should().HaveCount(2);
|
||||
|
||||
items.First(v => v.Quality.Id == 1).MaxSize.Should().Be(100);
|
||||
qualityDefinitions.Should().HaveCount(2);
|
||||
qualityDefinitions.First(v => v.Quality == 1).MaxSize.Should().Be(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Deluge;
|
||||
using NzbDrone.Core.Download.Clients.Sabnzbd;
|
||||
using NzbDrone.Core.Download.Clients.Transmission;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using System.Drawing;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class expand_transmission_urlbaseFixture : MigrationTest<Core.Datastore.Migration.expand_transmission_urlbase>
|
||||
public class expand_transmission_urlbaseFixture : MigrationTest<expand_transmission_urlbase>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_fail_if_no_transmission()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Deluge",
|
||||
Implementation = "Deluge",
|
||||
Settings = new DelugeSettings
|
||||
Settings = new DelugeSettings85
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc",
|
||||
@@ -34,51 +30,48 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<DelugeSettings>().UrlBase.Should().Be("/my/");
|
||||
items.First().Settings.ToObject<DelugeSettings85>().UrlBase.Should().Be("/my/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_updated_for_transmission()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Trans",
|
||||
Implementation = "Transmission",
|
||||
Settings = new TransmissionSettings
|
||||
Settings = new TransmissionSettings81
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc",
|
||||
UrlBase = null
|
||||
TvCategory = "abc"
|
||||
}.ToJson(),
|
||||
ConfigContract = "TransmissionSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<TransmissionSettings>().UrlBase.Should().Be("/transmission/");
|
||||
items.First().Settings.ToObject<TransmissionSettings81>().UrlBase.Should().Be("/transmission/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_append_to_existing_urlbase()
|
||||
{
|
||||
WithTestDb(c =>
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = 1,
|
||||
Name = "Trans",
|
||||
Implementation = "Transmission",
|
||||
Settings = new TransmissionSettings
|
||||
Settings = new TransmissionSettings81
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc",
|
||||
@@ -88,11 +81,10 @@ namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
});
|
||||
});
|
||||
|
||||
var items = Mocker.Resolve<DownloadClientRepository>().All();
|
||||
var items = db.Query<DownloadClientDefinition81>("SELECT * FROM DownloadClients");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Settings.As<TransmissionSettings>().UrlBase.Should().Be("/my/url/transmission/");
|
||||
items.First().Settings.ToObject<TransmissionSettings81>().UrlBase.Should().Be("/my/url/transmission/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user