1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/src/NzbDrone.Api/Update/UpdateModule.cs

61 lines
2.0 KiB
C#
Raw Normal View History

2013-05-20 03:30:02 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
2013-08-24 05:42:45 +03:00
using Newtonsoft.Json;
2013-05-20 03:30:02 +03:00
using NzbDrone.Api.REST;
2013-10-07 01:22:43 +03:00
using NzbDrone.Common.EnvironmentInfo;
2013-05-20 03:30:02 +03:00
using NzbDrone.Core.Update;
using NzbDrone.Api.Mapping;
namespace NzbDrone.Api.Update
{
public class UpdateModule : NzbDroneRestModule<UpdateResource>
{
private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IInstallUpdates _installUpdateService;
2013-05-20 03:30:02 +03:00
public UpdateModule(IRecentUpdateProvider recentUpdateProvider,
IInstallUpdates installUpdateService)
2013-05-20 03:30:02 +03:00
{
_recentUpdateProvider = recentUpdateProvider;
_installUpdateService = installUpdateService;
GetResourceAll = GetRecentUpdates;
2013-05-20 03:30:02 +03:00
}
private List<UpdateResource> GetRecentUpdates()
2013-05-20 03:30:02 +03:00
{
var resources = _recentUpdateProvider.GetRecentUpdatePackages()
.OrderByDescending(u => u.Version)
.InjectTo<List<UpdateResource>>();
2013-05-20 03:30:02 +03:00
2013-10-07 01:22:43 +03:00
foreach (var updateResource in resources)
2013-05-20 03:30:02 +03:00
{
2013-10-07 01:22:43 +03:00
if (updateResource.Version > BuildInfo.Version)
{
updateResource.IsUpgrade = true;
}
else if (updateResource.Version == BuildInfo.Version)
{
updateResource.Installed = true;
}
2013-05-20 03:30:02 +03:00
}
return resources;
2013-05-20 03:30:02 +03:00
}
}
public class UpdateResource : RestResource
{
2013-08-24 05:42:45 +03:00
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
2013-05-20 03:30:02 +03:00
public Version Version { get; set; }
2013-08-24 05:42:45 +03:00
public String Branch { get; set; }
public DateTime ReleaseDate { get; set; }
2013-05-20 03:30:02 +03:00
public String FileName { get; set; }
public String Url { get; set; }
2013-10-07 01:22:43 +03:00
public Boolean IsUpgrade { get; set; }
public Boolean Installed { get; set; }
public UpdateChanges Changes { get; set; }
2013-05-20 03:30:02 +03:00
}
}