Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public DataTransferStatus GetTransferStatus()
/// Sets the completion status
/// </summary>
/// <param name="state"></param>
/// <returns>Returns whether or not the status has been changed/set</returns>
public bool TrySetTransferState(DataTransferState state)
/// <returns>Returns whether or not the status has been changed from its original state.</returns>
public bool SetTransferState(DataTransferState state)
{
if (_status.TrySetTransferStateChange(state))
if (_status.SetTransferStateChange(state))
{
if (DataTransferState.Completed == _status.State ||
DataTransferState.Paused == _status.State)
Expand All @@ -104,9 +104,9 @@ public bool TrySetTransferState(DataTransferState state)
return false;
}

public bool TrySetFailedItemsState() => _status.TrySetFailedItem();
public bool SetFailedItemsState() => _status.SetFailedItem();

public bool TrySetSkippedItemsState() => _status.TrySetSkippedItem();
public bool SetSkippedItemsState() => _status.SetSkippedItem();

internal bool CanPause()
=> DataTransferState.InProgress == _status.State;
Expand All @@ -119,7 +119,7 @@ public async Task PauseIfRunningAsync(CancellationToken cancellationToken)
}
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
// Call the inner cancellation token to stop the transfer job
TrySetTransferState(DataTransferState.Pausing);
SetTransferState(DataTransferState.Pausing);
if (TriggerCancellation())
{
// Wait until full pause has completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected internal DataTransferStatus(DataTransferState state, bool hasFailureIt
///
/// This should only be triggered when a failed item has been seen.
/// </summary>
/// <returns>True if <see cref="HasFailedItems"/> was updated. False otherwise.</returns>
internal bool TrySetFailedItem()
/// <returns>True if this was the first time <see cref="HasFailedItems"/> was updated. False otherwise.</returns>
internal bool SetFailedItem()
{
return Interlocked.Exchange(ref _hasFailedItemValue, 1) != 1;
}
Expand All @@ -86,8 +86,8 @@ internal bool TrySetFailedItem()
///
/// This should only be triggered when a skipped item has been seen.
/// </summary>
/// /// <returns>True if <see cref="HasSkippedItems"/> was updated. False otherwise.</returns>
internal bool TrySetSkippedItem()
/// /// <returns>True if this was the first time <see cref="HasSkippedItems"/> was updated. False otherwise.</returns>
internal bool SetSkippedItem()
{
return Interlocked.Exchange(ref _hasSkippedItemValue, 1) != 1;
}
Expand All @@ -98,8 +98,8 @@ internal bool TrySetSkippedItem()
///
/// This should only be triggered when the state updates.
/// </summary>
/// <returns>True if <see cref="State"/> was updated. False otherwise.</returns>
internal bool TrySetTransferStateChange(DataTransferState state)
/// <returns>True if <see cref="State"/> was changed from its original state. False otherwise.</returns>
internal bool SetTransferStateChange(DataTransferState state)
{
return Interlocked.Exchange(ref _stateValue, (int)state) != (int)state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ internal async Task TriggerCancellationAsync()
/// <param name="transferState"></param>
internal async Task OnTransferStateChangedAsync(DataTransferState transferState)
{
if (JobPartStatus.TrySetTransferStateChange(transferState))
if (JobPartStatus.SetTransferStateChange(transferState))
{
// Progress tracking, do before invoking the event below
if (transferState == DataTransferState.InProgress)
Expand Down Expand Up @@ -355,7 +355,7 @@ await TransferSkippedEventHandler.RaiseAsync(

// Update the JobPartStatus. If was already updated (e.g. there was a failed item before)
// then don't raise the PartTransferStatusEventHandler
if (JobPartStatus.TrySetSkippedItem())
if (JobPartStatus.SetSkippedItem())
{
await PartTransferStatusEventHandler.RaiseAsync(
new TransferStatusEventArgs(
Expand Down Expand Up @@ -409,7 +409,7 @@ await TransferFailedEventHandler.RaiseAsync(

// Update the JobPartStatus. If was already updated (e.g. there was a failed item before)
// then don't raise the PartTransferStatusEventHandler
if (JobPartStatus.TrySetFailedItem())
if (JobPartStatus.SetFailedItem())
{
await PartTransferStatusEventHandler.RaiseAsync(
new TransferStatusEventArgs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override async IAsyncEnumerable<JobPartInternal> ProcessJobToJobPartAsync
{
if (!part.JobPartStatus.HasCompletedSuccessfully)
{
part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued);
part.JobPartStatus.SetTransferStateChange(DataTransferState.Queued);
yield return part;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override async IAsyncEnumerable<JobPartInternal> ProcessJobToJobPartAsync
{
if (!part.JobPartStatus.HasCompletedSuccessfully)
{
part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued);
part.JobPartStatus.SetTransferStateChange(DataTransferState.Queued);
yield return part;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private TransferJobInternal(
Argument.AssertNotNull(clientDiagnostics, nameof(clientDiagnostics));

_dataTransfer = dataTransfer ?? throw Errors.ArgumentNull(nameof(dataTransfer));
_dataTransfer.TransferStatus.TrySetTransferStateChange(DataTransferState.Queued);
_dataTransfer.TransferStatus.SetTransferStateChange(DataTransferState.Queued);
_checkpointer = checkPointer;
_arrayPool = arrayPool;
_jobParts = new List<JobPartInternal>();
Expand Down Expand Up @@ -344,15 +344,15 @@ public async Task JobPartEvent(TransferStatusEventArgs args)
}
else if (jobPartStatus.HasFailedItems)
{
if (_dataTransfer._state.TrySetFailedItemsState())
if (_dataTransfer._state.SetFailedItemsState())
{
await SetCheckpointerStatus().ConfigureAwait(false);
await OnJobPartStatusChangedAsync().ConfigureAwait(false);
}
}
else if (jobPartStatus.HasSkippedItems)
{
if (_dataTransfer._state.TrySetSkippedItemsState())
if (_dataTransfer._state.SetSkippedItemsState())
{
await SetCheckpointerStatus().ConfigureAwait(false);
await OnJobPartStatusChangedAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -387,7 +387,7 @@ public async Task JobPartEvent(TransferStatusEventArgs args)

public async Task OnJobStateChangedAsync(DataTransferState state)
{
if (_dataTransfer._state.TrySetTransferState(state))
if (_dataTransfer._state.SetTransferState(state))
{
// If we are in a final state, dispose the JobPartEvent handlers
if (state == DataTransferState.Completed ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override async IAsyncEnumerable<JobPartInternal> ProcessJobToJobPartAsync
{
if (!part.JobPartStatus.HasCompletedSuccessfully)
{
part.JobPartStatus.TrySetTransferStateChange(DataTransferState.Queued);
part.JobPartStatus.SetTransferStateChange(DataTransferState.Queued);
yield return part;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ public async Task TryPauseAsync()
Assert.AreEqual(DataTransferState.Pausing, transfer.TransferStatus.State);

// Assert
if (!transfer._state.TrySetTransferState(DataTransferState.Paused))
{
Assert.Fail("Unable to set the transfer status internally to the DataTransfer.");
}
Assert.IsTrue(transfer._state.SetTransferState(DataTransferState.Paused));

await pauseTask;

Expand Down