2014-09-06 20:09:35 +00:00
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2014-09-06 20:09:35 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.EntryPoints
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 14:21:07 +00:00
|
|
|
|
public Task ReportServerUsage(CancellationToken cancellationToken)
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var mac = _networkManager.GetMacAddress();
|
|
|
|
|
|
|
|
|
|
var data = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "feature", _applicationHost.Name },
|
|
|
|
|
{ "mac", mac },
|
2014-09-06 20:07:24 +00:00
|
|
|
|
{ "serverid", _applicationHost.SystemId },
|
|
|
|
|
{ "deviceid", _applicationHost.SystemId },
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{ "ver", _applicationHost.ApplicationVersion.ToString() },
|
|
|
|
|
{ "platform", Environment.OSVersion.VersionString },
|
2014-08-25 03:54:45 +00:00
|
|
|
|
{ "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()}
|
2014-02-15 22:42:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-09-06 20:09:35 +00:00
|
|
|
|
return _httpClient.Post(Common.Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken);
|
2014-02-15 22:42:06 +00:00
|
|
|
|
}
|
2014-05-28 14:21:07 +00:00
|
|
|
|
|
|
|
|
|
public Task ReportAppUsage(ClientInfo app, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(app.DeviceId))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Client info must have a device Id");
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 16:30:38 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var data = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "feature", app.AppName ?? "Unknown App" },
|
2014-09-06 20:07:24 +00:00
|
|
|
|
{ "serverid", _applicationHost.SystemId },
|
|
|
|
|
{ "deviceid", app.DeviceId },
|
2014-09-06 17:46:09 +00:00
|
|
|
|
{ "mac", app.DeviceId },
|
2014-05-28 16:30:38 +00:00
|
|
|
|
{ "ver", app.AppVersion ?? "Unknown" },
|
|
|
|
|
{ "platform", app.DeviceName },
|
|
|
|
|
};
|
2014-05-28 14:21:07 +00:00
|
|
|
|
|
2014-09-06 20:09:35 +00:00
|
|
|
|
return _httpClient.Post(Common.Constants.Constants.MbAdminUrl + "service/registration/ping", data, cancellationToken);
|
2014-05-28 14:21:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ClientInfo
|
|
|
|
|
{
|
|
|
|
|
public string AppName { get; set; }
|
|
|
|
|
public string AppVersion { get; set; }
|
2014-05-28 14:30:55 +00:00
|
|
|
|
public string DeviceName { get; set; }
|
2014-05-28 14:25:53 +00:00
|
|
|
|
public string DeviceId { get; set; }
|
2014-02-15 22:42:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|