mirror of
https://github.com/soukoku/ntwain.git
synced 2025-06-28 15:28:06 +08:00
Transfer logic tweaks for #42
This commit is contained in:
parent
abd3c9c65c
commit
1700e183c7
@ -297,6 +297,14 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal DGAudio DGAudio
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _session.DGAudio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//#region INotifyPropertyChanged Members
|
//#region INotifyPropertyChanged Members
|
||||||
|
@ -23,25 +23,21 @@ namespace NTwain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source.</param>
|
/// <param name="source">The source.</param>
|
||||||
/// <param name="nativeData">The native data.</param>
|
/// <param name="nativeData">The native data.</param>
|
||||||
/// <param name="imageInfo">The image information.</param>
|
public DataTransferredEventArgs(DataSource source, IntPtr nativeData)
|
||||||
public DataTransferredEventArgs(DataSource source, IntPtr nativeData, TWImageInfo imageInfo)
|
|
||||||
{
|
{
|
||||||
DataSource = source;
|
DataSource = source;
|
||||||
NativeData = nativeData;
|
NativeData = nativeData;
|
||||||
ImageInfo = imageInfo;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DataTransferredEventArgs"/> class.
|
/// Initializes a new instance of the <see cref="DataTransferredEventArgs"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source.</param>
|
/// <param name="source">The source.</param>
|
||||||
/// <param name="fileDataPath">The file data path.</param>
|
/// <param name="fileDataPath">The file data path.</param>
|
||||||
/// <param name="imageInfo">The image information.</param>
|
|
||||||
/// <param name="imageFileFormat">The image file format.</param>
|
/// <param name="imageFileFormat">The image file format.</param>
|
||||||
public DataTransferredEventArgs(DataSource source, string fileDataPath, TWImageInfo imageInfo, FileFormat imageFileFormat)
|
public DataTransferredEventArgs(DataSource source, string fileDataPath, FileFormat imageFileFormat)
|
||||||
{
|
{
|
||||||
DataSource = source;
|
DataSource = source;
|
||||||
FileDataPath = fileDataPath;
|
FileDataPath = fileDataPath;
|
||||||
ImageInfo = imageInfo;
|
|
||||||
ImageFileFormat = imageFileFormat;
|
ImageFileFormat = imageFileFormat;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -49,12 +45,10 @@ namespace NTwain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source.</param>
|
/// <param name="source">The source.</param>
|
||||||
/// <param name="memoryData">The memory data.</param>
|
/// <param name="memoryData">The memory data.</param>
|
||||||
/// <param name="imageInfo">The image information.</param>
|
public DataTransferredEventArgs(DataSource source, byte[] memoryData)
|
||||||
public DataTransferredEventArgs(DataSource source, byte[] memoryData, TWImageInfo imageInfo)
|
|
||||||
{
|
{
|
||||||
DataSource = source;
|
DataSource = source;
|
||||||
MemoryData = memoryData;
|
MemoryData = memoryData;
|
||||||
ImageInfo = imageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -94,13 +88,27 @@ namespace NTwain
|
|||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public byte[] MemoryData { get; private set; }
|
public byte[] MemoryData { get; private set; }
|
||||||
|
|
||||||
|
TWImageInfo _imgInfo;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the final image information if applicable.
|
/// Gets the final image information if applicable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The final image information.
|
/// The final image information.
|
||||||
/// </value>
|
/// </value>
|
||||||
public TWImageInfo ImageInfo { get; private set; }
|
public TWImageInfo ImageInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_imgInfo == null)
|
||||||
|
{
|
||||||
|
if (DataSource.DGImage.ImageInfo.Get(out _imgInfo) != ReturnCode.Success)
|
||||||
|
{
|
||||||
|
_imgInfo = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _imgInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the data source.
|
/// Gets the data source.
|
||||||
|
@ -19,37 +19,37 @@ namespace NTwain.Internals
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DoTransferRoutine(ITwainSessionInternal session)
|
public static void DoTransferRoutine(ITwainSessionInternal session)
|
||||||
{
|
{
|
||||||
|
#region get xfer types
|
||||||
|
|
||||||
|
bool xferImage = true; // default to always xfer image
|
||||||
|
bool xferAudio = false;
|
||||||
|
DataGroups xferGroup = DataGroups.None;
|
||||||
|
XferMech imgXferMech = XferMech.Native;
|
||||||
|
XferMech audXferMech = XferMech.Native;
|
||||||
|
if (session.DGControl.XferGroup.Get(ref xferGroup) == ReturnCode.Success)
|
||||||
|
{
|
||||||
|
xferAudio = (xferGroup & DataGroups.Audio) == DataGroups.Audio;
|
||||||
|
xferImage = xferGroup == DataGroups.None || (xferGroup & DataGroups.Image) == DataGroups.Image;
|
||||||
|
}
|
||||||
|
// some DS end up getting none but we will assume it's image
|
||||||
|
if (xferImage)
|
||||||
|
{
|
||||||
|
imgXferMech = session.CurrentSource.Capabilities.ICapXferMech.GetCurrent();
|
||||||
|
}
|
||||||
|
if (xferAudio)
|
||||||
|
{
|
||||||
|
var mech = session.CurrentSource.Capabilities.ACapXferMech.GetCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
var pending = new TWPendingXfers();
|
var pending = new TWPendingXfers();
|
||||||
//var rc = ReturnCode.Success;
|
|
||||||
var rc = session.DGControl.PendingXfers.Get(pending);
|
var rc = session.DGControl.PendingXfers.Get(pending);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
#region build and raise xfer ready
|
#region raise xfer ready
|
||||||
|
|
||||||
bool xferImage = true; // default to always xfer image
|
var preXferArgs = new TransferReadyEventArgs(session.CurrentSource, pending.Count, pending.EndOfJob == 0); ;
|
||||||
bool xferAudio = false;
|
|
||||||
DataGroups xferGroup = DataGroups.None;
|
|
||||||
if (session.DGControl.XferGroup.Get(ref xferGroup) == ReturnCode.Success)
|
|
||||||
{
|
|
||||||
xferAudio = (xferGroup & DataGroups.Audio) == DataGroups.Audio;
|
|
||||||
xferImage = xferGroup == DataGroups.None || (xferGroup & DataGroups.Image) == DataGroups.Image;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TWAudioInfo audInfo = null;
|
|
||||||
if (xferAudio && session.DGAudio.AudioInfo.Get(out audInfo) != ReturnCode.Success)
|
|
||||||
{
|
|
||||||
audInfo = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
TWImageInfo imgInfo = null;
|
|
||||||
if (xferImage && session.DGImage.ImageInfo.Get(out imgInfo) != ReturnCode.Success)
|
|
||||||
{
|
|
||||||
imgInfo = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ask consumer for xfer details
|
|
||||||
var preXferArgs = new TransferReadyEventArgs(pending.Count, pending.EndOfJob == 0, imgInfo, audInfo); ;
|
|
||||||
session.SafeSyncableRaiseEvent(preXferArgs);
|
session.SafeSyncableRaiseEvent(preXferArgs);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -64,13 +64,9 @@ namespace NTwain.Internals
|
|||||||
{
|
{
|
||||||
if (!preXferArgs.CancelCurrent)
|
if (!preXferArgs.CancelCurrent)
|
||||||
{
|
{
|
||||||
|
|
||||||
// some DS end up getting none but we will assume it's image
|
|
||||||
if (xferImage)
|
if (xferImage)
|
||||||
{
|
{
|
||||||
var mech = session.CurrentSource.Capabilities.ICapXferMech.GetCurrent();
|
switch (imgXferMech)
|
||||||
|
|
||||||
switch (mech)
|
|
||||||
{
|
{
|
||||||
case XferMech.Memory:
|
case XferMech.Memory:
|
||||||
DoImageMemoryXfer(session);
|
DoImageMemoryXfer(session);
|
||||||
@ -85,13 +81,11 @@ namespace NTwain.Internals
|
|||||||
default: // always assume native
|
default: // always assume native
|
||||||
DoImageNativeXfer(session);
|
DoImageNativeXfer(session);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xferAudio)
|
if (xferAudio)
|
||||||
{
|
{
|
||||||
var mech = session.CurrentSource.Capabilities.ACapXferMech.GetCurrent();
|
switch (audXferMech)
|
||||||
switch (mech)
|
|
||||||
{
|
{
|
||||||
case XferMech.File:
|
case XferMech.File:
|
||||||
DoAudioFileXfer(session);
|
DoAudioFileXfer(session);
|
||||||
@ -135,7 +129,7 @@ namespace NTwain.Internals
|
|||||||
lockedPtr = PlatformInfo.Current.MemoryManager.Lock(dataPtr);
|
lockedPtr = PlatformInfo.Current.MemoryManager.Lock(dataPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, lockedPtr, null));
|
session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, lockedPtr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -176,7 +170,7 @@ namespace NTwain.Internals
|
|||||||
var xrc = session.DGAudio.AudioFileXfer.Get();
|
var xrc = session.DGAudio.AudioFileXfer.Get();
|
||||||
if (xrc == ReturnCode.XferDone)
|
if (xrc == ReturnCode.XferDone)
|
||||||
{
|
{
|
||||||
session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, filePath, null, (FileFormat)0));
|
session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, filePath, (FileFormat)0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -421,23 +415,18 @@ namespace NTwain.Internals
|
|||||||
static void DoImageXferredEventRoutine(ITwainSessionInternal session, IntPtr dataPtr, byte[] dataArray, string filePath, FileFormat format)
|
static void DoImageXferredEventRoutine(ITwainSessionInternal session, IntPtr dataPtr, byte[] dataArray, string filePath, FileFormat format)
|
||||||
{
|
{
|
||||||
DataTransferredEventArgs args = null;
|
DataTransferredEventArgs args = null;
|
||||||
TWImageInfo imgInfo;
|
|
||||||
|
|
||||||
if (session.DGImage.ImageInfo.Get(out imgInfo) != ReturnCode.Success)
|
|
||||||
{
|
|
||||||
imgInfo = null;
|
|
||||||
}
|
|
||||||
if (dataPtr != IntPtr.Zero)
|
if (dataPtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
args = new DataTransferredEventArgs(session.CurrentSource, dataPtr, imgInfo);
|
args = new DataTransferredEventArgs(session.CurrentSource, dataPtr);
|
||||||
}
|
}
|
||||||
else if (dataArray != null)
|
else if (dataArray != null)
|
||||||
{
|
{
|
||||||
args = new DataTransferredEventArgs(session.CurrentSource, dataArray, imgInfo);
|
args = new DataTransferredEventArgs(session.CurrentSource, dataArray);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args = new DataTransferredEventArgs(session.CurrentSource, filePath, imgInfo, format);
|
args = new DataTransferredEventArgs(session.CurrentSource, filePath, format);
|
||||||
}
|
}
|
||||||
session.SafeSyncableRaiseEvent(args);
|
session.SafeSyncableRaiseEvent(args);
|
||||||
}
|
}
|
||||||
|
@ -11,18 +11,24 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TransferReadyEventArgs"/> class.
|
/// Initializes a new instance of the <see cref="TransferReadyEventArgs"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="source">The source.</param>
|
||||||
/// <param name="pendingCount">The pending count.</param>
|
/// <param name="pendingCount">The pending count.</param>
|
||||||
/// <param name="endOfJob">if set to <c>true</c> [end of job].</param>
|
/// <param name="endOfJob">if set to <c>true</c> then it's the end of job.</param>
|
||||||
/// <param name="imageInfo">The image information.</param>
|
public TransferReadyEventArgs(DataSource source, int pendingCount, bool endOfJob)
|
||||||
/// <param name="audioInfo">The audio information.</param>
|
|
||||||
public TransferReadyEventArgs(int pendingCount, bool endOfJob, TWImageInfo imageInfo, TWAudioInfo audioInfo)
|
|
||||||
{
|
{
|
||||||
|
DataSource = source;
|
||||||
PendingTransferCount = pendingCount;
|
PendingTransferCount = pendingCount;
|
||||||
EndOfJob = endOfJob;
|
EndOfJob = endOfJob;
|
||||||
PendingImageInfo = imageInfo;
|
|
||||||
AudioInfo = audioInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data source.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The data source.
|
||||||
|
/// </value>
|
||||||
|
public DataSource DataSource { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether the current transfer should be canceled
|
/// Gets or sets a value indicating whether the current transfer should be canceled
|
||||||
/// and continue next transfer if there are more data.
|
/// and continue next transfer if there are more data.
|
||||||
@ -49,6 +55,7 @@ namespace NTwain
|
|||||||
/// <value>The pending count.</value>
|
/// <value>The pending count.</value>
|
||||||
public int PendingTransferCount { get; private set; }
|
public int PendingTransferCount { get; private set; }
|
||||||
|
|
||||||
|
TWImageInfo _imgInfo;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the tentative image information for the current transfer if applicable.
|
/// Gets the tentative image information for the current transfer if applicable.
|
||||||
/// This may differ from the final image depending on the transfer mode used (mostly when doing mem xfer).
|
/// This may differ from the final image depending on the transfer mode used (mostly when doing mem xfer).
|
||||||
@ -56,15 +63,42 @@ namespace NTwain
|
|||||||
/// <value>
|
/// <value>
|
||||||
/// The image info.
|
/// The image info.
|
||||||
/// </value>
|
/// </value>
|
||||||
public TWImageInfo PendingImageInfo { get; private set; }
|
public TWImageInfo PendingImageInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_imgInfo == null)
|
||||||
|
{
|
||||||
|
if (DataSource.DGImage.ImageInfo.Get(out _imgInfo) != ReturnCode.Success)
|
||||||
|
{
|
||||||
|
_imgInfo = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _imgInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TWAudioInfo _audInfo;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the audio information for the current transfer if applicable.
|
/// Gets the audio information for the current transfer if applicable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The audio information.
|
/// The audio information.
|
||||||
/// </value>
|
/// </value>
|
||||||
public TWAudioInfo AudioInfo { get; private set; }
|
public TWAudioInfo AudioInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_audInfo == null)
|
||||||
|
{
|
||||||
|
if (DataSource.DGAudio.AudioInfo.Get(out _audInfo) != ReturnCode.Success)
|
||||||
|
{
|
||||||
|
_audInfo = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _audInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user