You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.1 KiB
52 lines
2.1 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using IoT.Shared.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IoTNode.Services
|
|
{
|
|
public class IoTNodeJob
|
|
{
|
|
private readonly ILogger<IoTNodeJob> _logger;
|
|
private readonly IRepository<SceneTimer> _sceneTimerRepo;
|
|
private readonly IRepository<SceneTigger> _sceneTiggerRepo;
|
|
private readonly IoTNodeClient _client;
|
|
|
|
public IoTNodeJob(ILogger<IoTNodeJob> logger, IRepository<SceneTimer> sceneTimerRepo, IRepository<SceneTigger> sceneTiggerRepo, IoTNodeClient client)
|
|
{
|
|
this._logger = logger;
|
|
this._sceneTimerRepo = sceneTimerRepo;
|
|
this._sceneTiggerRepo = sceneTiggerRepo;
|
|
this._client = client;
|
|
}
|
|
|
|
public void TimerHanle(Guid timerId)
|
|
{
|
|
this._logger.LogDebug($"node timer exec:{timerId}");
|
|
var commands = this._sceneTimerRepo.ReadOnlyTable()
|
|
.Include(o => o.Scene).ThenInclude(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Api)
|
|
.Include(o => o.Scene).ThenInclude(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Device)
|
|
.Where(o => o.Id == timerId)
|
|
.SelectMany(o => o.Scene.SceneCommands)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
this._client.ExecCommands(commands);
|
|
}
|
|
|
|
public void TiggerHandle(Guid tiggerId)
|
|
{
|
|
this._logger.LogDebug($"node tigger exec:{tiggerId}");
|
|
var commands = this._sceneTiggerRepo.ReadOnlyTable()
|
|
.Include(o => o.Scene).ThenInclude(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Api)
|
|
.Include(o => o.Scene).ThenInclude(o => o.SceneCommands).ThenInclude(o => o.Command).ThenInclude(o => o.Device)
|
|
.Where(o => o.Id == tiggerId)
|
|
.SelectMany(o => o.Scene.SceneCommands)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
this._client.ExecCommands(commands);
|
|
}
|
|
}
|
|
} |