コード例 #1
0
 private string ExecuteChar(ParameterValues configValues)
 {
     if (configValues.TryGetConfigValue(_ConfigChar, out var configValue))
     {
         // TODO Better Convert
         new Robot().Type(configValue.UntypedValue.ToString());
         _logger.Debug($"Pressed {configValue.UntypedValue}");
         return($"Pressed {configValue.UntypedValue}");
     }
     _logger.Debug("Config value not found!");
     return("Config value not found!");
 }
コード例 #2
0
        private string ExecuteCommand(ParameterValues arg)
        {
            if (!arg.TryGetConfigValue(_ConfigExecutable, out var command) || command?.UntypedValue == null || string.IsNullOrEmpty(command.UntypedValue.ToString()))
            {
                _logger.Error("No Command defined!", arg, command);
                return("No Command defined!");
            }

            _ = arg.TryGetConfigValue(_ConfigArguments, out var arguments);

            bool waitForExit = false;

            if (arg.TryGetConfigValue(_ConfigWaitForExit, out var waitForExitParameter) && waitForExitParameter?.UntypedValue is bool b)
            {
                waitForExit = b;
            }

            try
            {
                var process = Process.Start(new ProcessStartInfo(command.UntypedValue.ToString(), arguments?.UntypedValue?.ToString())
                {
                    UseShellExecute = true
                });
                if (waitForExit)
                {
                    process.WaitForExit();
                    _logger.Debug($"Successfully exited. ExitCode: {process.ExitCode}", arg, command);
                    return($"Successfully exited. ExitCode: {process.ExitCode}");
                }
            }
            catch (Exception e)
            {
                _logger.Error("Could not execute command", arg, command, e);
                return("Could not execute command");
            }

            _logger.Debug("Successfully started!", arg, command);
            return("Successfully Started!");
        }