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", ApplicationHost.Name }, { "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; }
}
}
}