public void AutomaticPrecisionTimeFormatterFormatsTimeAsZero_WhenTimeIsNull()
        {
            var sut = new AutomaticPrecisionTimeFormatter();

            var formattedTime = sut.Format(null);

            Assert.Equal("0", formattedTime);
        }
        public void AutomaticPrecisionTimeFormatterFormatsTimeCorrectly_WhenTimeIsValid(string timespanText, string expectedTime)
        {
            var sut  = new AutomaticPrecisionTimeFormatter();
            var time = TimeSpan.Parse(timespanText);

            var formattedTime = sut.Format(time);

            Assert.Equal(expectedTime, formattedTime);
        }
        public LeaderBoardComponent(LiveSplitState state)
        {
            State              = state;
            Client             = new SpeedrunComClient(userAgent: Updates.UpdateHelper.UserAgent, maxCacheElements: 0);
            RefreshInterval    = TimeSpan.FromMinutes(5);
            Cache              = new GraphicsCache();
            TimeFormatter      = new AutomaticPrecisionTimeFormatter();
            LocalTimeFormatter = new RegularTimeFormatter();
            InternalComponent  = new InfoTextComponent("Leaderboard", "-");

            Settings = new LeaderBoardSettings()
            {
                CurrentState = state
            };
        }
Ejemplo n.º 4
0
        public void TestAutomaticPrecisionTimeFormatter(string timespanText, string expected)
        {
            var formatter = new AutomaticPrecisionTimeFormatter();

            TimeSpan?time = null;

            if (timespanText != null)
            {
                time = TimeSpan.Parse(timespanText);
            }

            string formatted = formatter.Format(time);

            Assert.AreEqual(expected, formatted);
        }
Ejemplo n.º 5
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            splitsTreeView.Nodes.Clear();
            try
            {
                var fuzzyGameName = txtSearch.Text;
                if (!string.IsNullOrEmpty(fuzzyGameName))
                {
                    try
                    {
                        var games = SpeedrunCom.Client.Games.GetGames(name: fuzzyGameName, embeds: new GameEmbeds(embedCategories: true));

                        foreach (var game in games)
                        {
                            var gameNode = new TreeNode(game.Name);
                            gameNode.Tag = game.WebLink;
                            var categories    = game.FullGameCategories;
                            var timeFormatter = new AutomaticPrecisionTimeFormatter();

                            foreach (var category in categories)
                            {
                                var categoryNode = new TreeNode(category.Name);
                                categoryNode.Tag = category.WebLink;
                                var leaderboard = category.Leaderboard;
                                var records     = leaderboard.Records;

                                foreach (var record in records)
                                {
                                    var place   = record.Rank.ToString(CultureInfo.InvariantCulture).PadLeft(getDigits(records.Count())) + ".   ";
                                    var runners = string.Join(" & ", record.Players.Select(x => x.Name));
                                    var time    = record.Times.Primary;
                                    var runText = place + (time.HasValue ? timeFormatter.Format(time) : "") + " by " + runners;
                                    var runNode = new TreeNode(runText);
                                    runNode.Tag = record;
                                    if (!record.SplitsAvailable)
                                    {
                                        runNode.ForeColor = Color.Gray;
                                    }
                                    categoryNode.Nodes.Add(runNode);
                                }
                                gameNode.Nodes.Add(categoryNode);
                            }
                            splitsTreeView.Nodes.Add(gameNode);
                        }
                    }
                    catch { }

                    try
                    {
                        var fuzzyUserName = txtSearch.Text.TrimStart('@');
                        var users         = SpeedrunCom.Client.Users.GetUsersFuzzy(fuzzyName: fuzzyUserName);

                        foreach (var user in users)
                        {
                            var userNode = new TreeNode("@" + user.Name);
                            userNode.Tag = user.WebLink;
                            var recordsGroupedByGames = SpeedrunCom.Client.Users.GetPersonalBests(user.ID, embeds: new RunEmbeds(embedGame: true, embedCategory: true))
                                                        .GroupBy(x => x.Game.Name);

                            foreach (var recordsForGame in recordsGroupedByGames)
                            {
                                var gameName      = recordsForGame.Key;
                                var gameNode      = new TreeNode(gameName);
                                var game          = recordsForGame.First().Game;
                                var timeFormatter = new AutomaticPrecisionTimeFormatter();
                                gameNode.Tag = game.WebLink;

                                foreach (var record in recordsForGame)
                                {
                                    var categoryName = record.Category.Name;

                                    var place       = formatPlace(record.Rank);
                                    var coopRunners = record.Players.Count() > 1 ? " by " + string.Join(" & ", record.Players.Select(x => x.Name)) : "";
                                    var recordText  = timeFormatter.Format(record.Times.Primary) + " in " + categoryName + coopRunners + place;

                                    var recordNode = new TreeNode(recordText);
                                    recordNode.Tag = record;
                                    if (!record.SplitsAvailable)
                                    {
                                        recordNode.ForeColor = Color.Gray;
                                    }
                                    gameNode.Nodes.Add(recordNode);
                                }
                                userNode.Nodes.Add(gameNode);
                            }
                            splitsTreeView.Nodes.Add(userNode);
                        }
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                MessageBox.Show(this, "Search Failed!", "Search Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }