// TODO: Async/await. private ScriptResult ExecuteScriptContent(ScriptingShell shell, string terminalSessionId, string command, TimeSpan timeout) { switch (shell) { case ScriptingShell.PSCore: return(PSCore.GetCurrent(terminalSessionId).WriteInput(command)); case ScriptingShell.WinPS: if (EnvironmentHelper.IsWindows) { return(ExternalScriptingShell .GetCurrent(ScriptingShell.WinPS, terminalSessionId) .WriteInput(command, timeout)); } break; case ScriptingShell.CMD: if (EnvironmentHelper.IsWindows) { return(ExternalScriptingShell .GetCurrent(ScriptingShell.CMD, terminalSessionId) .WriteInput(command, timeout)); } break; case ScriptingShell.Bash: return(ExternalScriptingShell .GetCurrent(ScriptingShell.Bash, terminalSessionId) .WriteInput(command, timeout)); default: break; } return(null); }
public async Task RunCommandFromApi(ScriptingShell shell, string requestID, string command, string senderUsername, string authToken, HubConnection hubConnection) { try { var result = ExecuteScriptContent(shell, requestID, command, TimeSpan.FromMinutes(AppConstants.ScriptRunExpirationMinutes)); result.InputType = ScriptInputType.Api; result.SenderUserName = senderUsername; await SendResultsToApi(result, authToken); await hubConnection.SendAsync("ScriptResultViaApi", requestID); } catch (Exception ex) { Logger.Write(ex); } }