1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Web/Controllers/UpdateController.cs
Mark McDowall 6e86db66c8 New: After an update the update page will redirect to a success or failure page, depending on the result.
Fix: Notifications will attempt to reconnect to NzbDrone after it is shutdown.
2012-02-29 16:44:44 -08:00

65 lines
2.2 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using NzbDrone.Common;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class UpdateController : Controller
{
private readonly UpdateProvider _updateProvider;
private readonly JobProvider _jobProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly DiskProvider _diskProvider;
public UpdateController(UpdateProvider updateProvider, JobProvider jobProvider,
EnviromentProvider enviromentProvider, DiskProvider diskProvider)
{
_updateProvider = updateProvider;
_jobProvider = jobProvider;
_enviromentProvider = enviromentProvider;
_diskProvider = diskProvider;
}
public ActionResult Index()
{
var updateModel = new UpdateModel();
updateModel.UpdatePackage = _updateProvider.GetAvilableUpdate(_enviromentProvider.Version);
updateModel.LogFiles = _updateProvider.UpdateLogFile();
updateModel.LogFolder = _enviromentProvider.GetUpdateLogFolder();
return View(updateModel);
}
public ActionResult StartUpdate()
{
_jobProvider.QueueJob(typeof(AppUpdateJob), 0, 0);
return JsonNotificationResult.Info("Update will begin shortly", "NzbDrone will restart automatically.");
}
public ActionResult ViewLog( string filepath)
{
ViewBag.Log = _diskProvider.ReadAllText(filepath).Replace(Environment.NewLine, "<br/>");
return View();
}
[HttpGet]
public ActionResult Post(string expectedVersion)
{
var model = new PostUpgradeModel();
model.CurrentVersion = _enviromentProvider.Version;
model.ExpectedVersion = Version.Parse(expectedVersion);
model.Success = model.CurrentVersion >= model.ExpectedVersion;
if (!model.Success)
model.LogFile = _updateProvider.UpdateLogFile().FirstOrDefault();
return View(model);
}
}
}