Пример #1
0
        public async Task <Result> Delete(Action <ExchangeDeleteAction> action, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var impl = new ExchangeDeleteActionImpl();

            action(impl);

            impl.Validate();

            string vhost = impl.VirtualHost.Value.ToSanitizedName();

            string url = $"api/exchanges/{vhost}/{impl.ExchangeName.Value}";

            if (!string.IsNullOrWhiteSpace(impl.Query.Value))
            {
                url = $"api/exchanges/{vhost}/{impl.ExchangeName.Value}?{impl.Query.Value}";
            }

            if (impl.Errors.Value.Any())
            {
                return(new FaultedResult <ExchangeInfo>(impl.Errors.Value, new DebugInfoImpl(url)));
            }

            return(await Delete(url, cancellationToken).ConfigureAwait(false));
        }
Пример #2
0
        public async Task <Result> Delete(Action <ExchangeDeleteAction> action, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var impl = new ExchangeDeleteActionImpl();

            action(impl);

            string exchange = impl.ExchangeName.Value;
            string vhost    = impl.VirtualHost.Value;

            var errors = new List <Error>();

            if (string.IsNullOrWhiteSpace(exchange))
            {
                errors.Add(new ErrorImpl("The name of the exchange is missing."));
            }

            if (string.IsNullOrWhiteSpace(vhost))
            {
                errors.Add(new ErrorImpl("The name of the virtual host is missing."));
            }

            if (errors.Any())
            {
                return(new FaultedResult(errors));
            }

            string url = $"api/exchanges/{SanitizeVirtualHostName(vhost)}/{exchange}";

            string query = impl.Query.Value;

            if (!string.IsNullOrWhiteSpace(query))
            {
                url = $"api/exchanges/{SanitizeVirtualHostName(vhost)}/{exchange}?{query}";
            }

            Result result = await Delete(url, cancellationToken);

            return(result);
        }
Пример #3
0
        public async Task <Result> DeleteAsync(Action <ExchangeDeleteAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled(LogInfo);

            var impl = new ExchangeDeleteActionImpl();

            action(impl);

            string exchange = impl.ExchangeName.Value;
            string vhost    = impl.VirtualHost.Value;

            if (string.IsNullOrWhiteSpace(exchange))
            {
                throw new ExchangeMissingException("The name of the exchange is missing.");
            }

            if (string.IsNullOrWhiteSpace(vhost))
            {
                throw new VirtualHostMissingException("The name of the virtual host is missing.");
            }

            string sanitizedVHost = vhost.SanitizeVirtualHostName();

            string url = $"api/exchanges/{sanitizedVHost}/{exchange}";

            string query = impl.Query.Value;

            if (!string.IsNullOrWhiteSpace(query))
            {
                url = $"api/exchanges/{sanitizedVHost}/{exchange}?{query}";
            }

            HttpResponseMessage response = await HttpDelete(url, cancellationToken);

            Result result = response.GetResponse();

            LogInfo($"Sent request to RabbitMQ server to delete exchange '{exchange}' from virtual host '{sanitizedVHost}'.");

            return(result);
        }