Merge branch 'services-update' into develop

This commit is contained in:
Mark McDowall 2013-08-26 14:42:17 -07:00
commit 429460dd5e
15 changed files with 66 additions and 73 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NzbDrone.Api.REST;
using NzbDrone.Core.Update;
using NzbDrone.Api.Mapping;
@ -32,7 +33,13 @@ namespace NzbDrone.Api.Update
public class UpdateResource : RestResource
{
public String Id { get; set; }
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
public Version Version { get; set; }
public String Branch { get; set; }
public DateTime ReleaseDate { get; set; }
public String FileName { get; set; }
public String Url { get; set; }
}

View File

@ -93,6 +93,7 @@
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
<Compile Include="Instrumentation\ExceptronTarget.cs" />
<Compile Include="PathEqualityComparer.cs" />
<Compile Include="Services.cs" />
<Compile Include="TPL\LimitedConcurrencyLevelTaskScheduler.cs" />
<Compile Include="Security\IgnoreCertErrorPolicy.cs" />
<Compile Include="StringExtensions.cs" />

View File

@ -40,7 +40,6 @@ namespace NzbDrone.Common.Serializer
return JsonConvert.SerializeObject(obj);
}
public static void Serialize<TModel>(TModel model, TextWriter outputStream)
{
var jsonTextWriter = new JsonTextWriter(outputStream);
@ -52,7 +51,5 @@ namespace NzbDrone.Common.Serializer
{
Serialize(model, new StreamWriter(outputStream));
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Common
{
public class Services
{
public static String RootUrl
{
get
{
return "http://services.nzbdrone.com";
}
}
}
}

View File

@ -15,14 +15,6 @@ namespace NzbDrone.Core.Test.DataAugmentationFixture.Scene
{
private const string SCENE_MAPPING_URL = "http://services.nzbdrone.com/SceneMapping/Active";
[SetUp]
public void Setup()
{
Mocker.GetMock<IConfigService>().SetupGet(s => s.ServiceRootUrl)
.Returns("http://services.nzbdrone.com");
}
[Test]
public void fetch_should_return_list_of_mappings()
{

View File

@ -16,13 +16,7 @@ namespace NzbDrone.Core.Test.UpdateTests
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master");
var updates = Subject.GetAvailablePackages().ToList();
updates.Should().NotBeEmpty();
updates.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.FileName));
updates.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Url));
updates.Should().OnlyContain(c => c.Version != null);
updates.Should().OnlyContain(c => c.Version.Major == 2);
Subject.GetLatestUpdate().Should().BeNull();
}
}
}

View File

@ -172,11 +172,6 @@ namespace NzbDrone.Core.Configuration
set { SetValue("BlackholeFolder", value); }
}
public string ServiceRootUrl
{
get { return "http://services.nzbdrone.com"; }
}
public string PneumaticFolder
{
get { return GetValue("PneumaticFolder", String.Empty); }

View File

@ -25,7 +25,6 @@ namespace NzbDrone.Core.Configuration
int Retention { get; set; }
DownloadClientType DownloadClient { get; set; }
string BlackholeFolder { get; set; }
string ServiceRootUrl { get; }
string PneumaticFolder { get; set; }
string RecycleBin { get; set; }
String NzbgetUsername { get; set; }

View File

@ -17,13 +17,11 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
public class DailySeriesDataProxy : IDailySeriesDataProxy
{
private readonly IHttpProvider _httpProvider;
private readonly IConfigService _configService;
private readonly Logger _logger;
public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger)
public DailySeriesDataProxy(IHttpProvider httpProvider, Logger logger)
{
_httpProvider = httpProvider;
_configService = configService;
_logger = logger;
}
@ -31,7 +29,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
{
try
{
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds");
var dailySeriesIds = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/AllIds");
var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds);
@ -49,7 +47,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
{
try
{
var result = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/Check?seriesId=" + tvdbid);
var result = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/Check?seriesId=" + tvdbid);
return Convert.ToBoolean(result);
}
catch (Exception ex)

View File

@ -13,19 +13,15 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public class SceneMappingProxy : ISceneMappingProxy
{
private readonly IHttpProvider _httpProvider;
private readonly IConfigService _configService;
public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService)
public SceneMappingProxy(IHttpProvider httpProvider)
{
_httpProvider = httpProvider;
_configService = configService;
}
public List<SceneMapping> Fetch()
{
var mappingsJson = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/SceneMapping/Active");
var mappingsJson = _httpProvider.DownloadString(Services.RootUrl + "/SceneMapping/Active");
return Json.Deserialize<List<SceneMapping>>(mappingsJson);
}
}

View File

@ -493,6 +493,7 @@
<Compile Include="Tv\RefreshSeriesService.cs" />
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />
<Compile Include="Update\InstallUpdateService.cs" />
<Compile Include="Update\UpdatePackageAvailable.cs" />
<Compile Include="Update\UpdatePackageProvider.cs" />
<Compile Include="Update\UpdatePackage.cs" />
<Compile Include="Update\UpdateCheckService.cs" />

View File

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Update
{
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
if (latestAvailable == null || latestAvailable.Version <= BuildInfo.Version)
if (latestAvailable == null)
{
_logger.Debug("No update available.");
return null;

View File

@ -1,11 +1,18 @@
using System;
using Newtonsoft.Json;
namespace NzbDrone.Core.Update
{
public class UpdatePackage
{
public string Url { get; set; }
public string FileName { get; set; }
public String Id { get; set; }
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
public Version Version { get; set; }
public String Branch { get; set; }
public DateTime ReleaseDate { get; set; }
public String FileName { get; set; }
public String Url { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Update
{
public class UpdatePackageAvailable
{
public Boolean Available { get; set; }
public UpdatePackage UpdatePackage { get; set; }
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
@ -11,56 +12,30 @@ namespace NzbDrone.Core.Update
{
public interface IUpdatePackageProvider
{
IEnumerable<UpdatePackage> GetAvailablePackages();
UpdatePackage GetLatestUpdate();
}
public class UpdatePackageProvider : IUpdatePackageProvider
{
private readonly IConfigFileProvider _configService;
private readonly IConfigFileProvider _configFileProvider;
private readonly IHttpProvider _httpProvider;
private readonly Logger _logger;
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>(?<=\.)\d+\.\d+\.\d+\.\d+).+?)(?:\<\/a\>)",
RegexOptions.IgnoreCase);
public UpdatePackageProvider(IConfigFileProvider configService, IHttpProvider httpProvider, Logger logger)
public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger)
{
_configService = configService;
_configFileProvider = configFileProvider;
_httpProvider = httpProvider;
_logger = logger;
}
public IEnumerable<UpdatePackage> GetAvailablePackages()
{
var updateList = new List<UpdatePackage>();
var branch = _configService.Branch;
var version = BuildInfo.Version;
var updateUrl = String.Format("http://update.nzbdrone.com/v{0}/{1}/", version.Major, branch);
_logger.Debug("Getting a list of updates from {0}", updateUrl);
var rawUpdateList = _httpProvider.DownloadString(updateUrl);
var matches = ParseRegex.Matches(rawUpdateList);
foreach (Match match in matches)
{
var updatePackage = new UpdatePackage();
updatePackage.FileName = match.Groups["filename"].Value;
updatePackage.Url = updateUrl + updatePackage.FileName;
updatePackage.Version = new Version(match.Groups["version"].Value);
updateList.Add(updatePackage);
}
_logger.Debug("Found {0} update packages", updateUrl.Length);
return updateList;
}
public UpdatePackage GetLatestUpdate()
{
return GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault();
var url = String.Format("{0}/v1/update/{1}?version={2}", Services.RootUrl, _configFileProvider.Branch, BuildInfo.Version);
var update = JsonConvert.DeserializeObject<UpdatePackageAvailable>(_httpProvider.DownloadString(url));
if (!update.Available) return null;
return update.UpdatePackage;
}
}
}