diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-02-15 17:42:06 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-02-15 17:42:06 -0500 |
| commit | 4ebba2b2e87e33f083c095957a2294b6f8ae3828 (patch) | |
| tree | 0df44ee8bc3eaa9427aa7e9680caeed7715dd8f7 /MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs | |
| parent | b24d7de92e8e8ea21cc90076fa33e38ad44c920f (diff) | |
change usage reporting to a timer
Diffstat (limited to 'MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs new file mode 100644 index 000000000..3ab47f51b --- /dev/null +++ b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs @@ -0,0 +1,63 @@ +using MediaBrowser.Common; +using MediaBrowser.Common.Implementations.Security; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Model.Logging; +using System; +using System.Threading; + +namespace MediaBrowser.Server.Implementations.EntryPoints +{ + /// <summary> + /// Class UsageEntryPoint + /// </summary> + public class UsageEntryPoint : IServerEntryPoint + { + private readonly IApplicationHost _applicationHost; + private readonly INetworkManager _networkManager; + private readonly IHttpClient _httpClient; + private readonly ILogger _logger; + + private Timer _timer; + private readonly TimeSpan _frequency = TimeSpan.FromHours(24); + + public UsageEntryPoint(ILogger logger, IApplicationHost applicationHost, INetworkManager networkManager, IHttpClient httpClient) + { + _logger = logger; + _applicationHost = applicationHost; + _networkManager = networkManager; + _httpClient = httpClient; + } + + public void Run() + { + _timer = new Timer(OnTimerFired, null, TimeSpan.FromMilliseconds(5000), _frequency); + } + + /// <summary> + /// Called when [timer fired]. + /// </summary> + /// <param name="state">The state.</param> + private async void OnTimerFired(object state) + { + try + { + await new UsageReporter(_applicationHost, _networkManager, _httpClient).ReportUsage(CancellationToken.None) + .ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.ErrorException("Error sending anonymous usage statistics.", ex); + } + } + + public void Dispose() + { + if (_timer != null) + { + _timer.Dispose(); + _timer = null; + } + } + } +} |
