Almost finished #659

This commit is contained in:
Jamie.Rees 2016-11-07 17:21:05 +00:00
commit 0950f20278
14 changed files with 543 additions and 119 deletions

View file

@ -186,7 +186,6 @@ namespace PlexRequests.UI.Modules
Get["/emailnotification"] = _ => EmailNotifications();
Post["/emailnotification"] = _ => SaveEmailNotifications();
Post["/testemailnotification", true] = async (x, ct) => await TestEmailNotifications();
Get["/status", true] = async (x, ct) => await Status();
Get["/pushbulletnotification"] = _ => PushbulletNotifications();
Post["/pushbulletnotification"] = _ => SavePushbulletNotifications();
@ -209,7 +208,7 @@ namespace PlexRequests.UI.Modules
Post["/createapikey"] = x => CreateApiKey();
Post["/autoupdate"] = x => AutoUpdate();
Post["/testslacknotification", true] = async (x, ct) => await TestSlackNotification();
@ -568,28 +567,6 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private async Task<Negotiator> Status()
{
var checker = new StatusChecker();
var status = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async () => await checker.GetStatus(), 30);
var md = new Markdown(new MarkdownOptions { AutoNewLines = true, AutoHyperlink = true });
status.ReleaseNotes = md.Transform(status.ReleaseNotes);
return View["Status", status];
}
private Response AutoUpdate()
{
var url = Request.Form["url"];
var startInfo = Type.GetType("Mono.Runtime") != null
? new ProcessStartInfo("mono PlexRequests.Updater.exe") { Arguments = url }
: new ProcessStartInfo("PlexRequests.Updater.exe") { Arguments = url };
Process.Start(startInfo);
Environment.Exit(0);
return Nancy.Response.NoBody;
}
private Negotiator PushbulletNotifications()
{

View file

@ -0,0 +1,100 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SystemStatusModule.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using MarkdownSharp;
using Nancy;
using Nancy.ModelBinding;
using Nancy.Responses.Negotiation;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Core.StatusChecker;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Permissions;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules.Admin
{
public class SystemStatusModule : BaseModule
{
public SystemStatusModule(ISettingsService<PlexRequestSettings> settingsService, ICacheProvider cache, ISettingsService<SystemSettings> ss) : base("admin", settingsService)
{
Cache = cache;
SystemSettings = ss;
Security.HasPermissionsResponse(Permissions.Administrator);
Get["/status", true] = async (x, ct) => await Status();
Post["/save", true] = async (x, ct) => await Save();
Post["/autoupdate"] = x => AutoUpdate();
}
private ICacheProvider Cache { get; }
private ISettingsService<SystemSettings> SystemSettings { get; }
private async Task<Negotiator> Status()
{
var settings = await SystemSettings.GetSettingsAsync();
var checker = new StatusChecker(SystemSettings);
var status = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async () => await checker.GetStatus(), 30);
var md = new Markdown(new MarkdownOptions { AutoNewLines = true, AutoHyperlink = true });
status.ReleaseNotes = md.Transform(status.ReleaseNotes);
settings.Status = status;
return View["Status", settings];
}
private async Task<Response> Save()
{
var settings = this.Bind<SystemSettings>();
await SystemSettings.SaveSettingsAsync(settings);
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully Saved your settings"});
}
private Response AutoUpdate()
{
var url = Request.Form["url"];
var startInfo = Type.GetType("Mono.Runtime") != null
? new ProcessStartInfo("mono PlexRequests.Updater.exe") { Arguments = url }
: new ProcessStartInfo("PlexRequests.Updater.exe") { Arguments = url };
Process.Start(startInfo);
Environment.Exit(0);
return Nancy.Response.NoBody;
}
}
}

View file

@ -33,6 +33,7 @@ using NLog;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Core.StatusChecker;
using PlexRequests.Helpers;
using PlexRequests.UI.Models;
@ -40,9 +41,10 @@ namespace PlexRequests.UI.Modules
{
public class UpdateCheckerModule : BaseAuthModule
{
public UpdateCheckerModule(ICacheProvider provider, ISettingsService<PlexRequestSettings> pr) : base("updatechecker", pr)
public UpdateCheckerModule(ICacheProvider provider, ISettingsService<PlexRequestSettings> pr, ISettingsService<SystemSettings> settings) : base("updatechecker", pr)
{
Cache = provider;
SystemSettings = settings;
Get["/", true] = async (x,ct) => await CheckLatestVersion();
}
@ -50,6 +52,7 @@ namespace PlexRequests.UI.Modules
private ICacheProvider Cache { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private ISettingsService<SystemSettings> SystemSettings { get; }
private async Task<Response> CheckLatestVersion()
{
@ -62,7 +65,7 @@ namespace PlexRequests.UI.Modules
#if DEBUG
return Response.AsJson(new JsonUpdateAvailableModel {UpdateAvailable = false});
#endif
var checker = new StatusChecker();
var checker = new StatusChecker(SystemSettings);
var release = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async() => await checker.GetStatus(), 30);
return Response.AsJson(release.UpdateAvailable