2012-01-27 09:10:15 +03:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2012-01-25 06:09:49 +03:00
|
|
|
using DeskMetrics;
|
2012-01-27 09:10:15 +03:00
|
|
|
using NLog;
|
2012-01-25 06:09:49 +03:00
|
|
|
using Ninject;
|
|
|
|
using NzbDrone.Common;
|
2012-02-03 03:11:18 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2012-01-25 06:09:49 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
|
|
|
public class AnalyticsProvider
|
|
|
|
{
|
2012-01-27 09:10:15 +03:00
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2012-01-25 06:09:49 +03:00
|
|
|
private readonly IDeskMetricsClient _deskMetricsClient;
|
2012-02-03 03:11:18 +03:00
|
|
|
private readonly ConfigProvider _configProvider;
|
2012-01-26 04:52:47 +03:00
|
|
|
public const string DESKMETRICS_TEST_ID = "4ea8d347a14ad71442000002";
|
|
|
|
public const string DESKMETRICS_PRODUCTION_ID = "4f20b01ea14ad729b2000000";
|
2012-01-25 06:09:49 +03:00
|
|
|
|
|
|
|
[Inject]
|
2012-02-03 03:11:18 +03:00
|
|
|
public AnalyticsProvider(IDeskMetricsClient deskMetricsClient, ConfigProvider configProvider)
|
2012-01-25 06:09:49 +03:00
|
|
|
{
|
|
|
|
_deskMetricsClient = deskMetricsClient;
|
2012-02-03 03:11:18 +03:00
|
|
|
_configProvider = configProvider;
|
2012-01-25 06:09:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public AnalyticsProvider()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Checkpoint()
|
|
|
|
{
|
2012-01-27 09:10:15 +03:00
|
|
|
try
|
2012-01-25 06:09:49 +03:00
|
|
|
{
|
2012-02-03 03:11:18 +03:00
|
|
|
//Don't report anything unless working from master branch.
|
2012-02-13 10:49:53 +03:00
|
|
|
if (!IsOnMasterBranch())
|
2012-02-03 03:11:18 +03:00
|
|
|
return;
|
|
|
|
|
2012-03-07 05:59:43 +03:00
|
|
|
if (EnvironmentProvider.RegisterNewInstall)
|
2012-01-27 09:10:15 +03:00
|
|
|
{
|
|
|
|
_deskMetricsClient.RegisterInstall();
|
2012-03-07 05:59:43 +03:00
|
|
|
EnvironmentProvider.RegisterNewInstall = false;
|
2012-01-27 09:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_deskMetricsClient.Started)
|
|
|
|
{
|
|
|
|
_deskMetricsClient.Stop();
|
|
|
|
}
|
2012-01-25 06:09:49 +03:00
|
|
|
|
2012-01-27 09:10:15 +03:00
|
|
|
_deskMetricsClient.Start();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
2012-01-26 04:29:55 +03:00
|
|
|
{
|
2012-03-07 05:59:43 +03:00
|
|
|
if (!EnvironmentProvider.IsProduction)
|
2012-01-27 09:10:15 +03:00
|
|
|
throw;
|
|
|
|
|
|
|
|
logger.WarnException("Error while sending analytics data.", e);
|
2012-01-26 04:29:55 +03:00
|
|
|
}
|
2012-01-25 06:09:49 +03:00
|
|
|
}
|
2012-02-03 03:11:18 +03: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 06:09:49 +03:00
|
|
|
}
|
|
|
|
}
|