mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:15:42 +08:00
Refactoring different xfer modes and types.
This commit is contained in:
parent
4c3e2a50b3
commit
69feecde8d
@ -2,6 +2,7 @@
|
||||
using NTwain.Data;
|
||||
using NTwain.Values;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
@ -10,50 +11,6 @@ namespace NTwain
|
||||
/// </summary>
|
||||
public class TransferReadyEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TransferReadyEventArgs" /> class.
|
||||
/// </summary>
|
||||
/// <param name="pending">The pending data.</param>
|
||||
/// <param name="supportedFormats">The formats.</param>
|
||||
/// <param name="currentFormat">The current format.</param>
|
||||
/// <param name="supportedCompressions">The compressions.</param>
|
||||
/// <param name="currentCompression">The current compression.</param>
|
||||
/// <param name="canDoFileXfer">if set to <c>true</c> then allow file xfer properties.</param>
|
||||
/// <param name="imageInfo">The image info.</param>
|
||||
internal TransferReadyEventArgs(TWPendingXfers pending, IList<FileFormat> supportedFormats, FileFormat currentFormat,
|
||||
IList<Compression> supportedCompressions, Compression currentCompression, bool canDoFileXfer, TWImageInfo imageInfo)
|
||||
{
|
||||
PendingCount = pending.Count;
|
||||
EndOfJob = pending.EndOfJob == 0;
|
||||
_imageCompression = currentCompression;
|
||||
SupportedCompressions = supportedCompressions;
|
||||
_imageFormat = currentFormat;
|
||||
SupportedFormats = supportedFormats;
|
||||
CanDoFileXfer = canDoFileXfer;
|
||||
ImageInfo = imageInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the image info for the current transfer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The image info.
|
||||
/// </value>
|
||||
public TWImageInfo ImageInfo { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the known pending transfer count. This may not be appilicable
|
||||
/// for certain scanning modes.
|
||||
/// </summary>
|
||||
/// <value>The pending count.</value>
|
||||
public int PendingCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether current transfer signifies an end of job.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if transfer is end of job; otherwise, <c>false</c>.</value>
|
||||
public bool EndOfJob { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the current transfer should be canceled
|
||||
/// and continue next transfer if there are more data.
|
||||
@ -68,97 +25,126 @@ namespace NTwain
|
||||
public bool CancelAll { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether file transfer is supported.
|
||||
/// Gets a value indicating whether current transfer signifies an end of job in TWAIN world.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this instance can do file transfer; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool CanDoFileXfer { get; private set; }
|
||||
/// <value><c>true</c> if transfer is end of job; otherwise, <c>false</c>.</value>
|
||||
public bool EndOfJob { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the desired output file path if file transfer is supported.
|
||||
/// Note that not all sources will support the specified image type and compression
|
||||
/// when file transfer is used.
|
||||
/// Gets the known pending transfer count. This may not be appilicable
|
||||
/// for certain scanning modes.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The output file.
|
||||
/// </value>
|
||||
public string OutputFile { get; set; }
|
||||
/// <value>The pending count.</value>
|
||||
public int PendingTransferCount { get; internal set; }
|
||||
|
||||
#region image use
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported compression for image xfer.
|
||||
/// Gets the tentative image information for the current transfer if applicable.
|
||||
/// This may differ from the final image depending on the transfer mode used.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The supported compressions.
|
||||
/// The image info.
|
||||
/// </value>
|
||||
public IList<Compression> SupportedCompressions { get; private set; }
|
||||
public TWImageInfo PendingImageInfo { get; internal set; }
|
||||
|
||||
private Compression _imageCompression;
|
||||
///// <summary>
|
||||
///// Gets or sets a value indicating whether file transfer is supported.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// <c>true</c> if this instance can do file transfer; otherwise, <c>false</c>.
|
||||
///// </value>
|
||||
//public bool CanDoFileXfer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the image compression for image xfer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The image compression.
|
||||
/// </value>
|
||||
/// <exception cref="System.NotSupportedException"></exception>
|
||||
public Compression ImageCompression
|
||||
{
|
||||
get { return _imageCompression; }
|
||||
set
|
||||
{
|
||||
if (SupportedCompressions.Contains(value))
|
||||
{
|
||||
_imageCompression = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException(string.Format("{0} is not supported.", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// Gets or sets the desired output file path if file transfer is supported.
|
||||
///// Note that not all sources will support the specified image type and compression
|
||||
///// when file transfer is used.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The output file.
|
||||
///// </value>
|
||||
//public string OutputFile { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// Gets the supported compression for image xfer.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The supported compressions.
|
||||
///// </value>
|
||||
//public IList<Compression> SupportedImageCompressions { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported file formats for image file xfer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The supported formats.
|
||||
/// </value>
|
||||
public IList<FileFormat> SupportedFormats { get; private set; }
|
||||
//private Compression _imageCompression;
|
||||
|
||||
private FileFormat _imageFormat;
|
||||
/// <summary>
|
||||
/// Gets or sets the image format for image xfer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The image format.
|
||||
/// </value>
|
||||
/// <exception cref="System.NotSupportedException"></exception>
|
||||
public FileFormat ImageFormat
|
||||
{
|
||||
get { return _imageFormat; }
|
||||
set
|
||||
{
|
||||
if (SupportedFormats.Contains(value))
|
||||
{
|
||||
_imageFormat = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException(string.Format("{0} is not supported.", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// Gets or sets the image compression for image xfer.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The image compression.
|
||||
///// </value>
|
||||
///// <exception cref="System.NotSupportedException"></exception>
|
||||
//public Compression ImageCompression
|
||||
//{
|
||||
// get { return _imageCompression; }
|
||||
// set
|
||||
// {
|
||||
// if (SupportedImageCompressions.Contains(value))
|
||||
// {
|
||||
// _imageCompression = value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new NotSupportedException(string.Format("{0} is not supported.", value));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// Gets or sets the audio file format if <see cref="OutputFile"/> is specified
|
||||
///// and the data to be transferred is audio.
|
||||
///// Gets the supported file formats for image file xfer.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The audio file format.
|
||||
///// The supported formats.
|
||||
///// </value>
|
||||
//public AudioFileFormat AudioFileFormat { get; set; }
|
||||
//public IList<FileFormat> SupportedImageFormats { get; internal set; }
|
||||
|
||||
//private FileFormat _imageFormat;
|
||||
///// <summary>
|
||||
///// Gets or sets the image format for image xfer.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The image format.
|
||||
///// </value>
|
||||
///// <exception cref="System.NotSupportedException"></exception>
|
||||
//public FileFormat ImageFormat
|
||||
//{
|
||||
// get { return _imageFormat; }
|
||||
// set
|
||||
// {
|
||||
// if (SupportedImageFormats.Contains(value))
|
||||
// {
|
||||
// _imageFormat = value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new NotSupportedException(string.Format("{0} is not supported.", value));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
#region audio use
|
||||
|
||||
/// <summary>
|
||||
/// Gets the audio information for the current transfer if applicable.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The audio information.
|
||||
/// </value>
|
||||
public TWAudioInfo AudioInfo { get; internal set; }
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -663,168 +663,273 @@ namespace NTwain
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does the TWAIN transfer routine at state 6.
|
||||
/// Performs the TWAIN transfer routine at state 6.
|
||||
/// </summary>
|
||||
protected virtual void DoTransferRoutine()
|
||||
{
|
||||
TWPendingXfers pending = new TWPendingXfers();
|
||||
// TODO: better way to determine what's being xfered?
|
||||
if ((SourceId.DataGroup & DataGroups.Image) == DataGroups.Image)
|
||||
{
|
||||
DoImageXfer();
|
||||
}
|
||||
else if ((SourceId.DataGroup & DataGroups.Audio) == DataGroups.Audio)
|
||||
{
|
||||
DoAudioXfer();
|
||||
}
|
||||
else
|
||||
{
|
||||
// ??? just cancel it
|
||||
var pending = new TWPendingXfers();
|
||||
var rc = ReturnCode.Success;
|
||||
do
|
||||
{
|
||||
rc = DGControl.PendingXfers.Reset(pending);
|
||||
} while (rc == ReturnCode.Success && pending.Count != 0);
|
||||
|
||||
State = 5;
|
||||
DisableSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region audio xfers
|
||||
|
||||
private void DoAudioXfer()
|
||||
{
|
||||
var pending = new TWPendingXfers();
|
||||
var rc = ReturnCode.Success;
|
||||
|
||||
do
|
||||
{
|
||||
IList<FileFormat> formats = Enumerable.Empty<FileFormat>().ToList();
|
||||
IList<Compression> compressions = Enumerable.Empty<Compression>().ToList();
|
||||
bool canDoFileXfer = this.CapGetImageXferMech().Contains(XferMech.File);
|
||||
var curFormat = this.GetCurrentCap<FileFormat>(CapabilityId.ICapImageFileFormat);
|
||||
var curComp = this.GetCurrentCap<Compression>(CapabilityId.ICapCompression);
|
||||
TWImageInfo imgInfo;
|
||||
bool skip = false;
|
||||
if (DGImage.ImageInfo.Get(out imgInfo) != ReturnCode.Success)
|
||||
#region build pre xfer info
|
||||
TWAudioInfo audInfo;
|
||||
DGAudio.AudioInfo.Get(out audInfo);
|
||||
|
||||
// ask consumer for xfer details
|
||||
var preXferArgs = new TransferReadyEventArgs
|
||||
{
|
||||
// bad!
|
||||
skip = true;
|
||||
}
|
||||
AudioInfo = audInfo,
|
||||
PendingTransferCount = pending.Count,
|
||||
EndOfJob = pending.EndOfJob == 0
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
formats = this.CapGetImageFileFormat();
|
||||
}
|
||||
catch { }
|
||||
try
|
||||
{
|
||||
compressions = this.CapGetCompression();
|
||||
}
|
||||
catch { }
|
||||
OnTransferReady(preXferArgs);
|
||||
|
||||
// ask consumer for cancel in case of non-ui multi-page transfers
|
||||
TransferReadyEventArgs args = new TransferReadyEventArgs(pending, formats, curFormat, compressions,
|
||||
curComp, canDoFileXfer, imgInfo);
|
||||
args.CancelCurrent = skip;
|
||||
#endregion
|
||||
|
||||
OnTransferReady(args);
|
||||
|
||||
|
||||
if (!args.CancelAll && !args.CancelCurrent)
|
||||
{
|
||||
Values.XferMech mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech);
|
||||
|
||||
if (args.CanDoFileXfer && !string.IsNullOrEmpty(args.OutputFile))
|
||||
{
|
||||
var setXferRC = DGControl.SetupFileXfer.Set(new TWSetupFileXfer
|
||||
{
|
||||
FileName = args.OutputFile,
|
||||
Format = args.ImageFormat
|
||||
});
|
||||
if (setXferRC == ReturnCode.Success)
|
||||
{
|
||||
mech = XferMech.File;
|
||||
}
|
||||
}
|
||||
|
||||
// I don't know how this is supposed to work so it probably doesn't
|
||||
//this.CapSetImageFormat(args.ImageFormat);
|
||||
//this.CapSetImageCompression(args.ImageCompression);
|
||||
|
||||
#region do xfer
|
||||
|
||||
// TODO: expose all swallowed exceptions somehow later
|
||||
|
||||
IntPtr dataPtr = IntPtr.Zero;
|
||||
IntPtr lockedPtr = IntPtr.Zero;
|
||||
string file = null;
|
||||
try
|
||||
{
|
||||
ReturnCode xrc = ReturnCode.Cancel;
|
||||
switch (mech)
|
||||
{
|
||||
case Values.XferMech.Native:
|
||||
xrc = DGImage.ImageNativeXfer.Get(ref dataPtr);
|
||||
break;
|
||||
case Values.XferMech.File:
|
||||
xrc = DGImage.ImageFileXfer.Get();
|
||||
if (File.Exists(args.OutputFile))
|
||||
{
|
||||
file = args.OutputFile;
|
||||
}
|
||||
break;
|
||||
case Values.XferMech.MemFile:
|
||||
// not supported yet
|
||||
//TWImageMemXfer memxfer = new TWImageMemXfer();
|
||||
//xrc = DGImage.ImageMemXfer.Get(memxfer);
|
||||
break;
|
||||
}
|
||||
if (xrc == ReturnCode.XferDone)
|
||||
{
|
||||
State = 7;
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
lockedPtr = MemoryManager.Instance.Lock(dataPtr);
|
||||
}
|
||||
OnDataTransferred(new DataTransferredEventArgs(lockedPtr, file));
|
||||
}
|
||||
//}
|
||||
//else if (group == DataGroups.Audio)
|
||||
//{
|
||||
// var xrc = DGAudio.AudioNativeXfer.Get(ref dataPtr);
|
||||
// if (xrc == ReturnCode.XferDone)
|
||||
// {
|
||||
// State = 7;
|
||||
// try
|
||||
// {
|
||||
// var dtHand = DataTransferred;
|
||||
// if (dtHand != null)
|
||||
// {
|
||||
// lockedPtr = MemoryManager.Instance.MemLock(dataPtr);
|
||||
// dtHand(this, new DataTransferredEventArgs(lockedPtr));
|
||||
// }
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
finally
|
||||
{
|
||||
State = 6;
|
||||
// data here is allocated by source so needs to use shared mem calls
|
||||
if (lockedPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Unlock(lockedPtr);
|
||||
lockedPtr = IntPtr.Zero;
|
||||
}
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Free(dataPtr);
|
||||
dataPtr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (args.CancelAll)
|
||||
if (preXferArgs.CancelAll)
|
||||
{
|
||||
rc = DGControl.PendingXfers.Reset(pending);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
// if audio exit here
|
||||
//if (group == DataGroups.Audio)
|
||||
//{
|
||||
// //???
|
||||
// return;
|
||||
//}
|
||||
|
||||
// TODO: verify if audio exit directly?
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (!preXferArgs.CancelCurrent)
|
||||
{
|
||||
rc = DGControl.PendingXfers.EndXfer(pending);
|
||||
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ACapXferMech);
|
||||
switch (mech)
|
||||
{
|
||||
case XferMech.Native:
|
||||
DoAudioNativeXfer();
|
||||
break;
|
||||
case XferMech.File:
|
||||
DoAudioFileXfer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = DGControl.PendingXfers.EndXfer(pending);
|
||||
|
||||
} while (rc == ReturnCode.Success && pending.Count != 0);
|
||||
|
||||
State = 5;
|
||||
DisableSource();
|
||||
|
||||
}
|
||||
|
||||
private void DoAudioNativeXfer()
|
||||
{
|
||||
IntPtr dataPtr = IntPtr.Zero;
|
||||
IntPtr lockedPtr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var xrc = DGAudio.AudioNativeXfer.Get(ref dataPtr);
|
||||
if (xrc == ReturnCode.XferDone)
|
||||
{
|
||||
State = 7;
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
lockedPtr = MemoryManager.Instance.Lock(dataPtr);
|
||||
}
|
||||
OnDataTransferred(new DataTransferredEventArgs(lockedPtr, null));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
State = 6;
|
||||
// data here is allocated by source so needs to use shared mem calls
|
||||
if (lockedPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Unlock(lockedPtr);
|
||||
lockedPtr = IntPtr.Zero;
|
||||
}
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Free(dataPtr);
|
||||
dataPtr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DoAudioFileXfer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region image xfers
|
||||
|
||||
private void DoImageXfer()
|
||||
{
|
||||
var pending = new TWPendingXfers();
|
||||
var rc = ReturnCode.Success;
|
||||
|
||||
do
|
||||
{
|
||||
#region build pre xfer info
|
||||
TWImageInfo imgInfo;
|
||||
DGImage.ImageInfo.Get(out imgInfo);
|
||||
|
||||
//IList<FileFormat> formats = Enumerable.Empty<FileFormat>().ToList();
|
||||
//IList<Compression> compressions = Enumerable.Empty<Compression>().ToList();
|
||||
//var curFormat = this.GetCurrentCap<FileFormat>(CapabilityId.ICapImageFileFormat);
|
||||
//var curComp = this.GetCurrentCap<Compression>(CapabilityId.ICapCompression);
|
||||
//try
|
||||
//{
|
||||
// formats = this.CapGetImageFileFormat();
|
||||
//}
|
||||
//catch { }
|
||||
//try
|
||||
//{
|
||||
// compressions = this.CapGetCompression();
|
||||
//}
|
||||
//catch { }
|
||||
|
||||
// ask consumer for xfer details
|
||||
var preXferArgs = new TransferReadyEventArgs
|
||||
{
|
||||
PendingImageInfo = imgInfo,
|
||||
PendingTransferCount = pending.Count,
|
||||
EndOfJob = pending.EndOfJob == 0
|
||||
};
|
||||
|
||||
OnTransferReady(preXferArgs);
|
||||
|
||||
#endregion
|
||||
|
||||
if (preXferArgs.CancelAll)
|
||||
{
|
||||
rc = DGControl.PendingXfers.Reset(pending);
|
||||
}
|
||||
else if (!preXferArgs.CancelCurrent)
|
||||
{
|
||||
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech);
|
||||
switch (mech)
|
||||
{
|
||||
case XferMech.Native:
|
||||
DoImageNativeXfer();
|
||||
break;
|
||||
case XferMech.Memory:
|
||||
DoImageMemoryXfer();
|
||||
break;
|
||||
case XferMech.File:
|
||||
DoImageFileXfer();
|
||||
break;
|
||||
case XferMech.MemFile:
|
||||
DoImageMemoryFileXfer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = DGControl.PendingXfers.EndXfer(pending);
|
||||
|
||||
} while (rc == ReturnCode.Success && pending.Count != 0);
|
||||
|
||||
State = 5;
|
||||
DisableSource();
|
||||
}
|
||||
|
||||
private void DoImageNativeXfer()
|
||||
{
|
||||
IntPtr dataPtr = IntPtr.Zero;
|
||||
IntPtr lockedPtr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
ReturnCode xrc = DGImage.ImageNativeXfer.Get(ref dataPtr);
|
||||
if (xrc == ReturnCode.XferDone)
|
||||
{
|
||||
State = 7;
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
lockedPtr = MemoryManager.Instance.Lock(dataPtr);
|
||||
}
|
||||
OnDataTransferred(new DataTransferredEventArgs(lockedPtr, null));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
State = 6;
|
||||
// data here is allocated by source so needs to use shared mem calls
|
||||
if (lockedPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Unlock(lockedPtr);
|
||||
lockedPtr = IntPtr.Zero;
|
||||
}
|
||||
if (dataPtr != IntPtr.Zero)
|
||||
{
|
||||
MemoryManager.Instance.Free(dataPtr);
|
||||
dataPtr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DoImageMemoryFileXfer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void DoImageFileXfer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
//if (preXferArgs.CanDoFileXfer && !string.IsNullOrEmpty(preXferArgs.OutputFile))
|
||||
//{
|
||||
// var setXferRC = DGControl.SetupFileXfer.Set(new TWSetupFileXfer
|
||||
// {
|
||||
// FileName = preXferArgs.OutputFile,
|
||||
// Format = preXferArgs.ImageFormat
|
||||
// });
|
||||
// if (setXferRC == ReturnCode.Success)
|
||||
// {
|
||||
// mech = XferMech.File;
|
||||
// }
|
||||
//}
|
||||
//xrc = DGImage.ImageFileXfer.Get();
|
||||
//if (File.Exists(preXferArgs.OutputFile))
|
||||
//{
|
||||
// file = preXferArgs.OutputFile;
|
||||
//}
|
||||
}
|
||||
|
||||
private void DoImageMemoryXfer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
@ -36,11 +36,11 @@ namespace NTwain
|
||||
|
||||
do
|
||||
{
|
||||
IList<FileFormat> formats = Enumerable.Empty<FileFormat>().ToList();
|
||||
IList<Compression> compressions = Enumerable.Empty<Compression>().ToList();
|
||||
bool canDoFileXfer = this.CapGetImageXferMech().Contains(XferMech.File);
|
||||
var curFormat = this.GetCurrentCap<FileFormat>(CapabilityId.ICapImageFileFormat);
|
||||
var curComp = this.GetCurrentCap<Compression>(CapabilityId.ICapCompression);
|
||||
//IList<FileFormat> formats = Enumerable.Empty<FileFormat>().ToList();
|
||||
//IList<Compression> compressions = Enumerable.Empty<Compression>().ToList();
|
||||
//bool canDoFileXfer = this.CapGetImageXferMech().Contains(XferMech.File);
|
||||
//var curFormat = this.GetCurrentCap<FileFormat>(CapabilityId.ICapImageFileFormat);
|
||||
//var curComp = this.GetCurrentCap<Compression>(CapabilityId.ICapCompression);
|
||||
TWImageInfo imgInfo;
|
||||
bool skip = false;
|
||||
if (DGImage.ImageInfo.Get(out imgInfo) != ReturnCode.Success)
|
||||
@ -49,20 +49,26 @@ namespace NTwain
|
||||
skip = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
formats = this.CapGetImageFileFormat();
|
||||
}
|
||||
catch { }
|
||||
try
|
||||
{
|
||||
compressions = this.CapGetCompression();
|
||||
}
|
||||
catch { }
|
||||
//try
|
||||
//{
|
||||
// formats = this.CapGetImageFileFormat();
|
||||
//}
|
||||
//catch { }
|
||||
//try
|
||||
//{
|
||||
// compressions = this.CapGetCompression();
|
||||
//}
|
||||
//catch { }
|
||||
|
||||
// ask consumer for cancel in case of non-ui multi-page transfers
|
||||
TransferReadyEventArgs args = new TransferReadyEventArgs(pending, formats, curFormat, compressions,
|
||||
curComp, canDoFileXfer, imgInfo);
|
||||
//TransferReadyEventArgs args = new TransferReadyEventArgs(pending, formats, curFormat, compressions,
|
||||
// curComp, canDoFileXfer, imgInfo);
|
||||
var args = new TransferReadyEventArgs
|
||||
{
|
||||
PendingImageInfo = imgInfo,
|
||||
PendingTransferCount = pending.Count,
|
||||
EndOfJob = pending.EndOfJob == 0
|
||||
};
|
||||
args.CancelCurrent = skip;
|
||||
|
||||
OnTransferReady(args);
|
||||
@ -72,18 +78,18 @@ namespace NTwain
|
||||
{
|
||||
Values.XferMech mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech);
|
||||
|
||||
if (args.CanDoFileXfer && !string.IsNullOrEmpty(args.OutputFile))
|
||||
{
|
||||
var setXferRC = DGControl.SetupFileXfer.Set(new TWSetupFileXfer
|
||||
{
|
||||
FileName = args.OutputFile,
|
||||
Format = args.ImageFormat
|
||||
});
|
||||
if (setXferRC == ReturnCode.Success)
|
||||
{
|
||||
mech = XferMech.File;
|
||||
}
|
||||
}
|
||||
//if (args.CanDoFileXfer && !string.IsNullOrEmpty(args.OutputFile))
|
||||
//{
|
||||
// var setXferRC = DGControl.SetupFileXfer.Set(new TWSetupFileXfer
|
||||
// {
|
||||
// FileName = args.OutputFile,
|
||||
// Format = args.ImageFormat
|
||||
// });
|
||||
// if (setXferRC == ReturnCode.Success)
|
||||
// {
|
||||
// mech = XferMech.File;
|
||||
// }
|
||||
//}
|
||||
|
||||
// I don't know how this is supposed to work so it probably doesn't
|
||||
//this.CapSetImageFormat(args.ImageFormat);
|
||||
@ -105,11 +111,11 @@ namespace NTwain
|
||||
xrc = DGImage.ImageNativeXfer.Get(ref dataPtr);
|
||||
break;
|
||||
case Values.XferMech.File:
|
||||
xrc = DGImage.ImageFileXfer.Get();
|
||||
if (File.Exists(args.OutputFile))
|
||||
{
|
||||
file = args.OutputFile;
|
||||
}
|
||||
//xrc = DGImage.ImageFileXfer.Get();
|
||||
//if (File.Exists(args.OutputFile))
|
||||
//{
|
||||
// file = args.OutputFile;
|
||||
//}
|
||||
break;
|
||||
case Values.XferMech.MemFile:
|
||||
// not supported yet
|
||||
|
@ -11,28 +11,6 @@ namespace NTwain.Tests
|
||||
[TestClass]
|
||||
public class TransferReadyEventArgsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Constructor_Sets_Correct_Properties()
|
||||
{
|
||||
// just some non-default values to test
|
||||
TWPendingXfers pending = new TWPendingXfers();
|
||||
List<FileFormat> formats = new List<FileFormat> { FileFormat.Bmp, FileFormat.Tiff };
|
||||
FileFormat curFormat = FileFormat.Tiff;
|
||||
List<Compression> compressions = new List<Compression> { Compression.None, Compression.Group4 };
|
||||
Compression curCompress = Compression.None;
|
||||
bool fileXfer = true;
|
||||
TWImageInfo info = new TWImageInfo();
|
||||
|
||||
TransferReadyEventArgs target = new TransferReadyEventArgs(pending, formats, curFormat, compressions, curCompress, fileXfer, info);
|
||||
|
||||
Assert.AreEqual(pending.Count, target.PendingCount, "PendingCount mismatch.");
|
||||
Assert.AreEqual(formats, target.SupportedFormats, "SupportedFormats mismatch.");
|
||||
Assert.AreEqual(curFormat, target.ImageFormat, "ImageFormat mismatch.");
|
||||
Assert.AreEqual(compressions, target.SupportedCompressions, "SupportedCompressions mismatch.");
|
||||
Assert.AreEqual(curCompress, target.ImageCompression, "ImageCompression mismatch.");
|
||||
Assert.AreEqual(fileXfer, target.CanDoFileXfer, "CanDoFileXfer mismatch.");
|
||||
Assert.AreEqual(info, target.ImageInfo, "ImageInfo mismatch.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user