2012-02-05 06:34:36 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2012-02-16 06:16:57 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2012-02-05 06:34:36 +00:00
|
|
|
|
using NzbDrone.Common.Contract;
|
|
|
|
|
using NzbDrone.Services.Service.Repository.Reporting;
|
2012-02-17 22:04:22 +00:00
|
|
|
|
using Services.PetaPoco;
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Services.Service.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ReportingController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabase _database;
|
2012-03-01 06:38:42 +00:00
|
|
|
|
private readonly ExceptionController _exceptionController;
|
2012-02-16 06:16:57 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
|
|
|
|
private const string OK = "OK";
|
|
|
|
|
|
2012-03-01 06:38:42 +00:00
|
|
|
|
public ReportingController(IDatabase database, ExceptionController exceptionController)
|
2012-02-05 06:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
2012-03-01 06:38:42 +00:00
|
|
|
|
_exceptionController = exceptionController;
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public JsonResult ParseError(ParseErrorReport parseErrorReport)
|
|
|
|
|
{
|
2012-03-01 06:38:42 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-16 06:16:57 +00:00
|
|
|
|
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
2012-03-01 06:38:42 +00:00
|
|
|
|
logger.Trace(parseErrorReport.NullSafe());
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
2012-03-01 06:38:42 +00:00
|
|
|
|
if (ParseErrorExists(parseErrorReport.Title))
|
|
|
|
|
return Json(OK);
|
|
|
|
|
|
|
|
|
|
var row = new ParseErrorRow();
|
|
|
|
|
row.LoadBase(parseErrorReport);
|
|
|
|
|
row.Title = parseErrorReport.Title;
|
|
|
|
|
|
|
|
|
|
_database.Insert(row);
|
|
|
|
|
|
|
|
|
|
return Json(OK);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.FatalException("Error has occurred while saving parse report", e);
|
|
|
|
|
if (!parseErrorReport.IsProduction)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
2012-03-01 06:38:42 +00:00
|
|
|
|
return new JsonResult();
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool ParseErrorExists(string title)
|
|
|
|
|
{
|
2012-02-17 22:04:22 +00:00
|
|
|
|
return _database.Exists<ParseErrorRow>(title);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-04-22 23:14:02 +00:00
|
|
|
|
public JsonResult ReportException()
|
2012-02-05 06:34:36 +00:00
|
|
|
|
{
|
2012-04-22 23:14:02 +00:00
|
|
|
|
return new JsonResult();
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|