private async Task DisplayImageAsync(ScreenshotID id) { this.StartLoading(); try { HttpClient client = App.HttpClientCache.GetClient(); this.WriteStatusNormal($"Downloading image {id}..."); this._currentScreenshot = await client.DownloadScreenshotAsync(id); using (MemoryStream stream = new MemoryStream(this._currentScreenshot.Data)) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; image.CacheOption = BitmapCacheOption.OnLoad; image.UriSource = null; image.StreamSource = stream; image.EndInit(); image.Freeze(); ImageBox.Source = image; } this.ScreenshotIdBox.Text = this._currentScreenshot.ID.ToString(); this.WriteStatusNormal("Done."); } catch { this.WriteStatusError($"Failed loading image {id}."); } finally { this.StopLoading(); } }
private bool ValidateScreenshotIdInput() { bool isValid = ScreenshotID.Validate(this.ScreenshotIdBox.Text); this.ScreenshotIdBox.BorderBrush = isValid ? _normalScreenshotIdBoxBorderBrush : App.ErrorBrush; this.GoToIdButton.IsEnabled = isValid; this.GoToIdButton.Foreground = isValid ? App.DefaultForegroundBrush : App.ErrorBrush; this.ScreenshotInvalidWarning.Visibility = isValid ? Visibility.Collapsed : Visibility.Visible; return(isValid); }
private async void GoToIdButton_Click(object sender, RoutedEventArgs e) { if (!ScreenshotID.Validate(ScreenshotIdBox.Text)) { this.WriteStatusError("Incorrect Screenshot ID.", true); } else { await DisplayImageAsync(new ScreenshotID(ScreenshotIdBox.Text)); } }