diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs index 10d75fd55..47ff0f5f7 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs @@ -123,79 +123,7 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.Resolve().GetEpisode(1); } - [Test] - public void AttachSeries_empty_list() - { - //Act - var result = Mocker.Resolve().AttachSeries(new List()); - - //Assert - result.Should().HaveCount(0); - } - - [Test] - public void AttachSeries_list_success() - { - var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); - var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 12).Build(); - - Mocker.GetMock() - .Setup(c => c.GetSeries(12)) - .Returns(fakeSeries); - - //Act - - fakeEpisodes.Should().OnlyContain(e => e.Series == null); - var returnedSeries = Mocker.Resolve().AttachSeries(fakeEpisodes); - - //Assert - fakeEpisodes.Should().OnlyContain(e => e.Series == fakeSeries); - returnedSeries.Should().BeEquivalentTo(fakeEpisodes); - } - - [Test] - public void AttachSeries_null_episode_should_return_null() - { - Episode episode = null; - - //Act - var result = Mocker.Resolve().AttachSeries(episode); - - //Assert - result.Should().BeNull(); - } - - [Test] - public void AttachSeries_single_success() - { - var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 12).Build(); - var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); - - Mocker.GetMock() - .Setup(c => c.GetSeries(12)) - .Returns(fakeSeries); - - //Act - var returnedEpisode = Mocker.Resolve().AttachSeries(fakeEpisodes); - - //Assert - fakeEpisodes.Series.Should().Be(fakeSeries); - returnedEpisode.Should().Be(fakeEpisodes); - } - - [Test] - [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] - public void AttachSeries_single_invalid_series() - { - Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); - Mocker.Resolve(); - var fakeEpisodes = Builder.CreateNew().With(e => e.SeriesId = 12).Build(); - - //Act - var returnedEpisode = Mocker.Resolve().AttachSeries(fakeEpisodes); - } - + [Test] public void GetEpisodesBySeason_success() { diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 6c1263d14..d376b33fd 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core { public class CentralDispatch { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private readonly EnviromentProvider _enviromentProvider; public StandardKernel Kernel { get; private set; } @@ -28,7 +28,7 @@ namespace NzbDrone.Core { _enviromentProvider = new EnviromentProvider(); - Logger.Debug("Initializing Kernel:"); + logger.Debug("Initializing Kernel:"); Kernel = new StandardKernel(); InitDatabase(); @@ -43,7 +43,7 @@ namespace NzbDrone.Core private void InitDatabase() { - Logger.Info("Initializing Database..."); + logger.Info("Initializing Database..."); var appDataPath = _enviromentProvider.GetAppDataPath(); if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); @@ -75,14 +75,14 @@ namespace NzbDrone.Core private void InitQuality() { - Logger.Info("Initializing Quality..."); + logger.Debug("Initializing Quality..."); Kernel.Get().SetupDefaultProfiles(); Kernel.Get().SetupDefault(); } private void InitIndexers() { - Logger.Info("Initializing Indexers..."); + logger.Debug("Initializing Indexers..."); Kernel.Bind().To(); Kernel.Bind().To(); Kernel.Bind().To(); @@ -95,7 +95,7 @@ namespace NzbDrone.Core private void InitJobs() { - Logger.Info("Initializing Background Jobs..."); + logger.Debug("Initializing Background Jobs..."); Kernel.Bind().ToSelf().InSingletonScope(); @@ -119,6 +119,10 @@ namespace NzbDrone.Core Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); Kernel.Bind().To().InSingletonScope(); + + Kernel.Bind().To().InSingletonScope(); + + Kernel.Get().Initialize(); Kernel.Get().StartTimer(30); @@ -126,7 +130,7 @@ namespace NzbDrone.Core private void InitExternalNotifications() { - Logger.Info("Initializing External Notifications..."); + logger.Info("Initializing External Notifications..."); Kernel.Bind().To(); Kernel.Bind().To(); Kernel.Bind().To(); @@ -143,28 +147,28 @@ namespace NzbDrone.Core { var pid = _enviromentProvider.NzbDroneProcessIdFromEnviroment; - Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid); + logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid); var hostProcess = Process.GetProcessById(Convert.ToInt32(pid)); hostProcess.EnableRaisingEvents = true; hostProcess.Exited += (delegate { - Logger.Info("Host has been terminated. Shutting down web server."); + logger.Info("Host has been terminated. Shutting down web server."); ShutDown(); }); - Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName); + logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName); } catch (Exception e) { - Logger.FatalException("An error has occurred while dedicating to host.", e); + logger.FatalException("An error has occurred while dedicating to host.", e); } } private static void ShutDown() { - Logger.Info("Shutting down application..."); + logger.Info("Shutting down application..."); WebTimer.Stop(); Process.GetCurrentProcess().Kill(); } diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 54a644214..862a9b708 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Providers public class EpisodeProvider { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); //this will remove (1),(2) from the end of multi part episodes. private static readonly Regex multiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled); @@ -123,7 +123,7 @@ namespace NzbDrone.Core.Providers public virtual void MarkEpisodeAsFetched(int episodeId) { - Logger.Trace("Marking episode {0} as fetched.", episodeId); + logger.Trace("Marking episode {0} as fetched.", episodeId); _database.Execute("UPDATE Episodes SET GrabDate=@0 WHERE EpisodeId=@1", DateTime.Now, episodeId); } @@ -139,7 +139,7 @@ namespace NzbDrone.Core.Providers if (!parseResult.Series.IsDaily) { //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}. {1}", parseResult.Series.Title, parseResult.OriginalString); + logger.Warn("Found daily-style episode for non-daily series: {0}. {1}", parseResult.Series.Title, parseResult.OriginalString); return new List(); } @@ -147,7 +147,7 @@ namespace NzbDrone.Core.Providers if (episodeInfo == null && autoAddNew) { - Logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); + logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); episodeInfo = new Episode { SeriesId = parseResult.Series.SeriesId, @@ -199,7 +199,7 @@ namespace NzbDrone.Core.Providers //if still null we should add the temp episode if (episodeInfo == null && autoAddNew) { - Logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); + logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); episodeInfo = new Episode { SeriesId = parseResult.Series.SeriesId, @@ -231,7 +231,7 @@ namespace NzbDrone.Core.Providers } else { - Logger.Debug("Unable to find {0}-S{1:00}E{2:00}", parseResult.Series.Title, parseResult.SeasonNumber, episodeNumber); + logger.Debug("Unable to find {0}-S{1:00}E{2:00}", parseResult.Series.Title, parseResult.SeasonNumber, episodeNumber); } } @@ -269,7 +269,7 @@ namespace NzbDrone.Core.Providers public virtual void RefreshEpisodeInfo(Series series) { - Logger.Info("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); + logger.Info("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); int successCount = 0; int failCount = 0; var tvDbSeriesInfo = _tvDbProvider.GetSeries(series.SeriesId, true); @@ -287,15 +287,15 @@ namespace NzbDrone.Core.Providers string.IsNullOrWhiteSpace(episode.EpisodeName)) continue; - Logger.Trace("Updating info for [{0}] - S{1}E{2}", tvDbSeriesInfo.SeriesName, episode.SeasonNumber, episode.EpisodeNumber); + logger.Trace("Updating info for [{0}] - S{1}E{2}", tvDbSeriesInfo.SeriesName, episode.SeasonNumber, episode.EpisodeNumber); //first check using tvdbId, this should cover cases when and episode number in a season is changed - var episodeToUpdate = seriesEpisodes.Where(e => e.TvDbEpisodeId == episode.Id).SingleOrDefault(); + var episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.TvDbEpisodeId == episode.Id); //not found, try using season/episode number if (episodeToUpdate == null) { - episodeToUpdate = seriesEpisodes.Where(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber).SingleOrDefault(); + episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); } //Episode doesn't exist locally @@ -336,7 +336,7 @@ namespace NzbDrone.Core.Providers } catch (Exception e) { - Logger.FatalException( + logger.FatalException( String.Format("An error has occurred while updating episode info for series {0}", tvDbSeriesInfo.SeriesName), e); failCount++; } @@ -345,7 +345,7 @@ namespace NzbDrone.Core.Providers _database.InsertMany(newList); _database.UpdateMany(updateList); - Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", + logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", tvDbSeriesInfo.SeriesName, successCount, failCount); //DeleteEpisodesNotInTvdb @@ -374,13 +374,13 @@ namespace NzbDrone.Core.Providers var lastSeasonsEpisodes = _database.Fetch(@"SELECT * FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber - 1); - if (lastSeasonsEpisodes != null && lastSeasonsEpisodes.Count > 0 && lastSeasonsEpisodes.Count == lastSeasonsEpisodes.Where(e => e.Ignored).Count()) + if (lastSeasonsEpisodes != null && lastSeasonsEpisodes.Any() && lastSeasonsEpisodes.Count == lastSeasonsEpisodes.Count(e => e.Ignored)) return true; return false; } - if (episodes.Count == episodes.Where(e => e.Ignored).Count()) + if (episodes.Count == episodes.Count(e => e.Ignored)) return true; return false; @@ -398,31 +398,31 @@ namespace NzbDrone.Core.Providers public virtual void SetSeasonIgnore(long seriesId, int seasonNumber, bool isIgnored) { - Logger.Info("Setting ignore flag on Series:{0} Season:{1} to {2}", seriesId, seasonNumber, isIgnored); + logger.Info("Setting ignore flag on Series:{0} Season:{1} to {2}", seriesId, seasonNumber, isIgnored); _database.Execute(@"UPDATE Episodes SET Ignored = @0 WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3", isIgnored, seriesId, seasonNumber, !isIgnored); - Logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); + logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); } public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) { - Logger.Info("Setting ignore flag on Episode:{0} to {1}", episodeId, isIgnored); + logger.Info("Setting ignore flag on Episode:{0} to {1}", episodeId, isIgnored); _database.Execute(@"UPDATE Episodes SET Ignored = @0 WHERE EpisodeId = @1", isIgnored, episodeId); - Logger.Info("Ignore flag for Episode:{0} successfully set to {1}", episodeId, isIgnored); + logger.Info("Ignore flag for Episode:{0} successfully set to {1}", episodeId, isIgnored); } public virtual bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, int episodeNumber) { var episodes = GetEpisodesBySeason(seriesId, seasonNumber).OrderBy(e => e.EpisodeNumber); - if (episodes.Count() == 0) + if (!episodes.Any()) return false; //Ensure that this is either the first episode @@ -433,29 +433,9 @@ namespace NzbDrone.Core.Providers return false; } - public IList AttachSeries(IList episodes) - { - if (episodes.Count == 0) return episodes; - - if (episodes.Select(c => c.SeriesId).Distinct().Count() > 1) - throw new ArgumentException("Episodes belong to more than one series."); - - var series = _seriesProvider.GetSeries(episodes.First().SeriesId); - episodes.ToList().ForEach(c => c.Series = series); - - return episodes; - } - - public Episode AttachSeries(Episode episode) - { - if (episode == null) return episode; - episode.Series = _seriesProvider.GetSeries(episode.SeriesId); - return episode; - } - public virtual void DeleteEpisodesNotInTvdb(Series series, TvdbSeries tvDbSeriesInfo) { - Logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); + logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); //Delete Episodes not matching TvDbIds for this series var tvDbIds = tvDbSeriesInfo.Episodes.Select(e => e.Id); @@ -466,7 +446,7 @@ namespace NzbDrone.Core.Providers _database.Execute(tvDbIdQuery); - Logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId); + logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId); } public virtual void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus) @@ -478,7 +458,7 @@ namespace NzbDrone.Core.Providers var episodeIdQuery = String.Format(@"UPDATE Episodes SET PostDownloadStatus = {0} WHERE EpisodeId IN ({1})", (int)postDownloadStatus, episodeIdString); - Logger.Trace("Updating PostDownloadStatus for all episodeIds in {0}", episodeIdString); + logger.Trace("Updating PostDownloadStatus for all episodeIds in {0}", episodeIdString); _database.Execute(episodeIdQuery); } } diff --git a/NzbDrone.Web/Views/Log/Index.cshtml b/NzbDrone.Web/Views/Log/Index.cshtml index 0ad76834a..9a57feaa7 100644 --- a/NzbDrone.Web/Views/Log/Index.cshtml +++ b/NzbDrone.Web/Views/Log/Index.cshtml @@ -1,7 +1,5 @@ -@using NzbDrone.Common @using NzbDrone.Core.Instrumentation -@using NzbDrone.Web.Helpers -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = "Logs";} @section ActionMenu{ } - @section HeaderContent{ } -
Log entries older than 30 days are automatically deleted.
-
- - - - + + + + @*Details Column*@ - +
TimeLevelSourceMessage + Time + + Level + + Source + + Message + Details + Details +
- @section Scripts{ -} \ No newline at end of file +} diff --git a/ServiceHelpers/ServiceInstall/Program.cs b/ServiceHelpers/ServiceInstall/Program.cs index 1aa74f474..3736beeb3 100644 --- a/ServiceHelpers/ServiceInstall/Program.cs +++ b/ServiceHelpers/ServiceInstall/Program.cs @@ -1,6 +1,5 @@ using System.Linq; using System; -using InstallService; namespace ServiceInstall { diff --git a/ServiceHelpers/ServiceInstall/ServiceHelper.cs b/ServiceHelpers/ServiceInstall/ServiceHelper.cs index 007b74d69..c8c96d0a5 100644 --- a/ServiceHelpers/ServiceInstall/ServiceHelper.cs +++ b/ServiceHelpers/ServiceInstall/ServiceHelper.cs @@ -1,10 +1,11 @@ +using System.Linq; using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Security.Principal; -namespace InstallService +namespace ServiceInstall { internal static class ServiceHelper { diff --git a/ServiceHelpers/ServiceUninstall/Program.cs b/ServiceHelpers/ServiceUninstall/Program.cs index 5d6cb9a80..4f2459bea 100644 --- a/ServiceHelpers/ServiceUninstall/Program.cs +++ b/ServiceHelpers/ServiceUninstall/Program.cs @@ -1,6 +1,5 @@ using System.Linq; using System; -using UninstallService; namespace ServiceUninstall { diff --git a/ServiceHelpers/ServiceUninstall/ServiceHelper.cs b/ServiceHelpers/ServiceUninstall/ServiceHelper.cs index bdc0c5b18..1069c2fff 100644 --- a/ServiceHelpers/ServiceUninstall/ServiceHelper.cs +++ b/ServiceHelpers/ServiceUninstall/ServiceHelper.cs @@ -5,7 +5,7 @@ using System.IO; using System.Reflection; using System.Security.Principal; -namespace UninstallService +namespace ServiceUninstall { internal static class ServiceHelper {