Initial commit
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
@page "/transfer"
|
||||
@attribute [Authorize]
|
||||
@inject IUserSessionService Session
|
||||
@inject IUserContextAccessor UserContext
|
||||
@inject ISessionManager SessionMgr
|
||||
@inject IFileTransferService TransferSvc
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<h1 class="page-title">File Transfer</h1>
|
||||
|
||||
@if (!Session.HasProfile) { <NoProfilePrompt /> return; }
|
||||
@if (UserContext.Role < UserRole.TechN1) { <WriteGuard /> return; }
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">Source</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Source Site URL</label>
|
||||
<input class="form-input" @bind="_srcSiteUrl" placeholder="@Session.CurrentProfile!.TenantUrl" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Source Library</label>
|
||||
<input class="form-input" @bind="_srcLibrary" placeholder="Shared Documents" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Source Folder (optional)</label>
|
||||
<input class="form-input" @bind="_srcFolder" placeholder="SubFolder/Path" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">Destination</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Destination Site URL</label>
|
||||
<input class="form-input" @bind="_dstSiteUrl" placeholder="@Session.CurrentProfile!.TenantUrl" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Destination Library</label>
|
||||
<input class="form-input" @bind="_dstLibrary" placeholder="Shared Documents" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Destination Folder (optional)</label>
|
||||
<input class="form-input" @bind="_dstFolder" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Transfer Mode</label>
|
||||
<select class="form-select" @bind="_mode" style="width:100px">
|
||||
<option value="Copy">Copy</option>
|
||||
<option value="Move">Move</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Conflict Policy</label>
|
||||
<select class="form-select" @bind="_conflict" style="width:120px">
|
||||
<option value="Skip">Skip</option>
|
||||
<option value="Overwrite">Overwrite</option>
|
||||
<option value="Rename">Rename</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" style="display:flex;align-items:center;padding-top:20px">
|
||||
<label><input type="checkbox" @bind="_includeSourceFolder" /> Include source folder</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-row mt-8">
|
||||
<button class="btn btn-primary" @onclick="RunTransfer" disabled="@_running">
|
||||
@(_running ? "Transferring…" : "Start Transfer")
|
||||
</button>
|
||||
@if (_running) { <button class="btn btn-secondary" @onclick="Cancel">Cancel</button> }
|
||||
</div>
|
||||
<ProgressPanel IsRunning="_running" StatusMessage="_status" Current="_current" Total="_total" />
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_error)) { <div class="alert alert-error">@_error</div> }
|
||||
|
||||
@if (_summary != null)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="alert @(_summary.HasFailures ? "alert-warn" : "alert-success")">
|
||||
Transferred: @_summary.SuccessCount / @_summary.TotalCount files.
|
||||
@if (_summary.HasFailures) { <span>Failures: @_summary.FailedCount</span> }
|
||||
</div>
|
||||
@if (_summary.HasFailures)
|
||||
{
|
||||
<div class="data-table-wrap mt-8">
|
||||
<table class="data-table">
|
||||
<thead><tr><th>File</th><th>Error</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var f in _summary.FailedItems)
|
||||
{
|
||||
<tr><td>@f.Item</td><td style="color:var(--danger)">@f.ErrorMessage</td></tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string _srcSiteUrl = string.Empty, _srcLibrary = string.Empty, _srcFolder = string.Empty;
|
||||
private string _dstSiteUrl = string.Empty, _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<string>? _summary;
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
private async Task RunTransfer()
|
||||
{
|
||||
_error = string.Empty; _summary = null; _running = true;
|
||||
_cts = new CancellationTokenSource();
|
||||
var progress = new Progress<OperationProgress>(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); });
|
||||
try
|
||||
{
|
||||
var srcUrl = string.IsNullOrWhiteSpace(_srcSiteUrl) ? Session.CurrentProfile!.TenantUrl : _srcSiteUrl.Trim();
|
||||
var dstUrl = string.IsNullOrWhiteSpace(_dstSiteUrl) ? Session.CurrentProfile!.TenantUrl : _dstSiteUrl.Trim();
|
||||
var srcCtx = await SessionMgr.GetOrCreateContextAsync(srcUrl, Session.CurrentProfile!, _cts.Token);
|
||||
var dstCtx = await SessionMgr.GetOrCreateContextAsync(dstUrl, Session.CurrentProfile!, _cts.Token);
|
||||
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 TransferSvc.TransferAsync(srcCtx, dstCtx, job, progress, _cts.Token);
|
||||
_status = $"Complete: {_summary.SuccessCount} transferred.";
|
||||
}
|
||||
catch (OperationCanceledException) { _status = "Cancelled."; }
|
||||
catch (Exception ex) { _error = ex.Message; }
|
||||
finally { _running = false; await InvokeAsync(StateHasChanged); }
|
||||
}
|
||||
|
||||
private void Cancel() => _cts?.Cancel();
|
||||
}
|
||||
Reference in New Issue
Block a user