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

46 lines
1.4 KiB
C#
Raw Normal View History

2022-04-08 13:10:06 +05:00
using AsbCloudApp.Data.SAUB;
2021-04-23 10:21:25 +05:00
using AsbCloudApp.Services;
using AsbCloudDb;
2021-04-23 10:21:25 +05:00
using AsbCloudDb.Model;
using Microsoft.Extensions.Caching.Memory;
2021-04-23 10:21:25 +05:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2021-04-23 10:21:25 +05:00
2022-04-11 18:00:34 +05:00
namespace AsbCloudInfrastructure.Services.SAUB
2021-04-23 10:21:25 +05:00
{
public class EventService : IEventService
{
private readonly IAsbCloudDbContext db;
private readonly IMemoryCache memoryCache;
2021-04-23 10:21:25 +05:00
private readonly ITelemetryService telemetryService;
public EventService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService)
2021-04-23 10:21:25 +05:00
{
this.db = db;
this.memoryCache = memoryCache;
2021-04-23 10:21:25 +05:00
this.telemetryService = telemetryService;
}
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.GetOrCreateTelemetryIdByUid(uid);
2021-04-23 10:21:25 +05:00
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
});
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
memoryCache.DropBasic<TelemetryEvent>();
2021-04-23 10:21:25 +05:00
}
}
}