fixed some issues here and there.

This commit is contained in:
kay.one 2013-05-10 22:59:42 -07:00
parent 4deecde092
commit 85cd877b0c
12 changed files with 66 additions and 20 deletions

View File

@ -135,6 +135,7 @@ namespace NzbDrone.Api.REST
private TResource ReadFromRequest() private TResource ReadFromRequest()
{ {
//TODO: handle when request is null
var resource = Request.Body.FromJson<TResource>(); var resource = Request.Body.FromJson<TResource>();
var errors = SharedValidator.Validate(resource).Errors.ToList(); var errors = SharedValidator.Validate(resource).Errors.ToList();

View File

@ -23,19 +23,13 @@ namespace NzbDrone.Api.SignalR
protected override Task OnConnected(IRequest request, string connectionId) protected override Task OnConnected(IRequest request, string connectionId)
{ {
_logger.Debug("SignalR client connected. ID:{0}", connectionId); _logger.Trace("SignalR client connected. ID:{0}", connectionId);
return base.OnConnected(request, connectionId); return base.OnConnected(request, connectionId);
} }
public override Task ProcessRequest(Microsoft.AspNet.SignalR.Hosting.HostContext context)
{
_logger.Debug("Request: {0}", context);
return base.ProcessRequest(context);
}
public void HandleAsync(ModelEvent<T> message) public void HandleAsync(ModelEvent<T> message)
{ {
var context =((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
context.Connection.Broadcast(message); context.Connection.Broadcast(message);
} }
} }

View File

@ -31,6 +31,12 @@ namespace NzbDrone.Common
return info.FullName.TrimEnd('/').Trim('\\', ' '); return info.FullName.TrimEnd('/').Trim('\\', ' ');
} }
public static bool ContainsInvalidPathChars(this string text)
{
return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0;
}
private static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo) private static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
{ {
var parentDirInfo = dirInfo.Parent; var parentDirInfo = dirInfo.Parent;

View File

@ -88,10 +88,18 @@ namespace NzbDrone.Core.Test.Datastore
} }
[Test]
public void should_read_and_write_in_utc()
{
var storedTime = DateTime.UtcNow;
_sampleType.LastExecution =storedTime;
Subject.Insert(_sampleType);
StoredModel.LastExecution.Kind.Should().Be(DateTimeKind.Utc);
StoredModel.LastExecution.ToLongTimeString().Should().Be(storedTime.ToLongTimeString());
}
[Test] [Test]
public void should_have_id_when_returned_from_database() public void should_have_id_when_returned_from_database()

View File

@ -0,0 +1,40 @@
using System;
using System.Globalization;
using Marr.Data.Converters;
using Marr.Data.Mapping;
namespace NzbDrone.Core.Datastore.Converters
{
public class UtcDateTimeConverter : IConverter
{
public Type DbType
{
get
{
return typeof(DateTime);
}
}
public object FromDB(ColumnMap map, object dbValue)
{
if (dbValue != null && dbValue != DBNull.Value)
{
var dateTime = (DateTime)dbValue;
dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Local);
return dateTime.ToUniversalTime();
}
return null;
}
public object ToDB(object clrValue)
{
if (clrValue != null)
{
return ((DateTime)clrValue).ToUniversalTime();
}
return DBNull.Value;
}
}
}

View File

@ -78,6 +78,7 @@ namespace NzbDrone.Core.Datastore
MapRepository.Instance.RegisterTypeConverter(typeof(Boolean), new BooleanIntConverter()); MapRepository.Instance.RegisterTypeConverter(typeof(Boolean), new BooleanIntConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(Enum), new EnumIntConverter()); MapRepository.Instance.RegisterTypeConverter(typeof(Enum), new EnumIntConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(Quality), new QualityIntConverter()); MapRepository.Instance.RegisterTypeConverter(typeof(Quality), new QualityIntConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(DateTime), new UtcDateTimeConverter());
} }
private static void RegisterEmbeddedConverter() private static void RegisterEmbeddedConverter()

View File

@ -8,7 +8,6 @@ namespace NzbDrone.Core.Jobs
{ {
public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask> public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask>
{ {
IList<ScheduledTask> GetPendingJobs();
ScheduledTask GetDefinition(Type type); ScheduledTask GetDefinition(Type type);
void SetLastExecutionTime(int id, DateTime executionTime); void SetLastExecutionTime(int id, DateTime executionTime);
} }
@ -27,12 +26,6 @@ namespace NzbDrone.Core.Jobs
return Query.Single(c => c.TypeName == type.FullName); return Query.Single(c => c.TypeName == type.FullName);
} }
public IList<ScheduledTask> GetPendingJobs()
{
return Query.Where(c => c.Interval != 0).ToList().Where(c => c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList();
}
public void SetLastExecutionTime(int id, DateTime executionTime) public void SetLastExecutionTime(int id, DateTime executionTime)
{ {
var task = new ScheduledTask var task = new ScheduledTask

View File

@ -35,6 +35,8 @@ namespace NzbDrone.Core.Jobs
{ {
var tasks = _taskManager.GetPending(); var tasks = _taskManager.GetPending();
_logger.Trace("Pending Tasks: {0}", tasks.Count);
foreach (var task in tasks) foreach (var task in tasks)
{ {
try try
@ -46,7 +48,7 @@ namespace NzbDrone.Core.Jobs
} }
catch (Exception e) catch (Exception e)
{ {
_logger.ErrorException("Error occured while execution task " + task.TypeName, e); _logger.ErrorException("Error occurred while execution task " + task.TypeName, e);
} }
finally finally
{ {

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Jobs
public IList<ScheduledTask> GetPending() public IList<ScheduledTask> GetPending()
{ {
return _scheduledTaskRepository.GetPendingJobs(); return _scheduledTaskRepository.All().Where(c => c.LastExecution.AddMinutes(c.Interval) < DateTime.UtcNow).ToList();
} }
public void SetLastExecutionTime(int taskId) public void SetLastExecutionTime(int taskId)

View File

@ -192,6 +192,7 @@
<Compile Include="Datastore\Converters\QualityIntConverter.cs" /> <Compile Include="Datastore\Converters\QualityIntConverter.cs" />
<Compile Include="Datastore\Converters\Int32Converter.cs" /> <Compile Include="Datastore\Converters\Int32Converter.cs" />
<Compile Include="Datastore\Converters\EmbeddedDocumentConverter.cs" /> <Compile Include="Datastore\Converters\EmbeddedDocumentConverter.cs" />
<Compile Include="Datastore\Converters\UtcDateTimeConverter.cs" />
<Compile Include="Datastore\Database.cs" /> <Compile Include="Datastore\Database.cs" />
<Compile Include="Datastore\DbFactory.cs" /> <Compile Include="Datastore\DbFactory.cs" />
<Compile Include="Datastore\Converters\EnumIntConverter.cs" /> <Compile Include="Datastore\Converters\EnumIntConverter.cs" />

View File

@ -322,7 +322,7 @@ namespace NzbDrone.Core.Parser
} }
//Based on extension //Based on extension
if (result.Quality == Quality.Unknown) if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
{ {
try try
{ {

View File

@ -25,7 +25,7 @@
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/> layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
</targets> </targets>
<rules> <rules>
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/> <logger name="*" minlevel="Trace" writeTo="consoleLogger"/>
<logger name="*" minlevel="Off" writeTo="udpTarget"/> <logger name="*" minlevel="Off" writeTo="udpTarget"/>
<logger name="*" minlevel="Warn" writeTo="rollingFileLogger"/> <logger name="*" minlevel="Warn" writeTo="rollingFileLogger"/>
</rules> </rules>