{
internal static class ADBCommandExec
{
- public static bool AdbAddPortForward(int port, ILogger logger)
+ public static bool AdbAddPortForward(int port, bool rethrow, ILogger logger)
{
bool ownsPortForward = false;
- if (!RunAdbCommandInternal($"forward --list", $"tcp:{port}", 0, logger))
+ if (!RunAdbCommandInternal($"forward --list", $"tcp:{port}", 0, rethrow, logger))
{
- ownsPortForward = RunAdbCommandInternal($"forward tcp:{port} tcp:{port}", "", 0, logger);
+ ownsPortForward = RunAdbCommandInternal($"forward tcp:{port} tcp:{port}", "", 0, rethrow, logger);
if (!ownsPortForward)
{
logger?.LogError($"Failed setting up port forward for tcp:{port}.");
return ownsPortForward;
}
- public static bool AdbAddPortReverse(int port, ILogger logger)
+ public static bool AdbAddPortReverse(int port, bool rethrow, ILogger logger)
{
bool ownsPortForward = false;
- if (!RunAdbCommandInternal($"reverse --list", $"tcp:{port}", 0, logger))
+ if (!RunAdbCommandInternal($"reverse --list", $"tcp:{port}", 0, rethrow, logger))
{
- ownsPortForward = RunAdbCommandInternal($"reverse tcp:{port} tcp:{port}", "", 0, logger);
+ ownsPortForward = RunAdbCommandInternal($"reverse tcp:{port} tcp:{port}", "", 0, rethrow, logger);
if (!ownsPortForward)
{
logger?.LogError($"Failed setting up port forward for tcp:{port}.");
return ownsPortForward;
}
- public static void AdbRemovePortForward(int port, bool ownsPortForward, ILogger logger)
+ public static void AdbRemovePortForward(int port, bool ownsPortForward, bool rethrow, ILogger logger)
{
if (ownsPortForward)
{
- if (!RunAdbCommandInternal($"forward --remove tcp:{port}", "", 0, logger))
+ if (!RunAdbCommandInternal($"forward --remove tcp:{port}", "", 0, rethrow, logger))
{
logger?.LogError($"Failed removing port forward for tcp:{port}.");
}
}
}
- public static void AdbRemovePortReverse(int port, bool ownsPortForward, ILogger logger)
+ public static void AdbRemovePortReverse(int port, bool ownsPortForward, bool rethrow, ILogger logger)
{
if (ownsPortForward)
{
- if (!RunAdbCommandInternal($"reverse --remove tcp:{port}", "", 0, logger))
+ if (!RunAdbCommandInternal($"reverse --remove tcp:{port}", "", 0, rethrow, logger))
{
logger?.LogError($"Failed removing port forward for tcp:{port}.");
}
}
}
- public static bool RunAdbCommandInternal(string command, string expectedOutput, int expectedExitCode, ILogger logger)
+ public static bool RunAdbCommandInternal(string command, string expectedOutput, int expectedExitCode, bool rethrow, ILogger logger)
{
string sdkRoot = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT");
string adbTool = "adb";
if (!string.IsNullOrEmpty(sdkRoot))
{
- adbTool = sdkRoot + Path.DirectorySeparatorChar + "platform-tools" + Path.DirectorySeparatorChar + adbTool;
+ adbTool = Path.Combine(sdkRoot, "platform-tools", adbTool);
}
logger?.LogDebug($"Executing {adbTool} {command}.");
}
catch (Exception ex)
{
- logger.LogError($"Failed executing {adbTool} {command}. Error: {ex.Message}.");
+ logger.LogError($"Failed executing {adbTool} {command}. Error: {ex.Message}");
+ if (rethrow)
+ {
+ throw ex;
+ }
}
if (processStartedResult)
{
logger.LogError($"stderr: {stderr.TrimEnd()}");
}
- }
- if (processStartedResult)
- {
process.WaitForExit();
expectedExitCodeResult = (expectedExitCode != -1) ? (process.ExitCode == expectedExitCode) : true;
}
public override void Start()
{
// Enable port reverse.
- _ownsPortReverse = ADBCommandExec.AdbAddPortReverse(_port, Logger);
+ try
+ {
+ _ownsPortReverse = ADBCommandExec.AdbAddPortReverse(_port, true, Logger);
+ }
+ catch
+ {
+ _ownsPortReverse = false;
+ Logger.LogError("Failed setting up adb port reverse." +
+ " This might lead to problems communicating with Android application." +
+ " Make sure env variable ANDROID_SDK_ROOT is set and points to an Android SDK." +
+ $" Executing with unknown adb status for port {_port}.");
+ return;
+ }
_portReverseTaskCancelToken = new CancellationTokenSource();
_portReverseTask = Task.Run(async () => {
while (await timer.WaitForNextTickAsync(_portReverseTaskCancelToken.Token).ConfigureAwait(false) && !_portReverseTaskCancelToken.Token.IsCancellationRequested)
{
// Make sure reverse port configuration is still active.
- if (ADBCommandExec.AdbAddPortReverse(_port, Logger) && !_ownsPortReverse)
+ if (ADBCommandExec.AdbAddPortReverse(_port, false, Logger) && !_ownsPortReverse)
{
_ownsPortReverse = true;
}
catch { }
// Disable port reverse.
- ADBCommandExec.AdbRemovePortReverse(_port, _ownsPortReverse, Logger);
+ ADBCommandExec.AdbRemovePortReverse(_port, _ownsPortReverse, false, Logger);
_ownsPortReverse = false;
}
}
public override void Start()
{
// Enable port forwarding.
- _ownsPortForward = ADBCommandExec.AdbAddPortForward(_port, _logger);
+ try
+ {
+ _ownsPortForward = ADBCommandExec.AdbAddPortForward(_port, true, Logger);
+ }
+ catch
+ {
+ _ownsPortForward = false;
+ Logger.LogError("Failed setting up adb port forward." +
+ " This might lead to problems communicating with Android application." +
+ " Make sure env variable ANDROID_SDK_ROOT is set and points to an Android SDK." +
+ $" Executing with unknown adb status for port {_port}.");
+ return;
+ }
_portForwardTaskCancelToken = new CancellationTokenSource();
_portForwardTask = Task.Run(async () => {
while (await timer.WaitForNextTickAsync(_portForwardTaskCancelToken.Token).ConfigureAwait(false) && !_portForwardTaskCancelToken.Token.IsCancellationRequested)
{
// Make sure forward port configuration is still active.
- if (ADBCommandExec.AdbAddPortForward(_port, _logger) && !_ownsPortForward)
+ if (ADBCommandExec.AdbAddPortForward(_port, false, Logger) && !_ownsPortForward)
{
_ownsPortForward = true;
}
catch { }
// Disable port forwarding.
- ADBCommandExec.AdbRemovePortForward(_port, _ownsPortForward, _logger);
+ ADBCommandExec.AdbRemovePortForward(_port, _ownsPortForward, false, Logger);
_ownsPortForward = false;
}
}
LogLevel = logLevel;
}
- protected SpecificRunnerBase(string logLevel) : this(ParseLogLevel(logLevel))
- {
- }
-
public abstract void ConfigureLauncher(CancellationToken cancellationToken);
- protected static LogLevel ParseLogLevel(string verbose)
- {
- LogLevel logLevel = LogLevel.Information;
- if (string.Equals(verbose, "debug", StringComparison.OrdinalIgnoreCase))
- {
- logLevel = LogLevel.Debug;
- }
- else if (string.Equals(verbose, "trace", StringComparison.OrdinalIgnoreCase))
- {
- logLevel = LogLevel.Trace;
- }
-
- return logLevel;
- }
-
// The basic run loop: configure logging and the launcher, then create the router and run it until it exits or the user interrupts
public async Task<int> CommonRunLoop(Func<ILogger, DiagnosticsServerRouterRunner.ICallbacks, CancellationTokenSource, Task<int>> createRouterTask, CancellationToken token)
{
ConfigureLauncher(token);
- ILogger logger = loggerFactory.CreateLogger("dotnet-dsrouter");
+ int pid = Process.GetCurrentProcess().Id;
+
+ ILogger logger = loggerFactory.CreateLogger($"dotnet-dsrouter-{pid}");
- logger.LogInformation($"Starting dotnet-dsrouter using pid={Process.GetCurrentProcess().Id}");
+ logger.LogInformation($"Starting dotnet-dsrouter using pid={pid}");
Task<int> routerTask = createRouterTask(logger, Launcher, linkedCancelToken);
private sealed class IpcClientTcpServerRunner : SpecificRunnerBase
{
- public IpcClientTcpServerRunner(string verbose) : base(verbose) { }
+ public IpcClientTcpServerRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = true;
Launcher.ConnectMode = true;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
public async Task<int> RunIpcClientTcpServerRouter(CancellationToken token, string ipcClient, string tcpServer, int runtimeTimeout, string verbose, string forwardPort)
{
- checkLoopbackOnly(tcpServer);
+ LogLevel logLevel = ParseLogLevel(verbose);
- IpcClientTcpServerRunner runner = new(verbose);
+ checkLoopbackOnly(tcpServer, logLevel);
+
+ IpcClientTcpServerRunner runner = new(logLevel);
return await runner.CommonRunLoop((logger, launcherCallbacks, linkedCancelToken) => {
NetServerRouterFactory.CreateInstanceDelegate tcpServerRouterFactory = ChooseTcpServerRouterFactory(forwardPort, logger);
private sealed class IpcServerTcpServerRunner : SpecificRunnerBase
{
- public IpcServerTcpServerRunner(string verbose) : base(verbose) { }
+ public IpcServerTcpServerRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = false;
Launcher.ConnectMode = true;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
}
public async Task<int> RunIpcServerTcpServerRouter(CancellationToken token, string ipcServer, string tcpServer, int runtimeTimeout, string verbose, string forwardPort)
{
- checkLoopbackOnly(tcpServer);
+ LogLevel logLevel = ParseLogLevel(verbose);
+
+ checkLoopbackOnly(tcpServer, logLevel);
- IpcServerTcpServerRunner runner = new(verbose);
+ IpcServerTcpServerRunner runner = new(logLevel);
return await runner.CommonRunLoop((logger, launcherCallbacks, linkedCancelToken) => {
NetServerRouterFactory.CreateInstanceDelegate tcpServerRouterFactory = ChooseTcpServerRouterFactory(forwardPort, logger);
private sealed class IpcServerTcpClientRunner : SpecificRunnerBase
{
- public IpcServerTcpClientRunner(string verbose) : base(verbose) { }
+ public IpcServerTcpClientRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = false;
Launcher.ConnectMode = false;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
}
public async Task<int> RunIpcServerTcpClientRouter(CancellationToken token, string ipcServer, string tcpClient, int runtimeTimeout, string verbose, string forwardPort)
{
- IpcServerTcpClientRunner runner = new(verbose);
+ IpcServerTcpClientRunner runner = new(ParseLogLevel(verbose));
return await runner.CommonRunLoop((logger, launcherCallbacks, linkedCancelToken) => {
TcpClientRouterFactory.CreateInstanceDelegate tcpClientRouterFactory = ChooseTcpClientRouterFactory(forwardPort, logger);
private sealed class IpcClientTcpClientRunner : SpecificRunnerBase
{
- public IpcClientTcpClientRunner(string verbose) : base(verbose) { }
+ public IpcClientTcpClientRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = true;
Launcher.ConnectMode = false;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
}
public async Task<int> RunIpcClientTcpClientRouter(CancellationToken token, string ipcClient, string tcpClient, int runtimeTimeout, string verbose, string forwardPort)
{
- IpcClientTcpClientRunner runner = new(verbose);
+ IpcClientTcpClientRunner runner = new(ParseLogLevel(verbose));
return await runner.CommonRunLoop((logger, launcherCallbacks, linkedCancelToken) => {
TcpClientRouterFactory.CreateInstanceDelegate tcpClientRouterFactory = ChooseTcpClientRouterFactory(forwardPort, logger);
private sealed class IpcServerWebSocketServerRunner : SpecificRunnerBase
{
- public IpcServerWebSocketServerRunner(string verbose) : base(verbose) { }
+ public IpcServerWebSocketServerRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = false;
Launcher.ConnectMode = true;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
}
public async Task<int> RunIpcServerWebSocketServerRouter(CancellationToken token, string ipcServer, string webSocket, int runtimeTimeout, string verbose)
{
- IpcServerWebSocketServerRunner runner = new(verbose);
+ IpcServerWebSocketServerRunner runner = new(ParseLogLevel(verbose));
WebSocketServer.WebSocketServerImpl server = new(runner.LogLevel);
private sealed class IpcClientWebSocketServerRunner : SpecificRunnerBase
{
- public IpcClientWebSocketServerRunner(string verbose) : base(verbose) { }
+ public IpcClientWebSocketServerRunner(LogLevel logLevel) : base(logLevel) { }
public override void ConfigureLauncher(CancellationToken cancellationToken)
{
Launcher.SuspendProcess = true;
Launcher.ConnectMode = true;
- Launcher.Verbose = LogLevel != LogLevel.Information;
+ Launcher.Verbose = LogLevel < LogLevel.Information;
Launcher.CommandToken = cancellationToken;
}
}
public async Task<int> RunIpcClientWebSocketServerRouter(CancellationToken token, string ipcClient, string webSocket, int runtimeTimeout, string verbose)
{
- IpcClientWebSocketServerRunner runner = new(verbose);
+ IpcClientWebSocketServerRunner runner = new(ParseLogLevel(verbose));
WebSocketServer.WebSocketServerImpl server = new(runner.LogLevel);
}
}
- public async Task<int> RunIpcServerIOSSimulatorRouter(CancellationToken token, int runtimeTimeout, string verbose)
+ public async Task<int> RunIpcServerIOSSimulatorRouter(CancellationToken token, int runtimeTimeout, string verbose, bool info)
{
- logDiagnosticPortsConfiguration("ios simulator", "127.0.0.1:9000", false, verbose);
- return await RunIpcServerTcpServerRouter(token, "", "127.0.0.1:9000", runtimeTimeout, verbose, "").ConfigureAwait(false);
+ if (info)
+ {
+ logRouterUsageInfo("ios simulator", "127.0.0.1:9000", true);
+ }
+
+ return await RunIpcServerTcpClientRouter(token, "", "127.0.0.1:9000", runtimeTimeout, verbose, "").ConfigureAwait(false);
}
- public async Task<int> RunIpcServerIOSRouter(CancellationToken token, int runtimeTimeout, string verbose)
+ public async Task<int> RunIpcServerIOSRouter(CancellationToken token, int runtimeTimeout, string verbose, bool info)
{
- logDiagnosticPortsConfiguration("ios device", "127.0.0.1:9000", true, verbose);
+ if (info)
+ {
+ logRouterUsageInfo("ios device", "127.0.0.1:9000", true);
+ }
+
return await RunIpcServerTcpClientRouter(token, "", "127.0.0.1:9000", runtimeTimeout, verbose, "iOS").ConfigureAwait(false);
}
- public async Task<int> RunIpcServerAndroidEmulatorRouter(CancellationToken token, int runtimeTimeout, string verbose)
+ public async Task<int> RunIpcServerAndroidEmulatorRouter(CancellationToken token, int runtimeTimeout, string verbose, bool info)
{
- logDiagnosticPortsConfiguration("android emulator", "10.0.2.2:9000", false, verbose);
+ if (info)
+ {
+ logRouterUsageInfo("android emulator", "10.0.2.2:9000", false);
+ }
+
return await RunIpcServerTcpServerRouter(token, "", "127.0.0.1:9000", runtimeTimeout, verbose, "").ConfigureAwait(false);
}
- public async Task<int> RunIpcServerAndroidRouter(CancellationToken token, int runtimeTimeout, string verbose)
+ public async Task<int> RunIpcServerAndroidRouter(CancellationToken token, int runtimeTimeout, string verbose, bool info)
{
- logDiagnosticPortsConfiguration("android emulator", "127.0.0.1:9000", false, verbose);
+ if (info)
+ {
+ logRouterUsageInfo("android device", "127.0.0.1:9000", false);
+ }
+
return await RunIpcServerTcpServerRouter(token, "", "127.0.0.1:9000", runtimeTimeout, verbose, "Android").ConfigureAwait(false);
}
return tcpServerRouterFactory;
}
- private static void logDiagnosticPortsConfiguration(string deviceName, string deviceTcpIpAddress, bool deviceListenMode, string verbose)
+ private static LogLevel ParseLogLevel(string verbose)
{
- StringBuilder message = new();
-
- if (!string.IsNullOrEmpty(verbose))
+ LogLevel logLevel;
+ if (string.Equals(verbose, "none", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.None;
+ }
+ else if (string.Equals(verbose, "critical", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Critical;
+ }
+ else if (string.Equals(verbose, "error", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Error;
+ }
+ else if (string.Equals(verbose, "warning", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Warning;
+ }
+ else if (string.Equals(verbose, "info", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Information;
+ }
+ else if (string.Equals(verbose, "debug", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Debug;
+ }
+ else if (string.Equals(verbose, "trace", StringComparison.OrdinalIgnoreCase))
+ {
+ logLevel = LogLevel.Trace;
+ }
+ else
{
- deviceName = !string.IsNullOrEmpty(deviceName) ? $" on {deviceName} " : " ";
- message.AppendLine($"Start an application{deviceName}with one of the following environment variables set:");
+ throw new ArgumentException($"Unknown verbose log level, {verbose}");
}
- string listenMode = deviceListenMode ? ",listen" : ",connect";
- message.AppendLine($"DOTNET_DiagnosticPorts={deviceTcpIpAddress},nosuspend{listenMode}");
- message.AppendLine($"DOTNET_DiagnosticPorts={deviceTcpIpAddress},suspend{listenMode}");
+ return logLevel;
+ }
+
+ private static void logRouterUsageInfo(string deviceName, string deviceTcpIpAddress, bool deviceListenMode)
+ {
+ StringBuilder message = new();
+ string listenMode = deviceListenMode ? "listen" : "connect";
+ int pid = Process.GetCurrentProcess().Id;
+
+ message.AppendLine($"How to connect current dotnet-dsrouter pid={pid} with {deviceName} and diagnostics tooling.");
+ message.AppendLine($"Start an application on {deviceName} with ONE of the following environment variables set:");
+ message.AppendLine("[Default Tracing]");
+ message.AppendLine($"DOTNET_DiagnosticPorts={deviceTcpIpAddress},nosuspend,{listenMode}");
+ message.AppendLine("[Startup Tracing]");
+ message.AppendLine($"DOTNET_DiagnosticPorts={deviceTcpIpAddress},suspend,{listenMode}");
+ message.AppendLine($"Run diagnotic tool connecting application on {deviceName} through dotnet-dsrouter pid={pid}:");
+ message.AppendLine($"dotnet-trace collect -p {pid}");
+ message.AppendLine($"See https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dsrouter for additional details and examples.");
+
+ ConsoleColor currentColor = Console.ForegroundColor;
+ Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message.ToString());
+ Console.ForegroundColor = currentColor;
}
- private static void checkLoopbackOnly(string tcpServer)
+ private static void checkLoopbackOnly(string tcpServer, LogLevel logLevel)
{
- if (!string.IsNullOrEmpty(tcpServer) && !DiagnosticsServerRouterRunner.isLoopbackOnly(tcpServer))
+ if (logLevel != LogLevel.None && !string.IsNullOrEmpty(tcpServer) && !DiagnosticsServerRouterRunner.isLoopbackOnly(tcpServer))
{
StringBuilder message = new();
private delegate Task<int> DiagnosticsServerIpcClientWebSocketServerRouterDelegate(CancellationToken ct, string ipcClient, string webSocket, int runtimeTimeoutS, string verbose);
- private delegate Task<int> DiagnosticsServerIpcServerIOSSimulatorRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose);
+ private delegate Task<int> DiagnosticsServerIpcServerIOSSimulatorRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose, bool info);
- private delegate Task<int> DiagnosticsServerIpcServerIOSRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose);
+ private delegate Task<int> DiagnosticsServerIpcServerIOSRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose, bool info);
- private delegate Task<int> DiagnosticsServerIpcServerAndroidEmulatorRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose);
+ private delegate Task<int> DiagnosticsServerIpcServerAndroidEmulatorRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose, bool info);
- private delegate Task<int> DiagnosticsServerIpcServerAndroidRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose);
+ private delegate Task<int> DiagnosticsServerIpcServerAndroidRouterDelegate(CancellationToken ct, int runtimeTimeoutS, string verbose, bool info);
private static Command IpcClientTcpServerRouterCommand() =>
new(
// Handler
HandlerDescriptor.FromDelegate((DiagnosticsServerIpcServerIOSSimulatorRouterDelegate)new DiagnosticsServerRouterCommands().RunIpcServerIOSSimulatorRouter).GetCommandHandler(),
// Options
- RuntimeTimeoutOption(), VerboseOption()
+ RuntimeTimeoutOption(), VerboseOption(), InfoOption()
};
private static Command IOSRouterCommand() =>
// Handler
HandlerDescriptor.FromDelegate((DiagnosticsServerIpcServerIOSRouterDelegate)new DiagnosticsServerRouterCommands().RunIpcServerIOSRouter).GetCommandHandler(),
// Options
- RuntimeTimeoutOption(), VerboseOption()
+ RuntimeTimeoutOption(), VerboseOption(), InfoOption()
};
private static Command AndroidEmulatorRouterCommand() =>
// Handler
HandlerDescriptor.FromDelegate((DiagnosticsServerIpcServerAndroidEmulatorRouterDelegate)new DiagnosticsServerRouterCommands().RunIpcServerAndroidEmulatorRouter).GetCommandHandler(),
// Options
- RuntimeTimeoutOption(), VerboseOption()
+ RuntimeTimeoutOption(), VerboseOption(), InfoOption()
};
private static Command AndroidRouterCommand() =>
// Handler
HandlerDescriptor.FromDelegate((DiagnosticsServerIpcServerAndroidRouterDelegate)new DiagnosticsServerRouterCommands().RunIpcServerAndroidRouter).GetCommandHandler(),
// Options
- RuntimeTimeoutOption(), VerboseOption()
+ RuntimeTimeoutOption(), VerboseOption(), InfoOption()
};
private static Option IpcClientAddressOption() =>
private static Option VerboseOption() =>
new(
aliases: new[] { "--verbose", "-v" },
- description: "Enable verbose logging (debug|trace)")
+ description: "Enable verbose logging (none|critical|error|warning|info|debug|trace)")
{
- Argument = new Argument<string>(name: "verbose", getDefaultValue: () => "")
+ Argument = new Argument<string>(name: "verbose", getDefaultValue: () => "info")
};
private static Option ForwardPortOption() =>
Argument = new Argument<string>(name: "forwardPort", getDefaultValue: () => "")
};
+ private static Option InfoOption() =>
+ new(
+ aliases: new[] { "--info", "-i" },
+ description: "Print info on how to use current dotnet-dsrouter instance with application and diagnostic tooling.")
+ {
+ Argument = new Argument<bool>(name: "info", getDefaultValue: () => false)
+ };
+
private static int Main(string[] args)
{
- ConsoleColor currentColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("WARNING: dotnet-dsrouter is a development tool not intended for production environments." + Environment.NewLine);
- Console.ForegroundColor = currentColor;
-
Parser parser = new CommandLineBuilder()
.AddCommand(IpcClientTcpServerRouterCommand())
.AddCommand(IpcServerTcpServerRouterCommand())
ProcessLauncher.Launcher.PrepareChildProcess(args);
}
+ string verbose = parseResult.ValueForOption<string>("-v");
+ if (!string.Equals(verbose, "none", StringComparison.OrdinalIgnoreCase))
+ {
+ ConsoleColor currentColor = Console.ForegroundColor;
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine("WARNING: dotnet-dsrouter is a development tool not intended for production environments." + Environment.NewLine);
+ Console.ForegroundColor = currentColor;
+ }
+
return parser.InvokeAsync(args).Result;
}
}