/// <summary> /// Make OpenWeather API Call to get location coordinates from search string /// </summary> public async void SetLocation() { try { await LocationSearch.SearchLocations(); } catch (Exception) { var E = new ErrorMessage("An error occurred whilst searching for location"); DisplayErrors.Add(E); } if (LocationSearch.SearchResults.Count == 0) { var E = new ErrorMessage($"Could not find a Match for {LocationSearch.SearchText}"); DisplayErrors.Clear(); DisplayErrors.Add(E); } else { // results found DisplayErrors.Clear(); Location = LocationSearch.SearchResults[0]; GetForecast(); } }
private async Task ImportDeck_ExecuteAsync() { if (string.IsNullOrWhiteSpace(ImportDeckUri)) { return; } DisplayErrors.Clear(); Reporter.StartBusy(); Reporter.StatusReported += BuildingCardsErrors; var imported = string.Empty; try { imported = await DeckImport.ImportFromUrl(ImportDeckUri, Reporter); } catch (Exception exc) { DisplayError(exc, $"Could not import deck from {ImportDeckUri}\r\n"); } DecklistText += "\r\n" + imported; Reporter.StatusReported -= BuildingCardsErrors; Reporter.StopBusy(); }
private void BuildingCardsErrors(object sender, CardMimicStatusEventArgs e) { if (!e.IsError) { return; } DisplayErrors.Add(e.Message); }
/// <summary> /// Make OpenWeather API Call to get weather information /// </summary> public async void GetForecast() { try { var excludePeriod = new PeriodOptions[] { PeriodOptions.Minutely, PeriodOptions.Hourly }; OneCallResponse = await OpenWeather.OneCall(Location.Lat, Location.Lon, excludePeriod); SetForecast(); } catch (Exception) { var E = new ErrorMessage("An error occurred whilst getting weather forecast"); DisplayErrors.Add(E); } }
private async Task SearchSubmit_ExecuteAsync() { DisplayErrors.Clear(); TimeSpan?timeSinceUpdate = DateTime.Now - OracleCatalog.UpdateTime; if (timeSinceUpdate == null) { var yesNoDialog = new YesNoDialogViewModel("Card Catalog must be updated before continuing. Would you like to update the Card Catalog (~65 MB) now?", "Update?"); if (!(DialogService.ShowDialog(yesNoDialog) ?? false)) { return; } await UpdateCatalog_ExecuteAsync(); } if (timeSinceUpdate > TimeSpan.FromDays(7)) { var yesNoDialog = new YesNoDialogViewModel("Card Catalog is out of date, it is recommended you get a new catalog now." + "If you don't, cards may not appear in search results or you may receive old " + "imagery. Click 'Yes' to update the Card Catalog (~65 MB) now or 'No' use the old catalog.", "Update?"); if (!(DialogService.ShowDialog(yesNoDialog) ?? false)) { return; } await UpdateCatalog_ExecuteAsync(); } DisplayedCards.Clear(); await Task.Delay(100); Reporter.StartBusy(); Reporter.StartProgress(); Reporter.Report("Deciphering old one's poem"); Reporter.StatusReported += BuildingCardsErrors; List <SearchLine> lines = DecklistText .Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) .Where(s => !string.IsNullOrWhiteSpace(s)) .Select(l => new SearchLine(l)) .ToList(); for (var i = 0; i < lines.Count; i++) { List <Card> cards = OracleCatalog.FindExactCard(lines[i].SearchTerm); if (!cards.Any()) { cards.Add(await ScryfallService.GetFuzzyCardAsync(lines[i].SearchTerm, Reporter)); } if (!cards.Any() || cards.Any(c => c == null)) { Reporter.Report($"[{lines[i].SearchTerm}] returned no results", true); continue; } Card preferredCard; if (cards.Count > 1) { var cardChooser = new ChooseCardDialogViewModel(cards, Reporter); await cardChooser.LoadImagesFromCards(); if (!(DialogService.ShowDialog(cardChooser) ?? false)) { continue; } preferredCard = ArtPreferences.GetPreferredCard(cardChooser.ChosenCard); } else { preferredCard = ArtPreferences.GetPreferredCard(cards.Single()); } if (preferredCard.IsDoubleFaced) { BitmapSource frontImage = ImageHelper.LoadBitmap(await ImageCaching.GetImageAsync(preferredCard.CardFaces[0].ImageUris.BorderCrop, Reporter)); var frontVm = new CardViewModel(Reporter, ArtPreferences, preferredCard, frontImage, lines[i].Quantity, ZoomPercent); BitmapSource backImage = ImageHelper.LoadBitmap(await ImageCaching.GetImageAsync(preferredCard.CardFaces[1].ImageUris.BorderCrop, Reporter)); var backVm = new CardViewModel(Reporter, ArtPreferences, preferredCard, backImage, lines[i].Quantity, ZoomPercent, false); DisplayedCards.Add(frontVm); await Task.Delay(10); DisplayedCards.Add(backVm); await Task.Delay(10); Reporter.Progress(i, 0, lines.Count - 1); } else { BitmapSource preferredImage = ImageHelper.LoadBitmap(await ImageCaching.GetImageAsync(preferredCard.ImageUris.BorderCrop, Reporter)); var cardVm = new CardViewModel(Reporter, ArtPreferences, preferredCard, preferredImage, lines[i].Quantity, ZoomPercent); DisplayedCards.Add(cardVm); await Task.Delay(10); Reporter.Progress(i, 0, lines.Count - 1); } } Reporter.StatusReported -= BuildingCardsErrors; Reporter.StopBusy(); Reporter.StopProgress(); }