1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Common/ReportingService.cs

74 lines
2.1 KiB
C#
Raw Normal View History

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";
public static RestProvider RestProvider { get; set; }
2012-04-23 01:14:02 +02:00
2012-04-23 01:14:02 +02:00
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
public static void ClearCache()
{
lock (parserErrorCache)
{
parserErrorCache.Clear();
}
}
public static void ReportParseError(string title)
{
try
{
2012-04-23 01:14:02 +02:00
VerifyDependencies();
lock (parserErrorCache)
{
if (parserErrorCache.Contains(title.ToLower())) return;
2012-04-23 01:14:02 +02:00
parserErrorCache.Add(title.ToLower());
}
var report = new ParseErrorReport { Title = title };
RestProvider.PostData(PARSE_URL, report);
}
catch (Exception e)
{
if (!EnvironmentProvider.IsProduction)
{
throw;
}
e.Data.Add("title", title);
2012-02-22 05:43:19 +01:00
logger.InfoException("Unable to report parse error", e);
}
}
2012-04-23 01:14:02 +02:00
private static void VerifyDependencies()
{
if (RestProvider == null)
{
2012-04-23 01:14:02 +02:00
if (EnvironmentProvider.IsProduction)
{
logger.Warn("Rest provider wasn't provided. creating new one!");
RestProvider = new RestProvider(new EnvironmentProvider());
}
else
{
throw new InvalidOperationException("REST Provider wasn't configured correctly.");
}
}
}
}
}