From 4ebba2b2e87e33f083c095957a2294b6f8ae3828 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 15 Feb 2014 17:42:06 -0500 Subject: change usage reporting to a timer --- .../MediaBrowser.Common.Implementations.csproj | 2 +- .../ScheduledTasks/Tasks/StatisticsTask.cs | 127 --------------------- .../Security/UsageReporter.cs | 40 +++++++ 3 files changed, 41 insertions(+), 128 deletions(-) delete mode 100644 MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs create mode 100644 MediaBrowser.Common.Implementations/Security/UsageReporter.cs (limited to 'MediaBrowser.Common.Implementations') diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index dfe7d70ee..1688fac8b 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -92,7 +92,6 @@ - @@ -105,6 +104,7 @@ + diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs deleted file mode 100644 index 9c0fe165d..000000000 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs +++ /dev/null @@ -1,127 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Model.Logging; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks -{ - /// - /// Class ReloadLoggerFileTask - /// - public class StatisticsTask : IScheduledTask, IConfigurableScheduledTask - { - /// - /// Gets or sets the log manager. - /// - /// The log manager. - private ILogManager LogManager { get; set; } - /// - /// Gets or sets the app host - /// - /// The application host. - private IApplicationHost ApplicationHost { get; set; } - - /// - /// The network manager - /// - private INetworkManager NetworkManager { get; set; } - - /// - /// The http client - /// - private IHttpClient HttpClient { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The logManager. - /// - /// - public StatisticsTask(ILogManager logManager, IApplicationHost appHost, INetworkManager networkManager, IHttpClient httpClient) - { - LogManager = logManager; - ApplicationHost = appHost; - NetworkManager = networkManager; - HttpClient = httpClient; - } - - /// - /// Gets the default triggers. - /// - /// IEnumerable{BaseTaskTrigger}. - public IEnumerable GetDefaultTriggers() - { - var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(20) }; //8pm - when the system is most likely to be active - var trigger2 = new StartupTrigger(); //and also at system start - - return new ITaskTrigger[] { trigger, trigger2 }; - } - - /// - /// Executes the internal. - /// - /// The cancellation token. - /// The progress. - /// Task. - public async Task Execute(CancellationToken cancellationToken, IProgress progress) - { - cancellationToken.ThrowIfCancellationRequested(); - - progress.Report(0); - var mac = NetworkManager.GetMacAddress(); - - var data = new Dictionary - { - { "feature", ApplicationHost.Name }, - { "mac", mac }, - { "ver", ApplicationHost.ApplicationVersion.ToString() }, - { "platform", Environment.OSVersion.VersionString }, - { "isservice", ApplicationHost.IsRunningAsService.ToString().ToLower()} - }; - - await HttpClient.Post(Constants.Constants.MbAdminUrl + "service/registration/ping", data, CancellationToken.None).ConfigureAwait(false); - progress.Report(100); - - } - - /// - /// Gets the name. - /// - /// The name. - public string Name - { - get { return "Collect anonymous usage stats"; } - } - - /// - /// Gets the description. - /// - /// The description. - public string Description - { - get { return "Pings the admin site just so we know how many folks are out there and what version they are on."; } - } - - /// - /// Gets the category. - /// - /// The category. - public string Category - { - get { return "Application"; } - } - - public bool IsHidden - { - get { return true; } - } - - public bool IsEnabled - { - get { return true; } - } - } -} diff --git a/MediaBrowser.Common.Implementations/Security/UsageReporter.cs b/MediaBrowser.Common.Implementations/Security/UsageReporter.cs new file mode 100644 index 000000000..e32940be9 --- /dev/null +++ b/MediaBrowser.Common.Implementations/Security/UsageReporter.cs @@ -0,0 +1,40 @@ +using MediaBrowser.Common.Net; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.Implementations.Security +{ + public class UsageReporter + { + private readonly IApplicationHost _applicationHost; + private readonly INetworkManager _networkManager; + private readonly IHttpClient _httpClient; + + public UsageReporter(IApplicationHost applicationHost, INetworkManager networkManager, IHttpClient httpClient) + { + _applicationHost = applicationHost; + _networkManager = networkManager; + _httpClient = httpClient; + } + + public Task ReportUsage(CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + var mac = _networkManager.GetMacAddress(); + + var data = new Dictionary + { + { "feature", _applicationHost.Name }, + { "mac", mac }, + { "ver", _applicationHost.ApplicationVersion.ToString() }, + { "platform", Environment.OSVersion.VersionString }, + { "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()} + }; + + return _httpClient.Post(Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken); + } + } +} -- cgit v1.2.3