public async Task Save() { var arena = new ArenaSessionModel(); arena.Hero = Hero; arena.StartDate = Started; arena.Losses = Losses; arena.Wins = Wins; arena.Server = SelectedServer.Name; await gameManager.AddArenaSession(arena); events.PublishOnBackgroundThread(new SendNotification("Arena successfully saved.")); Reset(); IsOpen = false; ArenaFlyout.Load(arena); }
private async Task <ArenaSessionModel> TryCreateArenaSession(string detectedHero) { if (detectedHero == null) { Log.Warn("TryCreateArenaSession called without hero"); return(null); } using (await newArenaLock.LockAsync()) { var arena = new ArenaSessionModel { Hero = await heroRepository.FirstOrDefaultAsync(x => x.Key == detectedHero) }; arena = await gameManager.AddArenaSession(arena); // for web api events.PublishOnBackgroundThread(new ArenaSessionStarted(arena.StartDate, arena.Hero.Key, arena.Wins, arena.Losses)); return(arena); } }
private async Task Save() { using (var bsy = Busy.GetTicket()) { var gameResult = new GameResultModel(); ArenaSessionModel arenasession = null; var newArena = false; gameResult.GameMode = GameMode; gameResult.Conceded = Conceded; if (Deck != null) { gameResult.Deck = Deck; } gameResult.GoFirst = GoFirst; gameResult.Hero = Hero; gameResult.OpponentHero = OpponentHero; gameResult.Started = StartTime; gameResult.Stopped = Stopped; gameResult.Turns = Turns; gameResult.Victory = Victory; gameResult.Notes = Notes; gameResult.Server = BindableServerCollection.Instance.DefaultName; if (gameResult.GameMode == GameMode.Arena) { var serverName = gameResult.Server; var latestArena = arenaRepository.Query(a => a.Where(x => x.Server == serverName).OrderByDescending(x => x.StartDate).FirstOrDefault()); if (latestArena == null || latestArena.IsEnded || (gameResult.Hero != null && latestArena.Hero.Key != gameResult.Hero.Key)) { Log.Debug("Creating new arena."); newArena = true; arenasession = new ArenaSessionModel { Hero = gameResult.Hero, StartDate = gameResult.Started }; try { GlobalLocks.NewArenaLock.Reset(); await gameManager.AddArenaSession(arenasession); } finally { GlobalLocks.NewArenaLock.Set(); } } else { arenasession = latestArena.ToModel(); } gameResult.ArenaSession = arenasession; } await gameManager.AddGame(gameResult); // for webapi if (arenasession != null) { if (newArena) { events.PublishOnBackgroundThread(new ArenaSessionStarted(arenasession.StartDate, arenasession.Hero.Key, arenasession.Wins, arenasession.Losses)); } else { if (arenasession.IsEnded && arenasession.EndDate.HasValue) { events.PublishOnBackgroundThread(new ArenaSessionEnded(arenasession.StartDate, arenasession.EndDate.Value, arenasession.Hero.Key, arenasession.Wins, arenasession.Losses)); } } } // notifications //var wonString = gameResult.Victory ? "You won!" : "You lost!"; var title = "New game tracked."; //var hero = gameResult.Hero != null ? gameResult.Hero.ClassName : String.Empty; //var oppHero = gameResult.OpponentHero != null ? gameResult.OpponentHero.ClassName : String.Empty; //var msg = string.Format("Hero: {0}, Opponent: {1}, {2}", hero, oppHero, wonString); //events.PublishOnBackgroundThread(new SendNotification(String.Format("{0} {1}", title, msg))); var vm = IoC.Get <GameResultBalloonViewModel>(); vm.SetGameResult(gameResult); events.PublishOnBackgroundThread(new TrayNotification(title, vm, 10000) { BalloonType = BalloonTypes.GameStartEnd }); // reset Clear(); IsOpen = false; } }