2012-01-23 03:24:16 +01:00
|
|
|
|
using System;
|
2012-02-09 18:41:51 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Dynamic;
|
2012-01-23 03:24:16 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Mvc;
|
2012-04-21 07:02:18 +02:00
|
|
|
|
using DataTables.Mvc.Core.Models;
|
2012-01-23 03:24:16 +01:00
|
|
|
|
using NzbDrone.Common;
|
2010-10-24 09:46:58 +02:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2012-04-21 10:16:15 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository.Search;
|
2011-08-22 03:00:12 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
2010-10-24 09:46:58 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class LogController : Controller
|
|
|
|
|
{
|
2011-04-10 02:14:51 +02:00
|
|
|
|
private readonly LogProvider _logProvider;
|
2012-03-07 03:59:43 +01:00
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
2012-01-23 03:24:16 +01:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2012-04-21 10:16:15 +02:00
|
|
|
|
private readonly SearchResultProvider _searchResultProvider;
|
2010-10-24 09:46:58 +02:00
|
|
|
|
|
2012-04-21 10:16:15 +02:00
|
|
|
|
public LogController(LogProvider logProvider, EnvironmentProvider environmentProvider,
|
|
|
|
|
DiskProvider diskProvider, SearchResultProvider searchResultProvider)
|
2010-10-24 09:46:58 +02:00
|
|
|
|
{
|
|
|
|
|
_logProvider = logProvider;
|
2012-03-07 03:59:43 +01:00
|
|
|
|
_environmentProvider = environmentProvider;
|
2012-01-23 03:24:16 +01:00
|
|
|
|
_diskProvider = diskProvider;
|
2012-04-21 10:16:15 +02:00
|
|
|
|
_searchResultProvider = searchResultProvider;
|
2010-10-24 09:46:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-23 03:24:16 +01:00
|
|
|
|
public FileContentResult File()
|
|
|
|
|
{
|
|
|
|
|
string log = string.Empty;
|
|
|
|
|
|
2012-03-07 03:59:43 +01:00
|
|
|
|
if (_diskProvider.FileExists(_environmentProvider.GetArchivedLogFileName()))
|
2012-01-23 03:24:16 +01:00
|
|
|
|
{
|
2012-03-07 03:59:43 +01:00
|
|
|
|
log = _diskProvider.ReadAllText(_environmentProvider.GetArchivedLogFileName());
|
2012-01-23 03:24:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 03:59:43 +01:00
|
|
|
|
log += _diskProvider.ReadAllText(_environmentProvider.GetLogFileName());
|
2012-01-23 03:24:16 +01:00
|
|
|
|
|
|
|
|
|
return new FileContentResult(Encoding.ASCII.GetBytes(log), "text/plain");
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 04:04:35 +02:00
|
|
|
|
public JsonResult Clear()
|
2010-10-24 09:46:58 +02:00
|
|
|
|
{
|
|
|
|
|
_logProvider.DeleteAll();
|
2011-08-06 04:04:35 +02:00
|
|
|
|
|
2012-01-19 06:01:47 +01:00
|
|
|
|
return JsonNotificationResult.Info("Logs Cleared");
|
2011-09-05 21:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 10:16:15 +02:00
|
|
|
|
public ActionResult SearchResults()
|
|
|
|
|
{
|
|
|
|
|
var results = _searchResultProvider.AllSearchResults();
|
|
|
|
|
|
|
|
|
|
var model = results.Select(s => new SearchResultsModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
SearchTime = s.SearchTime.ToString(),
|
|
|
|
|
DisplayName = GetDisplayName(s),
|
|
|
|
|
ReportCount = s.TotalItems,
|
|
|
|
|
Successful = s.Successes > 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult SearchDetails(int searchId)
|
|
|
|
|
{
|
|
|
|
|
var model = _searchResultProvider.GetSearchResult(searchId);
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 18:41:51 +01:00
|
|
|
|
public ActionResult AjaxBinding(DataTablesParams dataTablesParams)
|
|
|
|
|
{
|
|
|
|
|
var logs = _logProvider.GetAllLogs();
|
|
|
|
|
var totalCount = logs.Count();
|
|
|
|
|
|
|
|
|
|
IQueryable<Log> q = logs;
|
|
|
|
|
if (!string.IsNullOrEmpty(dataTablesParams.sSearch))
|
|
|
|
|
{
|
|
|
|
|
q = q.Where(b => b.Logger.Contains(dataTablesParams.sSearch)
|
|
|
|
|
|| b.Exception.Contains(dataTablesParams.sSearch)
|
|
|
|
|
|| b.Message.Contains(dataTablesParams.sSearch));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int filteredCount = q.Count();
|
|
|
|
|
|
2012-02-26 00:14:48 +01:00
|
|
|
|
IQueryable<Log> sorted = q;
|
2012-02-09 18:41:51 +01:00
|
|
|
|
|
2012-02-26 00:14:48 +01:00
|
|
|
|
for (int i = 0; i < dataTablesParams.iSortingCols; i++)
|
|
|
|
|
{
|
|
|
|
|
int sortCol = dataTablesParams.iSortCol[i];
|
|
|
|
|
var sortColName = sortCol == 0 ? "Time" : sortCol == 1 ? "Level" : "Logger";
|
|
|
|
|
var sortExpression = String.Format("{0} {1}", sortColName, dataTablesParams.sSortDir[i]);
|
|
|
|
|
|
|
|
|
|
sorted = sorted.OrderBy(sortExpression);
|
|
|
|
|
}
|
2012-02-09 18:41:51 +01:00
|
|
|
|
|
|
|
|
|
IQueryable<Log> filteredAndSorted = sorted;
|
|
|
|
|
if (filteredCount > dataTablesParams.iDisplayLength)
|
|
|
|
|
{
|
|
|
|
|
filteredAndSorted = sorted.Skip(dataTablesParams.iDisplayStart).Take(dataTablesParams.iDisplayLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var logModels = filteredAndSorted.ToList().Select(s => new LogModel
|
|
|
|
|
{
|
|
|
|
|
Time = s.Time.ToString(),
|
|
|
|
|
Level = s.Level,
|
|
|
|
|
Source = s.Logger,
|
|
|
|
|
Message = s.Message,
|
|
|
|
|
Method = s.Method,
|
|
|
|
|
ExceptionType = s.ExceptionType,
|
|
|
|
|
Exception = s.Exception
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
sEcho = dataTablesParams.sEcho,
|
|
|
|
|
iTotalRecords = totalCount,
|
|
|
|
|
iTotalDisplayRecords = filteredCount,
|
|
|
|
|
aaData = logModels
|
|
|
|
|
},
|
|
|
|
|
JsonRequestBehavior.AllowGet);
|
|
|
|
|
}
|
2012-04-21 10:16:15 +02:00
|
|
|
|
|
|
|
|
|
public string GetDisplayName(SearchResult searchResult)
|
|
|
|
|
{
|
|
|
|
|
if (!searchResult.EpisodeNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return String.Format("{0} - Season {1}", searchResult.SeriesTitle, searchResult.SeasonNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string episodeString;
|
|
|
|
|
|
|
|
|
|
if (searchResult.IsDaily)
|
|
|
|
|
episodeString = searchResult.AirDate.ToShortDateString().Replace('/', '-');
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
episodeString = String.Format("S{0:00}E{1:00}", searchResult.SeasonNumber,
|
|
|
|
|
searchResult.EpisodeNumber);
|
|
|
|
|
|
|
|
|
|
return String.Format("{0} - {1} - {2}", searchResult.SeriesTitle, episodeString, searchResult.EpisodeTitle);
|
|
|
|
|
}
|
2010-10-24 09:46:58 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|