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