private static RunWebCommandResult RunWebCommand(string commandName, string commandParametersJson) { if (commandName == "RunApplication") { RunApplicationParameters runParams = JsonConvert.DeserializeObject <RunApplicationParameters>(commandParametersJson); if (runParams.CommandStartTimeoutMS == 0) { runParams.CommandStartTimeoutMS = 30000; } IRunApplication commandTextRunner = new WindowsCommandTextRunner(); return(commandTextRunner.Execute(runParams)); } else if (commandName == "DownloadFile") { var downloadParams = JsonConvert.DeserializeObject <FileDownloaderParams>(commandParametersJson); FileDownloader fd = new FileDownloader(); return(fd.Download(downloadParams.RemoteUri, downloadParams.FileName, downloadParams.TargetDirPath)); } else if (commandName == "ImportFromGoogleSheetToExcel") { var importGSParams = JsonConvert.DeserializeObject <ImportFromGoogleSheetParameters>(commandParametersJson); var igs = new ImportFromGoogleSheetToExcel(); return(igs.Execute(importGSParams)); } else { throw new NotSupportedException("CommandName not supported: " + commandName); } }
public RunWebCommandResult Execute(RunApplicationParameters param) { //ConsoleApp app = new ConsoleApp(param.CommandText, param.CommandParameters); //List<string> cmdOutput = new List<string>(); //app.ConsoleOutput += (o, args) => //{ // cmdOutput.Add(args.Line); //}; //app.Run(); //var exited = app.WaitForExit(2000); // 2 second to wait //string strOutput = String.Join("; ", cmdOutput.ToArray()); //Console.WriteLine("IsExited: {0}", exited); //Console.WriteLine("ExitCode: {0}", app.ExitCode); //Console.WriteLine("Result:" + strOutput); //var res = new CommandTextRunnerResult() //{ // OutputText = strOutput, // ResultCode = app.ExitCode.Value, // ErrorText = "no errors" //}; return(null); }
public RunWebCommandResult Execute(RunApplicationParameters parameters) { string errorText = null; string errorStackTrace = null; int resultCode = 0; ErrorText = new StringBuilder(); try { if (string.IsNullOrWhiteSpace(parameters.ApplicationPath)) { throw new ArgumentNullException("ApplicationPath"); } runCommand_cmd(parameters.ApplicationPath, parameters.CommandStartTimeoutMS); } catch (Exception ex) { errorText = ex.Message; errorStackTrace = ex.StackTrace; resultCode = -2; // runner error } // ToDo: странно, что сюда попадаем до получения errorOutput if (resultCode == 0 && ErrorText.Length > 2) { resultCode = -1; // execution program error errorText = ErrorText.ToString(); } return(new RunWebCommandResult() { ErrorText = errorText, OutputText = errorStackTrace, ResultCode = resultCode }); }