コード例 #1
0
        protected override async Task Handle(ConnectNetworkRequest request, CancellationToken cancellationToken)
        {
            var networkId   = request.Id;
            var containerId = request.Network.Container;

            var networkEntity = await _networkRepository.RetrieveNetworkAsync(networkId);

            if (networkEntity == null)
            {
                throw new StatusException(StatusCodes.Status404NotFound,
                                          $"Network with id '{request.Id}' does not exist.");
            }

            var containerEntity = await _containerRepository.RetrieveContainerAsync(containerId);

            if (containerEntity == null)
            {
                throw new StatusException(StatusCodes.Status404NotFound,
                                          $"Container with id '{request.Network.Container}' does not exist.");
            }

            var success = await _networkService.ConnectNetworkAsync(networkId, containerId);

            if (!success)
            {
                throw new StatusException(StatusCodes.Status500InternalServerError,
                                          $"Could not connect container '{containerId}' to network with id '{networkId}'.");
            }
        }
コード例 #2
0
        public async Task <NetworkDto> Handle(RetrieveNetworkRequest request, CancellationToken cancellationToken)
        {
            var networkEntity = await _networkRepository.RetrieveNetworkAsync(request.Id);

            if (networkEntity == null)
            {
                throw new StatusException(StatusCodes.Status404NotFound,
                                          $"Network with id '{request.Id}' does not exist.");
            }

            var network = _mapper.Map <NetworkDto>(networkEntity);

            return(network);
        }
コード例 #3
0
        protected override async Task Handle(DeleteNetworkRequest request, CancellationToken cancellationToken)
        {
            var networkEntity = await _networkRepository.RetrieveNetworkAsync(request.Id);

            if (networkEntity == null)
            {
                throw new StatusException(StatusCodes.Status404NotFound,
                                          $"Network with id '{request.Id}' does not exist.");
            }

            if (networkEntity.Containers.Count > 0)
            {
                throw new StatusException(StatusCodes.Status403Forbidden,
                                          $"Network '{request.Id}' is still connected to '{networkEntity.Containers.Count}' container(s). Please disconnect them first.");
            }

            var success = await _networkRepository.DeleteNetworkAsync(request.Id);

            if (!success)
            {
                throw new StatusException(StatusCodes.Status500InternalServerError,
                                          $"Could not delete network with id '{request.Id}'.");
            }
        }