forked from ddrilling/AsbCloudServer
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using AsbCloudApp.Data.SAUB;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.EfCache;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services.SAUB
|
|
{
|
|
public class EventService : IEventService
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
private readonly ITelemetryService telemetryService;
|
|
|
|
public EventService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
|
{
|
|
this.db = db;
|
|
this.telemetryService = telemetryService;
|
|
}
|
|
|
|
public async Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
|
CancellationToken token = default)
|
|
{
|
|
if (!dtos.Any())
|
|
return;
|
|
|
|
var telemetryId = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
|
|
|
var entities = dtos.Select(dto => new TelemetryEvent
|
|
{
|
|
IdEvent = dto.Id,
|
|
IdTelemetry = telemetryId,
|
|
IdCategory = dto.IdCategory,
|
|
MessageTemplate = dto.Message
|
|
});
|
|
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
|
|
db.TelemetryEvents.DropCache();
|
|
}
|
|
}
|
|
}
|