File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,6 @@ public FimDbContext(DbContextOptions options) : base(options)
1717 public DbSet < Alert > Alerts { get ; set ; } = null ! ;
1818
1919 public DbSet < AlertCart > AlertCarts { get ; set ; } = null ! ;
20+
21+ public DbSet < EquipmentLog > EquipmentLogs { get ; set ; } = null ! ;
2022}
Original file line number Diff line number Diff line change @@ -78,6 +78,23 @@ public async Task GetStreamInfo()
7878 i . RtmpKey
7979 } ) . ToList ( ) ) ;
8080 }
81+
82+ public async Task WriteLog ( string message )
83+ {
84+ if ( string . IsNullOrWhiteSpace ( message ) || message . Length > 500 )
85+ {
86+ logger . LogError ( "Got a bad log message from cart {cart}. Either empty or too long." , CartId ) ;
87+ }
88+
89+ var log = new EquipmentLog
90+ {
91+ EquipmentId = CartId ,
92+ LogMessage = message
93+ } ;
94+
95+ await dbContext . EquipmentLogs . AddAsync ( log ) ;
96+ await dbContext . SaveChangesAsync ( ) ;
97+ }
8198
8299 private async Task < Cart ? > GetCart ( bool includeStreamInfo = false )
83100 {
Original file line number Diff line number Diff line change 1+ using System . ComponentModel . DataAnnotations ;
2+ using Microsoft . EntityFrameworkCore ;
3+ using Microsoft . EntityFrameworkCore . Metadata . Builders ;
4+
5+ namespace fim_queueing_admin . Models ;
6+
7+ public class EquipmentLog
8+ {
9+ [ Key ]
10+ public int Id { get ; set ; }
11+
12+ [ Required ]
13+ public Guid EquipmentId { get ; set ; }
14+
15+ [ MaxLength ( 500 ) ]
16+ public required string LogMessage { get ; set ; }
17+
18+ public DateTime LogTimeUtc { get ; set ; } = DateTime . UtcNow ;
19+ }
20+
21+ public class AssistantLogEntityTypeConfiguration : IEntityTypeConfiguration < EquipmentLog >
22+ {
23+ public void Configure ( EntityTypeBuilder < EquipmentLog > builder )
24+ {
25+ builder . ToTable ( "equipment_logs" ) ;
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ public class Cart : BaseEquipment
1010 public AvCartConfiguration ? Configuration { get ; set ; } = new ( ) ;
1111
1212 public ICollection < AlertCart > ? AlertCarts { get ; set ; }
13+ public ICollection < EquipmentLog > ? EquipmentLogs { get ; set ; }
1314
1415 public class AvCartConfiguration
1516 {
@@ -33,5 +34,6 @@ protected override void ConfigureEntity(EntityTypeBuilder<Cart> builder)
3334 d . ToJson ( ) ;
3435 d . OwnsMany < CartStreamInfo > ( c => c . StreamInfo ) ;
3536 } ) ;
37+ builder . HasMany < EquipmentLog > ( c => c . EquipmentLogs ) . WithOne ( ) . HasForeignKey ( l => l . EquipmentId ) ;
3638 }
3739}
You can’t perform that action at this time.
0 commit comments