public async Task <Unit> Handle(SetParticipantRoomRequest request, CancellationToken cancellationToken) { var(conferenceId, assignments) = request; var changedRooms = new Dictionary <Participant, ParticipantRoomChangeInfo>(); foreach (var(participantId, roomId) in assignments) { var participant = new Participant(conferenceId, participantId); _logger.LogDebug("Switch participant {participant} to room {roomId}", participant, roomId); string?previousRoomId; try { previousRoomId = await _roomRepository.SetParticipantRoom(participant, roomId); } catch (ConcurrencyException) { _logger.LogWarning("Concurrency exception occurred, continue"); continue; } changedRooms[participant] = ParticipantRoomChangeInfo.Switched(previousRoomId, roomId); } if (changedRooms.Any()) { await _mediator.Send(new UpdateSynchronizedObjectRequest(conferenceId, SynchronizedRooms.SyncObjId)); await _mediator.Publish(new ParticipantsRoomChangedNotification(conferenceId, changedRooms)); } return(Unit.Value); }
public async Task Handle(ParticipantLeftNotification notification, CancellationToken cancellationToken) { var(participant, _) = notification; var previousRoom = await _roomRepository.UnsetParticipantRoom(participant); await _mediator.Send( new UpdateSynchronizedObjectRequest(participant.ConferenceId, SynchronizedRooms.SyncObjId)); await _mediator.Publish(new ParticipantsRoomChangedNotification(participant.ConferenceId, new Dictionary <Participant, ParticipantRoomChangeInfo> { { participant, ParticipantRoomChangeInfo.Left(previousRoom) } })); }
public async Task Handle(ConferenceClosedNotification notification, CancellationToken cancellationToken) { var conferenceId = notification.ConferenceId; // we can not use the other UseCases here as they implement custom logic to keep the participants in the room system, // here we especially want to kick all participants from all rooms // concurrency: as we delete all participants and all rooms at once, all future SetParticipantRoomUseCases will fail, // as no rooms exist any more, so it is impossible that new mappings will be created var result = await _roomRepository.DeleteAllRoomsAndMappingsOfConference(conferenceId); await _mediator.Send( new UpdateSynchronizedObjectRequest(notification.ConferenceId, SynchronizedRooms.SyncObjId)); await _mediator.Publish(new RoomsRemovedNotification(conferenceId, result.DeletedRooms)); await _mediator.Publish(new ParticipantsRoomChangedNotification(conferenceId, result.DeletedMapping.ToDictionary(pair => new Participant(conferenceId, pair.Key), pair => ParticipantRoomChangeInfo.Left(pair.Value)))); }