public void ParseTokensInCorrectOrder() { NamingPattern.TryParse("{PlayerName}{PlayerClass}", out np); Assert.AreEqual(2, np.Pattern.Count); Assert.AreEqual("{PlayerName}", np.Pattern[0]); Assert.AreEqual("{PlayerClass}", np.Pattern[1]); }
public async Task SaveImage(Screenshot screenshot) { if (screenshot != null) { var dir = Settings.Default.OutputDir; if (!Directory.Exists(dir)) { Log.Info($"Output dir does not exist ({dir}), using desktop"); dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var filename = DateTime.Now.ToString("dd.MM.yyyy_HH.mm"); var stats = CoreAPI.Game?.CurrentGameStats; if (stats != null) { // save with game details var pattern = Settings.Default.FileNamePattern; NamingPattern np = null; if (!NamingPattern.TryParse(pattern, out np)) { Log.Info("Invalid file name pattern, using default"); } filename = np.Apply(stats.PlayerHero, stats.OpponentHero, stats.PlayerName, stats.OpponentName); } await SaveAsPng(screenshot.Full, Path.Combine(dir, filename)); } else { throw new ArgumentNullException("Screenshot was null"); } }
public void ParseFullPatternInCorrectOrder() { NamingPattern.TryParse(" Before {PlayerName} Middle {PlayerClass} After ", out np); Assert.AreEqual(5, np.Pattern.Count); Assert.AreEqual(" Before ", np.Pattern[0]); Assert.AreEqual("{PlayerName}", np.Pattern[1]); Assert.AreEqual(" Middle ", np.Pattern[2]); Assert.AreEqual("{PlayerClass}", np.Pattern[3]); Assert.AreEqual(" After ", np.Pattern[4]); }
public static void SaveImage(GameStats game, Image screenshot, String note = null) { if (game != null) { if (!String.IsNullOrEmpty(note)) { game.Note = note; } DeckStatsList.Save(); //if(Config.Instance.StatsInWindow) //{ // ((DeckStatsControl)Hearthstone_Deck_Tracker.Core.Windows.StatsWindow.FindName("StatsControl")).Refresh(); //} //else //{ // ((DeckStatsControl)Hearthstone_Deck_Tracker.API.Core.MainWindow.FindName("DeckStatsFlyout")).Refresh(); //} if (screenshot != null) { try { var dir = Settings.Default.OutputDir; if (!Directory.Exists(dir)) { dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var pattern = Settings.Default.FileNamePattern; NamingPattern np = null; if (!NamingPattern.TryParse(pattern, out np)) { Log.Info("Invalid file name pattern, using default", "EndGame"); } var filename = np.Apply(game); SaveAsPng(screenshot.Full, Path.Combine(dir, filename)); } catch (Exception e) { Log.Info("Error saving image: " + e.Message, "EndGame"); } } else { Log.Info("Screenshot is null", "EndGame"); } } else { Log.Info("Game is null", "EndGame"); } }
private void FileNamePattern_TextChanged(object sender, TextChangedEventArgs e) { var success = NamingPattern.TryParse(FileNamePattern.Text, out _pattern); if (success) { TextBlockPatternPreview.Text = _pattern.Apply(_sampleGame); } else { TextBlockPatternPreview.Text = "Invalid Pattern"; } }
private void UpdatePattern(string x) { NamingPattern np = null; var success = NamingPattern.TryParse(x, out np); if (success) { PatternPreview = np.Apply("Mage", "Druid", "Player", "Opponent"); } else { PatternPreview = "the pattern is invalid"; } }
public void PatternWithNoTokens() { Assert.IsTrue(NamingPattern.TryParse("Just a String", out np)); }
public void ValidDatePattern() { NamingPattern.TryParse("{Date:ddMMyyy HH:mm}", out np); Assert.AreEqual(DateTime.Now.ToString("ddMMyyy HH:mm"), np.Apply(game)); }
public void PatternEvaluatesCorrectly() { NamingPattern.TryParse(" Before {PlayerName} ({PlayerClass}) VS {OpponentName} ({OpponentClass}) After ", out np); Assert.AreEqual(" Before Player1 (Mage) VS Player2 (Warlock) After ", np.Apply(game)); }
public void InValidDatePattern() { NamingPattern.TryParse("{Date:X}", out np); Assert.AreEqual(DateTime.Now.ToString("dd.MM.yyy_HH.mm"), np.Apply(game)); }
public void ValidTokens() { Assert.IsTrue(NamingPattern.TryParse("{PlayerName}", out np)); }
public void InValidTokens() { Assert.IsFalse(NamingPattern.TryParse("{nolower}", out np)); }
public void EmptyPatternReturnsDefault() { Assert.IsTrue(NamingPattern.TryParse("", out np)); Assert.AreEqual("Player1 (Mage) VS Player2 (Warlock) " + DateTime.Now.ToString("dd.MM.yyy_HH.mm"), np.Apply(game)); }
public void MultiTokenPlusStringsPattern() { Assert.IsTrue(NamingPattern.TryParse("Prefix {PlayerName} vs {OpponentName} Postfix", out np)); }
public void MultiTokenPattern() { Assert.IsTrue(NamingPattern.TryParse("{PlayerName}{PlayerClass}", out np)); }
public void SingleTokenPattern() { Assert.IsTrue(NamingPattern.TryParse("{PlayerName}", out np)); }
public void UnknownCustomDatePattern() { NamingPattern.TryParse("{Date:ABC}", out np); Assert.AreEqual(DateTime.Now.ToString("dd.MM.yyy_HH.mm"), np.Apply(game)); }