public async Task IntegrationTestUploadLatestLogs() { var logEventSource = new LogBurstPlayer(new SavedGamesDirectoryHelper().Directory, 5); var logCounter = new LogEventTypeCounter(); var stateRecorder = new PlayerStateRecorder(); var inaraRestClient = new ThrottlingRestClient("https://inara.cz/inapi/v1/"); var inaraConverter = new InaraEventConverter(stateRecorder); var inaraApiFacade = new InaraApiFacade(inaraRestClient, TestCredentials.ApiKey, TestCredentials.UserName); // Populate the state recorder to avoid missing ships/starsystems data foreach (var ev in logEventSource.Events) stateRecorder.OnNext(ev); var convertedEvents = logEventSource .Events .SelectMany(inaraConverter.Convert) .ToArray(); var results = await inaraApiFacade.ApiCall(convertedEvents); results = results .Where(e => e.EventStatus != 200) .Where(e => e.EventStatusText != "There is a newer inventory state recorded already.") .Where(e => e.EventStatusText != "This ship was not found but was added automatically.") .ToList(); CollectionAssert.IsEmpty(results); Assert.Pass("Uploaded {0} events", convertedEvents.Length); }
public async Task IntegrationTestUploadToInara() { var logEventSource = new JournalBurstPlayer(new SavedGamesDirectoryHelper().Directory, 5); var logCounter = new JournalEventTypeCounter(); var stateRecorder = new PlayerStateRecorder(); var inaraRestClient = new ThrottlingRestClient.Factory().CreateRestClient("https://inara.cz/inapi/v1/"); var inaraConverter = new InaraEventConverter(stateRecorder); var inaraApiFacade = new InaraApiFacade(inaraRestClient, TestCredentials.UserName, TestCredentials.Inara.ApiKey, null); // Populate the state recorder to avoid missing ships/starsystems data foreach (var ev in logEventSource.Events) { stateRecorder.OnNext(ev); } var convertedEvents = logEventSource .Events .SelectMany(inaraConverter.Convert) .ToArray(); var results = await inaraApiFacade.ApiCall(convertedEvents); results = results .Where(e => e.EventStatus != 200) .Where(e => !ignoredErrors.Contains(e.EventStatusText)) .ToList(); CollectionAssert.IsEmpty(results); Assert.Pass("Uploaded {0} events", convertedEvents.Length); }
public override async void FlushEvents(ICollection <ApiEvent> events) { if (!Settings.Verified) { return; } try { var facade = new InaraApiFacade(RestClient, Settings.ApiKey, GlobalSettings.CommanderName); var apiEvents = Compact(events).ToArray(); if (apiEvents.Length > 0) { await facade.ApiCall(apiEvents); } } catch (Exception e) { Log.Error(e, "Error while processing events"); } }
public override async void FlushEvents(ICollection <ApiInputEvent> events) { try { var commander = CurrentCommander; if (commander != null && ApiKeys.TryGetValue(commander.Name, out string apiKey)) { var facade = new InaraApiFacade(RestClient, commander.Name, apiKey, commander.FrontierID); var ApiInputs = Compact(events).ToArray(); if (ApiInputs.Length > 0) { await facade.ApiCall(ApiInputs); } Log.Info() .LoggerName(Log.Name) .Message("Uploaded events") .Property("eventsCount", events.Count) .Property("commander", commander) .Write(); } else { Log.Info() .LoggerName(Log.Name) .Message("No INARA API key set for commander, events discarded") .Property("eventsCount", events.Count) .Property("commander", commander?.Name ?? "null") .Write(); } } catch (InvalidApiKeyException) { notificationInterface.ShowErrorNotification("Invalid EDSM API key for CMDR " + CurrentCommander?.Name); } catch (Exception e) { Log.Error(e, "Error while processing events for INARA"); } }