Update logs are now in the UI

pull/4/head
kay.one 13 years ago
parent 54e5874770
commit 3520b56bb6

@ -170,5 +170,10 @@ namespace NzbDrone.Common
return freeBytesAvailable;
}
public virtual string ReadAllText(string filePath)
{
return File.ReadAllText(filePath);
}
}
}

@ -97,6 +97,7 @@
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDownloadFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\TestJobs.cs" />
<Compile Include="JobTests\AppUpdateJobFixture.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\GetUpdateLogFixture.cs" />
<Compile Include="ProviderTests\UpdateProviderTests\GetAvilableUpdateFixture.cs" />
<Compile Include="SortHelperTest.cs" />
<Compile Include="ProviderTests\EpisodeProviderTest_DeleteInvalidEpisodes.cs" />

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{
class GetUpdateLogFixture : CoreTest
{
String UpdateLogFolder;
[SetUp]
public void setup()
{
WithTempAsAppPath();
UpdateLogFolder = Mocker.GetMock<EnviromentProvider>().Object.GetUpdateLogFolder();
Mocker.GetMock<DiskProvider>()
.Setup(c => c.GetFiles(UpdateLogFolder, SearchOption.TopDirectoryOnly))
.Returns(new List<string>
{
"C:\\nzbdrone\\update\\2011.09.20-19-08.txt",
"C:\\nzbdrone\\update\\2011.10.20-20-08.txt",
"C:\\nzbdrone\\update\\2011.12.20-21-08.txt"
});
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(UpdateLogFolder))
.Returns(true);
}
[Test]
public void get_logs_should_return_empty_list_if_directory_doesnt_exist()
{
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(UpdateLogFolder))
.Returns(false);
var logs = Mocker.Resolve<UpdateProvider>().UpdateLogFile();
logs.Should().BeEmpty();
}
[Test]
public void get_logs_should_return_list_of_files_in_log_folder()
{
var logs = Mocker.Resolve<UpdateProvider>().UpdateLogFile();
logs.Should().HaveCount(3);
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
@ -17,10 +18,8 @@ namespace NzbDrone.Core.Providers
{
private readonly HttpProvider _httpProvider;
private readonly ConfigProvider _configProvider;
private readonly ConfigFileProvider _configFileProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly ArchiveProvider _archiveProvider;
private readonly ProcessProvider _processProvider;
private readonly DiskProvider _diskProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
@ -29,15 +28,12 @@ namespace NzbDrone.Core.Providers
[Inject]
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider, ConfigFileProvider configFileProvider,
EnviromentProvider enviromentProvider, ArchiveProvider archiveProvider, ProcessProvider processProvider, DiskProvider diskProvider)
public UpdateProvider(HttpProvider httpProvider, ConfigProvider configProvider,
EnviromentProvider enviromentProvider, DiskProvider diskProvider)
{
_httpProvider = httpProvider;
_configProvider = configProvider;
_configFileProvider = configFileProvider;
_enviromentProvider = enviromentProvider;
_archiveProvider = archiveProvider;
_processProvider = processProvider;
_diskProvider = diskProvider;
}
@ -77,5 +73,23 @@ namespace NzbDrone.Core.Providers
logger.Trace("No updates available");
return null;
}
public virtual Dictionary<DateTime, string> UpdateLogFile()
{
var list = new Dictionary<DateTime, string>();
CultureInfo provider = CultureInfo.InvariantCulture;
if (_diskProvider.FolderExists(_enviromentProvider.GetUpdateLogFolder()))
{
var files = _diskProvider.GetFiles(_enviromentProvider.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly).ToList();
foreach (var file in files.Select(c => new FileInfo(c)).OrderByDescending(c=>c.Name))
{
list.Add(DateTime.ParseExact(file.Name.Replace(file.Extension, string.Empty), "yyyy.MM.dd-H-mm", provider), file.FullName);
}
}
return list;
}
}
}

@ -43,7 +43,7 @@ namespace NzbDrone.Test.Common
[TearDown]
public void TestBaseTearDown()
{
Mocker.VerifyAllMocks();
}
protected virtual void WithStrictMocker()

@ -1,5 +1,8 @@
using System.Linq;
using System;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Web.Models;
@ -10,23 +13,39 @@ namespace NzbDrone.Web.Controllers
{
private readonly UpdateProvider _updateProvider;
private readonly JobProvider _jobProvider;
private readonly EnviromentProvider _enviromentProvider;
private readonly DiskProvider _diskProvider;
public UpdateController(UpdateProvider updateProvider, JobProvider jobProvider)
public UpdateController(UpdateProvider updateProvider, JobProvider jobProvider,
EnviromentProvider enviromentProvider, DiskProvider diskProvider)
{
_updateProvider = updateProvider;
_jobProvider = jobProvider;
_enviromentProvider = enviromentProvider;
_diskProvider = diskProvider;
}
public ActionResult Index()
{
return View(_updateProvider.GetAvilableUpdate());
var updateModel = new UpdateModel();
updateModel.UpdatePackage = _updateProvider.GetAvilableUpdate();
updateModel.LogFiles = _updateProvider.UpdateLogFile();
updateModel.LogFolder = _enviromentProvider.GetUpdateLogFolder();
return View(updateModel);
}
public ActionResult StartUpdate()
{
_jobProvider.QueueJob(typeof(AppUpdateJob), 0, 0);
return Json(new NotificationResult() { Title = "Update will begin shortly", NotificationType = NotificationType.Info, Text = "NzbDrone will restart automatically."});
return Json(new NotificationResult { Title = "Update will begin shortly", NotificationType = NotificationType.Info, Text = "NzbDrone will restart automatically." });
}
public ActionResult ViewLog( string filepath)
{
ViewBag.Log = _diskProvider.ReadAllText(filepath).Replace(Environment.NewLine, "<br/>");
return View();
}
}
}

@ -40,12 +40,10 @@ namespace NzbDrone.Web
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
//WebAssetDefaultSettings.UseTelerikContentDeliveryNetwork = true;
RegisterRoutes(RouteTable.Routes);
//base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
var razor = ViewEngines.Engines.Where(e => e.GetType() == typeof(RazorViewEngine)).Single();
var razor = ViewEngines.Engines.Single(e => e is RazorViewEngine);
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(razor);
@ -57,12 +55,12 @@ namespace NzbDrone.Web
protected override IKernel CreateKernel()
{
LogManager.Configuration = new XmlLoggingConfiguration(new EnviromentProvider().GetNlogConfigPath(), false);
Common.LogConfiguration.RegisterUdpLogger();
Common.LogConfiguration.RegisterExceptioneer();
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
LogConfiguration.RegisterUdpLogger();
LogConfiguration.RegisterExceptioneer();
LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
var dispatch = new CentralDispatch();
Logger.Info("NzbDrone Starting up.");

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NzbDrone.Core.Model;
namespace NzbDrone.Web.Models
{
public class UpdateModel
{
public UpdatePackage UpdatePackage { get; set; }
public Dictionary<DateTime, string> LogFiles { get; set; }
public String LogFolder { get; set; }
}
}

@ -497,6 +497,7 @@
<Compile Include="Models\SystemSettingsModel.cs" />
<Compile Include="Models\TvDbSearchResultModel.cs" />
<Compile Include="Models\UpcomingEpisodeModel.cs" />
<Compile Include="Models\UpdateModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@ -945,6 +946,9 @@
<ItemGroup>
<Content Include="Views\Update\Index.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Update\ViewLog.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -1,8 +1,8 @@
@model NzbDrone.Core.Model.UpdatePackage
@model NzbDrone.Web.Models.UpdateModel
@section TitleContent{
Update
}
@if (Model == null)
@if (Model.UpdatePackage == null)
{
<h2>
There are no updates available.</h2>
@ -10,7 +10,21 @@ Update
else
{
<h2>
Available Update: @Model.Version
Available Update: @Model.UpdatePackage.Version
@Ajax.ActionLink("Update", "StartUpdate", "Update", null)
</h2>
}
@if (Model.LogFiles.Count != 0)
{
<h3>
Update Logs (@Model.LogFolder)
</h3>
<br />
foreach (var log in Model.LogFiles)
{
<div>
<a href="@Url.Action("ViewLog", "Update", new { filePath = log.Value })">
@log.Key.ToString("MMM dd, hh:mm tt")</a>
</div>
}
}

@ -0,0 +1,4 @@
@section TitleContent{
Update Log
}
@Html.Raw(ViewBag.Log)
Loading…
Cancel
Save