private async void FetchData() { GetFrequency(); ApiAdapter.GenerateUri(); await this.Dispatcher.Invoke(async() => { await ApiAdapter.GetItems(); }); currentData.CheckActives(); SetOpacity(); }
private async void FetchData() { MainWindow.overlay.WarningMessage = ""; MainWindow.overlay.ShadowOpacity = 0; MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Hidden; //aTimer.Stop(); CalculationActive = true; this.Dispatcher.Invoke(() => { IsIndeterminate = true; }); await this.Dispatcher.Invoke(async() => { GetFrequency(); if (await ApiAdapter.GenerateUri()) { if (await ApiAdapter.GetItems()) { try { await Task.Run(() => { Data.CheckActives(); SetOpacity(); //ChaosRecipeEnhancer.aTimer.Enabled = true; Trace.WriteLine("timer enabled"); aTimer.Enabled = true; CalculationActive = false; this.Dispatcher.Invoke(() => { IsIndeterminate = false; }); }, Data.ct); } catch (OperationCanceledException ex) when(ex.CancellationToken == Data.ct) { Trace.WriteLine("abort"); CalculationActive = false; this.Dispatcher.Invoke(() => { IsIndeterminate = false; }); } } } if (RateLimit.RateLimitExceeded) { // TODO: show rate limit exceeded in ui MainWindow.overlay.WarningMessage = "Rate Limit Exceeded! Waiting..."; MainWindow.overlay.ShadowOpacity = 1; MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible; aTimer.Enabled = false; await Task.Delay(RateLimit.GetSecondsToWait() * 1000); RateLimit.RequestCounter = 0; RateLimit.RateLimitExceeded = false; aTimer.Enabled = true; } if (RateLimit.BanTime > 0) { MainWindow.overlay.WarningMessage = "Temporary Ban! Waiting..."; MainWindow.overlay.ShadowOpacity = 1; MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible; aTimer.Enabled = false; await Task.Delay(RateLimit.BanTime * 1000); RateLimit.BanTime = 0; aTimer.Enabled = true; } }); }
private async void FetchData() { if (FetchingActive) { return; } if (!Properties.Settings.Default.ChaosRecipe && !Properties.Settings.Default.RegalRecipe && !Properties.Settings.Default.ExaltedRecipe) { MessageBox.Show("No recipes are enabled. Please pick a recipe.", "No Recipes", MessageBoxButton.OK, MessageBoxImage.Error); return; } DisableWarnings(); FetchingActive = true; CalculationActive = true; this.Dispatcher.Invoke(() => { IsIndeterminate = true; FetchButtonEnabled = false; FetchButtonColor = Brushes.DimGray; }); await this.Dispatcher.Invoke(async() => { if (await ApiAdapter.GenerateUri()) { if (await ApiAdapter.GetItems()) { try { await Task.Run(async() => { await Data.CheckActives(); SetOpacity(); CalculationActive = false; this.Dispatcher.Invoke(() => { IsIndeterminate = false; }); }, Data.ct); await Task.Delay(fetchCooldown * 1000).ContinueWith(_ => { Trace.WriteLine("waited fetchcooldown"); //FetchButtonEnabled = true; //FetchButtonColor = Brushes.Green; //FetchingActive = false; }); } catch (OperationCanceledException ex) when(ex.CancellationToken == Data.ct) { Trace.WriteLine("abort"); } } } if (RateLimit.RateLimitExceeded) { MainWindow.overlay.WarningMessage = "Rate Limit Exceeded! Waiting..."; MainWindow.overlay.ShadowOpacity = 1; MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible; await Task.Delay(RateLimit.GetSecondsToWait() * 1000); RateLimit.RequestCounter = 0; RateLimit.RateLimitExceeded = false; } if (RateLimit.BanTime > 0) { MainWindow.overlay.WarningMessage = "Temporary Ban! Waiting..."; MainWindow.overlay.ShadowOpacity = 1; MainWindow.overlay.WarningMessageVisibility = System.Windows.Visibility.Visible; await Task.Delay(RateLimit.BanTime * 1000); RateLimit.BanTime = 0; } }); CalculationActive = false; FetchingActive = false; this.Dispatcher.Invoke(() => { IsIndeterminate = false; FetchButtonEnabled = true; FetchButtonColor = Brushes.Green; FetchingActive = false; }); Trace.WriteLine("end of fetch function reached"); }