diff --git a/NTwain/Data/TypesExtended.cs b/NTwain/Data/TypesExtended.cs
index 93aabe1..bba6977 100644
--- a/NTwain/Data/TypesExtended.cs
+++ b/NTwain/Data/TypesExtended.cs
@@ -2189,12 +2189,12 @@ namespace NTwain.Data
///
/// Condition Code describing the status.
///
- public ConditionCode ConditionCode { get { return (ConditionCode)_conditionCode; } set { _conditionCode = (ushort)value; } }
+ public ConditionCode ConditionCode { get { return (ConditionCode)_conditionCode; } internal set { _conditionCode = (ushort)value; } }
///
/// Valid for TWAIN 2.1 and later. This field contains additional
/// scanner-specific data. If there is no data, then this value must be zero.
///
- public ushort Data { get { return _data; } set { _data = Data; } }
+ public ushort Data { get { return _data; } internal set { _data = Data; } }
}
///
diff --git a/NTwain/NTwain.csproj b/NTwain/NTwain.csproj
index 350df8c..62826c4 100644
--- a/NTwain/NTwain.csproj
+++ b/NTwain/NTwain.csproj
@@ -72,6 +72,7 @@
+
diff --git a/NTwain/TwainSession.cs b/NTwain/TwainSession.cs
index 7fb67e0..cf94d9e 100644
--- a/NTwain/TwainSession.cs
+++ b/NTwain/TwainSession.cs
@@ -455,6 +455,11 @@ namespace NTwain
///
public event EventHandler DataTransferred;
+ ///
+ /// Occurs when an error has been encountered during transfer.
+ ///
+ public event EventHandler TransferError;
+
///
/// Called when changed
/// and raises the event.
@@ -557,6 +562,22 @@ namespace NTwain
}
}
+ ///
+ /// Raises the event.
+ ///
+ /// The instance containing the event data.
+ protected virtual void OnTransferError(TransferErrorEventArgs e)
+ {
+ var hand = TransferError;
+ if (hand != null)
+ {
+ try
+ {
+ hand(this, e);
+ }
+ catch { }
+ }
+ }
#endregion
#region TWAIN logic during xfer work
@@ -780,6 +801,14 @@ namespace NTwain
}
OnDataTransferred(new DataTransferredEventArgs { NativeData = lockedPtr });
}
+ else
+ {
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
+ }
+ }
+ catch (Exception ex)
+ {
+ OnTransferError(new TransferErrorEventArgs { Exception = ex });
}
finally
{
@@ -812,6 +841,10 @@ namespace NTwain
{
OnDataTransferred(new DataTransferredEventArgs { FileDataPath = filePath });
}
+ else
+ {
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
+ }
}
#endregion
@@ -839,6 +872,14 @@ namespace NTwain
}
OnDataTransferred(new DataTransferredEventArgs { NativeData = lockedPtr, ImageInfo = imgInfo });
}
+ else
+ {
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
+ }
+ }
+ catch (Exception ex)
+ {
+ OnTransferError(new TransferErrorEventArgs { Exception = ex });
}
finally
{
@@ -876,6 +917,10 @@ namespace NTwain
}
OnDataTransferred(new DataTransferredEventArgs { FileDataPath = filePath, ImageInfo = imgInfo });
}
+ else
+ {
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
+ }
}
private void DoImageMemoryXfer()
@@ -953,11 +998,14 @@ namespace NTwain
}
else
{
- // todo: provide better mechanism for failed xfer, like event handler
- throw new TwainException("Failed to transfer data.");
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
}
}
}
+ catch (Exception ex)
+ {
+ OnTransferError(new TransferErrorEventArgs { Exception = ex });
+ }
finally
{
State = 6;
@@ -1074,6 +1122,14 @@ namespace NTwain
}
File.Move(tempFile, finalFile);
}
+ else
+ {
+ OnTransferError(new TransferErrorEventArgs { ReturnCode = xrc, SourceStatus = this.GetSourceStatus() });
+ }
+ }
+ catch (Exception ex)
+ {
+ OnTransferError(new TransferErrorEventArgs { Exception = ex });
}
finally
{