forked from amkovkov/GranuSightSoftware2
Первый коммит
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-GSS2.Test-191ece0a-855d-46ec-9ecb-44378fc3db83</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GSS2.Core\GSS2.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Data;
|
||||
using GSS2.Core.Analysis.AmineContent.Database;
|
||||
using GSS2.Core.Hardware;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Protocols.Configuration;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddDbContext<AmineContentCalibrationContext>(
|
||||
options =>
|
||||
{
|
||||
var databasePath = builder.Configuration.GetConnectionString("AmineContentCalibrationDatabasePath");
|
||||
options.UseSqlite($"Data Source={databasePath}");
|
||||
},
|
||||
ServiceLifetime.Singleton
|
||||
);
|
||||
builder.Services.AddSingleton<LightsService>(
|
||||
serviceProvider =>
|
||||
{
|
||||
var configuration = serviceProvider.GetService<IConfiguration>();
|
||||
if (configuration is null)
|
||||
throw new Exception("Cannot get configuration");
|
||||
var serviceConfiguration = configuration.GetValue<LightsService.LightsServiceConfiguration>("Lights");
|
||||
if (serviceConfiguration is null)
|
||||
throw new InvalidConfigurationException("Cannot get configuration (Lights)");
|
||||
var logger = serviceProvider.GetService<ILogger<LightsService>>();
|
||||
if (logger is null)
|
||||
throw new Exception("Cannot get logger");
|
||||
return new LightsService(logger, serviceConfiguration);
|
||||
}
|
||||
);
|
||||
builder.Services.AddSingleton<TemperatureHumidityService>(
|
||||
serviceProvider =>
|
||||
{
|
||||
var configuration = serviceProvider.GetService<IConfiguration>();
|
||||
if (configuration is null)
|
||||
throw new Exception("Cannot get configuration");
|
||||
var serviceConfiguration = configuration.GetValue<TemperatureHumidityService.TemperatureHumidityServiceConfiguration>("TemperatureHumidity");
|
||||
if (serviceConfiguration is null)
|
||||
throw new InvalidConfigurationException("Cannot get configuration (TemperatureHumidity)");
|
||||
var logger = serviceProvider.GetService<ILogger<TemperatureHumidityService>>();
|
||||
if (logger is null)
|
||||
throw new Exception("Cannot get logger");
|
||||
return new TemperatureHumidityService(logger, serviceConfiguration);
|
||||
}
|
||||
);
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
using (var scope = host.Services.CreateScope())
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<AmineContentCalibrationContext>();
|
||||
context.Database.Migrate();
|
||||
}
|
||||
|
||||
host.Run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Drawing;
|
||||
using GSS2.Core.Analysis.AmineContent.Database;
|
||||
using GSS2.Core.Hardware;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
public class Worker(
|
||||
ILogger<Worker> logger,
|
||||
AmineContentCalibrationContext calibrationContext,
|
||||
LightsService lightsService,
|
||||
TemperatureHumidityService temperatureHumidity
|
||||
) : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger = logger;
|
||||
private readonly AmineContentCalibrationContext _calibrationContext = calibrationContext;
|
||||
private readonly LightsService _lightsService = lightsService;
|
||||
private readonly TemperatureHumidityService _temperatureHumidity = temperatureHumidity;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = _lightsService.Run(cancellationToken);
|
||||
await _lightsService.SnowfallAsync(0.3, 1, Color.Aqua, cancellationToken);
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var (temperature, humidity) = await _temperatureHumidity.MeasureAsync();
|
||||
_logger.LogInformation("Temperature: {}, RelativeHumidity: {}", temperature, humidity);
|
||||
await Task.Delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"AmineContentCalibrationDatabasePath": "AmineContentCalibration.db"
|
||||
},
|
||||
"Hardware": {
|
||||
"Illuminator": {
|
||||
"WhitePwmPin": 13,
|
||||
"Uv254PwmPin": 18,
|
||||
"Uv365PwmPin": 12,
|
||||
"WhiteRelayPin": 16,
|
||||
"Uv254RelayPin": 15,
|
||||
"Uv365RelayPin": 20,
|
||||
"FanPin": 21,
|
||||
"PwmFrequency": 200,
|
||||
"MaxWhitePwmDuty": 1.0,
|
||||
"MaxUv254PwmDuty": 1.0,
|
||||
"MaxUv365PwmDuty": 1.0
|
||||
},
|
||||
"TemperatureHumidity": {
|
||||
"Bus": 0,
|
||||
"Address": 68
|
||||
},
|
||||
"Lights": {
|
||||
"ServerAddress": "localhost:50051"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user