@page "/design/external-systems" @using ScadaLink.Security @using ScadaLink.Commons.Entities.ExternalSystems @using ScadaLink.Commons.Entities.InboundApi @using ScadaLink.Commons.Interfaces.Repositories @attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)] @inject IExternalSystemRepository ExternalSystemRepository @inject IInboundApiRepository InboundApiRepository @inject NavigationManager NavigationManager @inject IDialogService Dialog

Integration Definitions

@if (_loading) { } else if (_errorMessage != null) {
@_errorMessage
} else { @if (_tab == "extsys") {
@RenderExternalSystems()
} else if (_tab == "dbconn") {
@RenderDbConnections()
} else if (_tab == "inbound") {
@RenderInboundApiMethods()
} }
@code { private bool _loading = true; private string? _errorMessage; private string _tab = "extsys"; // External Systems private List _externalSystems = new(); private string _extsysSearch = ""; private IEnumerable FilteredExternalSystems => string.IsNullOrWhiteSpace(_extsysSearch) ? _externalSystems : _externalSystems.Where(es => es.Name?.Contains(_extsysSearch, StringComparison.OrdinalIgnoreCase) ?? false); // Database Connections private List _dbConnections = new(); private string _dbConnSearch = ""; private IEnumerable FilteredDbConnections => string.IsNullOrWhiteSpace(_dbConnSearch) ? _dbConnections : _dbConnections.Where(dc => dc.Name?.Contains(_dbConnSearch, StringComparison.OrdinalIgnoreCase) ?? false); // Inbound API Methods private List _apiMethods = new(); private string _apiMethodSearch = ""; private IEnumerable FilteredApiMethods => string.IsNullOrWhiteSpace(_apiMethodSearch) ? _apiMethods : _apiMethods.Where(m => m.Name?.Contains(_apiMethodSearch, StringComparison.OrdinalIgnoreCase) ?? false); private ToastNotification _toast = default!; protected override async Task OnInitializedAsync() { await LoadAllAsync(); } private async Task LoadAllAsync() { _loading = true; try { _externalSystems = (await ExternalSystemRepository.GetAllExternalSystemsAsync()).ToList(); _dbConnections = (await ExternalSystemRepository.GetAllDatabaseConnectionsAsync()).ToList(); _apiMethods = (await InboundApiRepository.GetAllApiMethodsAsync()).ToList(); } catch (Exception ex) { _errorMessage = ex.Message; } _loading = false; } // ==== External Systems ==== private RenderFragment RenderExternalSystems() => __builder => {
External Systems
@if (_externalSystems.Count == 0) {

No external systems configured.

} else {
@if (!FilteredExternalSystems.Any()) {

No external systems match the filter.

}
@foreach (var es in FilteredExternalSystems) {
@es.Name

@es.EndpointUrl

@es.AuthType Max @es.MaxRetries retries Delay @es.RetryDelay.TotalSeconds s
}
} }; private async Task DeleteExtSys(ExternalSystemDefinition es) { if (!await Dialog.ConfirmAsync("Delete External System", $"Delete '{es.Name}'?", danger: true)) return; try { await ExternalSystemRepository.DeleteExternalSystemAsync(es.Id); await ExternalSystemRepository.SaveChangesAsync(); _toast.ShowSuccess("Deleted."); await LoadAllAsync(); } catch (Exception ex) { _toast.ShowError(ex.Message); } } // ==== Database Connections ==== private RenderFragment RenderDbConnections() => __builder => {
Database Connections
@if (_dbConnections.Count == 0) {

No database connections configured.

} else {
@if (!FilteredDbConnections.Any()) {

No database connections match the filter.

}
@foreach (var dc in FilteredDbConnections) {
@dc.Name

@dc.ConnectionString

Max @dc.MaxRetries retries Delay @dc.RetryDelay.TotalSeconds s
}
} }; private async Task DeleteDbConn(DatabaseConnectionDefinition dc) { if (!await Dialog.ConfirmAsync("Delete DB Connection", $"Delete '{dc.Name}'?", danger: true)) return; try { await ExternalSystemRepository.DeleteDatabaseConnectionAsync(dc.Id); await ExternalSystemRepository.SaveChangesAsync(); _toast.ShowSuccess("Deleted."); await LoadAllAsync(); } catch (Exception ex) { _toast.ShowError(ex.Message); } } // ==== Inbound API Methods ==== private RenderFragment RenderInboundApiMethods() => __builder => {
Inbound API Methods
@if (_apiMethods.Count == 0) {

No API methods configured.

} else {
@if (!FilteredApiMethods.Any()) {

No API methods match the filter.

}
@foreach (var m in FilteredApiMethods) { var preview = m.Script.Length > 80 ? m.Script[..80] + "…" : m.Script;
@m.Name
POST /api/@m.Name
@preview
Timeout @m.TimeoutSeconds s
}
} }; private async Task DeleteApiMethod(ApiMethod m) { if (!await Dialog.ConfirmAsync("Delete", $"Delete API method '{m.Name}'?", danger: true)) return; try { await InboundApiRepository.DeleteApiMethodAsync(m.Id); await InboundApiRepository.SaveChangesAsync(); _toast.ShowSuccess("Deleted."); await LoadAllAsync(); } catch (Exception ex) { _toast.ShowError(ex.Message); } } }