public static ViewUpdate Create(Team t) { using (new RWLockHelper(Program.RWLockTeams, RWLockHelper.LockMode.Read)) { using (new RWLockHelper(Program.RWLockLevels, RWLockHelper.LockMode.Read)) { var currLevel = 0; var pointsNextLvl = t.CurrentPoints; while (currLevel < Program.Levels.Count && pointsNextLvl >= Program.Levels[currLevel].PointsRequired) { pointsNextLvl -= Program.Levels[currLevel].PointsRequired; currLevel++; } var vu = new ViewUpdate { ID = t.ID, Name = t.Name, Level = currLevel + 1, Score = pointsNextLvl }; if (currLevel == Program.Levels.Count) { vu.Target = 200; } else { vu.Target = Program.Levels[currLevel].PointsRequired; } return(vu); } } }
public static async Task UpdateAllClientsTeamChanged(IHubContext <LevelScoreHub> instance, Team team) { using (new RWLockHelper(Program.RWLockTeams, RWLockHelper.LockMode.Read)) { await instance.Clients.All.SendAsync("update_one", ViewUpdate.Create(team)); } }
public async Task RequestAllData() { using (new RWLockHelper(Program.RWLockTeams, RWLockHelper.LockMode.Read)) { var allVU = Program.Teams.Select(t => ViewUpdate.Create(t)).ToList(); await Clients.Caller.SendAsync("update_all", allVU); } }
public static async Task UpdateAllClientsFull(IHubContext <LevelScoreHub> instance) { using (new RWLockHelper(Program.RWLockTeams, RWLockHelper.LockMode.Read)) { var allVU = Program.Teams.Select(t => ViewUpdate.Create(t)).ToList(); await instance.Clients.All.SendAsync("update_all", allVU); } }
public override async Task OnConnectedAsync() { Console.WriteLine($"Client {Clients.Caller} connected"); var t1 = Clients.Caller.SendAsync("update_title", Program.GameTitle); using (new RWLockHelper(Program.RWLockTeams, RWLockHelper.LockMode.Read)) { var allList = Program.Teams.Select(t => ViewUpdate.Create(t)).ToList(); var t2 = Clients.Caller.SendAsync("update_all", allList); await t2; } await t1; }