-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTelemetryTransmitter.cs
51 lines (48 loc) · 1.69 KB
/
TelemetryTransmitter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
namespace AssetPacksManager;
public static class TelemetryTransmitter
{
private const string Endpoint = "http://apmtelemetry.webgadgets.de";
private const int Port = 5001;
private static bool _submitted;
public static async Task SubmitAsync(int loaded, int autoLoaded, int notLoaded, bool adaptiveLoadingEnabled)
{
if (Setting.Instance.DisableTelemetry)
{
ApmLogger.Instance.Info("Telemetry disabled");
return;
}
if (_submitted)
{
ApmLogger.Instance.Info("Telemetry already submitted");
return;
}
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
_submitted = true;
string uri = $"{Endpoint}:{Port}/submit?" +
$"loaded={loaded}&" +
$"autoLoaded={autoLoaded}&" +
$"notLoaded={notLoaded}&" +
$"adaptiveEnabled={adaptiveLoadingEnabled}&" +
$"version={version}";
try
{
var request = WebRequest.Create(uri);
request.Timeout = 10000;
request.Method = "GET";
await request.GetResponseAsync();
ApmLogger.Instance.Info($"{uri} -> Telemetry submit OK");
}
catch (WebException e) when (e.Status == WebExceptionStatus.Timeout)
{
ApmLogger.Instance.Info("Telemetry submit timeout; Server is probably unavailable at this time. This is not an issue.");
}
catch (Exception e)
{
ApmLogger.Instance.Warn($"{uri} -> {e}");
}
}
}