From d5915ccf72d1e056aeacbd89fe58d826824dfd8c Mon Sep 17 00:00:00 2001 From: ryzij Date: Thu, 2 Jul 2026 14:18:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=86=D0=B5=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MonitorAgent/MonitorAgent.API/Program.cs | 2 ++ .../Services/ProcessStarterService.cs | 27 +++++++++++++++++++ .../Abstraction/IProcessStarterService.cs | 6 +++++ 3 files changed, 35 insertions(+) create mode 100644 Backend/MonitorAgent/MonitorAgent.Application/Services/ProcessStarterService.cs create mode 100644 Backend/MonitorAgent/MonitorAgent.Core/Abstraction/IProcessStarterService.cs diff --git a/Backend/MonitorAgent/MonitorAgent.API/Program.cs b/Backend/MonitorAgent/MonitorAgent.API/Program.cs index 30b6d68..e890cda 100644 --- a/Backend/MonitorAgent/MonitorAgent.API/Program.cs +++ b/Backend/MonitorAgent/MonitorAgent.API/Program.cs @@ -15,7 +15,9 @@ builder.Services.AddSwaggerGen(); builder.Services.Configure(builder.Configuration.GetSection("CpuMonitorSettings")); +builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(provider => provider.GetRequiredService()); diff --git a/Backend/MonitorAgent/MonitorAgent.Application/Services/ProcessStarterService.cs b/Backend/MonitorAgent/MonitorAgent.Application/Services/ProcessStarterService.cs new file mode 100644 index 0000000..af65056 --- /dev/null +++ b/Backend/MonitorAgent/MonitorAgent.Application/Services/ProcessStarterService.cs @@ -0,0 +1,27 @@ +using MonitorAgent.Core.Abstraction; +using System.Diagnostics; + +namespace MonitorAgent.Application.Services; + +public class ProcessStarterService : IProcessStarterService +{ + public async Task StartProcessAsync( + string fileName, string arguments, CancellationToken cancellationToken = default) + { + using var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = fileName, + Arguments = arguments, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true + } + }; + + process.Start(); + + return await process.StandardOutput.ReadToEndAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/Backend/MonitorAgent/MonitorAgent.Core/Abstraction/IProcessStarterService.cs b/Backend/MonitorAgent/MonitorAgent.Core/Abstraction/IProcessStarterService.cs new file mode 100644 index 0000000..8fea053 --- /dev/null +++ b/Backend/MonitorAgent/MonitorAgent.Core/Abstraction/IProcessStarterService.cs @@ -0,0 +1,6 @@ +namespace MonitorAgent.Core.Abstraction; + +public interface IProcessStarterService +{ + Task StartProcessAsync(string fileName, string arguments, CancellationToken cancellationToken); +} \ No newline at end of file