feat(configdb): native alarm source repository CRUD + eager-load includes
This commit is contained in:
+24
@@ -96,6 +96,18 @@ public interface ITemplateEngineRepository
|
|||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
Task DeleteTemplateAlarmAsync(int id, CancellationToken cancellationToken = default);
|
Task DeleteTemplateAlarmAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
// TemplateNativeAlarmSource
|
||||||
|
/// <summary>Retrieves a template native alarm source by ID.</summary>
|
||||||
|
Task<TemplateNativeAlarmSource?> GetTemplateNativeAlarmSourceByIdAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Retrieves native alarm sources for a template.</summary>
|
||||||
|
Task<IReadOnlyList<TemplateNativeAlarmSource>> GetNativeAlarmSourcesByTemplateIdAsync(int templateId, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Adds a new template native alarm source.</summary>
|
||||||
|
Task AddTemplateNativeAlarmSourceAsync(TemplateNativeAlarmSource source, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Updates an existing template native alarm source.</summary>
|
||||||
|
Task UpdateTemplateNativeAlarmSourceAsync(TemplateNativeAlarmSource source, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Deletes a template native alarm source by ID.</summary>
|
||||||
|
Task DeleteTemplateNativeAlarmSourceAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
// TemplateScript
|
// TemplateScript
|
||||||
/// <summary>Retrieves a template script by ID.</summary>
|
/// <summary>Retrieves a template script by ID.</summary>
|
||||||
/// <param name="id">The script ID.</param>
|
/// <param name="id">The script ID.</param>
|
||||||
@@ -214,6 +226,18 @@ public interface ITemplateEngineRepository
|
|||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
Task DeleteInstanceAlarmOverrideAsync(int id, CancellationToken cancellationToken = default);
|
Task DeleteInstanceAlarmOverrideAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
// InstanceNativeAlarmSourceOverride
|
||||||
|
/// <summary>Retrieves native alarm source overrides for an instance.</summary>
|
||||||
|
Task<IReadOnlyList<InstanceNativeAlarmSourceOverride>> GetNativeAlarmSourceOverridesByInstanceIdAsync(int instanceId, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Retrieves a single native alarm source override by instance + source canonical name.</summary>
|
||||||
|
Task<InstanceNativeAlarmSourceOverride?> GetNativeAlarmSourceOverrideAsync(int instanceId, string sourceCanonicalName, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Adds a new instance native alarm source override.</summary>
|
||||||
|
Task AddInstanceNativeAlarmSourceOverrideAsync(InstanceNativeAlarmSourceOverride ovr, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Updates an existing instance native alarm source override.</summary>
|
||||||
|
Task UpdateInstanceNativeAlarmSourceOverrideAsync(InstanceNativeAlarmSourceOverride ovr, CancellationToken cancellationToken = default);
|
||||||
|
/// <summary>Deletes an instance native alarm source override by ID.</summary>
|
||||||
|
Task DeleteInstanceNativeAlarmSourceOverrideAsync(int id, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
// InstanceConnectionBinding
|
// InstanceConnectionBinding
|
||||||
/// <summary>Retrieves connection bindings for an instance.</summary>
|
/// <summary>Retrieves connection bindings for an instance.</summary>
|
||||||
/// <param name="instanceId">The instance ID.</param>
|
/// <param name="instanceId">The instance ID.</param>
|
||||||
|
|||||||
+86
@@ -29,6 +29,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(t => t.Alarms)
|
.Include(t => t.Alarms)
|
||||||
.Include(t => t.Scripts)
|
.Include(t => t.Scripts)
|
||||||
.Include(t => t.Compositions)
|
.Include(t => t.Compositions)
|
||||||
|
.Include(t => t.NativeAlarmSources)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
|
.FirstOrDefaultAsync(t => t.Id == id, cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -59,6 +60,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(t => t.Alarms)
|
.Include(t => t.Alarms)
|
||||||
.Include(t => t.Scripts)
|
.Include(t => t.Scripts)
|
||||||
.Include(t => t.Compositions)
|
.Include(t => t.Compositions)
|
||||||
|
.Include(t => t.NativeAlarmSources)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -71,6 +73,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(t => t.Alarms)
|
.Include(t => t.Alarms)
|
||||||
.Include(t => t.Scripts)
|
.Include(t => t.Scripts)
|
||||||
.Include(t => t.Compositions)
|
.Include(t => t.Compositions)
|
||||||
|
.Include(t => t.NativeAlarmSources)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -188,6 +191,45 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TemplateNativeAlarmSource
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<TemplateNativeAlarmSource?> GetTemplateNativeAlarmSourceByIdAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.TemplateNativeAlarmSources.FindAsync(new object[] { id }, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<IReadOnlyList<TemplateNativeAlarmSource>> GetNativeAlarmSourcesByTemplateIdAsync(int templateId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.TemplateNativeAlarmSources
|
||||||
|
.Where(s => s.TemplateId == templateId)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task AddTemplateNativeAlarmSourceAsync(TemplateNativeAlarmSource source, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _context.TemplateNativeAlarmSources.AddAsync(source, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task UpdateTemplateNativeAlarmSourceAsync(TemplateNativeAlarmSource source, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
_context.TemplateNativeAlarmSources.Update(source);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteTemplateNativeAlarmSourceAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var source = await _context.TemplateNativeAlarmSources.FindAsync(new object[] { id }, cancellationToken);
|
||||||
|
if (source != null)
|
||||||
|
{
|
||||||
|
_context.TemplateNativeAlarmSources.Remove(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TemplateScript
|
// TemplateScript
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -275,6 +317,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(i => i.AttributeOverrides)
|
.Include(i => i.AttributeOverrides)
|
||||||
.Include(i => i.AlarmOverrides)
|
.Include(i => i.AlarmOverrides)
|
||||||
.Include(i => i.ConnectionBindings)
|
.Include(i => i.ConnectionBindings)
|
||||||
|
.Include(i => i.NativeAlarmSourceOverrides)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(i => i.Id == id, cancellationToken);
|
.FirstOrDefaultAsync(i => i.Id == id, cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -286,6 +329,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(i => i.AttributeOverrides)
|
.Include(i => i.AttributeOverrides)
|
||||||
.Include(i => i.AlarmOverrides)
|
.Include(i => i.AlarmOverrides)
|
||||||
.Include(i => i.ConnectionBindings)
|
.Include(i => i.ConnectionBindings)
|
||||||
|
.Include(i => i.NativeAlarmSourceOverrides)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -306,6 +350,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(i => i.AttributeOverrides)
|
.Include(i => i.AttributeOverrides)
|
||||||
.Include(i => i.AlarmOverrides)
|
.Include(i => i.AlarmOverrides)
|
||||||
.Include(i => i.ConnectionBindings)
|
.Include(i => i.ConnectionBindings)
|
||||||
|
.Include(i => i.NativeAlarmSourceOverrides)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -317,6 +362,7 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
.Include(i => i.AttributeOverrides)
|
.Include(i => i.AttributeOverrides)
|
||||||
.Include(i => i.AlarmOverrides)
|
.Include(i => i.AlarmOverrides)
|
||||||
.Include(i => i.ConnectionBindings)
|
.Include(i => i.ConnectionBindings)
|
||||||
|
.Include(i => i.NativeAlarmSourceOverrides)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(i => i.UniqueName == uniqueName, cancellationToken);
|
.FirstOrDefaultAsync(i => i.UniqueName == uniqueName, cancellationToken);
|
||||||
}
|
}
|
||||||
@@ -419,6 +465,46 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InstanceNativeAlarmSourceOverride
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<IReadOnlyList<InstanceNativeAlarmSourceOverride>> GetNativeAlarmSourceOverridesByInstanceIdAsync(int instanceId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.InstanceNativeAlarmSourceOverrides
|
||||||
|
.Where(o => o.InstanceId == instanceId)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task<InstanceNativeAlarmSourceOverride?> GetNativeAlarmSourceOverrideAsync(int instanceId, string sourceCanonicalName, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.InstanceNativeAlarmSourceOverrides
|
||||||
|
.FirstOrDefaultAsync(o => o.InstanceId == instanceId && o.SourceCanonicalName == sourceCanonicalName, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task AddInstanceNativeAlarmSourceOverrideAsync(InstanceNativeAlarmSourceOverride ovr, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _context.InstanceNativeAlarmSourceOverrides.AddAsync(ovr, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task UpdateInstanceNativeAlarmSourceOverrideAsync(InstanceNativeAlarmSourceOverride ovr, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
_context.InstanceNativeAlarmSourceOverrides.Update(ovr);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task DeleteInstanceNativeAlarmSourceOverrideAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var ovr = await _context.InstanceNativeAlarmSourceOverrides.FindAsync(new object[] { id }, cancellationToken);
|
||||||
|
if (ovr != null)
|
||||||
|
{
|
||||||
|
_context.InstanceNativeAlarmSourceOverrides.Remove(ovr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// InstanceConnectionBinding
|
// InstanceConnectionBinding
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
+28
@@ -147,4 +147,32 @@ public class TemplateEngineRepositoryTests : IDisposable
|
|||||||
Assert.NotNull(loaded);
|
Assert.NotNull(loaded);
|
||||||
Assert.Equal(baseTemplate.Id, loaded!.ParentTemplateId);
|
Assert.Equal(baseTemplate.Id, loaded!.ParentTemplateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddAndGetNativeAlarmSourcesByTemplateId_RoundTrips()
|
||||||
|
{
|
||||||
|
var t = new Template("T");
|
||||||
|
_context.Templates.Add(t);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
await _repository.AddTemplateNativeAlarmSourceAsync(
|
||||||
|
new TemplateNativeAlarmSource("S") { TemplateId = t.Id, ConnectionName = "C", SourceReference = "r" });
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var list = await _repository.GetNativeAlarmSourcesByTemplateIdAsync(t.Id);
|
||||||
|
Assert.Single(list);
|
||||||
|
Assert.Equal("S", list[0].Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetTemplateWithChildren_IncludesNativeAlarmSources()
|
||||||
|
{
|
||||||
|
var t = new Template("T");
|
||||||
|
t.NativeAlarmSources.Add(new TemplateNativeAlarmSource("S") { ConnectionName = "C", SourceReference = "r" });
|
||||||
|
_context.Templates.Add(t);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var loaded = await _repository.GetTemplateWithChildrenAsync(t.Id);
|
||||||
|
Assert.Single(loaded!.NativeAlarmSources);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user