public MirrorAsync ( string id, string version, |
||
id | string | |
version | string | |
token | ||
return | Task |
public async Task<bool> MirrorAsync(string id, string version, CancellationToken token)
{
var publish = true;
if (!_overwriteExisting)
{
publish = !(await _destinationPackageDownloader.IsAvailableAsync(id, version, token));
}
if (publish)
{
publish = await _sourcePackageDownloader.ProcessAsync(
id,
version,
async streamResult =>
{
if (!streamResult.IsAvailable)
{
throw new InvalidOperationException($"The VSIX package '{id}' (version '{version}') is not available on the source.");
}
await _packagePusher.PushAsync(streamResult.Stream, token);
return true;
},
token);
}
return publish;
}
}
private async Task ProcessPackagesAsync(string taskName, ConcurrentBag <VsixPackage> packages, ManualResetEventSlim isFullyEnumerated, CancellationToken token) { while (true) { VsixPackage package; if (packages.TryTake(out package)) { var stopwatch = Stopwatch.StartNew(); var pushed = await _mirror.MirrorAsync(package.Id, package.Version, token); if (pushed) { _logger.LogInformationSummary($"[ {taskName} ] VSIX package {package} took {stopwatch.Elapsed.TotalSeconds:0.00} seconds to publish."); } else { _logger.LogInformationSummary($"[ {taskName} ] VSIX package {package} took {stopwatch.Elapsed.TotalSeconds:0.00} seconds to detect no push was necessary."); } _logger.LogInformationSummary($"[ {taskName} ] {packages.Count} VSIX package(s) remain in the queue."); } else { if (isFullyEnumerated.IsSet) { // The concurrent bag is empty and we are done enumerating, so the task // can safely terminate. break; } else { // The enumeration is not done yet, so wait a little bit for more work to // become available. await Task.Delay(TimeSpan.FromMilliseconds(50)); } } } }