DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/EventService.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2021-04-23 10:21:25 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2021-04-23 10:21:25 +05:00
namespace AsbCloudInfrastructure.Services
{
public class EventService : IEventService
{
private readonly ITelemetryService telemetryService;
2021-08-10 16:37:13 +05:00
private readonly CacheTable<TelemetryEvent> cacheEvents;
2021-04-23 10:21:25 +05:00
public EventService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
{
this.telemetryService = telemetryService;
2021-08-10 16:37:13 +05:00
cacheEvents = cacheDb.GetCachedTable<TelemetryEvent>((AsbCloudDbContext)db);
2021-04-23 10:21:25 +05:00
}
public async Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
CancellationToken token = default)
2021-04-23 10:21:25 +05:00
{
2021-05-20 11:17:55 +05:00
if (!dtos.Any())
2021-04-23 10:21:25 +05:00
return;
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
2021-08-10 16:37:13 +05:00
var entities = dtos.Select(dto => new TelemetryEvent
2021-04-23 10:21:25 +05:00
{
2021-07-16 09:15:10 +05:00
IdEvent = dto.Id,
IdTelemetry = telemetryId,
IdCategory = dto.IdCategory,
MessageTemplate = dto.Message
});
await cacheEvents.UpsertAsync(entities, token);
2021-04-23 10:21:25 +05:00
}
}
}