2012-02-05 07:34:36 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Contract;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common
|
|
|
|
|
{
|
|
|
|
|
public static class ReportingService
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2012-03-01 08:03:19 +01:00
|
|
|
|
private const string SERVICE_URL = "http://services.nzbdrone.com/reporting";
|
2012-02-05 17:53:08 +01:00
|
|
|
|
private const string PARSE_URL = SERVICE_URL + "/ParseError";
|
2012-02-05 07:34:36 +01:00
|
|
|
|
|
|
|
|
|
public static RestProvider RestProvider { get; set; }
|
2012-04-23 01:14:02 +02:00
|
|
|
|
|
2012-02-05 07:34:36 +01:00
|
|
|
|
|
2012-04-23 01:14:02 +02:00
|
|
|
|
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
|
2012-02-05 07:34:36 +01:00
|
|
|
|
|
|
|
|
|
public static void ClearCache()
|
|
|
|
|
{
|
|
|
|
|
lock (parserErrorCache)
|
|
|
|
|
{
|
|
|
|
|
parserErrorCache.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ReportParseError(string title)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-04-23 01:14:02 +02:00
|
|
|
|
VerifyDependencies();
|
2012-02-05 07:34:36 +01:00
|
|
|
|
|
|
|
|
|
lock (parserErrorCache)
|
|
|
|
|
{
|
|
|
|
|
if (parserErrorCache.Contains(title.ToLower())) return;
|
2012-04-23 01:14:02 +02:00
|
|
|
|
|
2012-02-05 07:34:36 +01:00
|
|
|
|
parserErrorCache.Add(title.ToLower());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var report = new ParseErrorReport { Title = title };
|
|
|
|
|
RestProvider.PostData(PARSE_URL, report);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2012-03-07 03:59:43 +01:00
|
|
|
|
if (!EnvironmentProvider.IsProduction)
|
2012-02-05 07:34:36 +01:00
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Data.Add("title", title);
|
2012-02-22 05:43:19 +01:00
|
|
|
|
logger.InfoException("Unable to report parse error", e);
|
2012-02-05 07:34:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 01:14:02 +02:00
|
|
|
|
private static void VerifyDependencies()
|
|
|
|
|
{
|
|
|
|
|
if (RestProvider == null)
|
2012-03-02 02:57:36 +01:00
|
|
|
|
{
|
2012-04-23 01:14:02 +02:00
|
|
|
|
if (EnvironmentProvider.IsProduction)
|
2012-03-02 02:57:36 +01:00
|
|
|
|
{
|
|
|
|
|
logger.Warn("Rest provider wasn't provided. creating new one!");
|
2012-03-07 03:59:43 +01:00
|
|
|
|
RestProvider = new RestProvider(new EnvironmentProvider());
|
2012-03-02 02:57:36 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("REST Provider wasn't configured correctly.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-05 07:34:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|