public void TestCommaTwoCount() { var deck = StringImporter.Import("Ragnaros, Lightlord x2"); var card = deck.Cards.FirstOrDefault(); Assert.AreEqual("OG_229", card.Id); Assert.AreEqual(2, card.Count); }
internal void ImportFromFile() { var dialog = new OpenFileDialog { Title = "Select Deck File", DefaultExt = "*.xml;*.txt", Filter = "Deck Files|*.txt;*.xml" }; dialog.Multiselect = true; var dialogResult = dialog.ShowDialog(); if (dialogResult == true) { foreach (var file in dialog.FileNames) { try { Deck deck = null; if (file.EndsWith(".txt")) { using (var sr = new StreamReader(file)) deck = StringImporter.Import(sr.ReadToEnd()); } else if (file.EndsWith(".xml")) { deck = XmlManager <Deck> .Load(file); //not all required information is saved in xml foreach (var card in deck.Cards) { card.Load(); } TagControlEdit.SetSelectedTags(deck.Tags); } if (Config.Instance.AutoSaveOnImport || dialog.FileNames.Length > 1) { DeckManager.SaveDeck(deck); } else { ShowDeckEditorFlyout(deck, true); } } catch (Exception ex) { Log.Error(ex); } } } }
public void AddDeck(string name, string playerClass, string cards, bool archive, params string[] tags) { var deck = StringImporter.Import(cards); if (deck != null) { deck.Name = name; if (deck.Class != playerClass) { deck.Class = playerClass; } if (tags.Any()) { var reloadTags = false; foreach (var t in tags) { if (!DeckList.Instance.AllTags.Contains(t)) { DeckList.Instance.AllTags.Add(t); reloadTags = true; } deck.Tags.Add(t); } if (reloadTags) { DeckList.Save(); Core.MainWindow.ReloadTags(); } } //// hack time! //// use MainWindow.ArchiveDeck to update //// set deck archive to opposite of desired //deck.Archived = !archive; //// add and save //DeckList.Instance.Decks.Add(deck); //DeckList.Save(); //// now reverse 'archive' of the deck //// this should refresh all ui elements //Core.MainWindow.ArchiveDeck(deck, archive); // Add and save deck deck.Archived = archive; DeckList.Instance.Decks.Add(deck); DeckList.Save(); // Refresh decklist //Core.MainWindow.LoadAndUpdateDecks(); } }
private void BtnFile_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog { Title = "Select Deck File", DefaultExt = "*.xml;*.txt", Filter = "Deck Files|*.txt;*.xml" }; dialog.Multiselect = true; var dialogResult = dialog.ShowDialog(); if (dialogResult == true) { foreach (String file in dialog.FileNames) { try { Deck deck = null; if (file.EndsWith(".txt")) { using (var sr = new StreamReader(file)) deck = StringImporter.Import(sr.ReadToEnd()); } else if (file.EndsWith(".xml")) { deck = XmlManager <Deck> .Load(file); //not all required information is saved in xml foreach (var card in deck.Cards) { card.Load(); } TagControlEdit.SetSelectedTags(deck.Tags); } SetNewDeck(deck); if (Config.Instance.AutoSaveOnImport || dialog.FileNames.Length > 1) { SaveDeckWithOverwriteCheck(); } } catch (Exception ex) { Log.Error(ex); } } } }
public void AddDeck(string name, string playerClass, string cards, bool archive, params string[] tags) { Common.Log.Debug($"Tracker: Adding Deck ({name}, {playerClass}, {cards}, {archive}, {tags})"); var deck = StringImporter.Import(cards); if (deck != null) { deck.Name = name; if (deck.Class != playerClass) { deck.Class = playerClass; } if (tags.Any()) { var reloadTags = false; foreach (var t in tags) { if (!DeckList.Instance.AllTags.Contains(t)) { DeckList.Instance.AllTags.Add(t); reloadTags = true; } deck.Tags.Add(t); } if (reloadTags) { DeckList.Save(); API.Core.MainWindow.ReloadTags(); } } // hacky way to update ui: // use MainWindow.ArchiveDeck to update // set deck archive to opposite of desired deck.Archived = !archive; // add and save DeckList.Instance.Decks.Add(deck); DeckList.Save(); // now reverse 'archive' of the deck // this should refresh all ui elements API.Core.MainWindow.ArchiveDeck(deck, archive); } else { Common.Log.Debug($"Tracker: Error importing cards from string"); } }
private async void BtnClipboardText_Click(object sender, RoutedEventArgs e) { try { if (NetDeck.CheckForClipboardImport()) { if (!Config.Instance.NetDeckClipboardCheck.HasValue) { Options.OptionsTrackerImporting.CheckboxImportNetDeck.IsChecked = true; Config.Instance.NetDeckClipboardCheck = true; Config.Save(); } return; } if (Clipboard.ContainsText()) { var english = true; if (Config.Instance.SelectedLanguage != "enUS") { try { english = await this.ShowLanguageSelectionDialog(); } catch (Exception ex) { Log.Error(ex); } } var deck = StringImporter.Import(Clipboard.GetText(), !english); if (deck != null) { SetNewDeck(deck); if (Config.Instance.AutoSaveOnImport) { SaveDeckWithOverwriteCheck(); } } } } catch (Exception ex) { Log.Error(ex); } }
public static bool CheckForClipboardImport() { try { if (Clipboard.ContainsText()) { var clipboardContent = Clipboard.GetText(); if (clipboardContent.StartsWith("netdeckimport") || clipboardContent.StartsWith("trackerimport")) { var clipboardLines = clipboardContent.Split('\n').ToList(); var deckName = clipboardLines.FirstOrDefault(line => line.StartsWith("name:")); if (!string.IsNullOrEmpty(deckName)) { clipboardLines.Remove(deckName); deckName = deckName.Replace("name:", "").Trim(); } var url = clipboardLines.FirstOrDefault(line => line.StartsWith("url:")); if (!string.IsNullOrEmpty(url)) { clipboardLines.Remove(url); url = url.Replace("url:", "").Trim(); } bool?isArenaDeck = null; var arena = clipboardLines.FirstOrDefault(line => line.StartsWith("arena:")); if (!string.IsNullOrEmpty(arena)) { clipboardLines.Remove(arena); bool isArena; if (bool.TryParse(arena.Replace("arena:", "").Trim(), out isArena)) { isArenaDeck = isArena; } } var localized = false; var nonEnglish = clipboardLines.FirstOrDefault(line => line.StartsWith("nonenglish:")); if (!string.IsNullOrEmpty(nonEnglish)) { clipboardLines.Remove(nonEnglish); bool.TryParse(nonEnglish.Replace("nonenglish:", "").Trim(), out localized); } var tagsRaw = clipboardLines.FirstOrDefault(line => line.StartsWith("tags:")); var tags = new List <string>(); if (!string.IsNullOrEmpty(tagsRaw)) { clipboardLines.Remove(tagsRaw); tags = tagsRaw.Replace("tags:", "").Trim().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } clipboardLines.RemoveAt(0); //"netdeckimport" / "trackerimport" var deck = StringImporter.Import(clipboardLines.Aggregate((c, n) => c + "\n" + n), localized); if (deck != null) { if (tags.Any()) { var reloadTags = false; foreach (var tag in tags) { if (!DeckList.Instance.AllTags.Contains(tag)) { DeckList.Instance.AllTags.Add(tag); reloadTags = true; } deck.Tags.Add(tag); } if (reloadTags) { DeckList.Save(); Core.MainWindow.ReloadTags(); } } if (isArenaDeck.HasValue) { deck.IsArenaDeck = isArenaDeck.Value; } deck.Url = url; deck.Name = deckName; if (Config.Instance.AutoSaveOnImport) { DeckManager.SaveDeck(deck); } else { Core.MainWindow.ShowDeckEditorFlyout(deck, true); } Core.MainWindow.ActivateWindow(); } Clipboard.Clear(); return(true); } } } catch (Exception e) { Log.Error(e); return(false); } return(false); }
public void TestNeutralOnly() { var deck = StringImporter.Import("Ragnaros the firelord"); Assert.IsNull(deck); }