2021-12-24 08:07:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2021-02-14 05:56:27 +00:00
|
|
|
|
using System.IO;
|
2023-07-03 04:58:44 +00:00
|
|
|
|
using System.Text.Json;
|
2021-02-08 06:37:37 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2016-05-07 15:56:29 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Core.Plugin
|
2016-05-07 15:56:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
internal class ExecutablePlugin : JsonRPCPlugin
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ProcessStartInfo _startInfo;
|
|
|
|
|
|
|
|
|
|
|
|
public ExecutablePlugin(string filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
_startInfo = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = filename,
|
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
|
RedirectStandardError = true
|
|
|
|
|
|
};
|
2021-12-24 08:07:51 +00:00
|
|
|
|
|
|
|
|
|
|
// required initialisation for below request calls
|
|
|
|
|
|
_startInfo.ArgumentList.Add(string.Empty);
|
2016-05-07 15:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-13 05:55:07 +00:00
|
|
|
|
protected override Task<Stream> RequestAsync(JsonRPCRequestModel request, CancellationToken token = default)
|
2016-05-07 15:56:29 +00:00
|
|
|
|
{
|
2021-12-24 08:07:51 +00:00
|
|
|
|
// since this is not static, request strings will build up in ArgumentList if index is not specified
|
2023-07-03 04:58:44 +00:00
|
|
|
|
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(request, RequestSerializeOption);
|
2021-02-08 06:37:37 +00:00
|
|
|
|
return ExecuteAsync(_startInfo, token);
|
2016-05-07 15:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-13 05:55:07 +00:00
|
|
|
|
protected override string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default)
|
2016-05-07 15:56:29 +00:00
|
|
|
|
{
|
2021-12-24 08:07:51 +00:00
|
|
|
|
// since this is not static, request strings will build up in ArgumentList if index is not specified
|
2023-07-03 04:58:44 +00:00
|
|
|
|
_startInfo.ArgumentList[0] = JsonSerializer.Serialize(rpcRequest, RequestSerializeOption);
|
2021-02-08 06:43:17 +00:00
|
|
|
|
return Execute(_startInfo);
|
2016-05-07 15:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-22 10:22:21 +00:00
|
|
|
|
}
|