Example #1
0
        private void Configure(IModel channel, EventingBasicConsumer consumer, Func<string, Task<string>> callbackMethod)
        {
            consumer.Received += async (model, ea) =>
            {
                string response = null;

                var body = ea.Body.ToArray();
                var props = ea.BasicProperties;
                var replyProps = channel.CreateBasicProperties();
                replyProps.CorrelationId = props.CorrelationId;

                try
                {
                    string message = Encoding.UTF8.GetString(body);
                    response = await callbackMethod(message);
                }
                catch (Exception e)
                {
                    _logLogic.Log(e);
                }
                finally
                {
                    var responseBytes = Encoding.UTF8.GetBytes(response);
                    channel.BasicPublish("", props.ReplyTo, replyProps, responseBytes);
                    channel.BasicAck(ea.DeliveryTag, false);
                }
            };
        }
Example #2
0
        public void LogTest()
        {
            var testInnerException = new NoNullAllowedException();
            var testException      = new Exception("test exception", testInnerException);

            Assert.DoesNotThrow(() => _logLogic.Log(testException));
        }
Example #3
0
        public async Task <ActionResult> Add(DisabledUser disabledUser)
        {
            try
            {
                await _disabledUserLogic.Add(disabledUser);

                return(Ok());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #4
0
        public async Task <ActionResult <List <LogViewmodel> > > All()
        {
            try
            {
                List <LogDto> logCollection = await _logLogic.All();

                return(_mapper.Map <List <LogViewmodel> >(logCollection));
            }
            catch (Exception e)
            {
                await _logLogic.Log(e);

                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #5
0
        public RpcServer(IModel channel, string queue, Func <string, Task <string> > callbackMethod, LogLogic logLogic)
        {
            channel.QueueDeclare(queue, false, false, false, null);
            channel.BasicQos(0, 1, false);
            var consumer = new EventingBasicConsumer(channel);

            channel.BasicConsume(queue,
                                 false, consumer);

            consumer.Received += async(model, ea) =>
            {
                string response = null;

                var body       = ea.Body.ToArray();
                var props      = ea.BasicProperties;
                var replyProps = channel.CreateBasicProperties();
                replyProps.CorrelationId = props.CorrelationId;

                try
                {
                    string message = Encoding.UTF8.GetString(body);
                    response = await callbackMethod(message);
                }
                catch (Exception e)
                {
                    logLogic.Log(e);
                }
                finally
                {
                    var responseBytes = Encoding.UTF8.GetBytes(response ?? "");
                    channel.BasicPublish("", props.ReplyTo, replyProps, responseBytes);
                    channel.BasicAck(ea.DeliveryTag, false);
                }
            };
        }
Example #6
0
        public void Consume()
        {
            _channel.ExchangeDeclare(RabbitMqExchange.AuthenticationExchange, ExchangeType.Direct);
            _channel.QueueDeclare(RabbitMqQueues.AddUserQueue, true, false, false, null);
            _channel.QueueBind(RabbitMqQueues.AddUserQueue, RabbitMqExchange.AuthenticationExchange, RabbitMqRouting.AddUser);
            _channel.BasicQos(0, 10, false);

            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += async(sender, e) =>
            {
                try
                {
                    byte[] body = e.Body.ToArray();
                    string json = Encoding.UTF8.GetString(body);
                    var    user = Newtonsoft.Json.JsonConvert.DeserializeObject <UserRabbitMqSensitiveInformation>(json);

                    await _userLogic.Add(user);
                }
                catch (Exception exception)
                {
                    _logLogic.Log(exception);
                }
            };

            _channel.BasicConsume(RabbitMqQueues.AddUserQueue, true, consumer);
        }
Example #7
0
 public ActionResult <List <string> > GetItemsInFolder(string path)
 {
     try
     {
         return(_directoryLogic.GetItems(path));
     }
     catch (UnprocessableException)
     {
         return(StatusCode(StatusCodes.Status422UnprocessableEntity));
     }
     catch (Exception e)
     {
         _logLogic.Log(e);
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Example #8
0
        /// <summary>
        /// This method listens for email messages on the message queue and sends an email if it receives a message
        /// </summary>
        public void Consume()
        {
            _channel.ExchangeDeclare(RabbitMqExchange.MailExchange, ExchangeType.Direct);
            _channel.QueueDeclare(RabbitMqQueues.MailQueue, true, false, false, null);
            _channel.QueueBind(RabbitMqQueues.MailQueue, RabbitMqExchange.MailExchange, RabbitMqRouting.SendMail);
            _channel.BasicQos(0, 10, false);

            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += (sender, e) =>
            {
                try
                {
                    byte[] body   = e.Body.ToArray();
                    string json   = Encoding.UTF8.GetString(body);
                    var    emails = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Email> >(json);

                    _emailLogic.SendMails(emails);
                }
                catch (Exception exception)
                {
                    _logLogic.Log(exception);
                }
            };

            _channel.BasicConsume(RabbitMqQueues.MailQueue, true, consumer);
        }
        /// <summary>
        /// This method listens for email messages on the message queue and sends an email if it receives a message
        /// </summary>
        public void Consume()
        {
            _channel.ExchangeDeclare(RabbitMqExchange.EventExchange, ExchangeType.Direct);
            _channel.QueueDeclare(RabbitMqQueues.ConvertDatepickerQueue, true, false, false, null);
            _channel.QueueBind(RabbitMqQueues.ConvertDatepickerQueue, RabbitMqExchange.EventExchange, RabbitMqRouting.ConvertDatepicker);
            _channel.BasicQos(0, 10, false);

            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += async(sender, e) =>
            {
                try
                {
                    byte[] body = e.Body.ToArray();
                    string json = Encoding.UTF8.GetString(body);
                    var    datepickerRabbitMq = Newtonsoft.Json.JsonConvert.DeserializeObject <DatepickerRabbitMq>(json);

                    await _eventLogic.ConvertToEventAsync(datepickerRabbitMq);
                }
                catch (Exception exception)
                {
                    _logLogic.Log(exception);
                }
            };

            _channel.BasicConsume(RabbitMqQueues.ConvertDatepickerQueue, true, consumer);
        }
        public void Consume()
        {
            _channel.ExchangeDeclare(RabbitMqExchange.DatepickerExchange, ExchangeType.Direct);
            _channel.QueueDeclare(RabbitMqQueues.DeleteUserQueue, true, false, false, null);
            _channel.QueueBind(RabbitMqQueues.DeleteUserQueue, RabbitMqExchange.DatepickerExchange, RabbitMqRouting.RemoveUserFromDatepickerService);
            _channel.BasicQos(0, 10, false);

            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += async(sender, e) =>
            {
                try
                {
                    byte[] body     = e.Body.ToArray();
                    string json     = Encoding.UTF8.GetString(body);
                    var    userUuid = Newtonsoft.Json.JsonConvert.DeserializeObject <Guid>(json);

                    await _datepickerAvailabilityLogic.DeleteUserFromAvailability(userUuid);
                }
                catch (Exception exception)
                {
                    _logLogic.Log(exception);
                }
            };

            _channel.BasicConsume(RabbitMqQueues.DeleteUserQueue, true, consumer);
        }
Example #11
0
        public async Task <ActionResult <List <EventViewmodel> > > All()
        {
            try
            {
                UserHelper      requestingUser = _controllerHelper.GetRequestingUser(this);
                List <EventDto> events         = await _eventLogic.All(requestingUser);

                events.ForEach(e =>
                               e.EventDates.ForEach(ed => ed.EventDateUsers
                                                    .RemoveAll(edu => edu.UserUuid != requestingUser.Uuid)));

                return(_mapper.Map <List <EventViewmodel> >(events));
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Add(Guid uuid)
        {
            try
            {
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                await _eventStepUserLogic.Add(uuid, requestingUser);

                return(Ok());
            }
            catch (DuplicateNameException)
            {
                return(StatusCode(StatusCodes.Status409Conflict));
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #13
0
        public async Task <ActionResult> AddOrUpdate([FromBody] UserAvailability availability)
        {
            try
            {
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                await _datepickerAvailabilityLogic.AddOrUpdateAsync(availability.AvailableDates, availability.DatepickerUuid, requestingUser);

                return(Ok());
            }
            catch (ArgumentNullException e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status304NotModified));
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #14
0
        public async Task <ActionResult> Register([FromBody] User user)
        {
            try
            {
                await _userLogic.Register(user);

                return(Ok());
            }
            catch (AlreadyClosedException)
            {
                return(StatusCode(StatusCodes.Status202Accepted));
            }
            catch (DuplicateNameException)
            {
                return(Conflict());
            }
            catch (UnprocessableException)
            {
                return(UnprocessableEntity());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Login([FromBody] Login login)
        {
            try
            {
                LoginResultViewmodel result = await _authorizationLogic.Login(login);

                return(Ok(result));
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }
            catch (DisabledUserException)
            {
                return(Forbid());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Add(string name)
        {
            try
            {
                await _favoriteArtistLogic.Add(new FavoriteArtistDto
                {
                    Uuid = Guid.NewGuid(),
                    Name = name
                });

                return(Ok());
            }
            catch (UnprocessableException)
            {
                return(UnprocessableEntity());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #17
0
        public async Task <ActionResult> SaveFilesAsync([FromForm] FileUpload fileUpload)
        {
            try
            {
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                await _fileLogic.SaveFile(fileUpload.Files, fileUpload.Path, requestingUser.Uuid);

                return(Ok());
            }
            catch (DirectoryNotFoundException)
            {
                return(NotFound());
            }
            catch (UnprocessableException)
            {
                return(StatusCode(StatusCodes.Status422UnprocessableEntity));
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #18
0
 public async Task<ActionResult> ActivateUser(string code)
 {
     try
     {
         await _activationLogic.ActivateUser(code);
         return Ok();
     }
     catch (KeyNotFoundException)
     {
         return NotFound();
     }
     catch (Exception e)
     {
         _logLogic.Log(e);
         return StatusCode(StatusCodes.Status500InternalServerError);
     }
 }
Example #19
0
        public ActionResult RemoveUserData([FromQuery(Name = "options")] List <RemovableOptions> options)
        {
            try
            {
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                _accountRemovalLogic.RemoveAccount(new AccountRemoval
                {
                    DataToRemove = options,
                    UserUuid     = requestingUser.Uuid
                });

                return(Ok());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> UnsubscribeFromEventDate(Guid uuid)
        {
            try
            {
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                await _eventDateUserLogic.Remove(uuid, requestingUser);

                return(Ok());
            }
            catch (NoNullAllowedException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #21
0
        public async Task <ActionResult> Add([FromBody] Datepicker datepicker)
        {
            try
            {
                var        datepickerDto  = _mapper.Map <DatepickerDto>(datepicker);
                UserHelper requestingUser = _controllerHelper.GetRequestingUser(this);
                await _datepickerLogic.Add(datepickerDto, requestingUser);

                return(Ok());
            }
            catch (DuplicateNameException)
            {
                return(StatusCode(StatusCodes.Status409Conflict));
            }
            catch (Exception e)
            {
                _logLogic.Log(e);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }