1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Core/Providers/AnalyticsProvider.cs

72 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Linq;
2012-01-25 04:09:49 +01:00
using DeskMetrics;
using NLog;
2012-01-25 04:09:49 +01:00
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Providers.Core;
2012-01-25 04:09:49 +01:00
namespace NzbDrone.Core.Providers
{
public class AnalyticsProvider
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2012-01-25 04:09:49 +01:00
private readonly IDeskMetricsClient _deskMetricsClient;
private readonly ConfigProvider _configProvider;
public const string DESKMETRICS_TEST_ID = "4ea8d347a14ad71442000002";
public const string DESKMETRICS_PRODUCTION_ID = "4f20b01ea14ad729b2000000";
2012-01-25 04:09:49 +01:00
[Inject]
public AnalyticsProvider(IDeskMetricsClient deskMetricsClient, ConfigProvider configProvider)
2012-01-25 04:09:49 +01:00
{
_deskMetricsClient = deskMetricsClient;
_configProvider = configProvider;
2012-01-25 04:09:49 +01:00
}
public AnalyticsProvider()
{
}
public virtual void Checkpoint()
{
try
2012-01-25 04:09:49 +01:00
{
//Don't report anything unless working from master branch.
2012-02-13 08:49:53 +01:00
if (!IsOnMasterBranch())
return;
if (EnvironmentProvider.RegisterNewInstall)
{
_deskMetricsClient.RegisterInstall();
EnvironmentProvider.RegisterNewInstall = false;
}
if (_deskMetricsClient.Started)
{
_deskMetricsClient.Stop();
}
2012-01-25 04:09:49 +01:00
_deskMetricsClient.Start();
}
catch (Exception e)
2012-01-26 02:29:55 +01:00
{
if (!EnvironmentProvider.IsProduction)
throw;
logger.WarnException("Error while sending analytics data.", e);
2012-01-26 02:29:55 +01:00
}
2012-01-25 04:09:49 +01:00
}
private bool IsOnMasterBranch()
{
var defaultUpdateUrl = UpdateProvider.DEFAULT_UPDATE_URL.Trim().Trim('/');
var currentUpdateUrl = _configProvider.UpdateUrl.Trim().Trim('/');
return String.Equals(defaultUpdateUrl, currentUpdateUrl, StringComparison.InvariantCultureIgnoreCase);
}
2012-01-25 04:09:49 +01:00
}
}