Add a TransferCanceled event

This commit is contained in:
Ben Olden-Cooligan 2023-03-10 13:31:04 -08:00
parent 25b612633c
commit 3807f69584
5 changed files with 35 additions and 1 deletions

View File

@ -41,6 +41,7 @@ namespace NTwain.Internals
ReturnCode DisableSource();
void SafeSyncableRaiseEvent(DataTransferredEventArgs e);
void SafeSyncableRaiseEvent(TransferCanceledEventArgs e);
void SafeSyncableRaiseEvent(TransferErrorEventArgs e);
void SafeSyncableRaiseEvent(TransferReadyEventArgs e);

View File

@ -145,9 +145,11 @@ namespace NTwain.Internals
{
case ReturnCode.Success:
case ReturnCode.XferDone:
case ReturnCode.Cancel:
// ok to keep going
break;
case ReturnCode.Cancel:
session.SafeSyncableRaiseEvent(new TransferCanceledEventArgs());
break;
default:
var status = session.CurrentSource.GetStatus();
session.SafeSyncableRaiseEvent(new TransferErrorEventArgs(rc, status));

View File

@ -0,0 +1,17 @@
using System;
namespace NTwain
{
/// <summary>
/// Indicates a transfer cancellation, e.g. if the user pressed the "Cancel" button.
/// </summary>
public class TransferCanceledEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="TransferCanceledEventArgs"/> class.
/// </summary>
public TransferCanceledEventArgs()
{
}
}
}

View File

@ -482,6 +482,10 @@ namespace NTwain
/// </summary>
public event EventHandler<DataTransferredEventArgs> DataTransferred;
/// <summary>
/// Occurs when a transfer was canceled.
/// </summary>
public event EventHandler<TransferCanceledEventArgs> TransferCanceled;
/// <summary>
/// Occurs when an error has been encountered during transfer.
/// </summary>
public event EventHandler<TransferErrorEventArgs> TransferError;
@ -680,6 +684,12 @@ namespace NTwain
/// <param name="e">The <see cref="DataTransferredEventArgs"/> instance containing the event data.</param>
protected virtual void OnDataTransferred(DataTransferredEventArgs e) { }
/// <summary>
/// Called when a transfer was canceled.
/// </summary>
/// <param name="e">The <see cref="TransferCanceledEventArgs"/> instance containing the event data.</param>
protected virtual void OnTransferCanceled(TransferCanceledEventArgs e) { }
/// <summary>
/// Called when an error has been encountered during transfer.
/// </summary>

View File

@ -96,6 +96,10 @@ namespace NTwain
{
SafeSyncableRaiseOnEvent(OnDataTransferred, DataTransferred, e);
}
void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferCanceledEventArgs e)
{
SafeSyncableRaiseOnEvent(OnTransferCanceled, TransferCanceled, e);
}
void ITwainSessionInternal.SafeSyncableRaiseEvent(TransferErrorEventArgs e)
{
SafeSyncableRaiseOnEvent(OnTransferError, TransferError, e);