From c7826003bc89d1f25989f51deb8f816383f48a0a Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 08:52:01 +0100 Subject: [PATCH 1/8] An attempt to fix #108 --- PlexRequests.Services/PlexAvailabilityChecker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PlexRequests.Services/PlexAvailabilityChecker.cs b/PlexRequests.Services/PlexAvailabilityChecker.cs index bc1cfb8e7..9b9f651ba 100644 --- a/PlexRequests.Services/PlexAvailabilityChecker.cs +++ b/PlexRequests.Services/PlexAvailabilityChecker.cs @@ -24,6 +24,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion +using System; using System.Collections.Generic; using System.Linq; @@ -97,17 +98,16 @@ namespace PlexRequests.Services { throw new ApplicationSettingsException("The settings are not configured for Plex or Authentication"); } + var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri); if (!string.IsNullOrEmpty(year)) { - var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri); - var result = results.Video?.FirstOrDefault(x => x.Title.Contains(title) && x.Year == year); + var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase) && x.Year == year); var directoryTitle = results.Directory?.Title == title && results.Directory?.Year == year; return result?.Title != null || directoryTitle; } else { - var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri); - var result = results.Video?.FirstOrDefault(x => x.Title.Contains(title)); + var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase)); var directoryTitle = results.Directory?.Title == title; return result?.Title != null || directoryTitle; } From 5843dee2a5f919025e6b92cef1cb8d7f35a35a79 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 09:58:23 +0100 Subject: [PATCH 2/8] Added the settings page for #32 --- PlexRequests.Core/PlexRequests.Core.csproj | 1 + .../SettingModels/HeadphonesSettings.cs | 58 +++++++ PlexRequests.UI/Bootstrapper.cs | 1 + PlexRequests.UI/Modules/AdminModule.cs | 37 +++- .../Modules/ApplicationTesterModule.cs | 6 + PlexRequests.UI/PlexRequests.UI.csproj | 3 + PlexRequests.UI/Views/Admin/Headphones.cshtml | 162 ++++++++++++++++++ PlexRequests.UI/Views/Admin/_Sidebar.cshtml | 8 + 8 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 PlexRequests.Core/SettingModels/HeadphonesSettings.cs create mode 100644 PlexRequests.UI/Views/Admin/Headphones.cshtml diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index a1e0538f7..13a1e74ec 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -74,6 +74,7 @@ + diff --git a/PlexRequests.Core/SettingModels/HeadphonesSettings.cs b/PlexRequests.Core/SettingModels/HeadphonesSettings.cs new file mode 100644 index 000000000..0da4971d7 --- /dev/null +++ b/PlexRequests.Core/SettingModels/HeadphonesSettings.cs @@ -0,0 +1,58 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoSettings.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 Newtonsoft.Json; +using PlexRequests.Helpers; + +namespace PlexRequests.Core.SettingModels +{ + public class HeadphonesSettings : Settings + { + public string Enabled { get; set; } + public string Ip { get; set; } + public int Port { get; set; } + public int ApiKey { get; set; } + public bool Ssl { get; set; } + public string SubDir { get; set; } + + [JsonIgnore] + public Uri FullUri + { + get + { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } + var formatted = Ip.ReturnUri(Port, Ssl); + return formatted; + } + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index 5e4f24343..e65ea82bd 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -76,6 +76,7 @@ namespace PlexRequests.UI container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); // Repo's container.Register, GenericRepository>(); diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index e8cd8961f..4009f1b5e 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -28,6 +28,8 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; +using System.Web.UI.HtmlControls; + using Humanizer; using MarkdownSharp; @@ -65,6 +67,7 @@ namespace PlexRequests.UI.Modules private ISettingsService EmailService { get; } private ISettingsService PushbulletService { get; } private ISettingsService PushoverService { get; } + private ISettingsService HeadphonesSerivce { get; } private IPlexApi PlexApi { get; } private ISonarrApi SonarrApi { get; } private IPushbulletApi PushbulletApi { get; } @@ -89,7 +92,8 @@ namespace PlexRequests.UI.Modules ISettingsService pushoverSettings, IPushoverApi pushoverApi, IRepository logsRepo, - INotificationService notify) : base("admin") + INotificationService notify, + ISettingsService headphones) : base("admin") { RpService = rpService; CpService = cpService; @@ -107,6 +111,7 @@ namespace PlexRequests.UI.Modules PushoverService = pushoverSettings; PushoverApi = pushoverApi; NotificationService = notify; + HeadphonesSerivce = headphones; #if !DEBUG this.RequiresAuthentication(); @@ -151,6 +156,9 @@ namespace PlexRequests.UI.Modules Get["/loglevel"] = _ => GetLogLevels(); Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level); Get["/loadlogs"] = _ => LoadLogs(); + + Get["/headphones"] = _ => Headphones(); + Post["/headphones"] = _ => SaveHeadphones(); } private Negotiator Authentication() @@ -509,5 +517,32 @@ namespace PlexRequests.UI.Modules LoggingHelper.ReconfigureLogLevel(newLevel); return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"}); } + + private Negotiator Headphones() + { + var settings = HeadphonesSerivce.GetSettings(); + return View["Headphones", settings]; + } + + private Response SaveHeadphones() + { + var settings = this.Bind(); + + var valid = this.Validate(settings); + if (!valid.IsValid) + { + var error = valid.SendJsonError(); + Log.Info("Error validating Headphones settings, message: {0}", error.Message); + return Response.AsJson(error); + } + Log.Trace(settings.DumpJson()); + + var result = HeadphonesSerivce.SaveSettings(settings); + + Log.Info("Saved headphones settings, result: {0}", result); + return Response.AsJson(result + ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Headphones!" } + : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApplicationTesterModule.cs b/PlexRequests.UI/Modules/ApplicationTesterModule.cs index 98d2bd591..98884d2f1 100644 --- a/PlexRequests.UI/Modules/ApplicationTesterModule.cs +++ b/PlexRequests.UI/Modules/ApplicationTesterModule.cs @@ -57,6 +57,7 @@ namespace PlexRequests.UI.Modules Post["/sonarr"] = _ => SonarrTest(); Post["/plex"] = _ => PlexTest(); Post["/sickrage"] = _ => SickRageTest(); + Post["/headphones"] = _ => HeadphonesTest(); } @@ -168,5 +169,10 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); } } + + private Response HeadphonesTest() + { + throw new NotImplementedException(); //TODO + } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index b561ad36b..9a32ef2b3 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -371,6 +371,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Views/Admin/Headphones.cshtml b/PlexRequests.UI/Views/Admin/Headphones.cshtml new file mode 100644 index 000000000..30f45985f --- /dev/null +++ b/PlexRequests.UI/Views/Admin/Headphones.cshtml @@ -0,0 +1,162 @@ +@Html.Partial("_Sidebar") +@{ + int port; + if (Model.Port == 0) + { + port = 8081; + } + else + { + port = Model.Port; + } +} +
+
+
+ Headphones Settings +
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+
+ +
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + + + +
+
+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml index efb8ce36b..e6d21e3fc 100644 --- a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml +++ b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml @@ -52,6 +52,14 @@ { SickRage } + @if (Context.Request.Path == "/admin/headphones") + { + Headphones + } + else + { + Headphones + } @if (Context.Request.Path == "/admin/emailnotification") { From fe0f6873e5af6ae8e17d1dcdd1b1b030cae6a392 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 10:34:20 +0100 Subject: [PATCH 3/8] Made the feedback from Sonarr better when Sonarr already has the series #85 --- .../PlexRequests.Api.Models.csproj | 1 + .../Sonarr/SonarrAddSeries.cs | 4 +++ PlexRequests.Api.Models/Sonarr/SonarrError.cs | 36 +++++++++++++++++++ PlexRequests.Api/ApiRequest.cs | 11 +++--- PlexRequests.Api/SonarrApi.cs | 15 ++++++-- PlexRequests.UI/Helpers/TvSender.cs | 4 --- PlexRequests.UI/Modules/ApprovalModule.cs | 5 +-- PlexRequests.UI/Modules/SearchModule.cs | 9 ++--- 8 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 PlexRequests.Api.Models/Sonarr/SonarrError.cs diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 1ec1a67ae..d67958e0d 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -64,6 +64,7 @@ + diff --git a/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs b/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs index 534f3068f..23540521f 100644 --- a/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs +++ b/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using Newtonsoft.Json; + namespace PlexRequests.Api.Models.Sonarr { public class Season @@ -23,6 +25,8 @@ namespace PlexRequests.Api.Models.Sonarr public string imdbId { get; set; } public string titleSlug { get; set; } public int id { get; set; } + [JsonIgnore] + public string ErrorMessage { get; set; } } public class AddOptions diff --git a/PlexRequests.Api.Models/Sonarr/SonarrError.cs b/PlexRequests.Api.Models/Sonarr/SonarrError.cs new file mode 100644 index 000000000..ae3fbdfca --- /dev/null +++ b/PlexRequests.Api.Models/Sonarr/SonarrError.cs @@ -0,0 +1,36 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SonarrError.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.Api.Models.Sonarr +{ + public class SonarrError + { + public string propertyName { get; set; } + public string errorMessage { get; set; } + public string attemptedValue { get; set; } + public string[] formattedMessageArguments { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api/ApiRequest.cs b/PlexRequests.Api/ApiRequest.cs index 62391386b..ad056fbfe 100644 --- a/PlexRequests.Api/ApiRequest.cs +++ b/PlexRequests.Api/ApiRequest.cs @@ -26,13 +26,9 @@ #endregion using System; using System.IO; -using System.Net; -using System.Text; -using System.Xml; using System.Xml.Serialization; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NLog; @@ -99,17 +95,18 @@ namespace PlexRequests.Api try { var json = JsonConvert.DeserializeObject(response.Content); + return json; } catch (Exception e) { - Log.Fatal(e); - Log.Info(response.Content); + Log.Error(e); + Log.Error(response.Content); throw; } } - public T DeserializeXml(string input) + private T DeserializeXml(string input) where T : class { var ser = new XmlSerializer(typeof(T)); diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs index 1d1a57f34..d70ba2eef 100644 --- a/PlexRequests.Api/SonarrApi.cs +++ b/PlexRequests.Api/SonarrApi.cs @@ -30,6 +30,8 @@ using System.Linq; using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.Sonarr; +using PlexRequests.Helpers; + using RestSharp; namespace PlexRequests.Api @@ -56,7 +58,8 @@ namespace PlexRequests.Api public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl) { - + Log.Debug("Adding series {0}", title); + Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount); var request = new RestRequest { Resource = "/api/Series?", @@ -74,7 +77,6 @@ namespace PlexRequests.Api rootFolderPath = rootPath }; - for (var i = 1; i <= seasonCount; i++) { var season = new Season @@ -85,11 +87,20 @@ namespace PlexRequests.Api options.seasons.Add(season); } + Log.Debug("Sonarr API Options:"); + Log.Debug(options.DumpJson()); + request.AddHeader("X-Api-Key", apiKey); request.AddJsonBody(options); var obj = Api.ExecuteJson(request, baseUrl); + if (obj == null) + { + var error = Api.ExecuteJson(request, baseUrl); + obj = new SonarrAddSeries { ErrorMessage = error.errorMessage }; + } + return obj; } diff --git a/PlexRequests.UI/Helpers/TvSender.cs b/PlexRequests.UI/Helpers/TvSender.cs index d26611321..703c813fd 100644 --- a/PlexRequests.UI/Helpers/TvSender.cs +++ b/PlexRequests.UI/Helpers/TvSender.cs @@ -24,17 +24,13 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion - -using Nancy; using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.SickRage; using PlexRequests.Api.Models.Sonarr; -using PlexRequests.Core; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; using PlexRequests.Store; -using PlexRequests.UI.Models; namespace PlexRequests.UI.Helpers { diff --git a/PlexRequests.UI/Modules/ApprovalModule.cs b/PlexRequests.UI/Modules/ApprovalModule.cs index b2c6217bb..1e129e3b3 100644 --- a/PlexRequests.UI/Modules/ApprovalModule.cs +++ b/PlexRequests.UI/Modules/ApprovalModule.cs @@ -131,7 +131,7 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = false, - Message = "Could not add the series to Sonarr" + Message = result.ErrorMessage ?? "Could not add the series to Sonarr" }); } @@ -276,7 +276,7 @@ namespace PlexRequests.UI.Modules if (sonarr.Enabled) { var result = sender.SendToSonarr(sonarr, r); - if (result != null) + if (!string.IsNullOrEmpty(result?.title)) { r.Approved = true; updatedRequests.Add(r); @@ -284,6 +284,7 @@ namespace PlexRequests.UI.Modules else { Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title); + Log.Error("Error message: {0}", result?.ErrorMessage); } } } diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 2a98e8933..9b307f983 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -371,18 +371,19 @@ namespace PlexRequests.UI.Modules if (sonarrSettings.Enabled) { var result = sender.SendToSonarr(sonarrSettings, model); - if (result != null) + if (result != null && !string.IsNullOrEmpty(result.title)) { model.Approved = true; Log.Debug("Adding tv to database requests (No approval required & Sonarr)"); RequestService.AddRequest(model); + var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; + NotificationService.Publish(notify1); return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" }); } - var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; - NotificationService.Publish(notify1); - return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." }); + + return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.ErrorMessage ?? "Something went wrong adding the movie to Sonarr! Please check your settings." }); } From 7349f78b80596e16eefa1586e70925e212d99926 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 10:44:23 +0100 Subject: [PATCH 4/8] Fixed the tests --- PlexRequests.UI.Tests/AdminModuleTests.cs | 3 +++ PlexRequests.UI/Modules/AdminModule.cs | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PlexRequests.UI.Tests/AdminModuleTests.cs b/PlexRequests.UI.Tests/AdminModuleTests.cs index fc8686086..34b2af4a7 100644 --- a/PlexRequests.UI.Tests/AdminModuleTests.cs +++ b/PlexRequests.UI.Tests/AdminModuleTests.cs @@ -59,6 +59,7 @@ namespace PlexRequests.UI.Tests private Mock> EmailMock { get; set; } private Mock> PushbulletSettings { get; set; } private Mock> PushoverSettings { get; set; } + private Mock> HeadphonesSettings { get; set; } private Mock PlexMock { get; set; } private Mock SonarrApiMock { get; set; } private Mock PushbulletApi { get; set; } @@ -94,6 +95,7 @@ namespace PlexRequests.UI.Tests PushoverSettings = new Mock>(); PushoverApi = new Mock(); NotificationService = new Mock(); + HeadphonesSettings = new Mock>(); Bootstrapper = new ConfigurableBootstrapper(with => { @@ -114,6 +116,7 @@ namespace PlexRequests.UI.Tests with.Dependency(PushoverSettings.Object); with.Dependency(PushoverApi.Object); with.Dependency(NotificationService.Object); + with.Dependency(HeadphonesSettings.Object); with.RootPathProvider(); with.RequestStartup((container, pipelines, context) => { diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index 4009f1b5e..e62b8b97b 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -67,7 +67,7 @@ namespace PlexRequests.UI.Modules private ISettingsService EmailService { get; } private ISettingsService PushbulletService { get; } private ISettingsService PushoverService { get; } - private ISettingsService HeadphonesSerivce { get; } + private ISettingsService HeadphonesService { get; } private IPlexApi PlexApi { get; } private ISonarrApi SonarrApi { get; } private IPushbulletApi PushbulletApi { get; } @@ -111,7 +111,7 @@ namespace PlexRequests.UI.Modules PushoverService = pushoverSettings; PushoverApi = pushoverApi; NotificationService = notify; - HeadphonesSerivce = headphones; + HeadphonesService = headphones; #if !DEBUG this.RequiresAuthentication(); @@ -520,7 +520,7 @@ namespace PlexRequests.UI.Modules private Negotiator Headphones() { - var settings = HeadphonesSerivce.GetSettings(); + var settings = HeadphonesService.GetSettings(); return View["Headphones", settings]; } @@ -537,7 +537,7 @@ namespace PlexRequests.UI.Modules } Log.Trace(settings.DumpJson()); - var result = HeadphonesSerivce.SaveSettings(settings); + var result = HeadphonesService.SaveSettings(settings); Log.Info("Saved headphones settings, result: {0}", result); return Response.AsJson(result From 1f9ed51320459fe7f0ec0d5c3f45e3d54c1b0f6e Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 10:49:30 +0100 Subject: [PATCH 5/8] Made #85 better --- PlexRequests.Api/ApiRequest.cs | 14 +++----------- PlexRequests.Api/SonarrApi.cs | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/PlexRequests.Api/ApiRequest.cs b/PlexRequests.Api/ApiRequest.cs index ad056fbfe..1b7975462 100644 --- a/PlexRequests.Api/ApiRequest.cs +++ b/PlexRequests.Api/ApiRequest.cs @@ -92,18 +92,10 @@ namespace PlexRequests.Api throw new ApplicationException(message, response.ErrorException); } - try - { - var json = JsonConvert.DeserializeObject(response.Content); - return json; - } - catch (Exception e) - { - Log.Error(e); - Log.Error(response.Content); - throw; - } + var json = JsonConvert.DeserializeObject(response.Content); + + return json; } private T DeserializeXml(string input) diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs index d70ba2eef..f9d68da31 100644 --- a/PlexRequests.Api/SonarrApi.cs +++ b/PlexRequests.Api/SonarrApi.cs @@ -27,6 +27,9 @@ using System; using System.Collections.Generic; using System.Linq; + +using Newtonsoft.Json; + using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.Sonarr; @@ -93,15 +96,19 @@ namespace PlexRequests.Api request.AddHeader("X-Api-Key", apiKey); request.AddJsonBody(options); - var obj = Api.ExecuteJson(request, baseUrl); - - if (obj == null) + SonarrAddSeries result; + try { + result = Api.ExecuteJson(request, baseUrl); + } + catch (JsonSerializationException jse) + { + Log.Error(jse); var error = Api.ExecuteJson(request, baseUrl); - obj = new SonarrAddSeries { ErrorMessage = error.errorMessage }; + result = new SonarrAddSeries { ErrorMessage = error.errorMessage }; } - return obj; + return result; } public SystemStatus SystemStatus(string apiKey, Uri baseUrl) From e2aa4016a8f3fc93c35233492f47e9b12f75ed65 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 14:13:13 +0100 Subject: [PATCH 6/8] Added some tests and fixed the issue where the DB would get created in the wrong place depending on how you launched the application --- PlexRequests.Core/JsonRequestService.cs | 4 + .../PlexAvailabilityCheckerTests.cs | 200 +++++++++++++++++- .../PlexRequests.Services.Tests.csproj | 4 + .../PlexAvailabilityChecker.cs | 19 +- PlexRequests.Store/DbConfiguration.cs | 15 +- PlexRequests.Store/PlexRequests.Store.csproj | 1 + PlexRequests.UI/Bootstrapper.cs | 9 +- PlexRequests.UI/Jobs/PlexTaskFactory.cs | 4 +- 8 files changed, 221 insertions(+), 35 deletions(-) diff --git a/PlexRequests.Core/JsonRequestService.cs b/PlexRequests.Core/JsonRequestService.cs index 1504faed6..64033b50c 100644 --- a/PlexRequests.Core/JsonRequestService.cs +++ b/PlexRequests.Core/JsonRequestService.cs @@ -79,6 +79,10 @@ namespace PlexRequests.Core public RequestedModel Get(int id) { var blob = Repo.Get(id); + if (blob == null) + { + return new RequestedModel(); + } var model = ByteConverterHelper.ReturnObject(blob.Content); return model; } diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index 8e641181e..d9c3f1881 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -32,12 +32,12 @@ using Moq; using NUnit.Framework; using PlexRequests.Api.Interfaces; -using PlexRequests.Api.Models; using PlexRequests.Api.Models.Plex; using PlexRequests.Core; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers.Exceptions; using PlexRequests.Services.Interfaces; +using PlexRequests.Store; namespace PlexRequests.Services.Tests { @@ -66,7 +66,7 @@ namespace PlexRequests.Services.Tests var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch {Video = new List