mirror of
https://github.com/ryzij/ServerMonitor.git
synced 2026-07-14 03:46:58 +00:00
Добавил сервис для запуска процессов
This commit is contained in:
@@ -15,7 +15,9 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
builder.Services.Configure<CpuMonitorSettings>(builder.Configuration.GetSection("CpuMonitorSettings"));
|
builder.Services.Configure<CpuMonitorSettings>(builder.Configuration.GetSection("CpuMonitorSettings"));
|
||||||
|
|
||||||
|
builder.Services.AddScoped<IProcessStarterService, ProcessStarterService>();
|
||||||
builder.Services.AddScoped<IMonitorService, MonitorService>();
|
builder.Services.AddScoped<IMonitorService, MonitorService>();
|
||||||
|
|
||||||
builder.Services.AddSingleton<RawCpuMonitorService>();
|
builder.Services.AddSingleton<RawCpuMonitorService>();
|
||||||
builder.Services.AddSingleton<CpuMonitorBackgroundService>();
|
builder.Services.AddSingleton<CpuMonitorBackgroundService>();
|
||||||
builder.Services.AddHostedService(provider => provider.GetRequiredService<CpuMonitorBackgroundService>());
|
builder.Services.AddHostedService(provider => provider.GetRequiredService<CpuMonitorBackgroundService>());
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using MonitorAgent.Core.Abstraction;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace MonitorAgent.Application.Services;
|
||||||
|
|
||||||
|
public class ProcessStarterService : IProcessStarterService
|
||||||
|
{
|
||||||
|
public async Task<string> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace MonitorAgent.Core.Abstraction;
|
||||||
|
|
||||||
|
public interface IProcessStarterService
|
||||||
|
{
|
||||||
|
Task<string> StartProcessAsync(string fileName, string arguments, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user