diff --git a/PlexRequests.Core/IStatusChecker.cs b/PlexRequests.Core/IStatusChecker.cs new file mode 100644 index 000000000..eec365b68 --- /dev/null +++ b/PlexRequests.Core/IStatusChecker.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Octokit; +using PlexRequests.Core.Models; + +namespace PlexRequests.Core +{ + public interface IStatusChecker + { + Task GetStatus(); + } +} \ No newline at end of file diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index 4def9282d..064f319e3 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -54,6 +54,10 @@ ..\packages\Quartz.2.3.3\lib\net40\Quartz.dll True + + ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + True + @@ -82,6 +86,7 @@ + @@ -120,9 +125,12 @@ + - + + + diff --git a/PlexRequests.Core/SettingModels/SystemSettings.cs b/PlexRequests.Core/SettingModels/SystemSettings.cs new file mode 100644 index 000000000..fe60baabc --- /dev/null +++ b/PlexRequests.Core/SettingModels/SystemSettings.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SystemSettings.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 PlexRequests.Core.Models; + +namespace PlexRequests.Core.SettingModels +{ + public class SystemSettings : Settings + { + public bool UseEarlyAccessPreviewBuilds { get; set; } + + public StatusModel Status { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/StatusChecker.cs b/PlexRequests.Core/StatusChecker.cs deleted file mode 100644 index bf9f0485e..000000000 --- a/PlexRequests.Core/StatusChecker.cs +++ /dev/null @@ -1,83 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: StatusChecker.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.Linq; -using System.Threading.Tasks; - -using Octokit; - -using PlexRequests.Core.Models; -using PlexRequests.Helpers; - -namespace PlexRequests.Core -{ - public class StatusChecker - { - public StatusChecker() - { - Git = new GitHubClient(new ProductHeaderValue("PlexRequests-StatusChecker")); - } - private IGitHubClient Git { get; } - private const string Owner = "tidusjar"; - private const string RepoName = "PlexRequests.Net"; - - public async Task GetLatestRelease() - { - var releases = await Git.Repository.Release.GetAll(Owner, RepoName); - return releases.FirstOrDefault(); - } - - public async Task GetStatus() - { - var assemblyVersion = AssemblyHelper.GetProductVersion(); - var model = new StatusModel - { - Version = assemblyVersion, - }; - - var latestRelease = await GetLatestRelease(); - if (latestRelease == null) - { - return new StatusModel { Version = "Unknown" }; - } - var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries); - var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty; - - if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase)) - { - model.UpdateAvailable = true; - model.UpdateUri = latestRelease.HtmlUrl; - } - - model.ReleaseNotes = latestRelease.Body; - model.DownloadUri = latestRelease.Assets[0].BrowserDownloadUrl; - model.ReleaseTitle = latestRelease.Name; - - return model; - } - } -} \ No newline at end of file diff --git a/PlexRequests.Core/StatusChecker/AppveyorArtifactResult.cs b/PlexRequests.Core/StatusChecker/AppveyorArtifactResult.cs new file mode 100644 index 000000000..9e67262d6 --- /dev/null +++ b/PlexRequests.Core/StatusChecker/AppveyorArtifactResult.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AppveyorArtifactResult.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 +namespace PlexRequests.Core.StatusChecker +{ + public class AppveyorArtifactResult + { + public string fileName { get; set; } + public string type { get; set; } + public int size { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/StatusChecker/AppveyorBranchResult.cs b/PlexRequests.Core/StatusChecker/AppveyorBranchResult.cs new file mode 100644 index 000000000..766e5a804 --- /dev/null +++ b/PlexRequests.Core/StatusChecker/AppveyorBranchResult.cs @@ -0,0 +1,138 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AppveyorBranchResult.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.Collections.Generic; + +namespace PlexRequests.Core.StatusChecker +{ + public class NuGetFeed + { + public string id { get; set; } + public string name { get; set; } + public bool publishingEnabled { get; set; } + public string created { get; set; } + } + + public class AccessRightDefinition + { + public string name { get; set; } + public string description { get; set; } + } + + public class AccessRight + { + public string name { get; set; } + public bool allowed { get; set; } + } + + public class RoleAce + { + public int roleId { get; set; } + public string name { get; set; } + public bool isAdmin { get; set; } + public List accessRights { get; set; } + } + + public class SecurityDescriptor + { + public List accessRightDefinitions { get; set; } + public List roleAces { get; set; } + } + + public class Project + { + public int projectId { get; set; } + public int accountId { get; set; } + public string accountName { get; set; } + public List builds { get; set; } + public string name { get; set; } + public string slug { get; set; } + public string repositoryType { get; set; } + public string repositoryScm { get; set; } + public string repositoryName { get; set; } + public string repositoryBranch { get; set; } + public bool isPrivate { get; set; } + public bool skipBranchesWithoutAppveyorYml { get; set; } + public bool enableSecureVariablesInPullRequests { get; set; } + public bool enableSecureVariablesInPullRequestsFromSameRepo { get; set; } + public bool enableDeploymentInPullRequests { get; set; } + public bool rollingBuilds { get; set; } + public bool alwaysBuildClosedPullRequests { get; set; } + public string tags { get; set; } + public NuGetFeed nuGetFeed { get; set; } + public SecurityDescriptor securityDescriptor { get; set; } + public string created { get; set; } + public string updated { get; set; } + } + + public class Job + { + public string jobId { get; set; } + public string name { get; set; } + public bool allowFailure { get; set; } + public int messagesCount { get; set; } + public int compilationMessagesCount { get; set; } + public int compilationErrorsCount { get; set; } + public int compilationWarningsCount { get; set; } + public int testsCount { get; set; } + public int passedTestsCount { get; set; } + public int failedTestsCount { get; set; } + public int artifactsCount { get; set; } + public string status { get; set; } + public string started { get; set; } + public string finished { get; set; } + public string created { get; set; } + public string updated { get; set; } + } + + public class Build + { + public int buildId { get; set; } + public List jobs { get; set; } + public int buildNumber { get; set; } + public string version { get; set; } + public string message { get; set; } + public string branch { get; set; } + public bool isTag { get; set; } + public string commitId { get; set; } + public string authorName { get; set; } + public string committerName { get; set; } + public string committed { get; set; } + public List messages { get; set; } + public string status { get; set; } + public string started { get; set; } + public string finished { get; set; } + public string created { get; set; } + public string updated { get; set; } + } + + public class AppveyorBranchResult + { + public Project project { get; set; } + public Build build { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/StatusChecker/StatusChecker.cs b/PlexRequests.Core/StatusChecker/StatusChecker.cs new file mode 100644 index 000000000..fcf41f65b --- /dev/null +++ b/PlexRequests.Core/StatusChecker/StatusChecker.cs @@ -0,0 +1,153 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StatusChecker.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.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octokit; +using PlexRequests.Api; +using PlexRequests.Core.Models; +using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers; +using RestSharp; + +namespace PlexRequests.Core.StatusChecker +{ + public class StatusChecker : IStatusChecker + { + public StatusChecker(ISettingsService ss) + { + SystemSettings = ss; + Git = new GitHubClient(new ProductHeaderValue("PlexRequests-StatusChecker")); + } + + private ISettingsService SystemSettings { get; } + + private IGitHubClient Git { get; } + private const string Owner = "tidusjar"; + private const string RepoName = "PlexRequests.Net"; + private const string AppveyorApiUrl = "https://ci.appveyor.com/api"; + + private const string Api = + "48Ku58C0794nBrXra8IxWav+dc6NqgkRw+PZB3/bQwbt/D0IrnJQkgtjzo0bd6nkooLMKsC8M+Ab7jyBO+ROjY14VRuxffpDopX9r0iG/fjBl6mZVvqkm+VTDNstDtzp"; + + public async Task GetStatus() + { + var settings = await SystemSettings.GetSettingsAsync(); + var isEap = settings.UseEarlyAccessPreviewBuilds; + + if (isEap) + { + // Early Access Preview Releases + return GetLatestEapRelease(); + } + + // Stable releases + return await GetLatestGithubRelease(); + } + + private async Task GetLatestGithubRelease() + { + var assemblyVersion = AssemblyHelper.GetProductVersion(); + var model = new StatusModel + { + Version = assemblyVersion, + }; + + var releases = await Git.Repository.Release.GetAll(Owner, RepoName); + var latestRelease = releases.FirstOrDefault(); + + if (latestRelease == null) + { + return new StatusModel { Version = "Unknown" }; + } + var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries); + var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty; + + if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase)) + { + model.UpdateAvailable = true; + model.UpdateUri = latestRelease.HtmlUrl; + } + + model.ReleaseNotes = latestRelease.Body; + model.DownloadUri = latestRelease.Assets[0].BrowserDownloadUrl; + model.ReleaseTitle = latestRelease.Name; + + return model; + } + + private StatusModel GetLatestEapRelease() + { + var request = new ApiRequest(); + + // Get latest EAP Build + var eapBranchRequest = new RestRequest + { + Resource = "/projects/tidusjar/requestplex/branch/EAP", + Method = Method.GET + }; + + var api = StringCipher.Decrypt(Api,"Appveyor"); + eapBranchRequest.AddHeader("Authorization", $"Bearer {api}"); + eapBranchRequest.AddHeader("Content-Type", "application/json"); + + var branchResult = request.ExecuteJson(eapBranchRequest, new Uri(AppveyorApiUrl)); + + var jobId = branchResult.build.jobs.FirstOrDefault()?.jobId ?? string.Empty; + + if (string.IsNullOrEmpty(jobId)) + { + return new StatusModel {UpdateAvailable = false}; + } + + // Get artifacts from the EAP Build + var eapAtrifactRequest = new RestRequest + { + Resource = $"/buildjobs/{jobId}/artifacts", + Method = Method.GET + }; + eapAtrifactRequest.AddHeader("Authorization", $"Bearer {api}"); + eapAtrifactRequest.AddHeader("Content-Type", "application/json"); + + var artifactResult = request.ExecuteJson>(eapAtrifactRequest, new Uri(AppveyorApiUrl)).FirstOrDefault(); + + var downloadLink = $"{AppveyorApiUrl}/buildjobs/{jobId}/artifacts/{artifactResult.fileName}"; + + return new StatusModel + { + DownloadUri = downloadLink, + ReleaseNotes = "Early Access Preview (See recent commits for details)", + ReleaseTitle = "Plex Requests Early Access Preview", + Version = branchResult.build.version, + UpdateAvailable = true, + UpdateUri = downloadLink + }; + } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/packages.config b/PlexRequests.Core/packages.config index 6f3ca4a6c..e8f81f5a9 100644 --- a/PlexRequests.Core/packages.config +++ b/PlexRequests.Core/packages.config @@ -8,5 +8,6 @@ + \ No newline at end of file diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/Admin/AdminModule.cs similarity index 97% rename from PlexRequests.UI/Modules/AdminModule.cs rename to PlexRequests.UI/Modules/Admin/AdminModule.cs index e48cd1fb7..06fe01780 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/Admin/AdminModule.cs @@ -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 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() { diff --git a/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs new file mode 100644 index 000000000..e3a04e39d --- /dev/null +++ b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs @@ -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 settingsService, ICacheProvider cache, ISettingsService 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 { get; } + + private async Task 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 Save() + { + var settings = this.Bind(); + + 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; + } + + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/UpdateCheckerModule.cs b/PlexRequests.UI/Modules/UpdateCheckerModule.cs index ddf869f28..3aa6a657d 100644 --- a/PlexRequests.UI/Modules/UpdateCheckerModule.cs +++ b/PlexRequests.UI/Modules/UpdateCheckerModule.cs @@ -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 pr) : base("updatechecker", pr) + public UpdateCheckerModule(ICacheProvider provider, ISettingsService pr, ISettingsService 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 { get; } private async Task 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 diff --git a/PlexRequests.UI/NinjectModules/ConfigurationModule.cs b/PlexRequests.UI/NinjectModules/ConfigurationModule.cs index 57cb76235..0ed22372a 100644 --- a/PlexRequests.UI/NinjectModules/ConfigurationModule.cs +++ b/PlexRequests.UI/NinjectModules/ConfigurationModule.cs @@ -33,6 +33,7 @@ using Ninject.Modules; using PlexRequests.Core; using PlexRequests.Core.Migration; +using PlexRequests.Core.StatusChecker; using PlexRequests.Helpers; using PlexRequests.Services.Interfaces; using PlexRequests.Services.Notification; @@ -56,6 +57,8 @@ namespace PlexRequests.UI.NinjectModules Bind().To().InSingletonScope(); Bind().To(); + + Bind().To(); } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index bc78a9f77..a18aec630 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -244,6 +244,7 @@ + @@ -324,7 +325,7 @@ - + diff --git a/PlexRequests.UI/Views/Admin/Status.cshtml b/PlexRequests.UI/Views/Admin/Status.cshtml index c6e3f6588..2051ea385 100644 --- a/PlexRequests.UI/Views/Admin/Status.cshtml +++ b/PlexRequests.UI/Views/Admin/Status.cshtml @@ -1,4 +1,5 @@ @using PlexRequests.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @Html.Partial("_Sidebar")
@@ -8,16 +9,35 @@
- +
+
+
+
+ + @if (Model.UseEarlyAccessPreviewBuilds) + { + + } + else + { + + } + +
+
+ +
+ +
- @if (Model.UpdateAvailable) + @if (Model.Status.UpdateAvailable) { - +
- @**@ //TODO + } else { @@ -26,14 +46,14 @@
- @if (Model.UpdateAvailable) + @if (Model.Status.UpdateAvailable) {

- @Model.ReleaseTitle + @Model.Status.ReleaseTitle


- @Html.Raw(Model.ReleaseNotes) + @Html.Raw(Model.Status.ReleaseNotes) } @@ -58,7 +78,7 @@ $.ajax({ type: "Post", url: "autoupdate", - data: { url: "@Model.DownloadUri" }, + data: { url: "@Model.Status.DownloadUri" }, dataType: "json", error: function () { setTimeout( @@ -68,4 +88,23 @@ } }); }); + + $('#saveSettings').click(function (e) { + e.preventDefault(); + var $form = $("#mainForm"); + $.ajax({ + type: $form.prop("method"), + url: $form.prop("action"), + data: $form.serialize(), + dataType: "json", + success: function (response) { + if (response.result === true) { + generateNotify(response.message, "success"); + + } else { + generateNotify(response.message, "warning"); + } + } + }); + }); \ No newline at end of file