Skip to content

Commit

Permalink
Subscribe to EDDN event when running StartAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Apr 14, 2024
1 parent 4afbd80 commit 9c50997
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions EDDN/EliteAPI.EDDN/EliteDangerousApiEddnBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,37 @@ namespace EliteAPI.EDDN;
public class EliteDangerousApiEddnBridge
{
private readonly ILogger<EliteDangerousApiEddnBridge> _log;
private readonly IEliteDangerousApi _api;
private readonly HttpClient _http;

private CommanderEvent _commander;
private FileheaderEvent _fileHeader;
private LoadGameEvent _loadGame;

private string productName;
private string productVersion;
private string _productName;
private string _productVersion;

public EliteDangerousApiEddnBridge(ILogger<EliteDangerousApiEddnBridge> log, IEliteDangerousApi api, IHttpClientFactory http)
{
_log = log;
_api = api;

_http = http.CreateClient("EDDN");

api.Events.On<CommanderEvent>(e => _commander = e);
api.Events.On<FileheaderEvent>(e => _fileHeader = e);
api.Events.On<LoadGameEvent>(e => _loadGame = e);
api.Events.On<MarketEvent>(OnMarketEvent);
}


public Task StartAsync(string productName, string productVersion)
{
this.productName = productName;
this.productVersion = productVersion;
_log.LogDebug("Starting EDDN bridge...");

_productName = productName;
_productVersion = productVersion;

_api.Events.On<CommanderEvent>(e => _commander = e);
_api.Events.On<FileheaderEvent>(e => _fileHeader = e);
_api.Events.On<LoadGameEvent>(e => _loadGame = e);
_api.Events.On<MarketEvent>(OnMarketEvent);

return Task.CompletedTask;
}

Expand All @@ -56,8 +61,8 @@ private async Task OnMarketEvent(MarketEvent e, EventContext c)
{
Gamebuild = _fileHeader.Build,
Gameversion = _fileHeader.Gameversion,
SoftwareName = productName,
SoftwareVersion = productVersion,
SoftwareName = _productName,
SoftwareVersion = _productVersion,
UploaderID = _commander.Name,
GatewayTimestamp = DateTime.Now
};
Expand Down Expand Up @@ -126,10 +131,10 @@ private async Task SendData(string json)

private bool IsValidEvent(IEvent e, EventContext c)
{
if (string.IsNullOrWhiteSpace(productName))
if (string.IsNullOrWhiteSpace(_productName))
return false;

if (string.IsNullOrWhiteSpace(productVersion))
if (string.IsNullOrWhiteSpace(_productVersion))
return false;

// Filter out events that are raised during catchup
Expand Down

0 comments on commit 9c50997

Please sign in to comment.