From a216e37d6a6f71d7bb4fe88ecd50076522359d11 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 4 Jul 2013 22:17:25 -0700 Subject: [PATCH] better Series.ToString() --- NzbDrone.Common/StringExtension.cs | 9 ++++----- .../CustomStartDateSpecification.cs | 2 +- .../MonitoredEpisodeSpecification.cs | 2 +- NzbDrone.Core/MediaCover/MediaCoverService.cs | 6 +++--- NzbDrone.Core/MediaFiles/DiskScanService.cs | 2 +- .../Notifications/Xbmc/HttpApiProvider.cs | 4 ++-- .../Notifications/Xbmc/JsonApiProvider.cs | 4 ++-- NzbDrone.Core/Parser/ParsingService.cs | 2 +- NzbDrone.Core/Providers/XemProvider.cs | 18 +++++++++--------- NzbDrone.Core/Tv/RefreshSeriesService.cs | 8 ++++---- NzbDrone.Core/Tv/Series.cs | 6 ++++++ NzbDrone.Core/Tv/SeriesService.cs | 2 +- 12 files changed, 35 insertions(+), 30 deletions(-) diff --git a/NzbDrone.Common/StringExtension.cs b/NzbDrone.Common/StringExtension.cs index 4f209a422..acd9aa70d 100644 --- a/NzbDrone.Common/StringExtension.cs +++ b/NzbDrone.Common/StringExtension.cs @@ -5,6 +5,10 @@ namespace NzbDrone.Common { public static class StringExtension { + public static string NullSafe(this string target) + { + return ((object)target).NullSafe().ToString(); + } public static object NullSafe(this object target) { @@ -12,11 +16,6 @@ namespace NzbDrone.Common return "[NULL]"; } - public static string NullSafe(this string target) - { - return ((object)target).NullSafe().ToString(); - } - public static string FirstCharToUpper(this string input) { return input.First().ToString().ToUpper() + String.Join("", input.Skip(1)); diff --git a/NzbDrone.Core/DecisionEngine/Specifications/CustomStartDateSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/CustomStartDateSpecification.cs index 0603c4bf8..46ab16648 100644 --- a/NzbDrone.Core/DecisionEngine/Specifications/CustomStartDateSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/Specifications/CustomStartDateSpecification.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications { if (!subject.Series.CustomStartDate.HasValue) { - _logger.Debug("{0} does not restrict downloads before date.", subject.Series.Title); + _logger.Debug("{0} does not restrict downloads before date.", subject.Series); return true; } diff --git a/NzbDrone.Core/DecisionEngine/Specifications/MonitoredEpisodeSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/MonitoredEpisodeSpecification.cs index 7d01ca688..0fae0fbd2 100644 --- a/NzbDrone.Core/DecisionEngine/Specifications/MonitoredEpisodeSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/Specifications/MonitoredEpisodeSpecification.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications { if (!subject.Series.Monitored) { - _logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.Series.Title); + _logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.Series); return false; } diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs index b455a7e8c..ccfa8dc89 100644 --- a/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -57,16 +57,16 @@ namespace NzbDrone.Core.MediaCover { var fileName = GetCoverPath(series.Id, cover.CoverType); - _logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series.Title, cover.Url); + _logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series, cover.Url); _httpProvider.DownloadFile(cover.Url, fileName); } catch (WebException e) { - _logger.WarnException("Couldn't download media cover for " + series.TvdbId, e); + _logger.WarnException("Couldn't download media cover for " + series, e); } catch (Exception e) { - _logger.ErrorException("Couldn't download media cover for " + series.TvdbId, e); + _logger.ErrorException("Couldn't download media cover for " + series, e); } } diff --git a/NzbDrone.Core/MediaFiles/DiskScanService.cs b/NzbDrone.Core/MediaFiles/DiskScanService.cs index 8e9612e73..e6ea286d6 100644 --- a/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -154,7 +154,7 @@ namespace NzbDrone.Core.MediaFiles } catch (Exception e) { - Logger.ErrorException("Diskscan failed for " + series.Title, e); + Logger.ErrorException("Disk scan failed for " + series, e); } } } diff --git a/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs b/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs index fc1948ef7..2e4a36487 100644 --- a/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs +++ b/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs @@ -150,7 +150,7 @@ namespace NzbDrone.Core.Notifications.Xbmc //If the path is found update it, else update the whole library if (!String.IsNullOrEmpty(xbmcSeriesPath)) { - _logger.Trace("Updating series [{0}] on XBMC host: {1}", series.Title, settings.Address); + _logger.Trace("Updating series [{0}] on XBMC host: {1}", series, settings.Address); var command = BuildExecBuiltInCommand(String.Format("UpdateLibrary(video,{0})", xbmcSeriesPath)); SendCommand(settings, command); } @@ -158,7 +158,7 @@ namespace NzbDrone.Core.Notifications.Xbmc else { //Update the entire library - _logger.Trace("Series [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", series.Title, settings.Address); + _logger.Trace("Series [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", series, settings.Address); var command = BuildExecBuiltInCommand("UpdateLibrary(video)"); SendCommand(settings, command); } diff --git a/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs b/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs index f70a69e5b..fc5e9af47 100644 --- a/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs +++ b/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs @@ -143,7 +143,7 @@ namespace NzbDrone.Core.Notifications.Xbmc if (seriesPath != null) { - _logger.Trace("Updating series [{0}] (Path: {1}) on XBMC host: {2}", series.Title, seriesPath, settings.Address); + _logger.Trace("Updating series {0} (Path: {1}) on XBMC host: {2}", series, seriesPath, settings.Address); var parameters = new JObject(new JObject(new JProperty("directory", seriesPath))); postJson = BuildJsonRequest("VideoLibrary.Scan", parameters); @@ -151,7 +151,7 @@ namespace NzbDrone.Core.Notifications.Xbmc else { - _logger.Trace("Series [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", series.Title, + _logger.Trace("Series {0} doesn't exist on XBMC host: {1}, Updating Entire Library", series, settings.Address); postJson = BuildJsonRequest("VideoLibrary.Scan"); diff --git a/NzbDrone.Core/Parser/ParsingService.cs b/NzbDrone.Core/Parser/ParsingService.cs index 8ac511d34..1de0aeb0b 100644 --- a/NzbDrone.Core/Parser/ParsingService.cs +++ b/NzbDrone.Core/Parser/ParsingService.cs @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Parser if (series.SeriesType == SeriesTypes.Standard) { //Todo: Collect this as a Series we want to treat as a daily series, or possible parsing error - _logger.Warn("Found daily-style episode for non-daily series: {0}.", series.Title); + _logger.Warn("Found daily-style episode for non-daily series: {0}.", series); return new List(); } diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 5699d3cdb..387ab99ea 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -7,7 +7,7 @@ using NzbDrone.Core.Tv; namespace NzbDrone.Core.Providers { - public class XemProvider :IExecute + public class XemProvider : IExecute { private readonly IEpisodeService _episodeService; private readonly XemCommunicationProvider _xemCommunicationProvider; @@ -15,7 +15,7 @@ namespace NzbDrone.Core.Providers private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); - public XemProvider(IEpisodeService episodeService,XemCommunicationProvider xemCommunicationProvider,ISeriesRepository seriesRepository) + public XemProvider(IEpisodeService episodeService, XemCommunicationProvider xemCommunicationProvider, ISeriesRepository seriesRepository) { _episodeService = episodeService; _xemCommunicationProvider = xemCommunicationProvider; @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Providers var series = _seriesRepository.All(); var wantedSeries = series.Where(s => ids.Contains(s.Id)).ToList(); - foreach(var ser in wantedSeries) + foreach (var ser in wantedSeries) { PerformUpdate(ser); } @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Providers _logger.Trace("Completed scene numbering update"); } - catch(Exception ex) + catch (Exception ex) { _logger.WarnException("Error updating Scene Mappings", ex); throw; @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Providers public virtual void PerformUpdate(Series series) { - _logger.Trace("Updating scene numbering mapping for: {0}", series.Title); + _logger.Trace("Updating scene numbering mapping for: {0}", series); try { var episodesToUpdate = new List(); @@ -77,7 +77,7 @@ namespace NzbDrone.Core.Providers if (mappings == null) { - _logger.Trace("Mappings for: {0} are null, skipping", series.Title); + _logger.Trace("Mappings for: {0} are null, skipping", series); return; } @@ -85,7 +85,7 @@ namespace NzbDrone.Core.Providers foreach (var mapping in mappings) { - _logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series.Title, mapping.Tvdb.Season, mapping.Tvdb.Episode); + _logger.Trace("Setting scene numbering mappings for {0} S{1:00}E{2:00}", series, mapping.Tvdb.Season, mapping.Tvdb.Episode); var episode = episodes.SingleOrDefault(e => e.SeasonNumber == mapping.Tvdb.Season && e.EpisodeNumber == mapping.Tvdb.Episode); @@ -101,10 +101,10 @@ namespace NzbDrone.Core.Providers episodesToUpdate.Add(episode); } - _logger.Trace("Committing scene numbering mappings to database for: {0}", series.Title); + _logger.Trace("Committing scene numbering mappings to database for: {0}", series); _episodeService.UpdateEpisodes(episodesToUpdate); - _logger.Trace("Setting UseSceneMapping for {0}", series.Title); + _logger.Trace("Setting UseSceneMapping for {0}", series); series.UseSceneNumbering = true; _seriesRepository.Update(series); } diff --git a/NzbDrone.Core/Tv/RefreshSeriesService.cs b/NzbDrone.Core/Tv/RefreshSeriesService.cs index e179f9712..05819f24e 100644 --- a/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Tv } catch (Exception e) { - _logger.ErrorException("Couldn't refresh info for {0}".Inject(series.Title), e); + _logger.ErrorException("Couldn't refresh info for {0}".Inject(series), e); } } } @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Tv private void RefreshEpisodeInfo(Series series, IEnumerable remoteEpisodes) { - _logger.Info("Starting series info refresh for: {0}", series.Title.WithDefault(series.Id)); + _logger.Info("Starting series info refresh for: {0}", series); var successCount = 0; var failCount = 0; @@ -151,7 +151,7 @@ namespace NzbDrone.Core.Tv } catch (Exception e) { - _logger.FatalException(String.Format("An error has occurred while updating episode info for series {0}", series.Title), e); + _logger.FatalException(String.Format("An error has occurred while updating episode info for series {0}", series), e); failCount++; } } @@ -192,7 +192,7 @@ namespace NzbDrone.Core.Tv } else { - _logger.Info("Finished episode refresh for series: {0}.", series.Title); + _logger.Info("Finished episode refresh for series: {0}.", series); } //DeleteEpisodesNotAvailableAnymore(series, remoteEpisodes); diff --git a/NzbDrone.Core/Tv/Series.cs b/NzbDrone.Core/Tv/Series.cs index c6b154ece..4925a66f7 100644 --- a/NzbDrone.Core/Tv/Series.cs +++ b/NzbDrone.Core/Tv/Series.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Marr.Data; using NzbDrone.Core.Datastore; using NzbDrone.Core.Qualities; +using NzbDrone.Common; namespace NzbDrone.Core.Tv @@ -39,5 +40,10 @@ namespace NzbDrone.Core.Tv public DateTime? FirstAired { get; set; } public LazyLoaded QualityProfile { get; set; } + + public override string ToString() + { + return string.Format("[{0}][{1}]", Id, Title.NullSafe()); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 8a604f17a..dae4e9512 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Tv _diskProvider.CreateFolder(newSeries.Path); } - _logger.Info("Adding Series [{0}] Path: [{1}]", newSeries.Title, newSeries.Path); + _logger.Info("Adding Series {0} Path: [{1}]", newSeries, newSeries.Path); newSeries.Monitored = true; newSeries.CleanTitle = Parser.Parser.CleanSeriesTitle(newSeries.Title);