1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Using services to get updates now

This commit is contained in:
Mark McDowall 2013-08-23 19:21:12 -07:00
parent ae590828da
commit 11c49c9260
14 changed files with 59 additions and 73 deletions

View File

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

View File

@ -40,7 +40,6 @@ public static string ToJson(this object obj)
return JsonConvert.SerializeObject(obj); return JsonConvert.SerializeObject(obj);
} }
public static void Serialize<TModel>(TModel model, TextWriter outputStream) public static void Serialize<TModel>(TModel model, TextWriter outputStream)
{ {
var jsonTextWriter = new JsonTextWriter(outputStream); var jsonTextWriter = new JsonTextWriter(outputStream);
@ -52,7 +51,5 @@ public static void Serialize<TModel>(TModel model, Stream outputStream)
{ {
Serialize(model, new StreamWriter(outputStream)); 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 @@ public class SceneMappingProxyFixture : CoreTest<SceneMappingProxy>
{ {
private const string SCENE_MAPPING_URL = "http://services.nzbdrone.com/SceneMapping/Active"; 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] [Test]
public void fetch_should_return_list_of_mappings() public void fetch_should_return_list_of_mappings()
{ {

View File

@ -16,13 +16,7 @@ public void should_get_list_of_available_updates()
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master"); Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master");
var updates = Subject.GetAvailablePackages().ToList(); Subject.GetLatestUpdate().Should().BeNull();
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);
} }
} }
} }

View File

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

View File

@ -25,7 +25,6 @@ public interface IConfigService
int Retention { get; set; } int Retention { get; set; }
DownloadClientType DownloadClient { get; set; } DownloadClientType DownloadClient { get; set; }
string BlackholeFolder { get; set; } string BlackholeFolder { get; set; }
string ServiceRootUrl { get; }
string PneumaticFolder { get; set; } string PneumaticFolder { get; set; }
string RecycleBin { get; set; } string RecycleBin { get; set; }
String NzbgetUsername { get; set; } String NzbgetUsername { get; set; }

View File

@ -17,13 +17,11 @@ public interface IDailySeriesDataProxy
public class DailySeriesDataProxy : IDailySeriesDataProxy public class DailySeriesDataProxy : IDailySeriesDataProxy
{ {
private readonly IHttpProvider _httpProvider; private readonly IHttpProvider _httpProvider;
private readonly IConfigService _configService;
private readonly Logger _logger; private readonly Logger _logger;
public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger) public DailySeriesDataProxy(IHttpProvider httpProvider, Logger logger)
{ {
_httpProvider = httpProvider; _httpProvider = httpProvider;
_configService = configService;
_logger = logger; _logger = logger;
} }
@ -31,7 +29,7 @@ public IEnumerable<int> GetDailySeriesIds()
{ {
try try
{ {
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds"); var dailySeriesIds = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/AllIds");
var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds); var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds);
@ -49,7 +47,7 @@ public bool IsDailySeries(int tvdbid)
{ {
try 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); return Convert.ToBoolean(result);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -13,19 +13,15 @@ public interface ISceneMappingProxy
public class SceneMappingProxy : ISceneMappingProxy public class SceneMappingProxy : ISceneMappingProxy
{ {
private readonly IHttpProvider _httpProvider; private readonly IHttpProvider _httpProvider;
private readonly IConfigService _configService;
public SceneMappingProxy(IHttpProvider httpProvider)
public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService)
{ {
_httpProvider = httpProvider; _httpProvider = httpProvider;
_configService = configService;
} }
public List<SceneMapping> Fetch() 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); return Json.Deserialize<List<SceneMapping>>(mappingsJson);
} }
} }

View File

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

View File

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

View File

@ -1,11 +1,18 @@
using System; using System;
using Newtonsoft.Json;
namespace NzbDrone.Core.Update namespace NzbDrone.Core.Update
{ {
public class UpdatePackage public class UpdatePackage
{ {
public string Url { get; set; } public String Id { get; set; }
public string FileName { get; set; }
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
public Version Version { get; set; } 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -11,56 +12,30 @@ namespace NzbDrone.Core.Update
{ {
public interface IUpdatePackageProvider public interface IUpdatePackageProvider
{ {
IEnumerable<UpdatePackage> GetAvailablePackages();
UpdatePackage GetLatestUpdate(); UpdatePackage GetLatestUpdate();
} }
public class UpdatePackageProvider : IUpdatePackageProvider public class UpdatePackageProvider : IUpdatePackageProvider
{ {
private readonly IConfigFileProvider _configService; private readonly IConfigFileProvider _configFileProvider;
private readonly IHttpProvider _httpProvider; private readonly IHttpProvider _httpProvider;
private readonly Logger _logger; private readonly Logger _logger;
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>(?<=\.)\d+\.\d+\.\d+\.\d+).+?)(?:\<\/a\>)", public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger)
RegexOptions.IgnoreCase);
public UpdatePackageProvider(IConfigFileProvider configService, IHttpProvider httpProvider, Logger logger)
{ {
_configService = configService; _configFileProvider = configFileProvider;
_httpProvider = httpProvider; _httpProvider = httpProvider;
_logger = logger; _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() public UpdatePackage GetLatestUpdate()
{ {
return GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault(); var url = String.Format("{0}/v1/update/{1}?{2}", Services.RootUrl, _configFileProvider.Branch, BuildInfo.Version);
var update = JsonConvert.DeserializeObject<UpdatePackageAvailable>(_httpProvider.DownloadString(url));
if (!update.Available) return null;
return update.UpdatePackage;
} }
} }
} }