public async Task <Unit> Handle(UpdateSynchronizedObjectRequest request, CancellationToken cancellationToken)
        {
            var(conferenceId, synchronizedObjectId) = request;

            var provider = GetProvider(synchronizedObjectId);
            var subscribedParticipants =
                await _mediator.Send(new FetchSubscribedParticipantsRequest(conferenceId, synchronizedObjectId),
                                     cancellationToken);

            _logger.LogDebug("Update synchronized object {syncObj} ({count} subscribers)", synchronizedObjectId,
                             subscribedParticipants.Count);

            if (!subscribedParticipants.Any())
            {
                await _synchronizedObjectRepository.Remove(conferenceId, synchronizedObjectId.ToString());

                return(Unit.Value);
            }

            var newValue = await provider.FetchValue(conferenceId, synchronizedObjectId);

            var previousValue = await _synchronizedObjectRepository.Create(conferenceId,
                                                                           synchronizedObjectId.ToString(), newValue, provider.Type);

            if (Equals(newValue, previousValue))
            {
                return(Unit.Value);
            }

            await _mediator.Publish(
                new SynchronizedObjectUpdatedNotification(subscribedParticipants, synchronizedObjectId.ToString(),
                                                          newValue, previousValue), cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public async Task <object> Handle(FetchSynchronizedObjectRequest request, CancellationToken cancellationToken)
        {
            var(conferenceId, syncObjId) = request;

            var provider = _providers.First(x => x.Id == syncObjId.Id);

            var currentStoredValue = await _repository.Get(conferenceId, syncObjId.ToString(), provider.Type);

            if (currentStoredValue != null)
            {
                return(currentStoredValue);
            }

            var currentValue = await provider.FetchValue(conferenceId, syncObjId);

            await _repository.Create(conferenceId, syncObjId.ToString(), currentValue, provider.Type);

            return(currentValue);
        }