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..1b7975462 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;
@@ -96,20 +92,13 @@ namespace PlexRequests.Api
throw new ApplicationException(message, response.ErrorException);
}
- try
- {
- var json = JsonConvert.DeserializeObject(response.Content);
- return json;
- }
- catch (Exception e)
- {
- Log.Fatal(e);
- Log.Info(response.Content);
- throw;
- }
+
+ var json = JsonConvert.DeserializeObject(response.Content);
+
+ return json;
}
- 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..f9d68da31 100644
--- a/PlexRequests.Api/SonarrApi.cs
+++ b/PlexRequests.Api/SonarrApi.cs
@@ -27,9 +27,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
+
+using Newtonsoft.Json;
+
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
+using PlexRequests.Helpers;
+
using RestSharp;
namespace PlexRequests.Api
@@ -56,7 +61,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 +80,6 @@ namespace PlexRequests.Api
rootFolderPath = rootPath
};
-
for (var i = 1; i <= seasonCount; i++)
{
var season = new Season
@@ -85,12 +90,25 @@ 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);
+ SonarrAddSeries result;
+ try
+ {
+ result = Api.ExecuteJson(request, baseUrl);
+ }
+ catch (JsonSerializationException jse)
+ {
+ Log.Error(jse);
+ var error = Api.ExecuteJson(request, baseUrl);
+ result = new SonarrAddSeries { ErrorMessage = error.errorMessage };
+ }
- return obj;
+ return result;
}
public SystemStatus SystemStatus(string apiKey, Uri baseUrl)
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.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.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