public async Task <Unit> Handle(UpdateUserConnectionMappingsCommand request, CancellationToken cancellationToken)
        {
            var mappings = await _dynamoDbClient.GetUserConnectionMappings();

            var messages = request.SqsEvent.Records.Select(record => JsonConvert.DeserializeObject <UpdateUserConnectionMappingQueueMessage>(record.Body));

            foreach (var message in messages)
            {
                if (message.IsDeletion)
                {
                    mappings.RemoveMapping(message.UserConnectionMapping);
                }
                else
                {
                    mappings.AddMapping(message.UserConnectionMapping);
                }
            }

            await _dynamoDbClient.SaveUserConnectionMappings(mappings);

            return(Unit.Value);
        }
Пример #2
0
        public async Task <Unit> Handle(SendWebSocketMessagesCommand command, CancellationToken cancellationToken)
        {
            var mappings = (await _dynamoDbClient.GetUserConnectionMappings()).GetUserConnectionMappings();

            foreach (var streamRecord in command.DynamoEvent.Records)
            {
                await command.EventDataMapper(streamRecord)
                .MatchAsync(async message =>
                {
                    foreach (var mapping in mappings.ToList())
                    {
                        if (!await _apiGatewayClient.PostMessage(mapping.ConnectionId, message))
                        {
                            await _dynamoDbClient.DeleteUser(mapping.UserId);
                        }
                    }

                    return(LanguageExt.Unit.Default);
                },
                            () => Task.FromResult(LanguageExt.Unit.Default));
            }

            return(Unit.Value);
        }