2014-09-06 20:09:35 +00:00
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2015-01-02 05:36:27 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Connect;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-01-02 05:36:27 +00:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-01-21 20:27:07 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2015-12-30 07:11:58 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
|
2016-11-03 22:06:00 +00:00
|
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{
|
|
|
|
|
public class UsageReporter
|
|
|
|
|
{
|
2017-01-21 20:27:07 +00:00
|
|
|
|
private readonly IServerApplicationHost _applicationHost;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
private readonly IHttpClient _httpClient;
|
2015-12-30 07:11:58 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2018-10-21 23:16:58 +00:00
|
|
|
|
private const string MbAdminUrl = "https://www.mb3admin.local/admin/";
|
2014-02-15 22:42:06 +00:00
|
|
|
|
|
2017-09-25 19:13:34 +00:00
|
|
|
|
public UsageReporter(IServerApplicationHost applicationHost, IHttpClient httpClient, ILogger logger)
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{
|
|
|
|
|
_applicationHost = applicationHost;
|
|
|
|
|
_httpClient = httpClient;
|
2015-12-30 07:11:58 +00:00
|
|
|
|
_logger = logger;
|
2014-02-15 22:42:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-23 18:21:35 +00:00
|
|
|
|
public async Task ReportServerUsage(CancellationToken cancellationToken)
|
2014-02-15 22:42:06 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var data = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "feature", _applicationHost.Name },
|
2015-01-10 19:42:14 +00:00
|
|
|
|
{ "mac", _applicationHost.SystemId },
|
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() },
|
2017-02-23 19:13:07 +00:00
|
|
|
|
{ "platform", _applicationHost.OperatingSystemDisplayName }
|
2014-02-15 22:42:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-07-23 05:25:55 +00:00
|
|
|
|
data["plugins"] = string.Join(",", _applicationHost.Plugins.Select(i => i.Id).ToArray());
|
2015-12-30 07:11:58 +00:00
|
|
|
|
|
2016-03-03 05:17:00 +00:00
|
|
|
|
var logErrors = false;
|
|
|
|
|
#if DEBUG
|
|
|
|
|
logErrors = true;
|
|
|
|
|
#endif
|
2016-01-23 18:21:35 +00:00
|
|
|
|
var options = new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = MbAdminUrl + "service/registration/ping",
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
|
|
|
|
|
// Seeing block length errors
|
2016-03-02 18:42:39 +00:00
|
|
|
|
EnableHttpCompression = false,
|
|
|
|
|
|
2016-03-03 05:17:00 +00:00
|
|
|
|
LogRequest = false,
|
2016-10-06 18:55:01 +00:00
|
|
|
|
LogErrors = logErrors,
|
|
|
|
|
BufferContent = false
|
2016-01-23 18:21:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options.SetPostData(data);
|
|
|
|
|
|
|
|
|
|
using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2014-02-15 22:42:06 +00:00
|
|
|
|
}
|
2014-05-28 14:21:07 +00:00
|
|
|
|
|
2016-01-23 18:21:35 +00:00
|
|
|
|
public async Task ReportAppUsage(ClientInfo app, CancellationToken cancellationToken)
|
2014-05-28 14:21:07 +00:00
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
|
if (string.IsNullOrEmpty(app.DeviceId))
|
2014-09-06 17:46:09 +00:00
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Client info must have a device Id");
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 07:11:58 +00:00
|
|
|
|
_logger.Info("App Activity: app: {0}, version: {1}, deviceId: {2}, deviceName: {3}",
|
|
|
|
|
app.AppName ?? "Unknown App",
|
|
|
|
|
app.AppVersion ?? "Unknown",
|
|
|
|
|
app.DeviceId,
|
|
|
|
|
app.DeviceName ?? "Unknown");
|
|
|
|
|
|
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
|
|
|
|
|
2016-03-03 05:17:00 +00:00
|
|
|
|
var logErrors = false;
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
logErrors = true;
|
|
|
|
|
#endif
|
2016-01-23 18:21:35 +00:00
|
|
|
|
var options = new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
Url = MbAdminUrl + "service/registration/ping",
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
|
|
|
|
|
// Seeing block length errors
|
2016-03-02 18:42:39 +00:00
|
|
|
|
EnableHttpCompression = false,
|
|
|
|
|
|
2016-03-03 05:17:00 +00:00
|
|
|
|
LogRequest = false,
|
2016-10-06 18:55:01 +00:00
|
|
|
|
LogErrors = logErrors,
|
|
|
|
|
BufferContent = false
|
2016-01-23 18:21:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options.SetPostData(data);
|
|
|
|
|
|
|
|
|
|
using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|