void Model_OnSplit(object sender, EventArgs e) { var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths); if (LiveSplitChannel != null && (RaceState == RaceState.RaceStarted || RaceState == RaceState.RaceEnded)) { if (Model.CurrentState.CurrentSplitIndex > 0) { var split = Model.CurrentState.Run[Model.CurrentState.CurrentSplitIndex - 1]; var timeRTA = "-"; var timeIGT = "-"; if (split.SplitTime.RealTime != null) { timeRTA = timeFormatter.Format(split.SplitTime.RealTime); } if (split.SplitTime.GameTime != null) { timeIGT = timeFormatter.Format(split.SplitTime.GameTime); } Client.LocalUser.SendMessage(LiveSplitChannel, String.Format(".time \"{0}\" {1}", Escape(split.Name), timeRTA)); Client.LocalUser.SendMessage(LiveSplitChannel, String.Format(".timeGT \"{0}\" {1}", Escape(split.Name), timeIGT)); } } if (RaceChannel != null) { if (Model.CurrentState.CurrentPhase == TimerPhase.Ended && RaceState == RaceState.RaceStarted) { Client.LocalUser.SendMessage(RaceChannel, ".done"); } } }
void goalBox_ValueChanged(object sender, EventArgs e) { String text = ((TextBox)sender).Text; try { GoalTime = TimeSpanParser.Parse(text); } catch (Exception ex) { GoalTime = new TimeSpan(); } goalBox.Text = SettingsFormatter.Format(GoalTime); }
private string FormatNotes(string notePlaceholder) { var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Seconds); var deltaTimeFormatter = new DeltaTimeFormatter(); var game = Run.GameName ?? ""; var category = Run.GetExtendedCategoryName(); var pb = timeFormatter.Format(Run.Last().PersonalBestSplitTime[State.CurrentTimingMethod]) ?? ""; var title = Run.GetExtendedName(); var splitName = ""; var splitTime = "-"; var deltaTime = "-"; if ((State.CurrentPhase == TimerPhase.Running || State.CurrentPhase == TimerPhase.Paused) && State.CurrentSplitIndex > 0) { var lastSplit = Run[State.CurrentSplitIndex - 1]; splitName = lastSplit.Name ?? ""; splitTime = timeFormatter.Format(lastSplit.SplitTime[State.CurrentTimingMethod]); deltaTime = deltaTimeFormatter.Format(lastSplit.SplitTime[State.CurrentTimingMethod] - lastSplit.PersonalBestSplitTime[State.CurrentTimingMethod]); } var streamLink = ""; if (notePlaceholder.Contains("$stream")) { try { if (Twitch.Instance.IsLoggedIn || Twitch.Instance.VerifyLogin()) { var userName = Twitch.Instance.ChannelName; streamLink = string.Format("http://twitch.tv/{0}", userName); } } catch { } } return(notePlaceholder .Replace("$game", game) .Replace("$category", category) .Replace("$title", title) .Replace("$pb", pb) .Replace("$splitname", splitName) .Replace("$splittime", splitTime) .Replace("$delta", deltaTime) .Replace("$stream", streamLink)); }
public void Save(IRun run, Stream stream) { var regularTimeFormatter = new RegularTimeFormatter(TimeAccuracy.Hundredths); var shortTimeFormatter = new ShortTimeFormatter(); var writer = new StreamWriter(stream); if (!string.IsNullOrEmpty(run.GameName)) { writer.Write(Escape(run.GameName)); if (!string.IsNullOrEmpty(run.CategoryName)) { writer.Write(" - "); } } writer.Write(Escape(run.CategoryName)); writer.Write(','); writer.WriteLine(Escape(run.AttemptCount.ToString())); foreach (var segment in run) { writer.Write(Escape(segment.Name)); writer.Write(','); writer.Write(Escape(regularTimeFormatter.Format(segment.PersonalBestSplitTime.RealTime))); writer.Write(','); writer.WriteLine(Escape(shortTimeFormatter.Format(segment.BestSegmentTime.RealTime))); } writer.Flush(); }
public void RegularTimeFormatterFormatsTimeCorrectlyInGivenAccuracy_WhenTimeIsNull(TimeAccuracy timeAccuracy, string expectedTime) { var sut = new RegularTimeFormatter(timeAccuracy); var formattedTime = sut.Format(null); Assert.Equal(expectedTime, formattedTime); }
public void RegularTimeFormatterFormatsTimeCorrectlyInGivenAccuracy_WhenTimeIsValid(string timespanText, TimeAccuracy timeAccuracy, string expectedTime) { var sut = new RegularTimeFormatter(timeAccuracy); var time = TimeSpan.Parse(timespanText); var formattedTime = sut.Format(time); Assert.Equal(expectedTime, formattedTime); }
[InlineData("-1.00:02:01.999", TimeAccuracy.Hundredths, "−24:02:01.99")] // Actual:<0:01.99> [Fail] public void NegativesTestRegularTimeFormatter(string timespanText, TimeAccuracy timeAccuracy, string expectedTime) { var formatter = new RegularTimeFormatter(timeAccuracy); var time = TimeSpan.Parse(timespanText); var formattedTime = formatter.Format(time); Assert.Equal(expectedTime, formattedTime); }
public string Format(TimeSpan?time) { var formatter = new RegularTimeFormatter(Accuracy); if (time == null) { return("-"); } else { return(formatter.Format(time)); } }
public void TestRegularTimeFormatter(string timespanText, TimeAccuracy timeAccuracy, string expected) { var formatter = new RegularTimeFormatter(timeAccuracy); TimeSpan?time = null; if (timespanText != null) { time = TimeSpan.Parse(timespanText); } string formatted = formatter.Format(time); Assert.AreEqual(expected, formatted); }
public bool SubmitRun(IRun run, string username, string password, Func <Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams) { var timeFormatter = new RegularTimeFormatter(TimeAccuracy.Seconds); if (attachSplits) { comment += " " + SplitsIO.Instance.Share(run, screenShotFunction); } var postRequest = (HttpWebRequest)WebRequest.Create(GetUri("submit")); postRequest.Method = "POST"; postRequest.ContentType = "application/x-www-form-urlencoded"; using (var postStream = postRequest.GetRequestStream()) { var writer = new StreamWriter(postStream); writer.Write("nickname="); writer.Write(HttpUtility.UrlEncode(username)); //nickname=CryZeTesting&country=Germany&twitter=CryZe107&youtube=CryZe92&twitch=CryZe92&game=The+Legend+of+Zelda%3A+The+Wind+Waker&category=Test%25&console=&played_on=Emulator&emulator=Dolphin+3.5®ion=NTSC-J&time=5%3A07%3A25&date=12%2F18%2F2013&video=http%3A%2F%2Fyoutube.com%2FTesting¬es=Still+in+Browser.+And+I+just+f****d+up+xD //Country //Twitter /*if (Twitter.Instance.) * writer.Write("nickname="); * writer.Write(HttpUtility.UrlEncode(username));*/ //Youtube /*writer.Write("nickname="); * writer.Write(HttpUtility.UrlEncode(username));*/ if (Twitch.Instance.IsLoggedIn) { writer.Write("&twitch="); writer.Write(HttpUtility.UrlEncode(Twitch.Instance.ChannelName)); } writer.Write("&game="); writer.Write(HttpUtility.UrlEncode(run.GameName)); writer.Write("&category="); writer.Write(HttpUtility.UrlEncode(run.CategoryName)); writer.Write("&console="); //TODO We need console //writer.Write(HttpUtility.UrlEncode(run.CategoryName)); //Played on //region //Time writer.Write("&time="); writer.Write(HttpUtility.UrlEncode(timeFormatter.Format(run.Last().PersonalBestSplitTime.RealTime))); writer.Write("&date="); var dateTime = run.AttemptHistory.First(x => x.Time.RealTime == run.Last().PersonalBestSplitTime.RealTime).Ended.Value; writer.Write(HttpUtility.UrlEncode(String.Format("{0:00}/{1:00}/{2}", dateTime.Month, dateTime.Day, dateTime.Year))); writer.Write("&video="); writer.Write(HttpUtility.UrlEncode(video)); writer.Write("¬es="); writer.Write(HttpUtility.UrlEncode(comment)); writer.Flush(); } using (var resultStream = postRequest.GetResponse().GetResponseStream()) { var reader = new StreamReader(resultStream); return(reader.ReadToEnd().Contains("<strong>Submitted!</strong>")); } }
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 RegularTimeFormatter(game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds); 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 RegularTimeFormatter(game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds); 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); } }