Feat/usage stats collection (#317)
* feat: implement anonymous usage data collection Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com>
This commit is contained in:
parent
b25335acbd
commit
1c9b2572ae
23 changed files with 613 additions and 17 deletions
55
API/Services/Clients/StatsApiClient.cs
Normal file
55
API/Services/Clients/StatsApiClient.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Services.Clients
|
||||
{
|
||||
public class StatsApiClient
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly ILogger<StatsApiClient> _logger;
|
||||
|
||||
public StatsApiClient(HttpClient client, ILogger<StatsApiClient> logger)
|
||||
{
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task SendDataToStatsServer(UsageStatisticsDto data)
|
||||
{
|
||||
var responseContent = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _client.PostAsJsonAsync("/api/InstallationStats", data);
|
||||
|
||||
responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
var info = new
|
||||
{
|
||||
dataSent = data,
|
||||
response = responseContent
|
||||
};
|
||||
|
||||
_logger.LogError(e, "The StatsServer did not respond successfully. {Content}", info);
|
||||
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "An error happened during the request to the Stats Server");
|
||||
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue