-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeleteTransportCommand.cs
More file actions
31 lines (28 loc) · 1.43 KB
/
DeleteTransportCommand.cs
File metadata and controls
31 lines (28 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using BuslyCLI.Config;
using Spectre.Console;
using Spectre.Console.Cli;
namespace BuslyCLI.Commands.Transport;
public class DeleteTransportCommand(IAnsiConsole console, INServiceBusConfiguration nservicebusConfiguration)
: AsyncCommand<DeleteTransportSettings>
{
public override async Task<int> ExecuteAsync(CommandContext context, DeleteTransportSettings settings, CancellationToken cancellationToken)
{
var nsbConfiguration = await nservicebusConfiguration.GetValidatedConfigurationAsync(settings.Config.Path);
var targetTransport = settings.TransportName.ToLower();
if (nsbConfiguration.Transports.Select(x => x.Name.ToLower()).Contains(targetTransport))
{
if (nsbConfiguration.CurrentTransport.ToLower() == targetTransport)
{
await nservicebusConfiguration.UpdateCurrentTransportAsync(settings.Config.Path, "");
console.WriteLine("This removed your active transport, use \"nservicebus transport set\" to select a different one.");
}
await nservicebusConfiguration.RemoveTransportAsync(settings.Config.Path, targetTransport);
console.WriteLine($"deleted transport named {targetTransport} from {settings.Config.Path}");
}
else
{
console.WriteLine($"Cannot delete transport {settings.TransportName} since it doesn't exist in the config file.");
}
return 0;
}
}