fixed some issues here and there.

pull/2/head
kay.one 12 years ago
parent 4deecde092
commit 85cd877b0c

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

@ -23,19 +23,13 @@ namespace NzbDrone.Api.SignalR
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);
}
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)
{
var context =((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType());
context.Connection.Broadcast(message);
}
}

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

@ -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]
public void should_have_id_when_returned_from_database()

@ -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;
}
}
}

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

@ -8,7 +8,6 @@ namespace NzbDrone.Core.Jobs
{
public interface IScheduledTaskRepository : IBasicRepository<ScheduledTask>
{
IList<ScheduledTask> GetPendingJobs();
ScheduledTask GetDefinition(Type type);
void SetLastExecutionTime(int id, DateTime executionTime);
}
@ -27,12 +26,6 @@ namespace NzbDrone.Core.Jobs
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)
{
var task = new ScheduledTask

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

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Jobs
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)

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

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

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

Loading…
Cancel
Save