#pragma warning disable 1998 public async Task <IActionResult> ExecuteAsync(SemanticInput parameter, CancellationToken cancellationToken) { string filepath = Path.Combine(this._hostingEnvironment.WebRootPath, "Matchmaking.jar"); string args = "/C java -jar " + filepath; string standaloneArguments = "java -jar Matchmaking.jar" + " " + HttpUtility.JavaScriptStringEncode(parameter.ToJson()); string complete_args = args + " " + HttpUtility.JavaScriptStringEncode(parameter.ToJson()); System.Diagnostics.Process clientProcess = new Process { StartInfo = { FileName = "java", Arguments = @"-jar " + filepath + " " + HttpUtility.JavaScriptStringEncode(parameter.ToJson()), RedirectStandardOutput = true, RedirectStandardError = true } }; clientProcess.Start(); // clientProcess.WaitForExit(); var result = clientProcess.StandardOutput.ReadToEnd(); var isError = clientProcess.StandardError.ReadToEnd(); int code = clientProcess.ExitCode; Console.WriteLine(code); Console.WriteLine(); // var result = await Cli.Wrap("cmd.exe").SetArguments(complete_args).SetCancellationToken(cancellationToken) // .ExecuteAsync(); /* var result = await Cli.Wrap("cmd.exe").SetStandardInput(complete_args) * .SetStandardOutputCallback(l => Console.WriteLine($"StdOut> {l}")) // triggered on every line in stdout * .SetStandardErrorCallback(l => Console.WriteLine($"StdErr> {l}")) // triggered on every line in stderr * .SetCancellationToken(cancellationToken).ExecuteAsync(); */ /*var process = new Process() * { * StartInfo = new ProcessStartInfo * { * FileName = "cmd.exe", * Arguments = complete_args, * RedirectStandardOutput = true, * RedirectStandardError = true, * UseShellExecute = false, * CreateNoWindow = true, * } * }; * process.Start(); * var output = new List<string>(); * * while (process.StandardOutput.Peek() > -1) * { * output.Add(process.StandardOutput.ReadLine()); * } * * while (process.StandardError.Peek() > -1) * { * output.Add(process.StandardError.ReadLine()); * }*/ // process.WaitForExit(); //string result = process.StandardOutput.ReadToEnd(); //process.WaitForExit(); // var result = await Cli.Wrap("cli.exe").SetArguments(args).SetCancellationToken(cancellationToken) // .ExecuteAsync(); /* var process = Opener.Open(args, processStartInfo: new ProcessStartInfo() * { * WorkingDirectory = this._hostingEnvironment.WebRootPath, * RedirectStandardOutput = true, * UseShellExecute = false, * CreateNoWindow = true, * }); * process.Start(); * string result = process.StandardOutput.ReadToEnd(); * process.WaitForExit();*/ //Console.WriteLine("ok"); bool isErr = result.Split('\n').Length > 5; return(isErr ? new OkObjectResult(isError) : new OkObjectResult(result)); }
public Task <IActionResult> Post( [FromServices] IGetSemanticScoreCommand command, [FromBody] SemanticInput input, CancellationToken cancellationToken) => command.ExecuteAsync(input);