d042863a56
- Aggiunto supporto schedulazione con intervalli flessibili (secondi/minuti/ore/giorni/settimane/mesi) - Esteso modello ProfileSchedule con campi IntervalValue e IntervalUnit - Ottimizzato ScheduledJobService per controlli ogni 30s con esecuzione parallela - Implementata interfaccia UI completa con anteprima real-time in italiano - Aggiunta migrazione database AddIntervalSchedulingFields - Implementati metodi calcolo NextExecutionTime per intervalli - Aggiunta gestione tracking anti-duplicati e cleanup automatico - Creata documentazione completa (6 file, 2500+ righe) Modifiche tecniche: - ProfileSchedule.cs: Nuovi campi e metodi CalculateNextInterval/GetScheduleDescription - ScheduledJobService.cs: Ridotto check interval a 30s, aggiunto parallel processing - ProfileScheduleService.cs: Supporto calcolo intervalli in UpdateNextExecutionTimeAsync - Scheduling.razor: Aggiunta sezione UI per configurazione intervalli - Scheduling.razor.cs: Implementato GetIntervalPreview() e gestione stato campi
281 lines
9.2 KiB
C#
281 lines
9.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using CredentialManager.Models;
|
|
|
|
namespace CredentialManager.Data;
|
|
|
|
/// <summary>
|
|
/// DbContext per la gestione delle credenziali
|
|
/// </summary>
|
|
public class CredentialDbContext : DbContext
|
|
{
|
|
public DbSet<CredentialEntity> Credentials { get; set; }
|
|
public DbSet<KeyAssociation> KeyAssociations { get; set; }
|
|
public DbSet<DataCouplerProfile> DataCouplerProfiles { get; set; }
|
|
public DbSet<ProfileSchedule> ProfileSchedules { get; set; }
|
|
public DbSet<ScheduleExecutionHistory> ScheduleExecutionHistories { get; set; }
|
|
|
|
public CredentialDbContext(DbContextOptions<CredentialDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder); // Configurazione della tabella Credentials
|
|
modelBuilder.Entity<CredentialEntity>(entity =>
|
|
{
|
|
entity.ToTable("Credentials");
|
|
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.Type)
|
|
.IsRequired()
|
|
.HasMaxLength(50);
|
|
|
|
entity.Property(e => e.DatabaseType)
|
|
.HasMaxLength(50);
|
|
|
|
entity.Property(e => e.ConnectionString)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.Host)
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DatabaseName)
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.Username)
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.EncryptedApiKey)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.EncryptedAuthToken)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.Headers)
|
|
.HasMaxLength(2000);
|
|
|
|
entity.Property(e => e.AdditionalParameters)
|
|
.HasMaxLength(2000);
|
|
|
|
entity.Property(e => e.CreatedBy)
|
|
.HasMaxLength(100);
|
|
|
|
// Valori di default
|
|
entity.Property(e => e.CommandTimeout)
|
|
.HasDefaultValue(30);
|
|
|
|
entity.Property(e => e.TimeoutSeconds)
|
|
.HasDefaultValue(100);
|
|
|
|
entity.Property(e => e.IgnoreSslErrors)
|
|
.HasDefaultValue(false);
|
|
|
|
entity.Property(e => e.IsActive)
|
|
.HasDefaultValue(true);
|
|
|
|
// Indici
|
|
entity.HasIndex(e => e.Name)
|
|
.IsUnique();
|
|
|
|
entity.HasIndex(e => e.Type);
|
|
|
|
entity.HasIndex(e => e.DatabaseType);
|
|
|
|
entity.HasIndex(e => e.IsActive);
|
|
});
|
|
|
|
// Configurazione della tabella KeyAssociations
|
|
modelBuilder.Entity<KeyAssociation>(entity =>
|
|
{
|
|
entity.ToTable("KeyAssociations");
|
|
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.KeyValue)
|
|
.IsRequired()
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.SourceKeyField)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DestinationKeyField)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DestinationEntity)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DestinationId)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.RestCredentialName)
|
|
.IsRequired()
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.SourcesInfo)
|
|
.HasMaxLength(2000);
|
|
|
|
entity.Property(e => e.AdditionalInfo)
|
|
.HasMaxLength(2000);
|
|
|
|
// Valori di default
|
|
entity.Property(e => e.IsActive)
|
|
.HasDefaultValue(true);
|
|
|
|
// Indici
|
|
entity.HasIndex(e => e.KeyValue)
|
|
.HasDatabaseName("IX_KeyAssociations_KeyValue");
|
|
|
|
entity.HasIndex(e => new { e.KeyValue, e.DestinationEntity, e.RestCredentialName })
|
|
.IsUnique()
|
|
.HasDatabaseName("IX_KeyAssociations_Unique");
|
|
|
|
entity.HasIndex(e => e.DestinationEntity);
|
|
entity.HasIndex(e => e.RestCredentialName);
|
|
entity.HasIndex(e => e.IsActive);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.LastVerifiedAt);
|
|
});
|
|
|
|
// Configurazione della tabella DataCouplerProfiles
|
|
modelBuilder.Entity<DataCouplerProfile>(entity =>
|
|
{
|
|
entity.ToTable("DataCouplerProfiles");
|
|
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.Description)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.SourceType)
|
|
.IsRequired()
|
|
.HasMaxLength(20);
|
|
|
|
entity.Property(e => e.SourceSchema)
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.SourceTable)
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.SourceFilePath)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.DestinationType)
|
|
.IsRequired()
|
|
.HasMaxLength(20);
|
|
|
|
entity.Property(e => e.DestinationSchema)
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DestinationTable)
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.DestinationEndpoint)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.FieldMappingJson)
|
|
.HasMaxLength(4000);
|
|
|
|
entity.Property(e => e.CreatedBy)
|
|
.HasMaxLength(100);
|
|
|
|
// Valori di default
|
|
entity.Property(e => e.CreatedAt)
|
|
.HasDefaultValueSql("CURRENT_TIMESTAMP");
|
|
|
|
entity.Property(e => e.IsActive)
|
|
.HasDefaultValue(true);
|
|
|
|
// Indici
|
|
entity.HasIndex(e => e.Name)
|
|
.IsUnique();
|
|
|
|
entity.HasIndex(e => e.SourceType);
|
|
entity.HasIndex(e => e.DestinationType);
|
|
entity.HasIndex(e => e.IsActive);
|
|
entity.HasIndex(e => e.CreatedAt);
|
|
entity.HasIndex(e => e.LastUsedAt);
|
|
|
|
// Relazioni con le credenziali
|
|
entity.HasOne(e => e.SourceCredential)
|
|
.WithMany()
|
|
.HasForeignKey(e => e.SourceCredentialId)
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
|
|
entity.HasOne(e => e.DestinationCredential)
|
|
.WithMany()
|
|
.HasForeignKey(e => e.DestinationCredentialId)
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
});
|
|
|
|
// Configurazione della tabella ScheduleExecutionHistories
|
|
modelBuilder.Entity<ScheduleExecutionHistory>(entity =>
|
|
{
|
|
entity.ToTable("ScheduleExecutionHistories");
|
|
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.ProfileName)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
entity.Property(e => e.Status)
|
|
.IsRequired()
|
|
.HasMaxLength(20);
|
|
|
|
entity.Property(e => e.Message)
|
|
.HasMaxLength(2000);
|
|
|
|
entity.Property(e => e.ErrorDetails)
|
|
.HasMaxLength(5000);
|
|
|
|
entity.Property(e => e.TriggerType)
|
|
.IsRequired()
|
|
.HasMaxLength(20);
|
|
|
|
entity.Property(e => e.TriggeredBy)
|
|
.HasMaxLength(100);
|
|
|
|
entity.Property(e => e.SourceType)
|
|
.HasMaxLength(50);
|
|
|
|
entity.Property(e => e.DestinationType)
|
|
.HasMaxLength(50);
|
|
|
|
entity.Property(e => e.SourceInfo)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.DestinationInfo)
|
|
.HasMaxLength(500);
|
|
|
|
entity.Property(e => e.AdditionalInfo)
|
|
.HasMaxLength(2000);
|
|
|
|
// Indici
|
|
entity.HasIndex(e => e.ScheduleId);
|
|
entity.HasIndex(e => e.ProfileId);
|
|
entity.HasIndex(e => e.Status);
|
|
entity.HasIndex(e => e.StartTime);
|
|
entity.HasIndex(e => e.TriggerType);
|
|
|
|
// Relazione con ProfileSchedule
|
|
entity.HasOne(e => e.Schedule)
|
|
.WithMany()
|
|
.HasForeignKey(e => e.ScheduleId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
}
|
|
}
|