示例#1
0
        private async void SubmitButton_OnClick(object sender, RoutedEventArgs e)
        {
            BusyBorder.Visibility = Visibility.Visible;
            var text = new TextRange(SubmitTextBox.Document.ContentStart, SubmitTextBox.Document.ContentEnd).Text;
            var card = await ScryfallService.GetCardsAsync(text);

            var bitmap = await ImageCaching.GetImageAsync(card);

            ImageDisplay.Source   = ImageHelper.LoadBitmap(bitmap);
            BusyBorder.Visibility = Visibility.Collapsed;
        }
示例#2
0
文件: App.xaml.cs 项目: bodines1/Boxy
 protected override void OnExit(ExitEventArgs e)
 {
     ImageCaching.Clear();
     base.OnExit(e);
 }
示例#3
0
        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();
        }
示例#4
0
 private async void UpdateCardImage()
 {
     CardImage = SelectedPrinting.IsDoubleFaced
         ? ImageHelper.LoadBitmap(await ImageCaching.GetImageAsync(SelectedPrinting.CardFaces[IsFront ? 0 : 1].ImageUris.BorderCrop, Reporter))
         : ImageHelper.LoadBitmap(await ImageCaching.GetImageAsync(SelectedPrinting.ImageUris.BorderCrop, Reporter));
 }