1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-03-11 15:19:56 -04:00

Compare commits

...

133 Commits

Author SHA1 Message Date
Taloth Saldono
229986033c Added logging of Sonarr API calls. 2016-05-11 21:13:31 +02:00
Taloth Saldono
c249ad5dbe Using a tiered fallback is safer in case there is another data-loss and ids get reset. 2016-05-11 19:06:35 +02:00
Mark McDowall
e2d6d374ab Update HttpAccept.Rss to include application/xml 2016-05-10 15:18:27 -07:00
Taloth Saldono
d3adb7ac40 Fixed: HDBits release age incorrect.
fixes #1272
2016-05-10 22:19:51 +02:00
Taloth Saldono
0f1afd416b Fixed: Adjusted BTN Recent Feed (RssSync) to better use their api db indexes. 2016-05-10 21:43:34 +02:00
Mark McDowall
2f3bc61af7 Nice try uTorrent, you're not Deluge
Fixed: uTorrent error message identity crisis
2016-05-02 10:38:59 -07:00
Mark McDowall
319b4f13b7 Fixed: Refreshing series that have duplicate season information 2016-04-30 11:02:40 -07:00
Mark McDowall
54fda3d648 Fixed: Updating Emby Library
Closes #1267
2016-04-28 23:42:53 -07:00
Mark McDowall
2f6fded7c3 Fixed: An issue preventing access to settings due to extraneous data in the database 2016-04-27 16:18:11 -07:00
Mark McDowall
7934003b5e Fixed: Rare error when removing pending items that have been rejected 2016-04-27 16:16:43 -07:00
Mark McDowall
8773d38ddd Fixed: Plex Meda Server authentication 2016-04-23 13:28:07 -07:00
Taloth Saldono
f16f097b3e Fixed: Sabnzbd 1.0.1 added two new status values.
fixes #1259
2016-04-23 11:40:49 +02:00
Mark McDowall
7284ef50eb Fixed: Manual Import not scrolling after using file browser
Closes #745
2016-04-17 16:07:08 -07:00
Mark McDowall
e9248e284e Return decisions when catching exceptions during decision making
Fixed: Manual Import not showing files that failed to process
Closes #1131
2016-04-17 14:17:46 -07:00
Sam Holmes
aff6af1806 Update package.json license expression (#1242) 2016-04-13 08:08:20 -07:00
Taloth Saldono
c0c35a0eba Updated NzbGet tests. 2016-04-09 20:45:11 +02:00
Taloth Saldono
072ca459bd Fixed: NzbGet DUPE/COPY status should be considered failure.
fixes #919
closes #693
closes #505
2016-04-09 20:28:37 +02:00
Taloth Saldono
0865306064 Fixed: Adding Nzb with {{password}} in name to NzbGet failed. 2016-04-09 20:13:58 +02:00
Taloth Saldono
ac14444d34 Removed redundant logging. 2016-04-09 18:05:33 +02:00
Mark McDowall
8a6d1ef373 Release scoring 2016-04-08 13:25:50 -07:00
Mark McDowall
dc694b0f34 Don't throw after catching the exception during TearDown 2016-04-08 10:16:29 -07:00
Mark McDowall
76f8cc81da Fixed: Don't force testing when updating connections, indexers or download clients 2016-04-07 17:40:52 -07:00
Mark McDowall
14f737bd60 Fixed: Set permissions on series metadata images when they are created
Closes #871
2016-04-07 17:37:16 -07:00
Mark McDowall
5942ddf9f1 Implement mono logic to not set owner/group with chown
New: Allow Owner or Group to be left blank to not set it when changing owner (mono only)
Closes #1220
2016-04-07 15:52:12 -07:00
Mark McDowall
ab7b427241 Fixed: Default display time for Kodi notifications 2016-04-07 15:52:12 -07:00
Taloth Saldono
15120270b4 Disabled unreliable lookup test. 2016-04-07 00:07:49 +02:00
Taloth Saldono
cc0406653a Readded logging Download Client responses. 2016-04-06 22:53:14 +02:00
Taloth Saldono
9f34127565 Better error handling in the Deluge ConnectDaemon code. 2016-04-06 22:07:25 +02:00
Taloth Saldono
71ecc96c70 Refactored IntegrationTests to work with Nunit3 VS adapter. 2016-04-06 22:06:40 +02:00
Taloth Saldono
2fa3873503 Give a couple of timing-based tests a bit more breathing room. 2016-04-06 21:35:00 +02:00
Taloth Saldono
96b7bd3b2b Merge branch 'http-uri-combine-path' into develop 2016-04-06 21:34:20 +02:00
Taloth Saldono
e1ea17cabf Fixed: uTorrent api proxy would fail on specific Win10 configurations. (The Phoenix Rises)
Moved token queryparam to start since uTorrent requires it.
Fixed handling response missing an expected Set-Cookie header.
Force Cache-Control: no-cache for uTorrent.
Added Connection: KeepAlive to fix inexplicable uTorrent api failure.
2016-04-05 23:49:28 +02:00
Taloth Saldono
3a162be265 CombinePath now simple, uri resolve done via operator and CombineRelativePath. 2016-04-05 23:42:10 +02:00
Mark McDowall
502298aab9 Cleanup HttpUri.PathCombine 2016-04-03 18:47:43 -07:00
Mark McDowall
edea488dbe Upgrade to NUnit3 2016-04-01 19:19:32 -07:00
vawen
2fabe2d198 New: Prevent grabbing season packs if full season hasn't aired yet
Closes #743
2016-03-29 19:44:33 -07:00
Mark McDowall
f2c8156c00 ParsingService.GetEpisodes will use TVDB season number when available 2016-03-28 19:32:58 -07:00
Mark McDowall
942be364dc Treat XEM aliases as SceneSeasonNumber
Fixed: Aliases used incorrectly when TVDB season number matched the seaon number of the alias
Closes #1140
2016-03-28 19:32:25 -07:00
Keivan Beigi
44e09e2220 build.sh uses msbuild 14 2016-03-28 11:45:06 -07:00
Keivan Beigi
0fcd20ec4a use npm-cache if installed 2016-03-28 11:37:29 -07:00
Taloth Saldono
4c5707bba8 Fixed: Newznab/Torznab used wrong query if tvrageid was unknown in combination with a specific indexer capability profile. 2016-03-28 20:15:31 +02:00
Taloth Saldono
947f494e72 Fixed: Release Group detection didn't handle RLSGRP_English properly.
fixes #1198
2016-03-26 21:42:51 +01:00
Taloth Saldono
3f74a87b45 Fixed: Removed TrollHD from the RawHD detection regex since they now also release other sources.
fixes #1193
2016-03-26 20:45:52 +01:00
Taloth Saldono
da0bdc5750 New: Added RERIP as REPACK (Proper). 2016-03-26 20:41:27 +01:00
Taloth Saldono
3ea59cd91b Don't set ACL if already set. 2016-03-26 19:31:12 +01:00
Taloth Saldono
9b42dc7082 Reconfigure Logging early in the process to set the correct log level. 2016-03-26 19:31:11 +01:00
Taloth Saldono
8b1c022244 Updated NLog to 4.3.0-rc1. 2016-03-26 19:31:09 +01:00
Mark McDowall
e5cb8bb0bd Fixed: Some releases with date and season/episode numbers with multiple episodes on a single day
Closes #1192
2016-03-25 19:13:24 -07:00
Mark McDowall
d37343bb7d Fixed: Prevent root folders from being added under the startup folder 2016-03-25 19:03:28 -07:00
Nathan
9c91f11cdc New: Safari Pinned tab icon
Closes #1122
2016-03-24 15:47:08 -07:00
Mark McDowall
444fcf5ae5 Fixed: Use new rTorrent commands when resolving magnets
Closes #1199
2016-03-24 14:35:36 -07:00
Mark McDowall
31f8e0a47a New: Windows Phone theme 2016-03-24 12:25:51 -07:00
Mark McDowall
1e0fcc877b New: Mobile Chrome theme (Android 5.0+) 2016-03-24 12:25:51 -07:00
Björn Dahlgren
1293bab868 Run gulp using npm Simplifies usage of gulp and makes sure everyone is using same version 2016-03-24 10:43:54 -07:00
GΛVĪN
9de92d18e1 Updated OS X startup script to work with macports mono 2016-03-23 22:56:45 -07:00
Mark McDowall
5a877cbd62 Fixed: RSS Sync failing due to one broken indexer 2016-03-23 19:04:35 -07:00
Taloth Saldono
99aa25bf83 New: Light green background color in Season Pass for seasons with all episodes downloaded. 2016-03-22 23:09:38 +01:00
Iain Nicol
5f66c15b91 Fixed: Allow underscore when validating hostnames
This is particularly useful on FreeNAS.  It uses underscores in the hostnames when creating plugin jails.
2016-03-22 20:06:41 +00:00
Mark McDowall
af220c7f7b ItemViewContainer didn't exist sometimes for root folders
Fixed: Error displaying existing root folders in some cases
Closes #1170
2016-03-21 15:02:09 -07:00
Mark McDowall
59e71a4cd9 Include series type for CustomScript 2016-03-19 19:35:02 -07:00
Mark McDowall
6b1a4c4198 Always validate settings when testing thingies
Fixed: Validation skipped when saving connections
2016-03-18 15:42:19 -07:00
Mark McDowall
1072c5247c On grab for custom scripts
New: On Grab handling for Custom Scripts
2016-03-17 18:40:58 -07:00
Taloth Saldono
6508e920fe New: Added (fairly strict) regex for the new scene WEB quality = WEB-DL. 2016-03-17 21:03:01 +01:00
Taloth Saldono
1154e0eeb3 Add WebException handlers to prevent them reaching the UI. 2016-03-17 20:53:11 +01:00
Taloth Saldono
2d96914bfa Send Http auth without waiting for challenge. 2016-03-17 20:15:53 +01:00
Taloth Saldono
70494c3674 Adding magnet to qbit should use FormData not QueryParam. 2016-03-17 19:49:05 +01:00
Taloth Saldono
d68ad98176 Fixed: UsenetBlackhole not importing since latest develop. 2016-03-17 08:01:07 +01:00
Taloth Saldono
eb70a6419c Fixed: Not uploading nzbs to Nzbget on linux since previous develop. 2016-03-17 07:53:23 +01:00
Taloth Saldono
22aa759abc Fixed: Rarbg indexer broken on develop. 2016-03-17 07:32:45 +01:00
Taloth Saldono
19b8fb6d8b Merge branch 'blackhole-delay' into develop 2016-03-15 21:47:18 +01:00
Taloth Saldono
d4bc835b1c New: Delaying Blackhole imports while they're still being updated. 2016-03-15 21:46:40 +01:00
Taloth Saldono
b99d82cccc Ensure auto-generated mocks are also registered in the test container. 2016-03-15 21:46:39 +01:00
Taloth Saldono
25d481d5d9 Migrated all Download client proxies from RestSharp to HttpClient. 2016-03-11 20:36:03 +01:00
Taloth Saldono
23871503a2 Replaced Uri with HttpUri. 2016-03-11 20:36:01 +01:00
Taloth Saldono
7c54fa70d7 Added support for FormData (AddFormParameter and AddFormUpload), which automatically gets converted to multipart/form-data or application/x-www-form-urlencoded. 2016-03-11 20:35:59 +01:00
Taloth Saldono
2ffbbb0e71 Refactored HttpRequest and HttpRequestBuilder, moving most of the logic to the HttpRequestBuilder.
Added ContentSummary to be able to describe the ContentData in a human readable form. (Useful for JsonRpc and FormData).
2016-03-11 20:35:58 +01:00
Taloth Saldono
7818f0c59b Fixed: Don't purge xem scene mapping cache when new series gets added. 2016-03-11 17:31:06 +01:00
Taloth Saldono
03e2adc332 Sort episodes in calendar by ep nr if airdate is the same. 2016-03-11 16:54:41 +01:00
Taloth Saldono
e6ab4196de Revert "Fixed: Sort episodes on the api by episode number when they air at the same time."
This reverts commit 9ffc0ec521.
2016-03-11 16:53:22 +01:00
Mark McDowall
f2784d3ec2 New: Trakt links on series details 2016-03-10 20:48:24 -08:00
Mark McDowall
ef3d508b31 Fixed: Anime season search won't search for missing episodes 2016-03-10 20:24:07 -08:00
Taloth Saldono
9ffc0ec521 Fixed: Sort episodes on the api by episode number when they air at the same time. 2016-03-06 00:43:04 +01:00
Mark McDowall
b598add64e Updated FluentValidation 2016-03-04 00:39:17 -08:00
Mark McDowall
47446515d1 Update CONTRIBUTING.md 2016-03-02 10:03:37 -08:00
Taloth Saldono
e5de7fb8cf Fixed: Don't trigger SceneMapping update and Housekeeping right on the startup event. 2016-03-01 23:50:09 +01:00
Taloth Saldono
55e870f295 Added version to logged exceptions. 2016-03-01 22:05:34 +01:00
Taloth Saldono
1485c83ab6 Don't hammer thexem, kthxbai. 2016-03-01 22:05:23 +01:00
Mark McDowall
e8d1623e96 Default Plex Media Server "Update Library" to true 2016-02-25 19:19:31 -08:00
Taloth Saldono
3bc6bf9e99 Don't die in MonoTorrent if nodes is an empty string. 2016-02-25 21:40:55 +01:00
Taloth Saldono
949d8bf49b Fixed: Warn if user has movie/date sorting enabled in Sabnzbd for the Sonarr category. 2016-02-25 20:39:42 +01:00
Taloth Saldono
c29e49da95 Clarified error message in MatchesFolderSpecification. 2016-02-25 19:44:29 +01:00
Taloth Saldono
79c565911c New: Changed the default of 'Use Hardlinks instead of Copy' to true. Most ppl seem to want that anyway. 2016-02-25 19:19:02 +01:00
Taloth Saldono
bb9a0371c5 Added TorrentRss test for ExtraTorrents, no other changes. 2016-02-25 19:18:46 +01:00
Taloth Saldono
e945231ab3 Fixed: Newznab should reject a Torznab feed. 2016-02-21 11:37:01 +01:00
Mark McDowall
c1298d162e Womble's has size parsing now 2016-02-18 18:39:23 -08:00
Taloth Saldono
f005edfcf0 Don't use Sonarr as ReleaseGroup if the pattern contains an advanced prefix/suffix. 2016-02-18 23:32:38 +01:00
Taloth Saldono
59c68ec6cc Write debug/trace log files separately to prevent trace from quickly rolling over debug. 2016-02-18 23:32:37 +01:00
Taloth Saldono
a5077b0b1b Replaced <removed> with (removed) for the log cleanser so it doesn't mess with forums. 2016-02-18 23:32:36 +01:00
Mark McDowall
a22c0499d5 Couple more anime version test cases 2016-02-17 23:06:44 -08:00
Mark McDowall
c38608e3cf Fixed Protocol returned for release/push endpoint 2016-02-17 20:26:37 -08:00
Taloth Saldono
3b57194d47 Fixed: Parses size in Wombles Description field so min/maxsize checks works on Wombles feed. 2016-02-17 23:22:22 +01:00
Taloth Saldono
21c901eab4 fixed failing torznab test 2016-02-17 21:52:55 +01:00
Taloth Saldono
9ad8311dd6 New: Use PageSize reported by newznab/torznab caps instead of hardcoded 100.
ref Jackett/Jackett#27
2016-02-17 21:23:27 +01:00
Taloth Saldono
df84028c90 Added DrunkenSlug and SimplyNZBs as Newznab presets. 2016-02-17 21:23:26 +01:00
Mark McDowall
7cb1e91ba1 Handle 1.1x version from Sabnzbd 2016-02-16 23:49:13 -08:00
Mark McDowall
974a7276c3 New: Explicitly enforce SABnzbd minimum version of 0.7.0 2016-02-16 22:40:12 -08:00
Mark McDowall
f0ca2bc11e Fixed: Don't collapse episode titles when episode titles contain Part x only 2016-02-16 21:28:32 -08:00
Mark McDowall
cb43888496 Fixed: Use Protocol over DownloadProtocol for ReleasePushModule
DownloadProtocol is still supported for backwards compatibility
2016-02-16 20:21:20 -08:00
Taloth Saldono
34d5fb1aa0 Fiddled with the Back to the Top button a bit so it's better visible on the white background, also only on widescreen now. 2016-02-15 22:56:10 +01:00
Taloth Saldono
72f0085ef7 Fixed: DownloadedEpisodesScan API command couldn't be used to process individual files. 2016-02-15 21:55:53 +01:00
Taloth Saldono
f25f5abced Cleaned up 2160p changes and added migration and tests.
Also reserved the quality ids for WEBRip etc.
2016-02-14 00:08:42 +01:00
Björn Dahlgren
94323f79e7 New: Added support for UltraHD (2160p) quality 2016-02-14 00:08:15 +01:00
Taloth Saldono
bdb1076100 Updated db migration testing framework so we only run migrations up to the one we're testing.
fixes #902
2016-02-13 23:21:32 +01:00
Mark McDowall
8818e39c63 Fixed: Daily + Standard with 3 digit episode numbers
Closes #1145
2016-02-11 18:46:32 -08:00
Taloth Saldono
6a90035a4c Updated NLog to v4.2.3. 2016-02-11 22:15:12 +01:00
Taloth Saldono
e01b2ef25c Fixed some compile warnings. 2016-02-11 22:11:53 +01:00
Taloth Saldono
91d91bc673 Fixed: Sample files of daily episodes should also be deleted after import. 2016-02-11 21:27:41 +01:00
Taloth Saldono
1c92ea58da Fixed: Replaced mono symlink resolve logic to better handle errors. 2016-02-11 21:12:42 +01:00
Taloth Saldono
bd6a38173e Add another nn preset. 2016-02-11 20:11:59 +01:00
Mark McDowall
5d05a85411 Delete the subfolder not the parent folder 2016-02-11 00:54:52 -08:00
Mark McDowall
1a5eafd2b1 New: Remove empty subfolders after renaming FileSetLastWriteTime
Closes #490
2016-02-11 00:38:44 -08:00
Mark McDowall
1603b06431 New: Prefer regular episodes over specials when absolute numbers conflict
Closes #676
2016-02-11 00:09:29 -08:00
Mark McDowall
2396af4589 New: Pushover Silent and Emergency priorities
Closes #878
2016-02-10 23:43:40 -08:00
Taloth Saldono
262b8daec1 Revert "Fixed regression, mono should resolve symlinks while trying to find out the available/total space."
This reverts commit d33efe59fc.
2016-02-11 01:52:47 +01:00
Taloth Saldono
d33efe59fc Fixed regression, mono should resolve symlinks while trying to find out the available/total space. 2016-02-11 01:14:16 +01:00
Taloth Saldono
5550565d6a Fixed: Manual Import didn't revert to parent folder when trying to parse series leading to issues with obfuscated releases. 2016-02-10 00:15:01 +01:00
Taloth Saldono
68540cb479 Certain log messages didn't include the exception. 2016-02-07 00:23:13 +01:00
Taloth Saldono
4038fa6907 Ignore -Obfuscated while parsing. 2016-02-06 10:43:56 +01:00
Taloth Saldono
f96f997506 Fixed: Handling xml responses containing invalid html entities.
fixes #1123
2016-02-05 20:08:54 +01:00
Taloth Saldono
4e84d1a17c Fixed: Throw more specific error when there's an issue with the curl root certificate bundle. 2016-02-02 22:11:39 +01:00
Taloth Saldono
97cdb6a4a5 Fixed: ZFS and other mounts now listed in the System page.
Will now also automatically revert to a fully transactional move/copy if the move is in our out of a cifs mount. (assuming the cifs mount can be detected)
2016-02-02 22:11:37 +01:00
Mark McDowall
f5b3d70641 Merge pull request #1112 from cturra/nzbplanet-api
updating nzbplanet.net api url to reflect recent change
2016-01-30 23:33:06 -08:00
cturra
db66d3da9e updating nzbplanet.net api url to reflect recent change 2016-01-30 21:27:18 -08:00
435 changed files with 8209 additions and 9546 deletions

1
.gitignore vendored
View File

@@ -128,3 +128,4 @@ output/*
._*
_start
_temp_*/**/*

View File

@@ -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 ###

View File

@@ -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

View File

@@ -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

View File

@@ -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" ] \

View File

@@ -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": {

View File

@@ -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.*

View File

@@ -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.

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"):

View File

@@ -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>

View File

@@ -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>

View File

@@ -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
{

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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>();

View File

@@ -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();
}

View File

@@ -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; }

View File

@@ -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>

View File

@@ -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 "{}";

View File

@@ -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);
}

View File

@@ -6,5 +6,6 @@ namespace NzbDrone.Api.Series
{
public string Title { get; set; }
public int SeasonNumber { get; set; }
public int SceneSeasonNumber { get; set; }
}
}

View File

@@ -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();
}

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View 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;
}
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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

View File

@@ -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/");
}
}

View File

@@ -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"));
}
}
}

View 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);
}
}
}

View File

@@ -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>

View File

@@ -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";

View File

@@ -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()
{

View File

@@ -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

View File

@@ -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();

View File

@@ -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]

View File

@@ -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>

View File

@@ -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));
}
}
}

View 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);
}
}
}

View 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);
}
}

View File

@@ -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)
{
}
}
}

View 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; }
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}
}
}
}

View File

@@ -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))

View 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);
}
}
}
}

View File

@@ -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)
{

View File

@@ -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);
}
}

View 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; }
}
}

View File

@@ -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");
}
}
}

View File

@@ -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;
}
}

View File

@@ -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));
}
}
}

View File

@@ -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);

View File

@@ -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")));
}
}
}

View File

@@ -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)
{

View File

@@ -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;
}
}

View File

@@ -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");

View File

@@ -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;
}
}

View File

@@ -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;

View 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; }
}
}

View File

@@ -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();
}
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}

View 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();
}
}
}

View File

@@ -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;
}

View 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);
}
}
}

View File

@@ -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()

View File

@@ -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; }
}
}

View File

@@ -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());
}
}
}

View File

@@ -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;

View File

@@ -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);
}
}
}

View File

@@ -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)

View File

@@ -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" />

View File

@@ -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;
}
}

View File

@@ -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;

View 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);
}
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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>

View File

@@ -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);

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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]

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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("");
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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