public async Task Create([FromBody] Book book)
        {
            if (ModelState.IsValid)
            {
                await _dataAccessProvider.AddBookRecord(book);

                await _queueService.Send(new BookQueueRequest
                {
                    ISBN          = book.ISBN,
                    Title         = book.Title,
                    Description   = book.Description,
                    OperationType = OperationType.Add
                });
            }
        }
Пример #2
0
        public async Task VoteAsync(Guid songId)
        {
            var votingCandidate = await _votingCandidateRepository.GetBySongAsync(songId);

            var userIdentifier = _primitiveUserIdentificationService.GetOrCreateUserId(HttpContext);

            await _voteService.UpdateOrCreateAsync(votingCandidate, userIdentifier);

            await _unitOfWork.CommitAsync();

            _messageQueueService.Send(Message.VotingMessage);
        }
Пример #3
0
        public async Task <string> NextAsync()
        {
            var votingResult = await _votingFinisher.CollectResultAndLockAsync();

            await _unitOfWork.CommitAsync();

            _messageQueueService.Send(Message.DisableVotingMessage);

            Response.OnCompleted(() => OnResponseCompleted(votingResult.Song.Id, _rootLifetimeScopeProvider));

            return(votingResult.Song.FileName);
        }
Пример #4
0
        private void ExtractAndPublishComportamentoMessage()
        {
            var httpContext = Request.HttpContext;

            var ipAddress  = httpContext.Connection.RemoteIpAddress.ToString();
            var browser    = GetUserAgent(httpContext);
            var action     = httpContext.Request.Path.Value;
            var parametros = httpContext.Request.QueryString.ToString();

            var comportamento       = new Comportamento(ipAddress, action, browser, parametros);
            var comportamentoString = JsonConvert.SerializeObject(comportamento);

            _messageQueueService.Send(Encoding.UTF8.GetBytes(comportamentoString));
        }
        public IActionResult Post([FromBody] ComportamentoRequest request)
        {
            var httpContext = Request.HttpContext;

            var parametros = httpContext.Request.QueryString.ToString();
            var ipAddress  = httpContext.Connection.RemoteIpAddress.ToString();

            request.Ip         = ipAddress;
            request.Parametros = parametros;

            var comportamento = _mapper.Map <Comportamento>(request);

            var comportamentoString = JsonConvert.SerializeObject(comportamento);

            _messageQueueService.Send(Encoding.UTF8.GetBytes(comportamentoString));

            return(Ok(comportamento));
        }
Пример #6
0
        public void MessageQueueService_CanSendAndReceive()
        {
            // Arrange & Act
            var cancellationTokenSource = new CancellationTokenSource(20000);
            var taskCompletionSource    = new TaskCompletionSource <Message>();

            Task.Factory.StartNew(() =>
            {
                _messageQueueService.Receive()
                .Subscribe(message => taskCompletionSource.SetResult(message));

                _messageQueueService.Send(Message.VotingMessage);
            });

            cancellationTokenSource.Token.Register(() => taskCompletionSource.TrySetCanceled(), useSynchronizationContext: false);

            var result = taskCompletionSource.Task.Result;

            // Assert
            Assert.That(result, Is.EqualTo(Message.VotingMessage));
        }