private async Task <object> ImportFromWeb() { logger.Debug($"ImportFromWeb started. Task.IsNotCompleted={CommandImportWeb.Execution?.IsNotCompleted}"); try { DeckImporter deckImporter = new DeckImporter(this.trackerFactory); var tcs = new TaskCompletionSource <bool>(); deckImporter.ImportFinished(tcs); //logger.Debug($"ImportFromWeb awaiting {CommandImportWeb.Execution}"); //await Task.Delay(5000) ; await deckImporter.ImportFromWeb(WebDeckUrl); logger.Debug($"ImportFromWeb done. tcs={tcs.Task.Result}; Errors={deckImporter.sbErrors.ToString()}"); if (tcs.Task.Result) { deck.DeckUrl = WebDeckUrl; deck.SelectedVersion.Cards = new PropertiesObservableCollection <CardInstance>(deckImporter.Cards); deck.Name = deckImporter.DeckName; deck.Class = ClassAttributesHelper.FindSingleClassByAttribute(deckImporter.Cards.SelectMany(c => c.Card.Attributes).Distinct()); //curr version shour equal deck.selected version, attch change to reflect clink for remove in deck history CurrentVersion.Cards.CollectionChanged += (s, e) => { RaisePropertyChangedEvent(nameof(ChangesFromCurrentVersion)); }; RaisePropertyChangedEvent(String.Empty); ShowImportFromUrlPanel = false; } else { WebDeckUrlImportError = deckImporter.sbErrors.ToString(); } } catch (Exception ex) { WebDeckUrlImportError = ex.Message; } return("done"); }
private async Task <object> CommandImportExecute(object obj) { this.ShowImportPanel = true; DeckImporter deckImporter = obj as DeckImporter; var tcs = new TaskCompletionSource <bool>(); deckImporter.ImportFinished(tcs); await tcs.Task; bool succeed = tcs.Task.Result; if (succeed) { if (deckImporter.DeltaImport) { foreach (var importedCard in deckImporter.Cards) { var instance = deck.SelectedVersion.Cards.Where(ci => ci.Card.Id == importedCard.CardId).FirstOrDefault(); if (instance != null) { instance.Quantity += importedCard.Quantity; if (instance.Quantity <= 0) { deck.SelectedVersion.Cards.Remove(instance); } if (LimitCardCount) { trackerFactory.GetService <IDeckService>().EnforceCardLimit(instance); } } else if (importedCard.Quantity > 0) { deck.SelectedVersion.Cards.Add(importedCard); } } } else { deck.SelectedVersion.Cards = new PropertiesObservableCollection <CardInstance>(deckImporter.Cards); //curr version shour equal deck.selected version, attch change to reflect clink for remove in deck history CurrentVersion.Cards.CollectionChanged += (s, e) => { RaisePropertyChangedEvent(nameof(ChangesFromCurrentVersion)); }; RaisePropertyChangedEvent(String.Empty); } } this.ShowImportPanel = false; return(null); }