From defc5a7a91f5720ab88966803caeee9043eb5251 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Sun, 11 Dec 2016 19:21:42 +0000 Subject: [PATCH 1/4] error checking around GA --- PlexRequests.Helpers/Analytics/Analytics.cs | 80 ++++++++++++++++----- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/PlexRequests.Helpers/Analytics/Analytics.cs b/PlexRequests.Helpers/Analytics/Analytics.cs index ed7eed4fd..67a92ed33 100644 --- a/PlexRequests.Helpers/Analytics/Analytics.cs +++ b/PlexRequests.Helpers/Analytics/Analytics.cs @@ -49,41 +49,89 @@ namespace PlexRequests.Helpers.Analytics public void TrackEvent(Category category, Action action, string label, string username, string clientId, int? value = null) { - var cat = category.ToString(); - var act = action.ToString(); - Track(HitType.@event, username, cat, act, label, clientId, value); + try + { + + var cat = category.ToString(); + var act = action.ToString(); + Track(HitType.@event, username, cat, act, label, clientId, value); + } + catch (Exception ex) + { + Log.Error(ex); + } } public async void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null) { - var cat = category.ToString(); - var act = action.ToString(); - await TrackAsync(HitType.@event, username, cat, act, clientId, label, value); + try + { + var cat = category.ToString(); + var act = action.ToString(); + await TrackAsync(HitType.@event, username, cat, act, clientId, label, value); + + } + catch (Exception ex) + { + Log.Error(ex); + } } public void TrackPageview(Category category, Action action, string label, string username, string clientId, int? value = null) { - var cat = category.ToString(); - var act = action.ToString(); - Track(HitType.@pageview, username, cat, act, clientId, label, value); + try + { + var cat = category.ToString(); + var act = action.ToString(); + Track(HitType.@pageview, username, cat, act, clientId, label, value); + + } + catch (Exception ex) + { + Log.Error(ex); + } } public async Task TrackPageviewAsync(Category category, Action action, string label, string username, string clientId, int? value = null) { - var cat = category.ToString(); - var act = action.ToString(); - await TrackAsync(HitType.@pageview, username, cat, act, clientId, label, value); + try + { + var cat = category.ToString(); + var act = action.ToString(); + await TrackAsync(HitType.@pageview, username, cat, act, clientId, label, value); + + } + catch (Exception ex) + { + Log.Error(ex); + } } public void TrackException(string message, string username, string clientId, bool fatal) { - var fatalInt = fatal ? 1 : 0; - Track(HitType.exception, message, fatalInt, username, clientId); + try + { + + var fatalInt = fatal ? 1 : 0; + Track(HitType.exception, message, fatalInt, username, clientId); + } + catch (Exception ex) + { + Log.Error(ex); + } } public async Task TrackExceptionAsync(string message, string username, string clientId, bool fatal) { - var fatalInt = fatal ? 1 : 0; - await TrackAsync(HitType.exception, message, fatalInt, username, clientId); + try + { + + var fatalInt = fatal ? 1 : 0; + await TrackAsync(HitType.exception, message, fatalInt, username, clientId); + } + catch (Exception ex) + { + Log.Error(ex); + } } private void Track(HitType type, string username, string category, string action, string clientId, string label, int? value = null) From 9165f3f31e8c614c93479c6b8f0146bd78ed7135 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Mon, 12 Dec 2016 08:43:40 +0000 Subject: [PATCH 2/4] added optional launch args for the auto updater --- .../Modules/Admin/SystemStatusModule.cs | 19 +++++++++++-- .../Views/SystemStatus/Status.cshtml | 9 ++++-- PlexRequests.Updater/Program.cs | 9 +++++- PlexRequests.Updater/Updater.cs | 28 +++++++++++-------- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs index 3f5b33947..32bc92abe 100644 --- a/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs +++ b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs @@ -28,6 +28,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Reflection; using System.Threading.Tasks; using MarkdownSharp; using Nancy; @@ -118,10 +120,23 @@ namespace PlexRequests.UI.Modules.Admin Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, "AutoUpdate", Username, CookieHelper.GetAnalyticClientId(Cookies)); var url = Request.Form["url"]; + var args = (string)Request.Form["args"].ToString(); + var lowered = args.ToLower(); + var appPath = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(SystemStatusModule)).Location ?? string.Empty) ?? string.Empty, "PlexRequests.Updater.exe"); + + if (!string.IsNullOrEmpty(lowered)) + { + if (lowered.Contains("plexrequests.exe")) + { + lowered = lowered.Replace("plexrequests.exe", ""); + } + } + + var startArgs = string.IsNullOrEmpty(lowered) ? appPath : $"{lowered} Plexrequests.Updater.exe"; var startInfo = Type.GetType("Mono.Runtime") != null - ? new ProcessStartInfo("mono PlexRequests.Updater.exe") { Arguments = url } - : new ProcessStartInfo("PlexRequests.Updater.exe") { Arguments = url }; + ? new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}", } + : new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}" }; Process.Start(startInfo); diff --git a/PlexRequests.UI/Views/SystemStatus/Status.cshtml b/PlexRequests.UI/Views/SystemStatus/Status.cshtml index 6b1c65403..9dd06986a 100644 --- a/PlexRequests.UI/Views/SystemStatus/Status.cshtml +++ b/PlexRequests.UI/Views/SystemStatus/Status.cshtml @@ -11,7 +11,7 @@ - + @if (Model.Status.UpdateAvailable) {
@@ -50,6 +50,8 @@ {
+ +
} else @@ -92,7 +94,10 @@ $.ajax({ type: "Post", url: "autoupdate", - data: { url: "@Model.Status.DownloadUri" }, + data: { + url: "@Model.Status.DownloadUri", + args: $('#args').val() + }, dataType: "json", error: function () { setTimeout( diff --git a/PlexRequests.Updater/Program.cs b/PlexRequests.Updater/Program.cs index 98692c11d..122f84966 100644 --- a/PlexRequests.Updater/Program.cs +++ b/PlexRequests.Updater/Program.cs @@ -8,7 +8,14 @@ namespace PlexRequests.Updater { Console.WriteLine ("Starting PlexRequests .Net updater"); var s = new Updater(); - s.Start(args[0]); + if (args.Length >= 2) + { + s.Start(args[0], args[1]); + } + else + { + s.Start(args[0], string.Empty); + } } } } diff --git a/PlexRequests.Updater/Updater.cs b/PlexRequests.Updater/Updater.cs index 2b32317b0..2b04776eb 100644 --- a/PlexRequests.Updater/Updater.cs +++ b/PlexRequests.Updater/Updater.cs @@ -29,6 +29,7 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Net; +using System.Reflection; using System.Windows.Forms; namespace PlexRequests.Updater @@ -67,7 +68,7 @@ namespace PlexRequests.Updater } } - public void Start(string downloadPath) + public void Start(string downloadPath, string launchOptions) { try { @@ -79,6 +80,10 @@ namespace PlexRequests.Updater Console.WriteLine("Downloading new version"); using (var client = new WebClient()) { + client.DownloadProgressChanged += (s, e) => + { + Console.WriteLine($"{e.ProgressPercentage}%"); + }; client.DownloadFile(downloadPath, TempPath); } Console.WriteLine("Downloaded!"); @@ -130,7 +135,7 @@ namespace PlexRequests.Updater RestoreBackup(); } - FinishUpdate(); + FinishUpdate(launchOptions); } } @@ -139,8 +144,9 @@ namespace PlexRequests.Updater Console.WriteLine("Backing up the current version"); try { - var dir = Directory.CreateDirectory("BackupSystem"); - var applicationPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath)); + var applicationPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty) ?? string.Empty; + + var dir = Directory.CreateDirectory(Path.Combine(applicationPath, "BackupSystem")); var allfiles = Directory.GetFiles(applicationPath, "*.*", SearchOption.AllDirectories); BackupPath = Path.Combine(dir.FullName, "PlexRequestsBackup.zip"); @@ -179,7 +185,9 @@ namespace PlexRequests.Updater { try { - return Directory.CreateDirectory("UpdateTemp"); + var location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty); + var path = Path.Combine(location, "UpdateTemp"); + return Directory.CreateDirectory(path); } catch (Exception e) { @@ -190,15 +198,13 @@ namespace PlexRequests.Updater } } - private void FinishUpdate() + private void FinishUpdate(string launchOptions) { - ProcessStartInfo startInfo; - startInfo = Type.GetType("Mono.Runtime") != null - ? new ProcessStartInfo("mono PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" } - : new ProcessStartInfo("PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" }; + var args = Error ? "-u 2" : "-u 1"; + var startInfo = new ProcessStartInfo($"{launchOptions}PlexRequests.exe") { Arguments = args, UseShellExecute = true }; Process.Start(startInfo); - + Environment.Exit(0); } } From 21039855619a4d1769654bed03f292ed99f9f855 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 13 Dec 2016 08:42:59 +0000 Subject: [PATCH 3/4] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 43fa06ea3..51425bda6 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,6 @@ ____ [![Github All Releases](https://img.shields.io/github/downloads/tidusjar/PlexRequests.net/total.svg)](https://github.com/tidusjar/PlexRequests.Net) [![Stories in Progress](https://badge.waffle.io/tidusjar/PlexRequests.Net.svg?label=in progress&title=In Progress)](http://waffle.io/tidusjar/PlexRequests.Net) -This is based off [Plex Requests by lokenx](https://github.com/lokenx/plexrequests-meteor) so big props to that guy! -I wanted to write a similar application in .Net! # Features Here some of the features Plex Requests.Net has: From a8865708accefa43e1ad4d02819eb830ed40f072 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Tue, 13 Dec 2016 09:14:51 +0000 Subject: [PATCH 4/4] Write out the actual file version --- PlexRequests.Core.Migration/Migrations/Version1100.cs | 2 +- PlexRequests.UI/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PlexRequests.Core.Migration/Migrations/Version1100.cs b/PlexRequests.Core.Migration/Migrations/Version1100.cs index 7e23cbdbe..bfe819fd3 100644 --- a/PlexRequests.Core.Migration/Migrations/Version1100.cs +++ b/PlexRequests.Core.Migration/Migrations/Version1100.cs @@ -243,7 +243,7 @@ namespace PlexRequests.Core.Migration.Migrations { return; } - var requestedModels = allRequests as RequestedModel[] ?? allRequests.ToArray(); + var requestedModels = allRequests.ToList(); foreach (var req in requestedModels) { if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/")) diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 2153aca13..76f00396e 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -128,7 +128,7 @@ namespace PlexRequests.UI private static void WriteOutVersion() { - var assemblyVer = AssemblyHelper.GetProductVersion(); + var assemblyVer = AssemblyHelper.GetFileVersion(); Log.Info($"Version: {assemblyVer}"); Console.WriteLine($"Version: {assemblyVer}"); }