private static Replay convertToEntity(ReplayDTO replayDTO) { var replay = new Replay(); replay.record_id = replayDTO.RecordID; replay.game_id = replayDTO.GameID; replay.inning = replayDTO.Inning; replay.game_team_code = replayDTO.GameTeamCode; replay.sequence = replayDTO.Sequence; replay.comment_sequence = replayDTO.ComSequence; replay.player_id = replayDTO.PlayerID; replay.team_id = replayDTO.TeamID; replay.umpire_id = replayDTO.UmpireID; replay.ballpark_id = replayDTO.BallparkID; replay.reason = replayDTO.Reason; if (replayDTO.Reversed == true) { replay.reversed = "Y"; } else { replay.reversed = "N"; } replay.initiated = replayDTO.Initiated; replay.replay_challenge_team_id = replayDTO.ReplayChallengeTeamID; replay.type = replayDTO.Type; return(replay); }
public static void CreateReplay(ReplayDTO replayDTO) { // ballpark instance of Replayer class in Retrosheet_Persist.Retrosheet var replay = convertToEntity(replayDTO); // entity data model //var dbCtx = new retrosheetDB(); var dbCtx = new retrosheetEntities(); dbCtx.Replays.Add(replay); try { dbCtx.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception e) { string text; text = e.Message; } }
private static void ReadWriteReplayFile() { string[] columnValue; string textLine = null; using (StreamReader reader = new StreamReader(@"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_com_replay")) { while (!reader.EndOfStream) { try { textLine = reader.ReadLine(); } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The " + @"C:\users\mmr\documents\retrosheet\2016 Regular Season\Output\2016SLN\2016SLN_com_replay" + " file could not be read:"); Console.WriteLine(e.Message); Console.ReadLine(); } columnValue = textLine.Split('|'); ReplayDTO replayDTO = new ReplayDTO(); replayDTO.RecordID = Guid.NewGuid(); replayDTO.GameID = columnValue[0]; replayDTO.Inning = Convert.ToInt16(columnValue[1]); replayDTO.GameTeamCode = Convert.ToInt16(columnValue[2]); replayDTO.Sequence = Convert.ToInt16(columnValue[3]); replayDTO.PlayerID = columnValue[7]; replayDTO.TeamID = columnValue[8]; replayDTO.UmpireID = columnValue[9]; replayDTO.BallparkID = columnValue[10]; replayDTO.Reason = columnValue[11]; if (columnValue[12] == "Y") { replayDTO.Reversed = true; } else { replayDTO.Reversed = false; } replayDTO.Initiated = columnValue[13]; replayDTO.ReplayChallengeTeamID = columnValue[14]; replayDTO.Type = columnValue[15]; ReplayPersist.CreateReplay(replayDTO); Console.WriteLine(textLine); } } }
private static DiscordEmbedBuilder AddReplayStatus(DiscordEmbedBuilder embed, ReplayDTO replay) => embed.AddField("Replay", replay is null ? "*No replay provided*" : $"[{replay.Id}]({replay.DownloadUri})");
public async Task SendNewPostWebhookAsync(Post post, Player author, Player player, ReplayDTO replay = null) { DiscordEmbedBuilder embed = new() { Author = new() { Name = author.Username, Url = author.GetPlayerProfileLink() }, Title = $"**New Post on {player.Username} :** \"{post.Title}\".", Url = post.GetPostLink(), Footer = GetDefaultFooter(), Color = DiscordColor.Green }; AddReplayStatus(embed, replay); AddPostContent(embed, post); await Client.BroadcastMessageAsync(GetCurrentRegionWebhookBuilder().AddEmbed(embed)); }