feat: OPC UA address-space search plumbing — actor + comm + BrowseService (T15)
This commit is contained in:
@@ -87,4 +87,59 @@ public sealed class BrowseService : IBrowseService
|
||||
new BrowseFailure(BrowseFailureKind.ServerError, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<SearchAddressSpaceResult> SearchAsync(
|
||||
string siteId,
|
||||
string connectionName,
|
||||
string query,
|
||||
int maxDepth,
|
||||
int maxResults,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Same CentralUI-side role guard as BrowseChildrenAsync — sites don't
|
||||
// enforce envelope-level roles, so the Designer check must happen here
|
||||
// before any cross-cluster traffic.
|
||||
var state = await _auth.GetAuthenticationStateAsync();
|
||||
if (!state.User.HasClaim(JwtTokenService.RoleClaimType, Roles.Designer))
|
||||
{
|
||||
return new SearchAddressSpaceResult(
|
||||
Array.Empty<AddressSpaceMatch>(),
|
||||
CapReached: false,
|
||||
new BrowseFailure(BrowseFailureKind.ServerError, "Not authorized."));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await _communication.SearchAddressSpaceAsync(
|
||||
siteId,
|
||||
new SearchAddressSpaceCommand(connectionName, query, maxDepth, maxResults),
|
||||
cancellationToken);
|
||||
}
|
||||
catch (TimeoutException ex)
|
||||
{
|
||||
// Akka Ask timed out — the site (or its OPC UA session) didn't answer
|
||||
// within CommunicationOptions.QueryTimeout. Surface as a typed Timeout
|
||||
// failure so the picker can render an inline banner.
|
||||
return new SearchAddressSpaceResult(
|
||||
Array.Empty<AddressSpaceMatch>(),
|
||||
CapReached: false,
|
||||
new BrowseFailure(BrowseFailureKind.Timeout, ex.Message));
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Caller-initiated cancel — propagate so Blazor can drop the response
|
||||
// cleanly. Distinct from Timeout (which the picker renders inline).
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Any other transport / serialization failure: keep the picker alive
|
||||
// and let the user fall back to manual browse / node-id paste.
|
||||
return new SearchAddressSpaceResult(
|
||||
Array.Empty<AddressSpaceMatch>(),
|
||||
CapReached: false,
|
||||
new BrowseFailure(BrowseFailureKind.ServerError, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,31 @@ public interface IBrowseService
|
||||
string? parentNodeId,
|
||||
string? continuationToken = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a bounded recursive search of the address space on the live server
|
||||
/// backing <paramref name="connectionName"/> at <paramref name="siteId"/>,
|
||||
/// returning the nodes whose DisplayName or root-relative path contains
|
||||
/// <paramref name="query"/>. The address-space analogue of
|
||||
/// <see cref="BrowseChildrenAsync"/>: it forwards a
|
||||
/// <see cref="SearchAddressSpaceCommand"/> to the owning site via
|
||||
/// <see cref="ZB.MOM.WW.ScadaBridge.Communication.CommunicationService"/> and
|
||||
/// enforces the same <c>Design</c>-role trust boundary at central. The depth
|
||||
/// and result caps are supplied by the caller (the picker's search box) and
|
||||
/// chosen to stay well under Akka's remote frame size.
|
||||
/// </summary>
|
||||
/// <param name="siteId">The target site identifier.</param>
|
||||
/// <param name="connectionName">Name of the site-local data connection to search against.</param>
|
||||
/// <param name="query">Case-insensitive substring matched against each node's DisplayName and root-relative path.</param>
|
||||
/// <param name="maxDepth">Maximum number of levels below the root to descend.</param>
|
||||
/// <param name="maxResults">Maximum number of matches to return; when reached the walk stops early and the result's <c>CapReached</c> flag is set.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task that resolves to a <see cref="SearchAddressSpaceResult"/> containing the matches or a <see cref="BrowseFailure"/> on error.</returns>
|
||||
Task<SearchAddressSpaceResult> SearchAsync(
|
||||
string siteId,
|
||||
string connectionName,
|
||||
string query,
|
||||
int maxDepth,
|
||||
int maxResults,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user