async void Cmdr2Selected(KeyValuePair <bool, string> selected) { if (isLoading) { return; } Request.Interest = selected.Value; if (selected.Key == true) { if (_config == null) { LoadData(Request, true); } else { await LoadData(Request, false); ChartService.AddChartDataSet(_config, Request, response); chartComponent.Update(); } } else { ChartService.RemoveChartDataSet(_config, Request, response); chartComponent.Update(); } await onOptionsChanged.InvokeAsync(Request); }
public async Task LoadData(DsRequest Request, bool resetChart = true) { await semaphoreSlim.WaitAsync(); try { if (isLoading == false) { isLoading = true; await InvokeAsync(() => StateHasChanged()); } response = await dataService.LoadData(Request); if (response != null) { Request.Responses.Add(response); isDataAvailable = true; if (resetChart) { SetChartData(); if (Request.doReloadSelected && Request.CmdrsSelected != null) { var cmdrsSelected = Request.CmdrsSelected.Where(x => x.Selected && x.Name != Request.Interest); if (cmdrsSelected.Any()) { foreach (var cmdr in cmdrsSelected) { var cmdrrequest = new DsRequest(Request.Mode, Request.Timespan, Request.Player, cmdr.Name); var cmdrresponse = await dataService.LoadData(cmdrrequest); ChartService.AddChartDataSet(_config, cmdrrequest, cmdrresponse); chartComponent.Update(); } } } } } else { Info = "Failed loading data :("; } } catch (Exception e) { logger.LogError($"failed loading data: {e.Message}"); } finally { semaphoreSlim.Release(); } isLoading = false; await InvokeAsync(() => StateHasChanged()); }
async void CmdrSelected(string cmdr) { if (isLoading) { return; } if (_config == null) { Request.Interest = cmdr; LoadData(Request); } else { ChartService.RemoveChartDataSet(_config, Request, response); Request.Interest = cmdr; await LoadData(Request, false); ChartService.AddChartDataSet(_config, Request, response); chartComponent.Update(); } await onOptionsChanged.InvokeAsync(Request); }