From 32204107dd1a99ddd6514ddfa680f3b5634ce482 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Mar 2016 00:17:00 -0500 Subject: [PATCH] add advanced setting --- .../Configuration/ServerConfiguration.cs | 3 +++ .../EntryPoints/UsageEntryPoint.cs | 17 ++++++++++++++--- .../EntryPoints/UsageReporter.cs | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 5527c16463..64edbdea9c 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -205,6 +205,8 @@ namespace MediaBrowser.Model.Configuration public int MigrationVersion { get; set; } public bool DownloadImagesInAdvance { get; set; } + + public bool EnableAnonymousUsageReporting { get; set; } /// /// Initializes a new instance of the class. @@ -221,6 +223,7 @@ namespace MediaBrowser.Model.Configuration EnableHttps = false; EnableDashboardResponseCaching = true; EnableDashboardResourceMinification = true; + EnableAnonymousUsageReporting = true; EnableAutomaticRestart = true; DenyIFrameEmbedding = true; diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs index d8aef909bb..f82bb01bb3 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UsageEntryPoint.cs @@ -10,6 +10,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; namespace MediaBrowser.Server.Implementations.EntryPoints { @@ -23,18 +24,18 @@ namespace MediaBrowser.Server.Implementations.EntryPoints private readonly ILogger _logger; private readonly ISessionManager _sessionManager; private readonly IUserManager _userManager; - - private readonly TimeSpan _frequency = TimeSpan.FromHours(24); + private readonly IServerConfigurationManager _config; private readonly ConcurrentDictionary _apps = new ConcurrentDictionary(); - public UsageEntryPoint(ILogger logger, IApplicationHost applicationHost, IHttpClient httpClient, ISessionManager sessionManager, IUserManager userManager) + public UsageEntryPoint(ILogger logger, IApplicationHost applicationHost, IHttpClient httpClient, ISessionManager sessionManager, IUserManager userManager, IServerConfigurationManager config) { _logger = logger; _applicationHost = applicationHost; _httpClient = httpClient; _sessionManager = sessionManager; _userManager = userManager; + _config = config; _sessionManager.SessionStarted += _sessionManager_SessionStarted; } @@ -64,6 +65,11 @@ namespace MediaBrowser.Server.Implementations.EntryPoints private async void ReportNewSession(ClientInfo client) { + if (!_config.Configuration.EnableAnonymousUsageReporting) + { + return; + } + try { await new UsageReporter(_applicationHost, _httpClient, _userManager, _logger) @@ -106,6 +112,11 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// private async void OnTimerFired() { + if (!_config.Configuration.EnableAnonymousUsageReporting) + { + return; + } + try { await new UsageReporter(_applicationHost, _httpClient, _userManager, _logger) diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs b/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs index 2473f3af69..cbec916791 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UsageReporter.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Logging; namespace MediaBrowser.Server.Implementations.EntryPoints @@ -51,6 +52,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints data["plugins"] = string.Join(",", _applicationHost.Plugins.Select(i => i.Id).ToArray()); + var logErrors = false; +#if DEBUG + logErrors = true; +#endif var options = new HttpRequestOptions { Url = MbAdminUrl + "service/registration/ping", @@ -59,7 +64,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints // Seeing block length errors EnableHttpCompression = false, - LogRequest = false + LogRequest = false, + LogErrors = logErrors }; options.SetPostData(data); @@ -95,6 +101,11 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { "platform", app.DeviceName }, }; + var logErrors = false; + +#if DEBUG + logErrors = true; +#endif var options = new HttpRequestOptions { Url = MbAdminUrl + "service/registration/ping", @@ -103,7 +114,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints // Seeing block length errors EnableHttpCompression = false, - LogRequest = false + LogRequest = false, + LogErrors = logErrors }; options.SetPostData(data);