1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-10 11:10:40 +02:00

Minor cleanups.

This commit is contained in:
kay.one 2012-02-12 22:38:57 -08:00
parent 34f8f0a78f
commit 83aa6330d1
8 changed files with 77 additions and 157 deletions

View File

@ -123,79 +123,7 @@ public void GetEpisodes_invalid_series()
Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
}
[Test]
public void AttachSeries_empty_list()
{
//Act
var result = Mocker.Resolve<EpisodeProvider>().AttachSeries(new List<Episode>());
//Assert
result.Should().HaveCount(0);
}
[Test]
public void AttachSeries_list_success()
{
var fakeSeries = Builder<Series>.CreateNew().With(s => s.SeriesId = 12).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.All().With(e => e.SeriesId = 12).Build();
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(12))
.Returns(fakeSeries);
//Act
fakeEpisodes.Should().OnlyContain(e => e.Series == null);
var returnedSeries = Mocker.Resolve<EpisodeProvider>().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<EpisodeProvider>().AttachSeries(episode);
//Assert
result.Should().BeNull();
}
[Test]
public void AttachSeries_single_success()
{
var fakeSeries = Builder<Series>.CreateNew().With(s => s.SeriesId = 12).Build();
var fakeEpisodes = Builder<Episode>.CreateNew().With(e => e.SeriesId = 12).Build();
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.GetSeries(12))
.Returns(fakeSeries);
//Act
var returnedEpisode = Mocker.Resolve<EpisodeProvider>().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<SeriesProvider>();
var fakeEpisodes = Builder<Episode>.CreateNew().With(e => e.SeriesId = 12).Build();
//Act
var returnedEpisode = Mocker.Resolve<EpisodeProvider>().AttachSeries(fakeEpisodes);
}
[Test]
public void GetEpisodesBySeason_success()
{

View File

@ -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 @@ public CentralDispatch()
{
_enviromentProvider = new EnviromentProvider();
Logger.Debug("Initializing Kernel:");
logger.Debug("Initializing Kernel:");
Kernel = new StandardKernel();
InitDatabase();
@ -43,7 +43,7 @@ public CentralDispatch()
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 @@ private void InitReporting()
private void InitQuality()
{
Logger.Info("Initializing Quality...");
logger.Debug("Initializing Quality...");
Kernel.Get<QualityProvider>().SetupDefaultProfiles();
Kernel.Get<QualityTypeProvider>().SetupDefault();
}
private void InitIndexers()
{
Logger.Info("Initializing Indexers...");
logger.Debug("Initializing Indexers...");
Kernel.Bind<IndexerBase>().To<NzbsOrg>();
Kernel.Bind<IndexerBase>().To<NzbMatrix>();
Kernel.Bind<IndexerBase>().To<NzbsRUs>();
@ -95,7 +95,7 @@ private void InitIndexers()
private void InitJobs()
{
Logger.Info("Initializing Background Jobs...");
logger.Debug("Initializing Background Jobs...");
Kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
@ -119,6 +119,10 @@ private void InitJobs()
Kernel.Bind<IJob>().To<TrimLogsJob>().InSingletonScope();
Kernel.Bind<IJob>().To<RecentBacklogSearchJob>().InSingletonScope();
Kernel.Bind<IJob>().To<CheckpointJob>().InSingletonScope();
Kernel.Bind<IJob>().To<FakeNotificationJob>().InSingletonScope();
Kernel.Get<JobProvider>().Initialize();
Kernel.Get<WebTimer>().StartTimer(30);
@ -126,7 +130,7 @@ private void InitJobs()
private void InitExternalNotifications()
{
Logger.Info("Initializing External Notifications...");
logger.Info("Initializing External Notifications...");
Kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
Kernel.Bind<ExternalNotificationBase>().To<Smtp>();
Kernel.Bind<ExternalNotificationBase>().To<Twitter>();
@ -143,28 +147,28 @@ public void DedicateToHost()
{
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();
}

View File

@ -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 @@ public virtual IList<Episode> GetEpisodesBySeason(long seriesId, int seasonNumbe
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 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
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<Episode>();
}
@ -147,7 +147,7 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
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 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
//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 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
}
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 @@ public virtual IList<Episode> EpisodesWithFiles()
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 @@ public virtual void RefreshEpisodeInfo(Series series)
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 @@ public virtual void RefreshEpisodeInfo(Series series)
}
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 @@ public virtual void RefreshEpisodeInfo(Series series)
_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 @@ public virtual bool IsIgnored(int seriesId, int seasonNumber)
var lastSeasonsEpisodes = _database.Fetch<Episode>(@"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 @@ public virtual IList<int> GetEpisodeNumbersBySeason(int seriesId, int seasonNumb
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 @@ public virtual bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber,
return false;
}
public IList<Episode> AttachSeries(IList<Episode> 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 @@ public virtual void DeleteEpisodesNotInTvdb(Series series, TvdbSeries tvDbSeries
_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<int> episodeIds, PostDownloadStatusType postDownloadStatus)
@ -478,7 +458,7 @@ public virtual void SetPostDownloadStatus(List<int> episodeIds, PostDownloadStat
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);
}
}

View File

@ -1,7 +1,5 @@
@using NzbDrone.Common
@using NzbDrone.Core.Instrumentation
@using NzbDrone.Web.Helpers
@model IEnumerable<NzbDrone.Core.Instrumentation.Log>
@model IEnumerable<Log>
@{ ViewBag.Title = "Logs";}
@section ActionMenu{
<ul class="sub-menu">
@ -9,38 +7,45 @@
<li>@Html.ActionLink("File", "File", "Log")</li>
</ul>
}
@section HeaderContent{
<style>
#logGrid td {
#logGrid td
{
padding: 2px 8px 2px 8px;
}
</style>
}
<div class="infoBox">
Log entries older than 30 days are automatically deleted.</div>
<div class="grid-container">
<table id="logGrid" class="dataTablesGrid hidden-grid">
<thead>
<tr>
<th>Time</th>
<th>Level</th>
<th>Source</th>
<th>Message</th>
<th>
Time
</th>
<th>
Level
</th>
<th>
Source
</th>
<th>
Message
</th>
@*Details Column*@
<th style="display: none;">Details</th>
<th style="display: none;">
Details
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
@section Scripts{
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function () {
$('.dataTablesGrid').removeClass('hidden-grid');
oTable = $('#logGrid').dataTable({
@ -58,20 +63,24 @@
"sPaginationType": "four_button",
"aoColumns": [
{ sWidth: '150px', "mDataProp": "Time" }, //Time
{ sWidth: '80px', "mDataProp": "Level" }, //Level
{ sWidth: '240px', "mDataProp": "Source" }, //Source
{ sWidth: 'auto', "mDataProp": "Message", "bSortable": false }, //Message
{ sWidth: 'auto', "mDataProp": "Details", "bSortable": false, "bVisible": false, "fnRender": function (row) {
var result = "<div>Method: " + row.aData["Method"] + "</div>" +
"<div>Exception Type: " + row.aData["ExceptionType"] + "</div>" +
"<div class=\"stackFrame\">Exception: " + row.aData["Exception"] + "</div>";
return result;
{sWidth: '80px', "mDataProp": "Level" }, //Level
{sWidth: '240px', "mDataProp": "Source" }, //Source
{sWidth: 'auto', "mDataProp": "Message", "bSortable": false }, //Message
{sWidth: 'auto', "mDataProp": "Details", "bSortable": false, "bVisible": false, "fnRender": function (row) {
var result = "<div>Method: " + row.aData["Method"] + "</div>";
if (row.aData["ExceptionType"] !== null) {
result += "<div>Exception Type: " + row.aData["ExceptionType"] + "</div>" +
"<div class=\"stackFrame\">Exception: " + row.aData["Exception"] + "</div>";
}
} //Details
return result;
}
} //Details
],
"aaSorting": [[0, 'desc']],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {
fnRowCallback(nRow, aData);
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
fnRowCallback(nRow, aData);
}
});
});
@ -91,4 +100,4 @@
}
}
</script>
}
}

View File

@ -1,6 +1,5 @@
using System.Linq;
using System;
using InstallService;
namespace ServiceInstall
{

View File

@ -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
{

View File

@ -1,6 +1,5 @@
using System.Linq;
using System;
using UninstallService;
namespace ServiceUninstall
{

View File

@ -5,7 +5,7 @@
using System.Reflection;
using System.Security.Principal;
namespace UninstallService
namespace ServiceUninstall
{
internal static class ServiceHelper
{