initial commit
This commit is contained in:
38
Lab505.Sim/OpcUaHostedService.cs
Normal file
38
Lab505.Sim/OpcUaHostedService.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Lab505.Sim;
|
||||
|
||||
public class OpcUaHostedService : IHostedService
|
||||
{
|
||||
private readonly OpcUaSimulationServer _server;
|
||||
private readonly ILogger<OpcUaHostedService> _logger;
|
||||
|
||||
public OpcUaHostedService(
|
||||
OpcUaSimulationServer server,
|
||||
ILogger<OpcUaHostedService> logger)
|
||||
{
|
||||
_server = server;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Starting OPC UA Simulation Server on port 4840");
|
||||
try
|
||||
{
|
||||
await _server.StartAsync();
|
||||
_logger.LogInformation("OPC UA Simulation Server started on port 4840");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("OPC UA Simulation Server failed to start (port 4840 may already be in use): {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("Stopping OPC UA Simulation Server");
|
||||
await _server.StopAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user