Ejemplo n.º 1
0
        public async Task <IActionResult> Post(IFormFile image, IFormFile audio)
        {
            if (image != null && audio != null)
            {
                var idRequest = Guid.NewGuid();

                Console.WriteLine($"Files received -> {idRequest}");

                //persist files

                var idImage = Guid.Empty;
                using (var ms = new MemoryStream())
                {
                    image.CopyTo(ms);
                    idImage = await _file.UploadFileAsync(new ByteArrayPart(ms.ToArray(), image.FileName, image.ContentType));
                }

                var idAudio = Guid.Empty;
                using (var ms = new MemoryStream())
                {
                    audio.CopyTo(ms);
                    idAudio = await _file.UploadFileAsync(new ByteArrayPart(ms.ToArray(), audio.FileName, audio.ContentType));
                }

                //put in queue

                var message = new Lip
                {
                    IdAudio   = idAudio,
                    IdImage   = idImage,
                    IdRequest = idRequest
                };

                //TODO: colocar conexão no singleton e serializar dentro do helper
                var connection = _bus.CreateConnection(_bus.GetConnectionFactory());
                var json       = JsonConvert.SerializeObject(message);
                _bus.WriteMessageOnQueue(json, "lip", connection);

                return(Ok(idRequest));
            }

            return(BadRequest());
        }
        public ICommandResult Handle(RegisterVotesCommand command)
        {
            var votes = new Votes(command.UserId, command.CardId, command.UserStoryId);

            AddNotifications(votes.Notifications);

            if (Invalid)
                return new CommandResult(false, "Por favor, corrija os campos abaixo", Notifications);

            var connectionFactory = _rabbitMQHelper.GetConnectionFactory();

            using (_connection = _rabbitMQHelper.CreateConnection(connectionFactory))
            {
                _rabbitMQHelper.WriteMessageOnQueue(votes.ToString(), queueName, _connection);
            }

            _votesRepository.Add(votes);

            return new CommandResult(true, "Cadastro realizado com sucesso", votes);
        }
Ejemplo n.º 3
0
        private static void SendRabbitMQQueue(string queueName, object dto)
        {
            try
            {
                var body = JsonConvert.SerializeObject(dto);

                using (var connection = _rabbitMQHelper.CreateConnection(_rabbitMQHelper.GetConnectionFactory()))
                    using (var model = connection.CreateModel())
                    {
                        _rabbitMQHelper.CreateQueue(queueName, model);

                        _rabbitMQHelper.WriteMessageOnQueue(body, queueName, model);
                    }

                Console.WriteLine($"Message Successfully Written: {queueName}");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Metrics Error");
                Console.WriteLine(ex.Message);
                Console.WriteLine("--------------");
            }
        }