コード例 #1
0
        public async Task <HttpResponseMessage> AddAsync(ContentActivity contentActivity)
        {
            var node        = contentActivity.Node;
            var httpContext = _httpContextAccessor.HttpContext;
            var userId      = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (node.CreatedBy != userId)
            {
                var allowed = await _securityService.IsAllowedAsync(
                    httpContext.User, node.Module, node.Type, Actions.Edit);

                if (!allowed)
                {
                    throw new Exception("User is not allowed to perform the action.");
                }
            }

            node.LastUpdatedBy   = userId;
            node.LastUpdatedDate = DateTimeOffset.UtcNow.ToString("s");
            await _nodeService.UpdateAsync(node);

            var message = contentActivity.Message;
            await _activityService.AddAsync(node.Id, message, userId);

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
コード例 #2
0
        /// <summary>
        /// Handles the incoming <see cref="CreateActivity"/> command and publishes a <see cref="ActivityCreated"/> event
        /// </summary>
        /// <param name="command">The <see cref="CreateActivity"/> command to handle</param>
        /// <returns>A <see cref="Task"/>The awaitable task</returns>
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation($"Creating activity: {command.Category} {command.Name}");

            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt));

                return;
            }
            catch (ActioException ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));

                _logger.LogInformation(ex.Message);
            }
            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, "error", ex.Message));

                _logger.LogInformation(ex.Message);
            }
        }
コード例 #3
0
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation($"Creating Activity: {@command.Name}");

            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category,
                                                command.Name, command.Description, command.CreatedAt);

                // Fire event by putting event into the queue.
                await _busClient.PublishAsync(new ActivityCreated(command.Id, command.UserId, command.Category,
                                                                  command.Name, command.Description));
            }
            catch (ActioException ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));

                _logger.LogError(ex.Message);
            }
            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, "Unexpected error", ex.Message));

                _logger.LogError(ex.Message);
            }
        }
コード例 #4
0
        public async Task HandleAsync(CreateActivity command)
        {
            var res = "failed";

            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.UserId, command.Id, command.Category, command.Name, command.Description));

                res = "success";
            }
            catch (ActioException ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));

                _logger.LogError(ex.Message);
            }
            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.GetType().ToString(), ex.Message));

                _logger.LogError(ex.Message);
            }

            _logger.LogInformation($"Creating activity: {command.Category} {command.Name} : {res}");
            Console.WriteLine($"Creating activity: {command.Category} {command.Name} : {res}");
        }
コード例 #5
0
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation("Creating activity: {Activity}", command.Name);

            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category,
                                                command.Name, command.Description, command.CreatedAt);

                await _bus.PublishAsync(new ActivityCreated(command.Id, command.UserId,
                                                            command.Category, command.Name));
            }
            catch (ActioException ex)
            {
                await _bus.PublishAsync(
                    new CreateActivityRejected(command.Id, ex.Code, ex.Message));

                _logger.LogError(ex, ex.Message);
            }
            catch (System.Exception ex)
            {
                await _bus.PublishAsync(new CreateActivityRejected(command.Id, "error", ex.Message));

                _logger.LogError(ex, ex.Message);
            }
        }
コード例 #6
0
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation($"Cr acti {command.Name}");

            try
            {
                await activityServise.AddAsync(command.Id, command.UserId,
                                               command.Category, command.Name, command.Description, command.CreatedAt);

                await _bus.PublishAsync(new ActivityCreated(command.Id, command.UserId,
                                                            command.Category, command.Name, command.Description, command.CreatedAt));

                return;
            }
            catch (MicroException e)
            {
                await _bus.PublishAsync(new CreateActivityRejected(command.Id, e.Code, e.Message));

                _logger.LogError(e.Message);
            }
            catch (Exception e)
            {
                await _bus.PublishAsync(new CreateActivityRejected(command.Id, "erroe", e.Message));

                _logger.LogError(e.Message);
            }
        }
コード例 #7
0
        public async Task HandleAsync(CreateActivity command)
        {
            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id,
                                                                  command.UserId,
                                                                  command.Category,
                                                                  command.Name,
                                                                  command.Description,
                                                                  command.CreatedAt));

                return;
            }
            catch (ActioException ex)
            {
                await _busClient.PublishAsync(new CreateUserRejected(command.Id.ToString(), ex.Code, ex.Message));
            }

            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateUserRejected(command.Id.ToString(), "error", ex.Message));
            }
        }
コード例 #8
0
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation($"Creating activity: '{command.Id}' for user: '******'.");
            try
            {
                await _activityService.AddAsync(command.Id, command.UserId,
                                                command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id,
                                                                  command.UserId, command.Category, command.Name, command.Description, command.CreatedAt));

                _logger.LogInformation($"Activity: '{command.Id}' was created for user: '******'.");

                return;
            }
            catch (MicroserviceException ex)
            {
                _logger.LogError(ex, ex.Message);
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id,
                                                                         ex.Message, ex.Code));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id,
                                                                         ex.Message, "error"));
            }
        }
コード例 #9
0
        public async Task HandleAsync(CreateActivity command)
        {
            Console.WriteLine($"Create Activity: {command.Name}");
            try{
                await _activityService.AddAsync(command.Id,
                                                command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id,
                                                                  command.UserId, command.Category, command.Name, command.Description, command.CreatedAt));

                Console.WriteLine($"Activity Created: {command.Name}");
                return;
            }catch (ShipmentException ex) {
                Console.WriteLine(ex.Message);
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id,
                                                                         ex.Code, ex.Message
                                                                         ));
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id,
                                                                         "error", ex.Message
                                                                         ));
            }
        }
コード例 #10
0
        public async Task HandleAsync(CreateActivity command)
        {
            _logger.LogInformation($"Creating Activity: {command.Name} ON {DateTime.Now}");

            try
            {
                Thread.Sleep(1000);
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt));

                return;
            }
            catch (RocchiniException ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));

                _logger.LogError(ex.Message);
            }
            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, "unexpected_error", ex.Message));

                _logger.LogError(ex.Message);
            }
        }
コード例 #11
0
        public async Task <IActionResult> PostAsync(ContentActivity contentActivity)
        {
            var node   = contentActivity.Node;
            var userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            var allowed = await _securityService.IsAllowedAsync(
                HttpContext.User,
                node.Module,
                node.Type,
                Actions.Add);

            if (!allowed)
            {
                throw new Exception("User is not allowed to perform the action.");
            }

            node.CreatedBy = userId;
            var id = await _nodeService.AddAsync(node);

            var message = contentActivity.Message;
            await _activityService.AddAsync(id, message, userId);

            return(Ok(id));
        }
コード例 #12
0
 public async Task HandleAsync(CreateActivity command)
 {
     try
     {
         await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);
         var activityCreated = new ActivityCreated(command.Id, command.UserId, command.Name, command.Category, command.Description, DateTime.Now);
         await _bus.PublishAsync(activityCreated);
     }
     catch (ActionException ex)
     {
         await _bus.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));
     }
     catch (Exception ex)
     {
         await _bus.PublishAsync(new CreateActivityRejected(command.Id, "error", ex.Message));
     }
 }
コード例 #13
0
        public async Task HandleAsync(CreateActivityCommandModel command)
        {
            logger.LogInformation($"Creating activity: {command.Id}: {command.Name}");
            try
            {
                await activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description,
                                               command.CreatedAt);

                await busClient.PublishAsync(
                    new ActivityCreatedEventModel(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt));
            }
            catch (ActioException ex)
            {
                await busClient.PublishAsync(new ActivityCreatedRejectedEventModel(ex.Message, ex.ErrorCode));

                logger.LogError(ex, $"Activity creating rejected {command.Id}");
            }
        }
コード例 #14
0
        public async Task HandleAsync(CreateActivityCommand command)
        {
            logger.LogInformation($"Creating Activity: {command.Name}");
            try
            {
                var activity = mapper.Map <Activity>(command);
                await activityService.AddAsync(activity);

                await busClient.PublishAsync(new ActivityCreatedEvent(command.Id, command.UserId, command.Category, command.Name, command.Description
                                                                      , command.CreatedBy, command.CreatedAt));
            }
            catch (CustomException ex)
            {
                await busClient.PublishAsync(new CreateActivityRejectedEvent(command.Id, ex.Code, ex.Message));

                logger.LogError(ex.Message);
            }
        }
コード例 #15
0
        public async Task HandleAsync(CreateAction command)
        {
            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name,
                                                command.Description, command.CreatedAt);
            }
            catch (ActioException e)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(e.Code, command.Id, e.Message));

                _logger.LogError(e.Message);
            }
            catch (Exception e)
            {
                await _busClient.PublishAsync(new CreateActivityRejected("error", command.Id, e.Message));

                _logger.LogError(e.Message);
            }
        }
コード例 #16
0
        public async Task HandleAsync(CreateActivity command)
        {
            Console.WriteLine($"Creating Activity : {command.Name}");
            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name,
                                                command.Description, command.CreatedAt);

                ActivityCreated created = new ActivityCreated(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);
                await _busClient.PublishAsync(created);
            }
            catch (MicroServicesException e)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id.ToString(), e.Message, e.Code));
            }
            catch (Exception e)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(command.Id.ToString(), e.Message, "error"));
            }
        }
コード例 #17
0
        public async Task HandleAsync(CreateActivity Command)
        {
            _logger.LogInformation($"Creating Activity: {Command.Name} !");
            try
            {
                await _activityService.AddAsync(Command.Id, Command.UserId, Command.Category, Command.Name, Command.Description, Command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(Command.Id, Command.UserId, Command.Category, Command.Name, Command.Description, Command.CreatedAt));
            }
            catch (ActioException ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(Command.Id, ex.Message, ex.Code));

                _logger.LogError(ex.Message);
            }
            catch (Exception ex)
            {
                await _busClient.PublishAsync(new CreateActivityRejected(Command.Id, ex.Message, "error"));

                _logger.LogError(ex.Message);
            }
        }
コード例 #18
0
        public async Task HandlerAsync(CreateActivity command)
        {
            Console.WriteLine($"Receive Create Activity command:{command.Name}");
            try
            {
                await _activityService.AddAsync(command.Id, command.Name, command.Description,
                                                command.Category, command.UserId, command.CreatedAt);

                await _bus.PublishAsync(new ActivityCreated(command.Id, command.UserId, command.Category,
                                                            command.Name, command.Description));

                return;
            }
            catch (ActioException ex)
            {
                await _bus.PublishAsync(new CreateActivtyRejected(ex.Code, ex.Message));
            }
            catch (Exception ex)
            {
                await _bus.PublishAsync(new CreateActivtyRejected("error", ex.Message));
            }
        }
コード例 #19
0
        public async Task HandleAsync(CreateActivity command)
        {
            Console.WriteLine($"{DateTime.Now} - Creating activity: {command.Name}");

            try
            {
                await _activityService.AddAsync(command.Id, command.UserId, command.Category, command.Name, command.Description, command.CreatedAt);

                await _busClient.PublishAsync(new ActivityCreated(command.Id, command.UserId, command.Category, command.Name, command.Description, DateTime.Now));
            }
            catch (ActioException ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);

                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, ex.Code, ex.Message));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);

                await _busClient.PublishAsync(new CreateActivityRejected(command.Id, "error", ex.Message));
            }
        }
コード例 #20
0
        public async Task HandleAsync(ActivityCreatedEvent @event)
        {
            await activityService.AddAsync(@event);

            Console.WriteLine($"Activity created: {@event.Name}");
        }
コード例 #21
0
        public async Task <IActionResult> AddActivity(AddActivityDto addActivityDto)
        {
            await _activityService.AddAsync(_mapper.Map <Activity>(addActivityDto));

            return(Created("", addActivityDto));
        }