diff --git a/NzbDrone.Common/Instrumentation/LogEventExtensions.cs b/NzbDrone.Common/Instrumentation/LogEventExtensions.cs index 80c911509..cb2fe44f2 100644 --- a/NzbDrone.Common/Instrumentation/LogEventExtensions.cs +++ b/NzbDrone.Common/Instrumentation/LogEventExtensions.cs @@ -8,7 +8,7 @@ public static class LogEventExtensions { public static string GetHash(this LogEventInfo logEvent) { - var stackString = Json.Serialize(logEvent.StackTrace); + var stackString = logEvent.StackTrace.ToJson(); var hashSeed = String.Concat(logEvent.LoggerName, logEvent.Exception.GetType().ToString(), stackString, logEvent.Level); return HashUtil.CalculateCrc(hashSeed); } diff --git a/NzbDrone.Common/Instrumentation/LogglyTarget.cs b/NzbDrone.Common/Instrumentation/LogglyTarget.cs index e43754454..5795f7369 100644 --- a/NzbDrone.Common/Instrumentation/LogglyTarget.cs +++ b/NzbDrone.Common/Instrumentation/LogglyTarget.cs @@ -69,7 +69,7 @@ protected override void Write(NLog.LogEventInfo logEvent) dictionary.Add("message", logEvent.GetFormattedMessage()); dictionary.Add("ver", _environmentProvider.Version.ToString()); - _logger.Log(Json.Serialize(dictionary)); + _logger.Log(dictionary.ToJson()); } } } \ No newline at end of file diff --git a/NzbDrone.Common/Serializer/Json.cs b/NzbDrone.Common/Serializer/Json.cs index 2fc8e133e..59c58946a 100644 --- a/NzbDrone.Common/Serializer/Json.cs +++ b/NzbDrone.Common/Serializer/Json.cs @@ -35,7 +35,7 @@ public static object Deserialize(string json, Type type) return JsonConvert.DeserializeObject(json, type); } - public static string Serialize(object obj) + public static string ToJson(this object obj) { return JsonConvert.SerializeObject(obj); } diff --git a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs index fa3ce2eee..b222eb320 100644 --- a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs +++ b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs @@ -1,7 +1,6 @@ using System; using Marr.Data.Converters; using Marr.Data.Mapping; -using NzbDrone.Common; using NzbDrone.Common.Serializer; namespace NzbDrone.Core.Datastore.Converters @@ -23,15 +22,14 @@ public object FromDB(ColumnMap map, object dbValue) return null; } - return Json.Deserialize(stringValue, map.FieldType); + return Json.Deserialize(stringValue, map.FieldType); } public object ToDB(object clrValue) { if (clrValue == null) return null; - var json = Json.Serialize(clrValue); - return json; + return clrValue.ToJson(); } public Type DbType diff --git a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 4ce0d790f..87bc97a33 100644 --- a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; +using NzbDrone.Common.Serializer; namespace NzbDrone.Core.DecisionEngine { @@ -110,8 +111,8 @@ private string EvaluateSpec(IRejectWithReason spec, RemoteEpisode remoteEpisode, } catch (Exception e) { - e.Data.Add("report", remoteEpisode.Report); - e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo); + e.Data.Add("report", remoteEpisode.Report.ToJson()); + e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson()); _logger.ErrorException("Couldn't evaluate decision", e); return string.Format("{0}: {1}", spec.GetType().Name, e.Message); } diff --git a/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index 728dfb9d5..caa4a689a 100644 --- a/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -6,8 +6,6 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Indexers; -using NzbDrone.Core.Model; -using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Tv; using System.Linq; diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index 86b1c5808..400704ffd 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -80,7 +80,7 @@ public Indexer Create(Indexer indexer) Name = indexer.Name, Enable = indexer.Enable, Implementation = indexer.Implementation, - Settings = Json.Serialize(indexer.Settings) + Settings = indexer.Settings.ToJson() }; definition = _indexerRepository.Insert(definition); diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 805d93c25..9e88d1e7b 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -48,7 +48,7 @@ public override IEnumerable DefaultDefinitions private string GetSettings(string url) { - return Json.Serialize(new NewznabSettings { Url = url }); + return new NewznabSettings { Url = url }.ToJson(); } public override IEnumerable RecentFeed diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index c983fb89b..d2591714d 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -71,7 +71,7 @@ public List Schema() var instanceType = newNotification.Instance.GetType(); var baseGenArgs = instanceType.BaseType.GetGenericArguments(); - newNotification.Settings = (INotifcationSettings) Activator.CreateInstance(baseGenArgs[0]); + newNotification.Settings = (INotifcationSettings)Activator.CreateInstance(baseGenArgs[0]); newNotification.Implementation = type.Name; notifications.Add(newNotification); @@ -85,7 +85,7 @@ public Notification Create(Notification notification) { var definition = new NotificationDefinition(); definition.InjectFrom(notification); - definition.Settings = Json.Serialize(notification.Settings); + definition.Settings = notification.Settings.ToJson(); definition = _notificationRepository.Insert(definition); notification.Id = definition.Id; @@ -97,7 +97,7 @@ public Notification Update(Notification notification) { var definition = _notificationRepository.Get(notification.Id); definition.InjectFrom(notification); - definition.Settings = Json.Serialize(notification.Settings); + definition.Settings = notification.Settings.ToJson(); _notificationRepository.Update(definition); diff --git a/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs b/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs index 0b2c83217..19a663db4 100644 --- a/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs +++ b/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs @@ -17,9 +17,7 @@ public void should_be_able_to_deserialize_numbers() { var quality = new TypeWithNumbers { Id = 12 }; - var json = Json.Serialize(quality); - - Json.Deserialize(json); + Json.Deserialize(quality.ToJson()); } } }