InventoryAgent/Inventory.Core/UpdateWorkflow.cs
2025-10-21 12:58:33 +08:00

38 lines
1.4 KiB
C#

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace Inventory.Core
{
public class UpdateWorkflow
{
private readonly DatabaseUpdater _databaseUpdater;
private readonly SystemInfoCollector _collector;
private readonly InventoryContext _db;
private readonly SlurpitClient _slurpitClient;
public UpdateWorkflow(DatabaseUpdater databaseUpdater, SystemInfoCollector collector, InventoryContext db, SlurpitClient slurpitClient)
{
_databaseUpdater = databaseUpdater;
_collector = collector;
_db = db;
_slurpitClient = slurpitClient;
}
public async Task Run()
{
// This updates all properties EXCEPT printers.
await _databaseUpdater.UpsertDevice();
// Fetch the final, complete device object from the database to send to Slurpit.
// This ensures that when the agent runs, it sends the printer data that the AdminTool saved.
var identifier = _databaseUpdater.GetLocalIdentifier();
if (!string.IsNullOrEmpty(identifier))
{
var finalDevice = await _db.Devices.AsNoTracking().FirstOrDefaultAsync(d => d.HardwareIdentifier == identifier);
if (finalDevice != null) await _slurpitClient.SendDeviceData(finalDevice);
}
}
}
}