public static void EnsureCreated(this User user, PostMortemContext context) { var existingUser = context .Users .SingleOrDefault(x => x.CookieId == user.CookieId); if (existingUser == null) { context.Users.Add(new User() { CookieId = user.CookieId, CreatedDateTime = DateTime.UtcNow, GameMode = user.GameMode }); context.SaveChanges(); } var dbUser = context .Users .Include(u => u.Objectives) .Single(x => x.CookieId == user.CookieId); user = dbUser; }
static async Task Main(string[] args) { /* * ---EF commands (because I ALWAYS forget them)--- * Add-Migration MigrationName -StartupProject DatabaseUpdater -Project Database * Update-Database -StartupProject DatabaseUpdater -Project Database * Remove-Migration -StartupProject DatabaseUpdater -Project Database */ using (var db = new PostMortemContext()) { await db.Database.MigrateAsync(); await db.SaveChangesAsync(); } }
public static void Save(this User user, PostMortemContext context) { var dbUser = context.Users.Single(x => x.CookieId == user.CookieId); dbUser.GameMode = user.GameMode; dbUser.UsedDevCommand = user.UsedDevCommand; dbUser.Facts = user.Facts; dbUser.Objectives = user.Objectives; // Only save the first win time if (dbUser.WinDateTime == null) { dbUser.WinDateTime = user.WinDateTime; } context.SaveChanges(); }
public override void _Ready() { GD.Print(_version); Context = new PostMortemContext(); _objectivesHUD = GetNode <ObjectivesHUD>("Game/YSort/Player/Player/ObjectivesLayer/ObjectivesHUD"); _letterBox = GetNode <LetterBox>("Game/YSort/Buildings/LetterBox"); _reggie = GetNode <DeadBody>("Game/YSort/NPCs/DeadBody"); _cow = GetNode <Cow>("Game/YSort/NPCs/Cow"); _olive = GetNode <Barkeep>("Game/YSort/NPCs/Barkeep"); _clarence = GetNode <Farmer>("Game/YSort/NPCs/Farmer"); // Connect to signals _letterBox.Connect("PlayerAtLetterBox", this, "PlayerAtLocation", new Godot.Collections.Array(new[] { _letterBox })); _letterBox.Connect("PlayerLeftLetterBox", this, "PlayerLeftLocation", new Godot.Collections.Array(new[] { _letterBox })); _letterBox.Connect("NewFacts", this, "NewFacts"); _reggie.Connect("PlayerAtNpc", this, "PlayerAtLocation", new Godot.Collections.Array(new[] { _reggie })); _reggie.Connect("PlayerLeftNpc", this, "PlayerLeftLocation", new Godot.Collections.Array(new[] { _reggie })); _reggie.Connect("NewFacts", this, "NewFacts"); _cow.Connect("PlayerAtNpc", this, "PlayerAtLocation", new Godot.Collections.Array(new[] { _cow })); _cow.Connect("PlayerLeftNpc", this, "PlayerLeftLocation", new Godot.Collections.Array(new[] { _cow })); _cow.Connect("NewFacts", this, "NewFacts"); _olive.Connect("PlayerAtNpc", this, "PlayerAtLocation", new Godot.Collections.Array(new[] { _olive })); _olive.Connect("PlayerLeftNpc", this, "PlayerLeftLocation", new Godot.Collections.Array(new[] { _olive })); _olive.Connect("NewFacts", this, "NewFacts"); _clarence.Connect("PlayerAtNpc", this, "PlayerAtLocation", new Godot.Collections.Array(new[] { _clarence })); _clarence.Connect("PlayerLeftNpc", this, "PlayerLeftLocation", new Godot.Collections.Array(new[] { _clarence })); _clarence.Connect("NewFacts", this, "NewFacts"); // Sort out player var player = GetNode <Player>("Game/YSort/Player/Player"); player.Disable(); _playerLocation = MapLocation.Wandering; // Show game if (OS.HasFeature("JavaScript")) { string javaScript = "parent.GameLoaded();"; JavaScript.Eval(javaScript); } }
public SendMessageResponse SendMessage(SendMessageRequest request, PostMortemContext context) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.UserCookieId)) { throw new ArgumentNullException(nameof(request.UserCookieId)); } if (request.Message?.IndexOf(char.MinValue) > -1) { throw new InvalidOperationException("Message contains null terminator"); } LogMessage(context, request.BotName, request.UserCookieId, TranscriptMessageDirection.Outbound, request.Message); string prefix = request.UserCookieId + char.MinValue + request.BotName + char.MinValue; string message = "[ " + request.InputData + " ] " + request.Message; string sendDataStr = prefix + message + char.MinValue; //Console.WriteLine(sendDataStr); var sendData = System.Text.Encoding.ASCII.GetBytes(sendDataStr); if (_tcpClient.Connected) { _stream.Write(sendData, 0, sendData.Length); var response = GetResponse(); LogMessage(context, request.BotName, request.UserCookieId, TranscriptMessageDirection.Inbound, string.Join("\n", response.Messages)); return(response); } else { throw new InvalidOperationException("Client not connected"); } }
private void LogMessage(PostMortemContext context, string botName, string userCookieId, TranscriptMessageDirection direction, string message) { try { var bot = context.Bots.Single(x => x.Name == botName); var user = context.Users.Single(x => x.CookieId == new Guid(userCookieId)); context.Transcripts.Add(new Transcript() { DateTime = DateTime.UtcNow, Bot = bot, User = user, Direction = direction, Message = message }); context.SaveChanges(); } catch { // } }
public IndexModel(ILogger <IndexModel> logger, PostMortemContext context) { _logger = logger; _context = context; }