public Alice TryGetAliceBy(Guid uniqueId) { using (RoundSyncronizerLock.Lock()) { return(Alices.SingleOrDefault(x => x.UniqueId == uniqueId)); } }
public void StartAliceTimeout(Guid uniqueId) { // 1. Find Alice and set its LastSeen propery. var foundAlice = false; var started = DateTimeOffset.UtcNow; using (RoundSyncronizerLock.Lock()) { if (Phase != CcjRoundPhase.InputRegistration || Status != CcjRoundStatus.Running) { return; // Then no need to timeout alice. } Alice alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId); foundAlice = alice != default(Alice); if (foundAlice) { alice.LastSeen = started; } } if (foundAlice) { Task.Run(async() => { // 2. Delay asyncronously to the requested timeout await Task.Delay(AliceRegistrationTimeout); using (await RoundSyncronizerLock.LockAsync()) { // 3. If the round is still running and the phase is still InputRegistration if (Status == CcjRoundStatus.Running && Phase == CcjRoundPhase.InputRegistration) { Alice alice = Alices.SingleOrDefault(x => x.UniqueId == uniqueId); if (alice != default(Alice)) { // 4. If LastSeen isn't changed by then, remove Alice. if (alice.LastSeen == started) { Alices.Remove(alice); Logger.LogInfo <CcjRound>($"Round ({RoundId}): Alice ({alice.UniqueId}) timed out."); } } } } }); } }