private async void DownloadImageButton_Click(object sender, RoutedEventArgs e) { if (!(Application.Current.MainWindow.DataContext is MainWindowViewModel context)) { return; } // Clear the error text box DownloadImageErrorText.Text = String.Empty; // What do we download? bool downloadChamps = ChampionCheckBox.IsChecked ?? false; bool downloadItems = ItemCheckBox.IsChecked ?? false; bool downloadRunes = RunesCheckBox.IsChecked ?? false; // Nothing was selected, do nothing if (downloadChamps == false && downloadItems == false && downloadRunes == false) { DownloadImageErrorText.Text = (string)TryFindResource("WswDownloadNoSelectionError"); return; } // Create all the requests we need List <RequestBase> requests = new List <RequestBase>(); if (downloadChamps) { requests.AddRange(await context.RequestManager.GetAllChampionRequests() .ConfigureAwait(true)); } if (downloadItems) { requests.AddRange(await context.RequestManager.GetAllItemRequests() .ConfigureAwait(true)); } if (downloadRunes) { requests.AddRange(await context.RequestManager.GetAllRuneRequests(RuneHelper.GetAllRunes()) .ConfigureAwait(true)); } // No requests? nothing to do if (requests.Count < 1) { DownloadImageErrorText.Text = (string)TryFindResource("WswDownloadMissingError"); return; } // Disable buttons while download happens ItemCheckBox.IsEnabled = false; ChampionCheckBox.IsEnabled = false; DownloadImageButton.IsEnabled = false; RunesCheckBox.IsChecked = false; // Make progress elements visible DownloadProgressGrid.Visibility = Visibility.Visible; DownloadProgressBar.Value = 0; DownloadProgressBar.Minimum = 0; DownloadProgressBar.Maximum = requests.Count; foreach (var request in requests) { var response = await context.RequestManager.MakeRequestAsync(request) .ConfigureAwait(true); string splitSubstring = response.ResponsePath; if (splitSubstring.Length > 50) { splitSubstring = response.ResponsePath.Substring(0, 35) + "..." + response.ResponsePath.Substring(response.ResponsePath.Length - 15); } DownloadProgressText.Text = splitSubstring; DownloadProgressBar.Value++; } }
private async void DownloadButton_OnClick(object sender, RoutedEventArgs e) { if (!(sender is Button)) { return; } if (!(this.DataContext is WelcomeSetupWindow parent)) { return; } if (!(parent.DataContext is MainWindowViewModel context)) { return; } // Clear the error text box ErrorText.Text = String.Empty; // What do we download? bool downloadChamps = ChampionCheckBox.IsChecked ?? false; bool downloadItems = ItemCheckBox.IsChecked ?? false; bool downloadRunes = RunesCheckBox.IsChecked ?? false; // Nothing was selected, do nothing if (downloadChamps == false && downloadItems == false && downloadRunes == false) { ErrorText.Text = (string)TryFindResource("WswDownloadNoSelectionError"); return; } // Create all the requests we need var requests = new List <RequestBase>(); if (downloadChamps) { requests.AddRange(await context.RequestManager.GetAllChampionRequests() .ConfigureAwait(true)); } if (downloadItems) { requests.AddRange(await context.RequestManager.GetAllItemRequests() .ConfigureAwait(true)); } if (downloadRunes) { requests.AddRange(await context.RequestManager.GetAllRuneRequests(RuneHelper.GetAllRunes()) .ConfigureAwait(true)); } // No requests? nothing to do if (requests.Count < 1) { ErrorText.Text = (string)TryFindResource("WswDownloadMissingError"); return; } // Disable buttons while download happens DownloadButton.IsEnabled = false; ItemCheckBox.IsEnabled = false; ChampionCheckBox.IsEnabled = false; RunesCheckBox.IsEnabled = false; NextButton.IsEnabled = false; PreviousButton.IsEnabled = false; SkipButton.IsEnabled = false; // Make progress elements visible DownloadProgressGrid.Visibility = Visibility.Visible; DownloadProgressBar.Value = 0; DownloadProgressBar.Minimum = 0; DownloadProgressBar.Maximum = requests.Count; foreach (RequestBase request in requests) { ResponseBase response = await context.RequestManager.MakeRequestAsync(request) .ConfigureAwait(true); DownloadProgressText.Text = response.ResponsePath; DownloadProgressBar.Value++; } }