Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Data/FimDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public FimDbContext(DbContextOptions options) : base(options)
public DbSet<Alert> Alerts { get; set; } = null!;

public DbSet<AlertCart> AlertCarts { get; set; } = null!;

public DbSet<EquipmentLog> EquipmentLogs { get; set; } = null!;
}
17 changes: 17 additions & 0 deletions Hubs/AssistantHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ public async Task GetStreamInfo()
i.RtmpKey
}).ToList());
}

public async Task WriteLog(string message)
{
if (string.IsNullOrWhiteSpace(message) || message.Length > 500)
{
logger.LogError("Got a bad log message from cart {cart}. Either empty or too long.", CartId);
}

var log = new EquipmentLog
{
EquipmentId = CartId,
LogMessage = message
};

await dbContext.EquipmentLogs.AddAsync(log);
await dbContext.SaveChangesAsync();
}

private async Task<Cart?> GetCart(bool includeStreamInfo = false)
{
Expand Down
27 changes: 27 additions & 0 deletions Models/AssistantLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace fim_queueing_admin.Models;

public class EquipmentLog
{
[Key]
public int Id { get; set; }

[Required]
public Guid EquipmentId { get; set; }

[MaxLength(500)]
public required string LogMessage { get; set; }

public DateTime LogTimeUtc { get; set; } = DateTime.UtcNow;
}

public class AssistantLogEntityTypeConfiguration : IEntityTypeConfiguration<EquipmentLog>
{
public void Configure(EntityTypeBuilder<EquipmentLog> builder)
{
builder.ToTable("equipment_logs");
}
}
2 changes: 2 additions & 0 deletions Models/Cart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Cart : BaseEquipment
public AvCartConfiguration? Configuration { get; set; } = new();

public ICollection<AlertCart>? AlertCarts { get; set; }
public ICollection<EquipmentLog>? EquipmentLogs { get; set; }

public class AvCartConfiguration
{
Expand All @@ -33,5 +34,6 @@ protected override void ConfigureEntity(EntityTypeBuilder<Cart> builder)
d.ToJson();
d.OwnsMany<CartStreamInfo>(c => c.StreamInfo);
});
builder.HasMany<EquipmentLog>(c => c.EquipmentLogs).WithOne().HasForeignKey(l => l.EquipmentId);
}
}
Loading