private async Task <uint> SynchronizeOriginCore(ObjectInfos originInfos, ObjectInfos destinationInfos, CancellationToken cancellationToken) { var count = 0u; foreach (var objectInfo in originInfos) { var name = objectInfo.Name; if (destinationInfos.LastName is string lastName && string.CompareOrdinal(name, lastName) > 0) { break; } cancellationToken.ThrowIfCancellationRequested(); if (!objectInfo.IsHidden && !destinationInfos.HasObject(objectInfo)) { await _taskManager.Enqueue( this, token => Upload(name, token), cancellationToken); } originInfos.Skip(); ++count; } return(count); }
private async Task SynchronizeCore(CancellationToken cancellationToken) { string?lastName = null; var originInfos = new ObjectInfos(_originReader, lastName); var destinationInfos = new ObjectInfos(_destinationWriter, lastName); while (true) { _logger?.LogDebug(Events.Populating, "Populating infos."); await Task.WhenAll( originInfos.Populate(cancellationToken), destinationInfos.Populate(cancellationToken)); _logger?.LogDebug(Events.Populated, "Populated infos."); var counts = await Task.WhenAll( SynchronizeOrigin(originInfos, destinationInfos, cancellationToken), SynchronizeDestination(originInfos, destinationInfos, cancellationToken)); if (!destinationInfos.IsLive && !originInfos.IsLive) { break; } if (counts[0] == 0 && counts[1] == 0) { throw new InvalidProgramException( FormattableString.Invariant($"No progress for iteration.\nOrigin: {originInfos}\nDestination: {destinationInfos}\n")); } } }
private async Task <uint> SynchronizeOrigin(ObjectInfos originInfos, ObjectInfos destinationInfos, CancellationToken cancellationToken) { _logger?.LogDebug(Events.SynchronizingOrigin, "Synchronizing origin, last name: \"{LastName}\".", originInfos.LastName); uint count; try { count = await SynchronizeOriginCore(originInfos, destinationInfos, cancellationToken); } catch (Exception exception) { _logger?.LogWarning(Events.SynchronizeOriginFailed, exception, "Failed to synchronize origin."); throw; } _logger?.LogInformation(Events.SynchronizedOrigin, "Synchronized origin, count: {Count}, last name: \"{LastName}\".", count, originInfos.LastName); return(count); }