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;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class EventService : IEventService
|
|
|
|
|
{
|
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2021-05-20 14:14:51 +05:00
|
|
|
|
private readonly CacheTable<Event> cacheEvents;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
|
|
|
|
public EventService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
|
|
|
|
|
{
|
|
|
|
|
this.telemetryService = telemetryService;
|
|
|
|
|
cacheEvents = cacheDb.GetCachedTable<Event>((AsbCloudDbContext)db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Upsert(string uid, IEnumerable<EventDto> dtos)
|
|
|
|
|
{
|
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-07-16 09:15:10 +05:00
|
|
|
|
var entities = dtos.Select(dto => new Event
|
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
|
|
|
|
|
});
|
|
|
|
|
cacheEvents.Upsert(entities);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|