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.
45 lines
1.6 KiB
45 lines
1.6 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using IoT.Shared.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IoTNode.Services
|
|
{
|
|
public class IoTNodeJob
|
|
{
|
|
private readonly IRepository<IoTTimerCommand> _timerCommandRepo;
|
|
private readonly IRepository<IoTTiggerCommand> _tiggerCommandRepo;
|
|
private readonly IoTNodeClient _client;
|
|
|
|
public IoTNodeJob(IRepository<IoTTimerCommand> timerCommandRepo, IRepository<IoTTiggerCommand> tiggerCommandRepo, IoTNodeClient client)
|
|
{
|
|
this._timerCommandRepo = timerCommandRepo;
|
|
this._tiggerCommandRepo = tiggerCommandRepo;
|
|
this._client = client;
|
|
}
|
|
|
|
public void TimerHanle(Guid timerId)
|
|
{
|
|
var commands = this._timerCommandRepo.ReadOnlyTable()
|
|
.Include(o => o.Command).ThenInclude(o => o.Api)
|
|
.Include(o => o.Command).ThenInclude(o => o.Device)
|
|
.Where(o => o.IoTTimerId == timerId)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
this._client.ExecCommands(commands);
|
|
}
|
|
|
|
public void TiggerHandle(Guid tiggerId)
|
|
{
|
|
var commands = this._tiggerCommandRepo.ReadOnlyTable()
|
|
.Include(o => o.Command).ThenInclude(o => o.Api)
|
|
.Include(o => o.Command).ThenInclude(o => o.Device)
|
|
.Where(o => o.IoTTiggerId == tiggerId)
|
|
.Select(o => o.Command)
|
|
.ToList();
|
|
this._client.ExecCommands(commands);
|
|
}
|
|
}
|
|
} |