From 818c2e80f7d376f6498d63a613b06eab80bf1ec6 Mon Sep 17 00:00:00 2001 From: Drewster727 Date: Wed, 22 Jun 2016 11:27:09 -0500 Subject: [PATCH 1/5] better way of obtaining clean enum string --- .../Notification/EmailMessageNotification.cs | 4 ++-- PlexRequests.Services/Notification/PushbulletNotification.cs | 4 ++-- PlexRequests.Services/Notification/PushoverNotification.cs | 2 +- PlexRequests.Store/RequestedModel.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PlexRequests.Services/Notification/EmailMessageNotification.cs b/PlexRequests.Services/Notification/EmailMessageNotification.cs index 466ff7a24..77b71e58a 100644 --- a/PlexRequests.Services/Notification/EmailMessageNotification.cs +++ b/PlexRequests.Services/Notification/EmailMessageNotification.cs @@ -120,8 +120,8 @@ namespace PlexRequests.Services.Notification { var message = new MimeMessage { - Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" }, - Subject = $"Plex Requests: New {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} request for {model.Title}!" + Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" }, + Subject = $"Plex Requests: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); diff --git a/PlexRequests.Services/Notification/PushbulletNotification.cs b/PlexRequests.Services/Notification/PushbulletNotification.cs index 8eda8d0b9..f6003bf1d 100644 --- a/PlexRequests.Services/Notification/PushbulletNotification.cs +++ b/PlexRequests.Services/Notification/PushbulletNotification.cs @@ -105,8 +105,8 @@ namespace PlexRequests.Services.Notification private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings) { - var message = $"The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; - var pushTitle = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} {model.Title} has been requested!"; + var message = $"The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; + var pushTitle = $"Plex Requests: The {model.RequestType.GetString()?.ToLower()} {model.Title} has been requested!"; await Push(settings, message, pushTitle); } diff --git a/PlexRequests.Services/Notification/PushoverNotification.cs b/PlexRequests.Services/Notification/PushoverNotification.cs index 9831e6562..b259a6faa 100644 --- a/PlexRequests.Services/Notification/PushoverNotification.cs +++ b/PlexRequests.Services/Notification/PushoverNotification.cs @@ -105,7 +105,7 @@ namespace PlexRequests.Services.Notification private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings) { - var message = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; + var message = $"Plex Requests: The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; await Push(settings, message); } diff --git a/PlexRequests.Store/RequestedModel.cs b/PlexRequests.Store/RequestedModel.cs index 254b4f7be..b203db7d3 100644 --- a/PlexRequests.Store/RequestedModel.cs +++ b/PlexRequests.Store/RequestedModel.cs @@ -80,7 +80,7 @@ namespace PlexRequests.Store public static class RequestTypeDisplay { - public static string Get(RequestType type) + public static string GetString(this RequestType type) { switch (type) { From 752915ea0a2dbeac9fc0da4e5ef782cbab988fda Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 22 Jun 2016 20:22:38 +0100 Subject: [PATCH 2/5] Potential fix for #350 --- PlexRequests.Services/Jobs/CouchPotatoCacher.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs index 3fb831b12..8a9f666b1 100644 --- a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs +++ b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs @@ -87,7 +87,12 @@ namespace PlexRequests.Services.Jobs public int[] QueuedIds() { var movies = Cache.Get(CacheKeys.CouchPotatoQueued); - return movies?.movies?.Select(x => x.info.tmdb_id).ToArray() ?? new int[] { }; + var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast().ToArray(); + if (items == null) + { + return new int[] { }; + } + return items; } public void Execute(IJobExecutionContext context) From 0b1edcc488956a7efd1a679d66d7ceb0057719c2 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 22 Jun 2016 20:33:24 +0100 Subject: [PATCH 3/5] Slight changes, moved the donate button --- .../Jobs/CouchPotatoCacher.cs | 6 +- PlexRequests.UI/Views/Shared/_Layout.cshtml | 314 +++++++++--------- 2 files changed, 159 insertions(+), 161 deletions(-) diff --git a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs index 8a9f666b1..471965842 100644 --- a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs +++ b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs @@ -88,11 +88,7 @@ namespace PlexRequests.Services.Jobs { var movies = Cache.Get(CacheKeys.CouchPotatoQueued); var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast().ToArray(); - if (items == null) - { - return new int[] { }; - } - return items; + return items ?? new int[] { }; } public void Execute(IJobExecutionContext context) diff --git a/PlexRequests.UI/Views/Shared/_Layout.cshtml b/PlexRequests.UI/Views/Shared/_Layout.cshtml index fee4537f8..b108cf6ce 100644 --- a/PlexRequests.UI/Views/Shared/_Layout.cshtml +++ b/PlexRequests.UI/Views/Shared/_Layout.cshtml @@ -1,157 +1,159 @@ -@using Nancy.Security -@using Nancy.Session -@using PlexRequests.UI.Helpers -@using PlexRequests.UI.Models -@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase -@{ - var baseUrl = Html.GetBaseUrl(); - var url = string.Empty; - if (!string.IsNullOrEmpty(baseUrl.ToHtmlString())) - { - url = "/" + baseUrl.ToHtmlString(); - } -} - - - - Plex Requests - - - @Html.LoadAnalytics() - @Html.LoadAssets() - - - - - - -
- @RenderBody() -
-
- - - -
- - - \ No newline at end of file From af9953be6cf280ecf4cec08048f145b03ed4f9b7 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 22 Jun 2016 21:49:50 +0100 Subject: [PATCH 4/5] Added logging #350 --- PlexRequests.Services/Jobs/CouchPotatoCacher.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs index 471965842..ee93513ab 100644 --- a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs +++ b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs @@ -86,7 +86,12 @@ namespace PlexRequests.Services.Jobs // we do not want to set here... public int[] QueuedIds() { + Log.Error("This is not an error, starting to get the CP Cached Id's"); + var movies = Cache.Get(CacheKeys.CouchPotatoQueued); + Log.Error("Cached result:"); + Log.Error(movies.DumpJson()); + var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast().ToArray(); return items ?? new int[] { }; } From 8b52ba29679bcb0a602d4c057ed416c61a196cef Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 22 Jun 2016 22:21:25 +0100 Subject: [PATCH 5/5] Generic try catch to fix #350 --- .../Jobs/CouchPotatoCacher.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs index ee93513ab..be36d004f 100644 --- a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs +++ b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs @@ -24,6 +24,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion + +using System; using System.Linq; using NLog; @@ -86,14 +88,18 @@ namespace PlexRequests.Services.Jobs // we do not want to set here... public int[] QueuedIds() { - Log.Error("This is not an error, starting to get the CP Cached Id's"); - - var movies = Cache.Get(CacheKeys.CouchPotatoQueued); - Log.Error("Cached result:"); - Log.Error(movies.DumpJson()); + try + { + var movies = Cache.Get(CacheKeys.CouchPotatoQueued); - var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast().ToArray(); - return items ?? new int[] { }; + var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast().ToArray(); + return items ?? new int[] { }; + } + catch (Exception e) + { + Log.Error(e); + return new int[] {}; + } } public void Execute(IJobExecutionContext context)