@page "/transfer" @attribute [Authorize] @inject IUserSessionService Session @inject IUserContextAccessor UserContext @inject ISessionManager SessionMgr @inject IElevationCoordinator Elevation @inject IFileTransferService TransferSvc @inject TranslationSource T @rendermode InteractiveServer

@T["transfer.page.title"]

@if (!Session.HasProfile) { return; } @if (UserContext.Role < UserRole.TechN1) { return; }
@T["transfer.source"]
@T["transfer.destination"]
@if (_running) { }
@if (!string.IsNullOrEmpty(_error)) {
@_error
} @if (_summary != null) {
@string.Format(T["transfer.result.transferred"], _summary.SuccessCount, _summary.TotalCount) @if (_summary.HasFailures) { @string.Format(T["transfer.result.failures"], _summary.FailedCount) }
@if (_summary.HasFailures) {
@foreach (var f in _summary.FailedItems) { }
@T["versions.col.file"]@T["report.col.error"]
@f.Item@f.ErrorMessage
}
} @code { private List _srcSites = new(), _dstSites = new(); private string _srcLibrary = string.Empty, _srcFolder = string.Empty; private string _dstLibrary = string.Empty, _dstFolder = string.Empty; private string _mode = "Copy", _conflict = "Skip"; private bool _includeSourceFolder; private bool _running; private string _status = string.Empty, _error = string.Empty; private int _current, _total; private BulkOperationSummary? _summary; private CancellationTokenSource? _cts; private async Task RunTransfer() { _error = string.Empty; _summary = null; _running = true; _cts = new CancellationTokenSource(); var progress = new Progress(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); }); try { var srcUrl = _srcSites.FirstOrDefault()?.Url; var dstUrl = _dstSites.FirstOrDefault()?.Url; if (string.IsNullOrWhiteSpace(srcUrl)) { _error = T["transfer.err.no_source_site"]; return; } if (string.IsNullOrWhiteSpace(dstUrl)) { _error = T["transfer.err.no_dest_site"]; return; } var job = new TransferJob { SourceSiteUrl = srcUrl, SourceLibrary = _srcLibrary, SourceFolderPath = _srcFolder, DestinationSiteUrl = dstUrl, DestinationLibrary = _dstLibrary, DestinationFolderPath = _dstFolder, Mode = _mode == "Move" ? TransferMode.Move : TransferMode.Copy, ConflictPolicy = _conflict == "Overwrite" ? ConflictPolicy.Overwrite : _conflict == "Rename" ? ConflictPolicy.Rename : ConflictPolicy.Skip, IncludeSourceFolder = _includeSourceFolder }; _summary = await Elevation.RunAsync(async c => { // Closure rebuilds both contexts each attempt so an elevated retry re-issues cleanly. var srcCtx = await SessionMgr.GetOrCreateContextAsync(srcUrl, Session.CurrentProfile!, c); var dstCtx = await SessionMgr.GetOrCreateContextAsync(dstUrl, Session.CurrentProfile!, c); return await TransferSvc.TransferAsync(srcCtx, dstCtx, job, progress, c); }, _cts.Token); _status = string.Format(T["transfer.status.complete"], _summary.SuccessCount); } catch (OperationCanceledException) { _status = T["transfer.status.cancelled"]; } catch (Exception ex) { _error = ex.Message; } finally { _running = false; await InvokeAsync(StateHasChanged); } } private void Cancel() => _cts?.Cancel(); }