public static async Task <bool> ImportWithHearthmirror(PluginSettings theSettings) { var importObject = new HearthstoneImporter(); try { var collection = importObject.Import(); var setChangesList = new List <BasicSetCollectionInfo>(); foreach (var set in collection) { var existingSet = theSettings.ActiveAccountSetsInfo.FirstOrDefault(s => s.CardSet == set.CardSet); if (existingSet == null) { theSettings.ActiveAccountSetsInfo.Add(set); } else { var setChanges = setChangesList.FirstOrDefault(s => s.CardSet == set.CardSet) ?? new BasicSetCollectionInfo { CardSet = set.CardSet, Cards = new List <CardInCollection>(), }; // keep desired amount foreach (var card in set.Cards) { var existingCardInfo = existingSet.Cards.FirstOrDefault(c => c.CardId == card.CardId); if (existingCardInfo != null) { card.DesiredAmount = existingCardInfo.DesiredAmount; if (card.AmountNonGolden != existingCardInfo.AmountNonGolden || card.AmountGolden != existingCardInfo.AmountGolden) { setChanges?.Cards.Add(new CardInCollection(card.Card, card.AmountNonGolden - existingCardInfo.AmountNonGolden, card.AmountGolden - existingCardInfo.AmountGolden)); } } } existingSet.Cards = set.Cards; if (setChanges.Cards.Count > 0) { setChangesList.Add(setChanges); } } } if (theSettings.EnableImportHistory) { ImportHistory.SaveChange(theSettings.Accounts.FirstOrDefault(a => a.AccountName == theSettings.ActiveAccount), setChangesList); } } catch (ImportingException) { return(false); } // save imported collection HearthstoneCollectionTrackerPlugin.Settings.SaveCurrentAccount(); return(true); }
public static async Task <bool> ImportWithHearthmirror(PluginSettings theSettings) { var importObject = new HearthstoneImporter(); importObject.ImportStepDelay = 60; //MessageBox.Show(importObject.ImportStepDelay.ToString()); //importObject.PasteFromClipboard = CheckboxImportPasteClipboard.IsChecked.HasValue ? //CheckboxImportPasteClipboard.IsChecked.Value : false; //importObject.NonGoldenFirst = CheckboxPrioritizeFullCollection.IsChecked.HasValue ? //CheckboxPrioritizeFullCollection.IsChecked.Value : false; try { var selectedSetToImport = new KeyValuePair <string, string>("All", "").Value; var collection = await importObject.Import(selectedSetToImport); // close plugin window foreach (var set in collection) { var existingSet = theSettings.ActiveAccountSetsInfo.FirstOrDefault(s => s.SetName == set.SetName); if (existingSet == null) { theSettings.ActiveAccountSetsInfo.Add(set); } else { // keep desired amount foreach (var card in set.Cards) { var existingCardInfo = existingSet.Cards.FirstOrDefault(c => c.CardId == card.CardId); if (existingCardInfo != null) { card.DesiredAmount = existingCardInfo.DesiredAmount; } } existingSet.Cards = set.Cards; } } } catch (ImportingException ex) { return(false); } // save imported collection HearthstoneCollectionTrackerPlugin.Settings.SaveCurrentAccount(); return(true); }
public static async Task <bool> ImportWithHearthmirror(PluginSettings theSettings) { var importObject = new HearthstoneImporter(); try { var selectedSetToImport = new KeyValuePair <string, string>("All", "").Value; var collection = importObject.Import(selectedSetToImport); foreach (var set in collection) { var existingSet = theSettings.ActiveAccountSetsInfo.FirstOrDefault(s => s.SetName == set.SetName); if (existingSet == null) { theSettings.ActiveAccountSetsInfo.Add(set); } else { // keep desired amount foreach (var card in set.Cards) { var existingCardInfo = existingSet.Cards.FirstOrDefault(c => c.CardId == card.CardId); if (existingCardInfo != null) { card.DesiredAmount = existingCardInfo.DesiredAmount; } } existingSet.Cards = set.Cards; } } } catch (ImportingException ex) { return(false); } // save imported collection HearthstoneCollectionTrackerPlugin.Settings.SaveCurrentAccount(); return(true); }
private async void ButtonImportFromGame_Click(object sender, RoutedEventArgs e) { const string message = "1) open My Collection in Hearthstone\n2) clear card filters\n3) do not move your mouse or type after clicking \"Import\""; var settings = new MetroDialogSettings { AffirmativeButtonText = "Import" }; var result = await this.ShowMessageAsync("Import collection from Hearthstone", message, MessageDialogStyle.AffirmativeAndNegative, settings); if (result != MessageDialogResult.Affirmative) { return; } var importObject = new HearthstoneImporter(); importObject.ImportStepDelay = int.Parse((ComboboxImportSpeed.SelectedItem as ComboBoxItem).Tag.ToString()); importObject.PasteFromClipboard = CheckboxImportPasteClipboard.IsChecked.HasValue ? CheckboxImportPasteClipboard.IsChecked.Value : false; importObject.NonGoldenFirst = CheckboxPrioritizeFullCollection.IsChecked.HasValue ? CheckboxPrioritizeFullCollection.IsChecked.Value : false; try { var selectedSetToImport = ((KeyValuePair <string, string>)ComboboxImportingSet.SelectedItem).Value; var collection = await importObject.Import(selectedSetToImport); // close plugin window if (PluginWindow != null && PluginWindow.IsVisible) { PluginWindow.Close(); } foreach (var set in collection) { var existingSet = Settings.ActiveAccountSetsInfo.FirstOrDefault(s => s.SetName == set.SetName); if (existingSet == null) { Settings.ActiveAccountSetsInfo.Add(set); } else { // keep desired amount foreach (var card in set.Cards) { var existingCardInfo = existingSet.Cards.FirstOrDefault(c => c.CardId == card.CardId); if (existingCardInfo != null) { card.DesiredAmount = existingCardInfo.DesiredAmount; } } existingSet.Cards = set.Cards; } } this.ShowMessageAsync("Import succeed", "Your collection is successfully imported from Hearthstone!"); } catch (ImportingException ex) { this.ShowMessageAsync("Importing aborted", ex.Message); } // bring settings window to front if (WindowState == WindowState.Minimized) { WindowState = WindowState.Normal; } Activate(); Topmost = true; Topmost = false; Focus(); // save imported collection HearthstoneCollectionTrackerPlugin.Settings.SaveCurrentAccount(); }