private async Task ProcessSourceAsync(ICounterSmugglerSource source, CounterSmugglerOperationState state, CancellationToken cancellationToken) { while (true) { var type = await source .GetNextSmuggleTypeAsync(cancellationToken) .ConfigureAwait(false); switch (type) { case CounterSmuggleType.None: return; case CounterSmuggleType.Delta: await new DeltaSmuggler(_options, _notifications, source, _destination) .SmuggleAsync(state, cancellationToken) .ConfigureAwait(false); continue; case CounterSmuggleType.Snapshots: await new SnapshotSmuggler(_options, _notifications, source, _destination) .SmuggleAsync(state, cancellationToken) .ConfigureAwait(false); continue; default: throw new NotSupportedException(type.ToString()); } } }
private static async Task <CounterSmugglerOperationState> GetOperationStateAsync(CounterSmugglerOptions options, ICounterSmugglerSource source, ICounterSmugglerDestination destination, CancellationToken cancellationToken) { CounterSmugglerOperationState state = null; if (destination.SupportsOperationState) { state = await destination .LoadOperationStateAsync(options, cancellationToken) .ConfigureAwait(false); } if (state == null) { state = new CounterSmugglerOperationState { LastEtag = options.StartEtag }; } Debug.Assert(state.LastEtag != null); return(state); }
public override async Task SmuggleAsync(CounterSmugglerOperationState state, CancellationToken cancellationToken) { using (var actions = Destination.DeltaActions()) { if (Destination.ImportDeltas == false) { await Source.SkipDeltasAsync(cancellationToken).ConfigureAwait(false); return; } var count = 0; var retries = Source.SupportsRetries ? DatabaseSmuggler.NumberOfRetries : 1; var pageSize = Source.SupportsPaging ? Options.BatchSize : int.MaxValue; do { List <CounterState> deltas; try { deltas = await Source.ReadDeltasAsync(count, pageSize, cancellationToken).ConfigureAwait(false); } catch (Exception e) { if (retries-- == 0 && Options.IgnoreErrorsAndContinue) { Notifications.ShowProgress("Failed getting deltas too much times, stopping the deltas export entirely. Message: {0}", e.Message); return; } if (Options.IgnoreErrorsAndContinue == false) { throw new SmugglerException(e.Message, e); } Notifications.ShowProgress("Failed fetching deltas. {0} retries remaining. Message: {1}", retries, e.Message); continue; } if (deltas.Count == 0) { Notifications.ShowProgress("Done with reading deltas, total: {0}", count); break; } count += deltas.Count; Notifications.ShowProgress("Reading batch of {0,3} deltas, read so far: {1,10:#,#;;0}", deltas.Count, count); foreach (var delta in deltas) { try { await actions.WriteDeltaAsync(delta, cancellationToken).ConfigureAwait(false); } catch (Exception e) { if (Options.IgnoreErrorsAndContinue == false) { throw new SmugglerException(e.Message, e); } Notifications.ShowProgress("Failed to export delta {0}. Message: {1}", delta, e.Message); } } } while (Source.SupportsPaging || Source.SupportsRetries); } }
public Task AfterExecuteAsync(CounterSmugglerOperationState state) { return(new CompletedTask()); }
public abstract Task SmuggleAsync(CounterSmugglerOperationState state, CancellationToken cancellationToken);