mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:26:30 +00:00
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using System.Diagnostics;
|
|
using Azaion.CommonSecurity.DTO;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Azaion.CommonSecurity.Services;
|
|
|
|
public class LoaderClient
|
|
{
|
|
private readonly IMediator _mediator;
|
|
private readonly ILogger<LoaderClient> _logger;
|
|
|
|
public LoaderClient(IMediator mediator, IOptions<LoaderClientConfig> config, ILogger<LoaderClient> logger)
|
|
{
|
|
_mediator = mediator;
|
|
_logger = logger;
|
|
try
|
|
{
|
|
using var process = new Process();
|
|
process.StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = SecurityConstants.LoaderPath,
|
|
Arguments = $"--port {config.Value.ZeroMqPort} --api {config.Value.ApiUrl}",
|
|
//RedirectStandardOutput = true,
|
|
//RedirectStandardError = true,
|
|
//CreateNoWindow = true
|
|
};
|
|
|
|
process.OutputDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
|
|
process.ErrorDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
|
|
process.Start();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
//throw;
|
|
}
|
|
|
|
_requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}";
|
|
_requestSocket.Connect(_requestAddress);
|
|
|
|
_subscriberAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqReceiverPort}";
|
|
_subscriberSocket.Connect(_subscriberAddress);
|
|
_subscriberSocket.Subscribe("");
|
|
_subscriberSocket.ReceiveReady += async (sender, e) => await ProcessClientCommand(sender, e);
|
|
|
|
_poller.Add(_subscriberSocket);
|
|
_poller.RunAsync();
|
|
}
|
|
} |