public override string ToString(BotElement bot, Func <string, string> transform) { string formattedTime = String.IsNullOrEmpty(bot.Text.DateTimeFormat) ? AuthorTime.ToString() : AuthorTime.ToString(bot.Text.DateTimeFormat); var sb = new StringBuilder(); if (RefNames != null) { sb.AppendFormat("{0} ", transform(String.Concat(RefNames))); } sb.Append(bot.Text.CommitFormat.FormatWith(new { Action = Type == CommitRowType.Commit ? bot.Text.Commit : bot.Text.RefPointer, CommitUri = CommitUri, CommitId = transform(CommitId.ToHexString(settings.HashLength)), ChangeCounts = (ChangeCounts != null) ? String.Join(", ", ChangeCounts.Select(c => ChangeCountToString(bot, c))) : "", AuthorTime = formattedTime, Author = transform(Author), AuthorName = transform(AuthorName), AuthorEmail = transform(AuthorEmail), Comment = transform(Comment.Truncate(settings.CommentMaxLength)) })); return(sb.ToString()); }
private string ChangeCountsToString(TextElement text, ChangeCounts changeCounts) { var counters = new[] { new ChangeCounter(TfsGitChangeType.Add, text.ChangeCountAddFormat, changeCounts.Adds), new ChangeCounter(TfsGitChangeType.Edit, text.ChangeCountEditFormat, changeCounts.Edits), new ChangeCounter(TfsGitChangeType.Delete, text.ChangeCountDeleteFormat, changeCounts.Deletes) }; return(string.Join(", ", counters.Where(c => c.Count > 0).Select(c => c.Format.FormatWith(new { c.Count })))); }
private static ChangeCounts UpdateActivePlayers(IEnumerable <Player> playersRetrievedFromTheWebSite) { Console.Write("\rUpdating the players table in the database."); var changeCounts = new ChangeCounts(); foreach (var retrievedPlayer in playersRetrievedFromTheWebSite) { var existingPlayerInTheDatabase = GetPlayerBySourcePlayerId(retrievedPlayer.SourcePlayerId); if (existingPlayerInTheDatabase != null) { if (existingPlayerInTheDatabase.Position != retrievedPlayer.Position || existingPlayerInTheDatabase.Number != retrievedPlayer.Number || existingPlayerInTheDatabase.LastName != retrievedPlayer.LastName || existingPlayerInTheDatabase.FirstName != retrievedPlayer.FirstName || existingPlayerInTheDatabase.Status != retrievedPlayer.Status || existingPlayerInTheDatabase.Team != retrievedPlayer.Team) { existingPlayerInTheDatabase.Position = retrievedPlayer.Position; existingPlayerInTheDatabase.Number = retrievedPlayer.Number; existingPlayerInTheDatabase.LastName = retrievedPlayer.LastName; existingPlayerInTheDatabase.FirstName = retrievedPlayer.FirstName; existingPlayerInTheDatabase.Status = retrievedPlayer.Status; existingPlayerInTheDatabase.Team = retrievedPlayer.Team; existingPlayerInTheDatabase.UpdateDate = DateTimeOffset.Now; existingPlayerInTheDatabase.IsActive = true; Database.Update(existingPlayerInTheDatabase); changeCounts.Updated++; } } else { Database.Insert("Players", "PlayerID", retrievedPlayer); changeCounts.Inserted++; } } return(changeCounts); }
private static ChangeCounts UpdateActivePlayers(IEnumerable<Player> playersRetrievedFromTheWebSite) { Console.Write("\rUpdating the players table in the database."); var changeCounts = new ChangeCounts(); foreach (var retrievedPlayer in playersRetrievedFromTheWebSite) { var existingPlayerInTheDatabase = GetPlayerBySourcePlayerId(retrievedPlayer.SourcePlayerId); if (existingPlayerInTheDatabase != null) { if (existingPlayerInTheDatabase.Position != retrievedPlayer.Position || existingPlayerInTheDatabase.Number != retrievedPlayer.Number || existingPlayerInTheDatabase.LastName != retrievedPlayer.LastName || existingPlayerInTheDatabase.FirstName != retrievedPlayer.FirstName || existingPlayerInTheDatabase.Status != retrievedPlayer.Status || existingPlayerInTheDatabase.Team != retrievedPlayer.Team) { existingPlayerInTheDatabase.Position = retrievedPlayer.Position; existingPlayerInTheDatabase.Number = retrievedPlayer.Number; existingPlayerInTheDatabase.LastName = retrievedPlayer.LastName; existingPlayerInTheDatabase.FirstName = retrievedPlayer.FirstName; existingPlayerInTheDatabase.Status = retrievedPlayer.Status; existingPlayerInTheDatabase.Team = retrievedPlayer.Team; existingPlayerInTheDatabase.UpdateDate = DateTimeOffset.Now; existingPlayerInTheDatabase.IsActive = true; Database.Update(existingPlayerInTheDatabase); changeCounts.Updated++; } } else { Database.Insert("Players", "PlayerID", retrievedPlayer); changeCounts.Inserted++; } } return changeCounts; }