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 _timerCommandRepo; private readonly IRepository _tiggerCommandRepo; private readonly IoTNodeClient _client; public IoTNodeJob(IRepository timerCommandRepo, IRepository 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); } } }