|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using DataTables.Mvc.Core.Helpers;
|
|
|
|
|
using DataTables.Mvc.Core.Models;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using PetaPoco;
|
|
|
|
@ -10,24 +12,20 @@ namespace NzbDrone.Core.Instrumentation
|
|
|
|
|
public class LogProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
private readonly LogDbContext _logDbContext;
|
|
|
|
|
private readonly DiskProvider _diskProvider;
|
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LogProvider(IDatabase database, LogDbContext logDbContext, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
|
|
|
|
|
public LogProvider(IDatabase database, DiskProvider diskProvider, EnvironmentProvider environmentProvider)
|
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
_logDbContext = logDbContext;
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
_environmentProvider = environmentProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQueryable<Log> GetAllLogs()
|
|
|
|
|
public List<Log> GetAllLogs()
|
|
|
|
|
{
|
|
|
|
|
return _logDbContext.Logs;
|
|
|
|
|
return _database.Fetch<Log>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<Log> TopLogs(int count)
|
|
|
|
@ -44,9 +42,35 @@ namespace NzbDrone.Core.Instrumentation
|
|
|
|
|
return logs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<Log> GetPagedLogs(int pageNumber, int pageSize)
|
|
|
|
|
public virtual Page<Log> GetPagedItems(DataTablesPageRequest pageRequest)
|
|
|
|
|
{
|
|
|
|
|
var query = Sql.Builder
|
|
|
|
|
.Select(@"*")
|
|
|
|
|
.From("Logs");
|
|
|
|
|
|
|
|
|
|
var startPage = (pageRequest.DisplayLength == 0) ? 1 : pageRequest.DisplayStart / pageRequest.DisplayLength + 1;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(pageRequest.Search))
|
|
|
|
|
{
|
|
|
|
|
var whereClause = string.Join(" OR ", SqlBuilderHelper.GetSearchClause(pageRequest));
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(whereClause))
|
|
|
|
|
query.Append("WHERE " + whereClause, "%" + pageRequest.Search + "%");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var orderBy = string.Join(",", SqlBuilderHelper.GetOrderByClause(pageRequest));
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(orderBy))
|
|
|
|
|
{
|
|
|
|
|
query.Append("ORDER BY " + orderBy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _database.Page<Log>(startPage, pageRequest.DisplayLength, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual long Count()
|
|
|
|
|
{
|
|
|
|
|
return _database.Page<Log>(pageNumber, pageSize, "SELECT * FROM Logs ORDER BY Time DESC");
|
|
|
|
|
return _database.Single<long>(@"SELECT COUNT(*) from Logs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteAll()
|
|
|
|
|