2019-12-15 04:33:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common
|
|
|
|
|
{
|
|
|
|
|
public class Metrics
|
|
|
|
|
{
|
2020-01-18 19:28:24 +00:00
|
|
|
|
public const string Downloading = "downloading";
|
|
|
|
|
public const string BeginInstall = "begin_install";
|
|
|
|
|
public const string FinishInstall = "finish_install";
|
|
|
|
|
|
2020-01-04 02:49:08 +00:00
|
|
|
|
static Metrics()
|
|
|
|
|
{
|
|
|
|
|
if (!Utils.HaveEncryptedJson(Consts.MetricsKeyHeader))
|
|
|
|
|
{
|
2020-05-25 16:24:16 +00:00
|
|
|
|
Utils.MakeRandomKey().ToEcryptedJson(Consts.MetricsKeyHeader).AsTask().Wait();
|
2020-01-04 02:49:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-15 04:33:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is all we track for metrics, action, and value. The action will be like
|
|
|
|
|
/// "downloaded", the value "Joe's list".
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="action"></param>
|
|
|
|
|
/// <param name="value"></param>
|
2019-12-15 05:04:02 +00:00
|
|
|
|
public static async Task Send(string action, string value)
|
2019-12-15 04:33:48 +00:00
|
|
|
|
{
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-01-04 23:47:51 +00:00
|
|
|
|
client.DefaultRequestHeaders.Add(Consts.MetricsKeyHeader,
|
2020-05-25 14:31:56 +00:00
|
|
|
|
await Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader));
|
2020-04-08 22:28:50 +00:00
|
|
|
|
await client.GetAsync($"{Consts.WabbajackBuildServerUri}metrics/{action}/{value}");
|
2019-12-15 04:33:48 +00:00
|
|
|
|
}
|
2020-03-28 13:33:39 +00:00
|
|
|
|
catch (Exception)
|
2020-01-04 23:47:51 +00:00
|
|
|
|
{
|
2020-03-28 13:33:39 +00:00
|
|
|
|
// ignored
|
2020-01-04 23:47:51 +00:00
|
|
|
|
}
|
2019-12-15 04:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|