| | | 1 | | namespace ZhEaIsNsAaBn.DbSeeder; |
| | | 2 | | |
| | | 3 | | /// What the seed configuration says about one entity type (step 1 of the resolution order). Setting something twice: la |
| | | 4 | | internal sealed class SeedEntitySettings |
| | | 5 | | { |
| | 34 | 6 | | private readonly List<string> _warnings = []; |
| | | 7 | | |
| | | 8 | | |
| | 34 | 9 | | internal SeedEntitySettings( Type clrType ) => ClrType = clrType; |
| | | 10 | | |
| | | 11 | | |
| | | 12 | | public Type ClrType { get; } |
| | | 13 | | |
| | | 14 | | public Dictionary<SeedRole, string> Roles { get; } = []; |
| | | 15 | | |
| | 34 | 16 | | public HashSet<string> Ignored { get; } = new( StringComparer.Ordinal ); |
| | | 17 | | |
| | | 18 | | public IReadOnlyList<string>? MatchBy { get; private set; } |
| | | 19 | | |
| | | 20 | | public SeedDeleteMode? DeleteMode { get; private set; } |
| | | 21 | | |
| | 28 | 22 | | public IReadOnlyList<string> Warnings => _warnings; |
| | | 23 | | |
| | | 24 | | |
| | | 25 | | public void SetRole( SeedRole role, string propertyName ) |
| | | 26 | | { |
| | 15 | 27 | | if ( Roles.TryGetValue( role, out var previous ) ) |
| | | 28 | | { |
| | 3 | 29 | | _warnings.Add( $"{ClrType.Name}: {role} is set twice ({previous}, then {propertyName}); the last one wins." |
| | | 30 | | } |
| | | 31 | | |
| | 15 | 32 | | Roles[ role ] = propertyName; |
| | 15 | 33 | | } |
| | | 34 | | |
| | | 35 | | public void SetMatchBy( IReadOnlyList<string> propertyNames ) |
| | | 36 | | { |
| | 27 | 37 | | if ( MatchBy is not null ) { _warnings.Add( $"{ClrType.Name}: MatchBy is set twice; the last one wins." ); } |
| | | 38 | | |
| | 21 | 39 | | MatchBy = propertyNames; |
| | 21 | 40 | | } |
| | | 41 | | |
| | | 42 | | public void SetDeleteMode( SeedDeleteMode mode ) |
| | | 43 | | { |
| | 28 | 44 | | if ( DeleteMode is not null ) { _warnings.Add( $"{ClrType.Name}: DeleteMode is set twice ({DeleteMode}, then {mo |
| | | 45 | | |
| | 22 | 46 | | DeleteMode = mode; |
| | 22 | 47 | | } |
| | | 48 | | |
| | | 49 | | public void Ignore( string propertyName ) |
| | | 50 | | { |
| | 3 | 51 | | if ( !Ignored.Add( propertyName ) ) { _warnings.Add( $"{ClrType.Name}: {propertyName} is ignored twice." ); } |
| | 3 | 52 | | } |
| | | 53 | | } |