Add edit and delete for systems, containers, and paths in settings.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1299,6 +1299,434 @@ public sealed class SonicSetupRepository
|
||||
return Convert.ToInt32(result);
|
||||
}
|
||||
|
||||
public async Task UpdateSonicConnectionAsync(
|
||||
int sonicConnectionId,
|
||||
string connectionName,
|
||||
string managementHost,
|
||||
int managementPort,
|
||||
string domainName,
|
||||
string connectionProtocol,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (sonicConnectionId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(sonicConnectionId));
|
||||
}
|
||||
|
||||
string name = RequireTrimmed(
|
||||
connectionName,
|
||||
150,
|
||||
"ConnectionName");
|
||||
|
||||
string host = RequireTrimmed(
|
||||
managementHost,
|
||||
255,
|
||||
"ManagementHost");
|
||||
|
||||
string domain = RequireTrimmed(
|
||||
domainName,
|
||||
150,
|
||||
"DomainName");
|
||||
|
||||
string protocol = string.IsNullOrWhiteSpace(connectionProtocol)
|
||||
? "tcp"
|
||||
: connectionProtocol.Trim().TrimEnd(':', '/');
|
||||
|
||||
if (managementPort is < 1 or > 65535)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(managementPort),
|
||||
"Der ManagementPort muss zwischen 1 und 65535 liegen.");
|
||||
}
|
||||
|
||||
const string sql = """
|
||||
UPDATE [dbo].[SonicConnection]
|
||||
SET
|
||||
[ConnectionName] = @ConnectionName,
|
||||
[ManagementHost] = @ManagementHost,
|
||||
[ManagementPort] = @ManagementPort,
|
||||
[DomainName] = @DomainName,
|
||||
[ConnectionProtocol] = @ConnectionProtocol,
|
||||
[ModifiedDateTime] = SYSUTCDATETIME(),
|
||||
[ModifiedBy] = SUSER_SNAME()
|
||||
WHERE [SonicConnectionId] = @SonicConnectionId
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await using SqlConnection connection =
|
||||
new(_connectionString);
|
||||
|
||||
await connection.OpenAsync(cancellationToken);
|
||||
|
||||
await using SqlCommand command =
|
||||
new(sql, connection);
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@SonicConnectionId", SqlDbType.Int)
|
||||
{
|
||||
Value = sonicConnectionId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@ConnectionName",
|
||||
SqlDbType.NVarChar,
|
||||
150)
|
||||
{
|
||||
Value = name
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@ManagementHost",
|
||||
SqlDbType.NVarChar,
|
||||
255)
|
||||
{
|
||||
Value = host
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@ManagementPort", SqlDbType.Int)
|
||||
{
|
||||
Value = managementPort
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@DomainName",
|
||||
SqlDbType.NVarChar,
|
||||
150)
|
||||
{
|
||||
Value = domain
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@ConnectionProtocol",
|
||||
SqlDbType.NVarChar,
|
||||
20)
|
||||
{
|
||||
Value = protocol
|
||||
});
|
||||
|
||||
int affected =
|
||||
await command.ExecuteNonQueryAsync(cancellationToken);
|
||||
|
||||
if (affected == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Sonic-System Id {sonicConnectionId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeactivateSonicConnectionAsync(
|
||||
int sonicConnectionId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (sonicConnectionId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(sonicConnectionId));
|
||||
}
|
||||
|
||||
const string sql = """
|
||||
UPDATE [dbo].[SonicConnection]
|
||||
SET
|
||||
[IsActive] = 0,
|
||||
[ModifiedDateTime] = SYSUTCDATETIME(),
|
||||
[ModifiedBy] = SUSER_SNAME()
|
||||
WHERE [SonicConnectionId] = @SonicConnectionId
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await ExecuteSoftDeleteAsync(
|
||||
sql,
|
||||
"@SonicConnectionId",
|
||||
sonicConnectionId,
|
||||
$"Sonic-System Id {sonicConnectionId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public async Task UpdateSonicContainerAsync(
|
||||
int sonicContainerId,
|
||||
int companyId,
|
||||
int sonicConnectionId,
|
||||
string containerName,
|
||||
string? containerDisplayName,
|
||||
int restartTimeoutSeconds,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (sonicContainerId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(sonicContainerId));
|
||||
}
|
||||
|
||||
if (companyId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(companyId));
|
||||
}
|
||||
|
||||
if (sonicConnectionId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(sonicConnectionId));
|
||||
}
|
||||
|
||||
string name = RequireTrimmed(
|
||||
containerName,
|
||||
250,
|
||||
"ContainerName");
|
||||
|
||||
string? display =
|
||||
string.IsNullOrWhiteSpace(containerDisplayName)
|
||||
? null
|
||||
: containerDisplayName.Trim();
|
||||
|
||||
if (display is { Length: > 250 })
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Der Anzeigename darf maximal 250 Zeichen enthalten.",
|
||||
nameof(containerDisplayName));
|
||||
}
|
||||
|
||||
if (restartTimeoutSeconds is < 10 or > 3600)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(restartTimeoutSeconds),
|
||||
"Timeout muss zwischen 10 und 3600 Sekunden liegen.");
|
||||
}
|
||||
|
||||
const string sql = """
|
||||
UPDATE [dbo].[SonicContainer]
|
||||
SET
|
||||
[CompanyId] = @CompanyId,
|
||||
[SonicConnectionId] = @SonicConnectionId,
|
||||
[ContainerName] = @ContainerName,
|
||||
[ContainerDisplayName] = @ContainerDisplayName,
|
||||
[RestartTimeoutSeconds] = @RestartTimeoutSeconds,
|
||||
[ModifiedDateTime] = SYSUTCDATETIME(),
|
||||
[ModifiedBy] = SUSER_SNAME()
|
||||
WHERE [SonicContainerId] = @SonicContainerId
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await using SqlConnection connection =
|
||||
new(_connectionString);
|
||||
|
||||
await connection.OpenAsync(cancellationToken);
|
||||
|
||||
await using SqlCommand command =
|
||||
new(sql, connection);
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@SonicContainerId", SqlDbType.Int)
|
||||
{
|
||||
Value = sonicContainerId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@CompanyId", SqlDbType.Int)
|
||||
{
|
||||
Value = companyId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@SonicConnectionId", SqlDbType.Int)
|
||||
{
|
||||
Value = sonicConnectionId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@ContainerName",
|
||||
SqlDbType.NVarChar,
|
||||
250)
|
||||
{
|
||||
Value = name
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@ContainerDisplayName",
|
||||
SqlDbType.NVarChar,
|
||||
250)
|
||||
{
|
||||
Value = display is null
|
||||
? DBNull.Value
|
||||
: display
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@RestartTimeoutSeconds",
|
||||
SqlDbType.Int)
|
||||
{
|
||||
Value = restartTimeoutSeconds
|
||||
});
|
||||
|
||||
int affected =
|
||||
await command.ExecuteNonQueryAsync(cancellationToken);
|
||||
|
||||
if (affected == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Container Id {sonicContainerId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeactivateSonicContainerAsync(
|
||||
int sonicContainerId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (sonicContainerId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(sonicContainerId));
|
||||
}
|
||||
|
||||
const string sql = """
|
||||
UPDATE [dbo].[SonicContainer]
|
||||
SET
|
||||
[IsActive] = 0,
|
||||
[ModifiedDateTime] = SYSUTCDATETIME(),
|
||||
[ModifiedBy] = SUSER_SNAME()
|
||||
WHERE [SonicContainerId] = @SonicContainerId
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await ExecuteSoftDeleteAsync(
|
||||
sql,
|
||||
"@SonicContainerId",
|
||||
sonicContainerId,
|
||||
$"Container Id {sonicContainerId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public async Task UpdateCertificateTargetAsync(
|
||||
int certificateTargetId,
|
||||
int sonicContainerId,
|
||||
string targetDirectory,
|
||||
string targetFileName,
|
||||
bool backupEnabled,
|
||||
string backupDirectoryName,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (certificateTargetId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(certificateTargetId));
|
||||
}
|
||||
|
||||
if (sonicContainerId <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(sonicContainerId));
|
||||
}
|
||||
|
||||
string directory = RequireTrimmed(
|
||||
targetDirectory,
|
||||
500,
|
||||
"TargetDirectory");
|
||||
|
||||
string fileName = RequireTrimmed(
|
||||
targetFileName,
|
||||
260,
|
||||
"TargetFileName");
|
||||
|
||||
string backupName = string.IsNullOrWhiteSpace(backupDirectoryName)
|
||||
? "Backup"
|
||||
: backupDirectoryName.Trim();
|
||||
|
||||
if (backupName.Length > 100)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Der Backup-Ordnername darf maximal 100 Zeichen enthalten.",
|
||||
nameof(backupDirectoryName));
|
||||
}
|
||||
|
||||
const string sql = """
|
||||
UPDATE [dbo].[CertificateTarget]
|
||||
SET
|
||||
[SonicContainerId] = @SonicContainerId,
|
||||
[TargetDirectory] = @TargetDirectory,
|
||||
[TargetFileName] = @TargetFileName,
|
||||
[BackupEnabled] = @BackupEnabled,
|
||||
[BackupDirectoryName] = @BackupDirectoryName,
|
||||
[ModifiedDateTime] = SYSUTCDATETIME(),
|
||||
[ModifiedBy] = SUSER_SNAME()
|
||||
WHERE [CertificateTargetId] = @CertificateTargetId
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await using SqlConnection connection =
|
||||
new(_connectionString);
|
||||
|
||||
await connection.OpenAsync(cancellationToken);
|
||||
|
||||
await using SqlCommand command =
|
||||
new(sql, connection);
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@CertificateTargetId", SqlDbType.Int)
|
||||
{
|
||||
Value = certificateTargetId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@SonicContainerId", SqlDbType.Int)
|
||||
{
|
||||
Value = sonicContainerId
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@TargetDirectory",
|
||||
SqlDbType.NVarChar,
|
||||
500)
|
||||
{
|
||||
Value = directory
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@TargetFileName",
|
||||
SqlDbType.NVarChar,
|
||||
260)
|
||||
{
|
||||
Value = fileName
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter("@BackupEnabled", SqlDbType.Bit)
|
||||
{
|
||||
Value = backupEnabled
|
||||
});
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@BackupDirectoryName",
|
||||
SqlDbType.NVarChar,
|
||||
100)
|
||||
{
|
||||
Value = backupName
|
||||
});
|
||||
|
||||
int affected =
|
||||
await command.ExecuteNonQueryAsync(cancellationToken);
|
||||
|
||||
if (affected == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Zertifikat-Pfad Id {certificateTargetId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeactivateCertificateTargetAsync(
|
||||
int certificateTargetId,
|
||||
CancellationToken cancellationToken = default)
|
||||
@@ -1319,6 +1747,22 @@ public sealed class SonicSetupRepository
|
||||
AND [IsActive] = 1;
|
||||
""";
|
||||
|
||||
await ExecuteSoftDeleteAsync(
|
||||
sql,
|
||||
"@CertificateTargetId",
|
||||
certificateTargetId,
|
||||
$"Zertifikat-Pfad Id {certificateTargetId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ExecuteSoftDeleteAsync(
|
||||
string sql,
|
||||
string idParameterName,
|
||||
int id,
|
||||
string notFoundMessage,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqlConnection connection =
|
||||
new(_connectionString);
|
||||
|
||||
@@ -1328,11 +1772,9 @@ public sealed class SonicSetupRepository
|
||||
new(sql, connection);
|
||||
|
||||
command.Parameters.Add(
|
||||
new SqlParameter(
|
||||
"@CertificateTargetId",
|
||||
SqlDbType.Int)
|
||||
new SqlParameter(idParameterName, SqlDbType.Int)
|
||||
{
|
||||
Value = certificateTargetId
|
||||
Value = id
|
||||
});
|
||||
|
||||
int affected =
|
||||
@@ -1340,9 +1782,7 @@ public sealed class SonicSetupRepository
|
||||
|
||||
if (affected == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Zertifikat-Pfad Id {certificateTargetId} "
|
||||
+ "wurde nicht gefunden oder ist bereits inaktiv.");
|
||||
throw new InvalidOperationException(notFoundMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user