From 2c4c19cd9f7742fb292f18a5aaf6956cd5f6cd40 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Sat, 25 Jan 2014 16:12:33 -0500 Subject: [PATCH] Add startup ping task --- .../ScheduledTasks/Tasks/StatisticsTask.cs | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs new file mode 100644 index 0000000000..41216460df --- /dev/null +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/StatisticsTask.cs @@ -0,0 +1,120 @@ +using System.Reflection; +using MediaBrowser.Common.Configuration; +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", Assembly.GetExecutingAssembly().GetName().ToString() }, { "mac", mac }, { "ver", ApplicationHost.ApplicationVersion.ToString() }, { "platform", Environment.OSVersion.VersionString } }; + 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 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; } + } + } +}