Merged in v2 (pull request #3)

Sync v2 to master
This commit is contained in:
Eugene Wang
2014-09-02 11:23:14 -04:00
25 changed files with 239 additions and 110 deletions

View File

@@ -35,7 +35,7 @@ namespace NTwain
/// The memory data. /// The memory data.
/// </value> /// </value>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public byte[] MemData { get; internal set; } public byte[] MemoryData { get; internal set; }
/// <summary> /// <summary>
/// Gets the final image information if applicable. /// Gets the final image information if applicable.

View File

@@ -55,14 +55,14 @@ namespace NTwain.Internals
} }
} }
internal override void BeginInvoke(Action action) public override void BeginInvoke(Action action)
{ {
if (_dispatcher == null) { throw new InvalidOperationException(Resources.MsgLoopUnavailble); } if (_dispatcher == null) { throw new InvalidOperationException(Resources.MsgLoopUnavailble); }
_dispatcher.BeginInvoke(DispatcherPriority.Normal, action); _dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
} }
internal override void Invoke(Action action) public override void Invoke(Action action)
{ {
if (_dispatcher == null) { throw new InvalidOperationException(Resources.MsgLoopUnavailble); } if (_dispatcher == null) { throw new InvalidOperationException(Resources.MsgLoopUnavailble); }

View File

@@ -12,7 +12,7 @@ namespace NTwain.Internals
/// The MSG structure in Windows for TWAIN use. /// The MSG structure in Windows for TWAIN use.
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct MESSAGE struct MESSAGE
{ {
public MESSAGE(IntPtr hwnd, int message, IntPtr wParam, IntPtr lParam) public MESSAGE(IntPtr hwnd, int message, IntPtr wParam, IntPtr lParam)
{ {

View File

@@ -118,9 +118,9 @@ namespace NTwain.Internals
} while (rc == ReturnCode.Success && pending.Count != 0); } while (rc == ReturnCode.Success && pending.Count != 0);
// some poorly written scanner drivers return failure on EndXfer so also check for pending count now // some poorly written scanner drivers return failure on EndXfer so also check for pending count now.
// this may break with other sources but we'll see // this may break with other sources but we'll see
if (pending.Count == 0) if (pending.Count == 0 && session.State > 5)
{ {
session.ChangeState(5, true); session.ChangeState(5, true);
session.DisableSource(); session.DisableSource();
@@ -441,7 +441,7 @@ namespace NTwain.Internals
session.SafeSyncableRaiseEvent(new DataTransferredEventArgs session.SafeSyncableRaiseEvent(new DataTransferredEventArgs
{ {
NativeData = dataPtr, NativeData = dataPtr,
MemData = dataArray, MemoryData = dataArray,
FileDataPath = filePath, FileDataPath = filePath,
ImageInfo = imgInfo, ImageInfo = imgInfo,
//ExImageInfo = extInfo //ExImageInfo = extInfo

View File

@@ -16,7 +16,11 @@ namespace NTwain
internal abstract void Start(IWinMessageFilter filter); internal abstract void Start(IWinMessageFilter filter);
internal abstract void Stop(); internal abstract void Stop();
internal virtual void BeginInvoke(Action action) /// <summary>
/// Asynchronously invokes the specified action on the message loop thread.
/// </summary>
/// <param name="action">The action.</param>
public virtual void BeginInvoke(Action action)
{ {
if (SyncContext == null) if (SyncContext == null)
{ {
@@ -30,7 +34,12 @@ namespace NTwain
}, null); }, null);
} }
} }
internal virtual void Invoke(Action action)
/// <summary>
/// Synchronously invokes the specified action on the message loop thread.
/// </summary>
/// <param name="action">The action.</param>
public virtual void Invoke(Action action)
{ {
if (SyncContext == null) if (SyncContext == null)
{ {
@@ -63,11 +72,11 @@ namespace NTwain
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WindowsFormsMessageLoopHook"/> class. /// Initializes a new instance of the <see cref="WindowsFormsMessageLoopHook"/> class.
/// </summary> /// </summary>
/// <param name="hwnd">The handle to the app window.</param> /// <param name="windowHandle">The handle to the app window.</param>
/// <exception cref="System.ArgumentException">A valid window handle is required.</exception> /// <exception cref="System.ArgumentException">A valid window handle is required.</exception>
public WindowsFormsMessageLoopHook(IntPtr hwnd) public WindowsFormsMessageLoopHook(IntPtr windowHandle)
{ {
if (hwnd == IntPtr.Zero) { throw new ArgumentException("A valid window handle is required."); } if (windowHandle == IntPtr.Zero) { throw new ArgumentException("A valid window handle is required."); }
if (!System.Windows.Forms.Application.MessageLoop) if (!System.Windows.Forms.Application.MessageLoop)
{ {
@@ -78,7 +87,7 @@ namespace NTwain
{ {
ThrowInvalidOp(); ThrowInvalidOp();
} }
Handle = hwnd; Handle = windowHandle;
SyncContext = sync; SyncContext = sync;
} }
internal override string InvalidMessage internal override string InvalidMessage
@@ -133,11 +142,11 @@ namespace NTwain
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WpfMessageLoopHook"/> class. /// Initializes a new instance of the <see cref="WpfMessageLoopHook"/> class.
/// </summary> /// </summary>
/// <param name="hwnd">The handle to the app window.</param> /// <param name="windowHandle">The handle to the app window.</param>
/// <exception cref="System.ArgumentException">A valid window handle is required.</exception> /// <exception cref="System.ArgumentException">A valid window handle is required.</exception>
public WpfMessageLoopHook(IntPtr hwnd) public WpfMessageLoopHook(IntPtr windowHandle)
{ {
if (hwnd == IntPtr.Zero) { throw new ArgumentException("A valid window handle is required."); } if (windowHandle == IntPtr.Zero) { throw new ArgumentException("A valid window handle is required."); }
if (System.Windows.Application.Current == null || if (System.Windows.Application.Current == null ||
!System.Windows.Application.Current.Dispatcher.CheckAccess()) !System.Windows.Application.Current.Dispatcher.CheckAccess())
@@ -149,7 +158,7 @@ namespace NTwain
{ {
ThrowInvalidOp(); ThrowInvalidOp();
} }
Handle = hwnd; Handle = windowHandle;
SyncContext = sync; SyncContext = sync;
} }
internal override string InvalidMessage internal override string InvalidMessage

View File

@@ -14,6 +14,6 @@ namespace NTwain
// keep this same in majors releases // keep this same in majors releases
public const string Release = "2.0.0.0"; public const string Release = "2.0.0.0";
// change this for each nuget release // change this for each nuget release
public const string Build = "2.0.3"; public const string Build = "2.0.6";
} }
} }

View File

@@ -16,6 +16,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode Get(ushort customDAT, TWCapability capability) public ReturnCode Get(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.Get); Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.Get);
@@ -28,6 +29,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode GetCurrent(ushort customDAT, TWCapability capability) public ReturnCode GetCurrent(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetCurrent); Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetCurrent);
@@ -40,6 +42,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode GetDefault(ushort customDAT, TWCapability capability) public ReturnCode GetDefault(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetDefault); Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetDefault);
@@ -53,6 +56,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode GetHelp(ushort customDAT, TWCapability capability) public ReturnCode GetHelp(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetHelp); Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetHelp);
@@ -66,6 +70,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode GetLabel(ushort customDAT, TWCapability capability) public ReturnCode GetLabel(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabel); Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabel);
@@ -79,6 +84,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode GetLabelEnum(ushort customDAT, TWCapability capability) public ReturnCode GetLabelEnum(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabelEnum); Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabelEnum);
@@ -91,6 +97,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode QuerySupport(ushort customDAT, TWCapability capability) public ReturnCode QuerySupport(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.QuerySupport); Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.QuerySupport);
@@ -104,6 +111,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode Reset(ushort customDAT, TWCapability capability) public ReturnCode Reset(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.Reset); Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.Reset);
@@ -117,6 +125,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode ResetAll(ushort customDAT, TWCapability capability) public ReturnCode ResetAll(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.ResetAll); Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.ResetAll);
@@ -133,6 +142,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode Set(ushort customDAT, TWCapability capability) public ReturnCode Set(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 6, DataGroups.Control, (DataArgumentType)customDAT, Message.Set); Session.VerifyState(4, 6, DataGroups.Control, (DataArgumentType)customDAT, Message.Set);
@@ -148,6 +158,7 @@ namespace NTwain.Triplets
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param> /// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param> /// <param name="capability">The capability.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "DAT")]
public ReturnCode SetConstraint(ushort customDAT, TWCapability capability) public ReturnCode SetConstraint(ushort customDAT, TWCapability capability)
{ {
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.SetConstraint); Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.SetConstraint);

View File

@@ -16,7 +16,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="setupFileXfer">The setup file xfer.</param> /// <param name="setupFileXfer">The setup file xfer.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWSetupFileXfer setupFileXfer) public ReturnCode Get(out TWSetupFileXfer setupFileXfer)
{ {
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Get); Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Get);
@@ -29,7 +29,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="setupFileXfer">The setup file xfer.</param> /// <param name="setupFileXfer">The setup file xfer.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode GetDefault(out TWSetupFileXfer setupFileXfer) public ReturnCode GetDefault(out TWSetupFileXfer setupFileXfer)
{ {
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.GetDefault); Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.GetDefault);
@@ -43,7 +43,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="setupFileXfer">The setup file xfer.</param> /// <param name="setupFileXfer">The setup file xfer.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Reset(out TWSetupFileXfer setupFileXfer) public ReturnCode Reset(out TWSetupFileXfer setupFileXfer)
{ {
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Reset); Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Reset);
@@ -60,6 +60,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="setupFileXfer">The setup file xfer.</param> /// <param name="setupFileXfer">The setup file xfer.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer")]
public ReturnCode Set(TWSetupFileXfer setupFileXfer) public ReturnCode Set(TWSetupFileXfer setupFileXfer)
{ {
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Set); Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupFileXfer, Message.Set);

View File

@@ -6,7 +6,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Represents <see cref="DataArgumentType.SetupMemXfer"/>. /// Represents <see cref="DataArgumentType.SetupMemXfer"/>.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mem")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mem")]
public sealed class SetupMemXfer : OpBase public sealed class SetupMemXfer : OpBase
{ {
internal SetupMemXfer(ITwainSessionInternal session) : base(session) { } internal SetupMemXfer(ITwainSessionInternal session) : base(session) { }
@@ -16,7 +16,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="setupMemXfer">The setup mem xfer.</param> /// <param name="setupMemXfer">The setup mem xfer.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mem"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWSetupMemXfer setupMemXfer) public ReturnCode Get(out TWSetupMemXfer setupMemXfer)
{ {
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupMemXfer, Message.Get); Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.SetupMemXfer, Message.Get);

View File

@@ -6,6 +6,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Represents <see cref="DataArgumentType.XferGroup"/>. /// Represents <see cref="DataArgumentType.XferGroup"/>.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer")]
public sealed class XferGroup : OpBase public sealed class XferGroup : OpBase
{ {
internal XferGroup(ITwainSessionInternal session) : base(session) { } internal XferGroup(ITwainSessionInternal session) : base(session) { }

View File

@@ -28,6 +28,7 @@ namespace NTwain.Triplets
/// <param name="message">The message.</param> /// <param name="message">The message.</param>
/// <param name="data">The data.</param> /// <param name="data">The data.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "3#"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "dat"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dsm")]
public ReturnCode DsmEntry( public ReturnCode DsmEntry(
DataGroups group, DataGroups group,
DataArgumentType dat, DataArgumentType dat,

View File

@@ -6,6 +6,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Represents <see cref="DataArgumentType.CieColor"/>. /// Represents <see cref="DataArgumentType.CieColor"/>.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cie")]
public sealed class CieColor : OpBase public sealed class CieColor : OpBase
{ {
internal CieColor(ITwainSessionInternal session) : base(session) { } internal CieColor(ITwainSessionInternal session) : base(session) { }
@@ -16,7 +17,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="cieColor">Color data.</param> /// <param name="cieColor">Color data.</param>
/// <returns></returns> /// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "cie"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWCieColor cieColor) public ReturnCode Get(out TWCieColor cieColor)
{ {
Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.CieColor, Message.Get); Session.VerifyState(4, 6, DataGroups.Image, DataArgumentType.CieColor, Message.Get);

View File

@@ -6,6 +6,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Represents <see cref="DataArgumentType.IccProfile"/>. /// Represents <see cref="DataArgumentType.IccProfile"/>.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Icc")]
public sealed class IccProfile : OpBase public sealed class IccProfile : OpBase
{ {
internal IccProfile(ITwainSessionInternal session) : base(session) { } internal IccProfile(ITwainSessionInternal session) : base(session) { }

View File

@@ -6,6 +6,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Represents <see cref="DataArgumentType.RgbResponse"/>. /// Represents <see cref="DataArgumentType.RgbResponse"/>.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rgb")]
public sealed class RgbResponse : OpBase public sealed class RgbResponse : OpBase
{ {
internal RgbResponse(ITwainSessionInternal session) : base(session) { } internal RgbResponse(ITwainSessionInternal session) : base(session) { }

View File

@@ -19,6 +19,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Gets the operations defined for DAT_CIECOLOR. /// Gets the operations defined for DAT_CIECOLOR.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cie")]
public CieColor CieColor public CieColor CieColor
{ {
get get
@@ -73,6 +74,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Gets the operations defined for DAT_ICCPROFILE. /// Gets the operations defined for DAT_ICCPROFILE.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Icc")]
public IccProfile IccProfile public IccProfile IccProfile
{ {
get get
@@ -175,6 +177,7 @@ namespace NTwain.Triplets
/// <summary> /// <summary>
/// Gets the operations defined for DAT_RGBRESPONSE. /// Gets the operations defined for DAT_RGBRESPONSE.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rgb")]
public RgbResponse RgbResponse public RgbResponse RgbResponse
{ {
get get

View File

@@ -41,7 +41,10 @@ namespace NTwain
_appId = appId; _appId = appId;
((ITwainSessionInternal)this).ChangeState(1, false); ((ITwainSessionInternal)this).ChangeState(1, false);
#if DEBUG
// defaults to false on release since it's only useful during dev
EnforceState = true; EnforceState = true;
#endif
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
@@ -54,12 +57,18 @@ namespace NTwain
internal static TwainSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId) internal static TwainSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId)
{ {
TwainSource source = null;
var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}", sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName); var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}", sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);
if (__ownedSources.ContainsKey(key)) if (__ownedSources.ContainsKey(key))
{ {
return __ownedSources[key]; source = __ownedSources[key];
source.Session = session;
} }
return __ownedSources[key] = new TwainSource(session, sourceId); else
{
__ownedSources[key] = source = new TwainSource(session, sourceId);
}
return source;
} }
/// <summary> /// <summary>
@@ -428,7 +437,7 @@ namespace NTwain
_msgLoopHook.Invoke(() => _msgLoopHook.Invoke(() =>
{ {
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource.", Thread.CurrentThread.ManagedThreadId)); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode));
// app v2.2 or higher uses callback2 // app v2.2 or higher uses callback2
if (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2) if (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2)
@@ -477,10 +486,15 @@ namespace NTwain
return rc; return rc;
} }
bool _disabling;
ReturnCode ITwainSessionInternal.DisableSource() ReturnCode ITwainSessionInternal.DisableSource()
{ {
var rc = ReturnCode.Failure; var rc = ReturnCode.Failure;
if (!_disabling) // temp hack as a workaround to this being called from multiple threads (xfer logic & closedsreq msg)
{
_disabling = true;
try
{
_msgLoopHook.Invoke(() => _msgLoopHook.Invoke(() =>
{ {
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId)); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId));
@@ -492,6 +506,12 @@ namespace NTwain
SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled); SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled);
} }
}); });
}
finally
{
_disabling = false;
}
}
return rc; return rc;
} }
@@ -524,15 +544,15 @@ namespace NTwain
_msgLoopHook.Invoke(() => _msgLoopHook.Invoke(() =>
{ {
if (targetState < 7) if (targetState < 7 && CurrentSource != null)
{ {
((ITwainSessionInternal)this).DGControl.PendingXfers.EndXfer(new TWPendingXfers()); ((ITwainSessionInternal)this).DGControl.PendingXfers.EndXfer(new TWPendingXfers());
} }
if (targetState < 6) if (targetState < 6 && CurrentSource != null)
{ {
((ITwainSessionInternal)this).DGControl.PendingXfers.Reset(new TWPendingXfers()); ((ITwainSessionInternal)this).DGControl.PendingXfers.Reset(new TWPendingXfers());
} }
if (targetState < 5) if (targetState < 5 && CurrentSource != null)
{ {
((ITwainSessionInternal)this).DisableSource(); ((ITwainSessionInternal)this).DisableSource();
} }
@@ -782,6 +802,7 @@ namespace NTwain
break; break;
case Message.CloseDSReq: case Message.CloseDSReq:
case Message.CloseDSOK: case Message.CloseDSOK:
Debug.WriteLine("Got msg " + msg);
// even though it says closeDS it's really disable. // even though it says closeDS it's really disable.
// dsok is sent if source is enabled with uionly // dsok is sent if source is enabled with uionly

View File

@@ -18,7 +18,7 @@ namespace NTwain
QuerySupport retVal = QuerySupport.None; QuerySupport retVal = QuerySupport.None;
using (TWCapability cap = new TWCapability(capId)) using (TWCapability cap = new TWCapability(capId))
{ {
var rc = _session.DGControl.Capability.QuerySupport(cap); var rc = Session.DGControl.Capability.QuerySupport(cap);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
var read = CapabilityReader.ReadValue(cap); var read = CapabilityReader.ReadValue(cap);
@@ -41,7 +41,7 @@ namespace NTwain
{ {
using (TWCapability cap = new TWCapability(capId)) using (TWCapability cap = new TWCapability(capId))
{ {
var rc = _session.DGControl.Capability.GetCurrent(cap); var rc = Session.DGControl.Capability.GetCurrent(cap);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
var read = CapabilityReader.ReadValue(cap); var read = CapabilityReader.ReadValue(cap);
@@ -82,7 +82,7 @@ namespace NTwain
var list = new List<object>(); var list = new List<object>();
using (TWCapability cap = new TWCapability(capabilityId)) using (TWCapability cap = new TWCapability(capabilityId))
{ {
var rc = _session.DGControl.Capability.Get(cap); var rc = Session.DGControl.Capability.Get(cap);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
cap.ReadMultiCapValues(list); cap.ReadMultiCapValues(list);
@@ -126,7 +126,7 @@ namespace NTwain
{ {
using (TWCapability compressCap = new TWCapability(CapabilityId.ICapCompression, new TWOneValue { Item = (uint)compression, ItemType = ItemType.UInt16 })) using (TWCapability compressCap = new TWCapability(CapabilityId.ICapCompression, new TWOneValue { Item = (uint)compression, ItemType = ItemType.UInt16 }))
{ {
return _session.DGControl.Capability.Set(compressCap); return Session.DGControl.Capability.Set(compressCap);
} }
} }
@@ -153,7 +153,7 @@ namespace NTwain
{ {
using (TWCapability formatCap = new TWCapability(CapabilityId.ICapImageFileFormat, new TWOneValue { Item = (uint)format, ItemType = ItemType.UInt16 })) using (TWCapability formatCap = new TWCapability(CapabilityId.ICapImageFileFormat, new TWOneValue { Item = (uint)format, ItemType = ItemType.UInt16 }))
{ {
return _session.DGControl.Capability.Set(formatCap); return Session.DGControl.Capability.Set(formatCap);
} }
} }
@@ -183,7 +183,7 @@ namespace NTwain
one.ItemType = ItemType.UInt16; one.ItemType = ItemType.UInt16;
using (TWCapability dx = new TWCapability(CapabilityId.ICapPixelType, one)) using (TWCapability dx = new TWCapability(CapabilityId.ICapPixelType, one))
{ {
return _session.DGControl.Capability.Set(dx); return Session.DGControl.Capability.Set(dx);
} }
} }
@@ -223,7 +223,7 @@ namespace NTwain
one.ItemType = ItemType.UInt16; one.ItemType = ItemType.UInt16;
using (TWCapability dx = new TWCapability(CapabilityId.ICapXferMech, one)) using (TWCapability dx = new TWCapability(CapabilityId.ICapXferMech, one))
{ {
return _session.DGControl.Capability.Set(dx); return Session.DGControl.Capability.Set(dx);
} }
} }
@@ -239,7 +239,7 @@ namespace NTwain
one.ItemType = ItemType.UInt16; one.ItemType = ItemType.UInt16;
using (TWCapability dx = new TWCapability(CapabilityId.ACapXferMech, one)) using (TWCapability dx = new TWCapability(CapabilityId.ACapXferMech, one))
{ {
return _session.DGControl.Capability.Set(dx); return Session.DGControl.Capability.Set(dx);
} }
} }
@@ -282,13 +282,13 @@ namespace NTwain
using (TWCapability xres = new TWCapability(CapabilityId.ICapXResolution, one)) using (TWCapability xres = new TWCapability(CapabilityId.ICapXResolution, one))
{ {
var rc = _session.DGControl.Capability.Set(xres); var rc = Session.DGControl.Capability.Set(xres);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
one.Item = (uint)yDPI; one.Item = (uint)yDPI;
using (TWCapability yres = new TWCapability(CapabilityId.ICapYResolution, one)) using (TWCapability yres = new TWCapability(CapabilityId.ICapYResolution, one))
{ {
rc = _session.DGControl.Capability.Set(yres); rc = Session.DGControl.Capability.Set(yres);
} }
} }
return rc; return rc;
@@ -322,7 +322,7 @@ namespace NTwain
using (TWCapability xres = new TWCapability(CapabilityId.ICapSupportedSizes, one)) using (TWCapability xres = new TWCapability(CapabilityId.ICapSupportedSizes, one))
{ {
var rc = _session.DGControl.Capability.Set(xres); var rc = Session.DGControl.Capability.Set(xres);
return rc; return rc;
} }
} }
@@ -351,7 +351,7 @@ namespace NTwain
using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticDeskew, en)) using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticDeskew, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
else else
@@ -362,7 +362,7 @@ namespace NTwain
using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticDeskew, one)) using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticDeskew, one))
{ {
rc = _session.DGControl.Capability.Set(capValue); rc = Session.DGControl.Capability.Set(capValue);
} }
} }
} }
@@ -389,7 +389,7 @@ namespace NTwain
using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticRotate, en)) using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticRotate, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
else else
@@ -400,7 +400,7 @@ namespace NTwain
using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticRotate, one)) using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticRotate, one))
{ {
rc = _session.DGControl.Capability.Set(capValue); rc = Session.DGControl.Capability.Set(capValue);
} }
} }
} }
@@ -428,11 +428,11 @@ namespace NTwain
using (TWCapability dx = new TWCapability(CapabilityId.ICapUndefinedImageSize, en)) using (TWCapability dx = new TWCapability(CapabilityId.ICapUndefinedImageSize, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, en)) using (TWCapability dx = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
else else
@@ -443,11 +443,11 @@ namespace NTwain
using (TWCapability capValue = new TWCapability(CapabilityId.ICapUndefinedImageSize, one)) using (TWCapability capValue = new TWCapability(CapabilityId.ICapUndefinedImageSize, one))
{ {
rc = _session.DGControl.Capability.Set(capValue); rc = Session.DGControl.Capability.Set(capValue);
} }
using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, one)) using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, one))
{ {
rc = _session.DGControl.Capability.Set(capValue); rc = Session.DGControl.Capability.Set(capValue);
} }
} }
} }
@@ -471,7 +471,7 @@ namespace NTwain
using (TWCapability dx = new TWCapability(CapabilityId.CapDuplexEnabled, en)) using (TWCapability dx = new TWCapability(CapabilityId.CapDuplexEnabled, en))
{ {
return _session.DGControl.Capability.Set(dx); return Session.DGControl.Capability.Set(dx);
} }
} }
else else
@@ -482,7 +482,7 @@ namespace NTwain
using (TWCapability dx = new TWCapability(CapabilityId.CapDuplexEnabled, one)) using (TWCapability dx = new TWCapability(CapabilityId.CapDuplexEnabled, one))
{ {
return _session.DGControl.Capability.Set(dx); return Session.DGControl.Capability.Set(dx);
} }
} }
} }
@@ -512,7 +512,7 @@ namespace NTwain
{ {
using (TWCapability dx = new TWCapability(CapabilityId.CapFeederEnabled, en)) using (TWCapability dx = new TWCapability(CapabilityId.CapFeederEnabled, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
@@ -522,14 +522,14 @@ namespace NTwain
{ {
using (TWCapability dx = new TWCapability(CapabilityId.CapAutoScan, en)) using (TWCapability dx = new TWCapability(CapabilityId.CapAutoScan, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
else if (SupportedCaps.Contains(CapabilityId.CapAutoFeed)) else if (SupportedCaps.Contains(CapabilityId.CapAutoFeed))
{ {
using (TWCapability dx = new TWCapability(CapabilityId.CapAutoFeed, en)) using (TWCapability dx = new TWCapability(CapabilityId.CapAutoFeed, en))
{ {
rc = _session.DGControl.Capability.Set(dx); rc = Session.DGControl.Capability.Set(dx);
} }
} }
} }
@@ -543,7 +543,7 @@ namespace NTwain
{ {
using (TWCapability enabled = new TWCapability(CapabilityId.CapFeederEnabled, one)) using (TWCapability enabled = new TWCapability(CapabilityId.CapFeederEnabled, one))
{ {
rc = _session.DGControl.Capability.Set(enabled); rc = Session.DGControl.Capability.Set(enabled);
} }
} }
// to really use feeder we must also set autofeed or autoscan, but only // to really use feeder we must also set autofeed or autoscan, but only
@@ -552,14 +552,14 @@ namespace NTwain
{ {
using (TWCapability autoScan = new TWCapability(CapabilityId.CapAutoScan, one)) using (TWCapability autoScan = new TWCapability(CapabilityId.CapAutoScan, one))
{ {
rc = _session.DGControl.Capability.Set(autoScan); rc = Session.DGControl.Capability.Set(autoScan);
} }
} }
else if (SupportedCaps.Contains(CapabilityId.CapAutoFeed)) else if (SupportedCaps.Contains(CapabilityId.CapAutoFeed))
{ {
using (TWCapability autoScan = new TWCapability(CapabilityId.CapAutoFeed, one)) using (TWCapability autoScan = new TWCapability(CapabilityId.CapAutoFeed, one))
{ {
rc = _session.DGControl.Capability.Set(autoScan); rc = Session.DGControl.Capability.Set(autoScan);
} }
} }
} }

View File

@@ -17,11 +17,11 @@ namespace NTwain
/// </summary> /// </summary>
public partial class TwainSource public partial class TwainSource
{ {
ITwainSessionInternal _session; internal ITwainSessionInternal Session { get; set; }
internal TwainSource(ITwainSessionInternal session, TWIdentity sourceId) internal TwainSource(ITwainSessionInternal session, TWIdentity sourceId)
{ {
_session = session; Session = session;
Identity = sourceId; Identity = sourceId;
} }
@@ -32,11 +32,11 @@ namespace NTwain
public ReturnCode Open() public ReturnCode Open()
{ {
var rc = ReturnCode.Failure; var rc = ReturnCode.Failure;
_session.MessageLoopHook.Invoke(() => Session.MessageLoopHook.Invoke(() =>
{ {
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId)); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
rc = _session.DGControl.Identity.OpenDS(this); rc = Session.DGControl.Identity.OpenDS(this);
}); });
return rc; return rc;
} }
@@ -48,11 +48,11 @@ namespace NTwain
public ReturnCode Close() public ReturnCode Close()
{ {
var rc = ReturnCode.Failure; var rc = ReturnCode.Failure;
_session.MessageLoopHook.Invoke(() => Session.MessageLoopHook.Invoke(() =>
{ {
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId)); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId));
rc = _session.DGControl.Identity.CloseDS(); rc = Session.DGControl.Identity.CloseDS();
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
SupportedCaps = null; SupportedCaps = null;
@@ -71,7 +71,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public ReturnCode StartTransfer(SourceEnableMode mode, bool modal, IntPtr windowHandle) public ReturnCode StartTransfer(SourceEnableMode mode, bool modal, IntPtr windowHandle)
{ {
return _session.EnableSource(mode, modal, windowHandle); return Session.EnableSource(mode, modal, windowHandle);
} }
/// <summary> /// <summary>
@@ -81,7 +81,7 @@ namespace NTwain
public TWStatus GetStatus() public TWStatus GetStatus()
{ {
TWStatus stat; TWStatus stat;
_session.DGControl.Status.GetSource(out stat); Session.DGControl.Status.GetSource(out stat);
return stat; return stat;
} }
/// <summary> /// <summary>
@@ -91,7 +91,7 @@ namespace NTwain
public TWStatusUtf8 GetStatusUtf8() public TWStatusUtf8 GetStatusUtf8()
{ {
TWStatusUtf8 stat; TWStatusUtf8 stat;
_session.DGControl.StatusUtf8.GetSource(out stat); Session.DGControl.StatusUtf8.GetSource(out stat);
return stat; return stat;
} }
@@ -170,7 +170,7 @@ namespace NTwain
{ {
get get
{ {
if (_supportedCaps == null && _session.State > 3) if (_supportedCaps == null && Session.State > 3)
{ {
_supportedCaps = CapGetValues(CapabilityId.CapSupportedCaps).CastToEnum<CapabilityId>(false); _supportedCaps = CapGetValues(CapabilityId.CapSupportedCaps).CastToEnum<CapabilityId>(false);
} }
@@ -191,7 +191,7 @@ namespace NTwain
{ {
get get
{ {
return _session.DGControl; return Session.DGControl;
} }
} }
@@ -202,7 +202,7 @@ namespace NTwain
{ {
get get
{ {
return _session.DGImage; return Session.DGImage;
} }
} }
@@ -213,7 +213,7 @@ namespace NTwain
{ {
get get
{ {
return _session.DGCustom; return Session.DGCustom;
} }
} }
@@ -232,7 +232,7 @@ namespace NTwain
///// <param name="propertyName">Name of the property.</param> ///// <param name="propertyName">Name of the property.</param>
//protected void OnPropertyChanged(string propertyName) //protected void OnPropertyChanged(string propertyName)
//{ //{
// var syncer = _session.SynchronizationContext; // var syncer = Session.SynchronizationContext;
// if (syncer == null) // if (syncer == null)
// { // {
// try // try

View File

@@ -1,7 +1,7 @@
<Application x:Class="Tester.WPF.App" <Application x:Class="Tester.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"> StartupUri="Dummy.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<!-- Dummy Style, anything you won't use goes --> <!-- Dummy Style, anything you won't use goes -->

View File

@@ -0,0 +1,12 @@
<Window x:Class="Tester.WPF.Dummy"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Dummy" Height="300" Width="300">
<Grid>
<StackPanel VerticalAlignment="Center">
<Button Content="Open scan window" Click="Button_Click" Margin="4 0"></Button>
<TextBlock Text="This is to test opening/closing multiple twain sessions in an app" Margin="8"
TextWrapping="Wrap"></TextBlock>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Tester.WPF
{
/// <summary>
/// Interaction logic for Dummy.xaml
/// </summary>
public partial class Dummy : Window
{
public Dummy()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
new MainWindow().ShowDialog();
}
}
}

View File

@@ -4,6 +4,7 @@ using NTwain;
using NTwain.Data; using NTwain.Data;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@@ -51,13 +52,18 @@ namespace Tester.WPF
}); });
} }
} }
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = _twainVM.State > 4;
base.OnClosing(e);
}
protected override void OnClosed(EventArgs e) protected override void OnClosed(EventArgs e)
{ {
if (_twainVM.State == 4) if (_twainVM.State == 4)
{ {
_twainVM.CurrentSource.Close(); _twainVM.CurrentSource.Close();
} }
_twainVM.Close();
base.OnClosed(e); base.OnClosed(e);
} }
@@ -68,6 +74,8 @@ namespace Tester.WPF
// use this for internal msg loop // use this for internal msg loop
//var rc = _twainVM.Open(); //var rc = _twainVM.Open();
// use this to hook into current app loop // use this to hook into current app loop
var rc = _twainVM.Open(new WpfMessageLoopHook(new WindowInteropHelper(this).Handle)); var rc = _twainVM.Open(new WpfMessageLoopHook(new WindowInteropHelper(this).Handle));
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
@@ -82,6 +90,15 @@ namespace Tester.WPF
private void SrcList_SelectionChanged(object sender, SelectionChangedEventArgs e) private void SrcList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
//var test = new NTwain.Internals.InternalMessageLoopHook();
//test.StartTest();
//test.BeginInvoke(() =>
//{
// Debug.WriteLine("doodle");
// test.StopTest();
//});
if (_twainVM.State == 4) if (_twainVM.State == 4)
{ {
_twainVM.CurrentSource.Close(); _twainVM.CurrentSource.Close();

View File

@@ -80,7 +80,14 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Dummy.xaml.cs">
<DependentUpon>Dummy.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\TwainVM.cs" /> <Compile Include="ViewModels\TwainVM.cs" />
<Page Include="Dummy.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

View File

@@ -3,6 +3,7 @@ using GalaSoft.MvvmLight.Messaging;
using NTwain; using NTwain;
using NTwain.Data; using NTwain.Data;
using System; using System;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Windows.Media; using System.Windows.Media;
@@ -76,12 +77,23 @@ namespace Tester.WPF
var fileSetup = new TWSetupFileXfer var fileSetup = new TWSetupFileXfer
{ {
Format = wantFormat, Format = wantFormat,
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif") FileName = GetUniqueName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test", ".tif")
}; };
var rc = this.CurrentSource.DGControl.SetupFileXfer.Set(fileSetup); var rc = this.CurrentSource.DGControl.SetupFileXfer.Set(fileSetup);
} }
} }
private string GetUniqueName(string dir, string name, string ext)
{
var filePath = Path.Combine(dir, name + ext);
int next = 1;
while (File.Exists(filePath))
{
filePath = Path.Combine(dir, string.Format("{0} ({1}){2}", name, next++, ext));
}
return filePath;
}
protected override void OnDataTransferred(DataTransferredEventArgs e) protected override void OnDataTransferred(DataTransferredEventArgs e)
{ {
ImageSource img = null; ImageSource img = null;

View File

@@ -40,6 +40,8 @@ namespace Tester.Winform
} }
protected override void OnFormClosing(FormClosingEventArgs e) protected override void OnFormClosing(FormClosingEventArgs e)
{
if (_twain != null)
{ {
if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4) if (e.CloseReason == CloseReason.UserClosing && _twain.State > 4)
{ {
@@ -49,6 +51,7 @@ namespace Tester.Winform
{ {
CleanupTwain(); CleanupTwain();
} }
}
base.OnFormClosing(e); base.OnFormClosing(e);
} }
@@ -104,8 +107,6 @@ namespace Tester.Winform
} }
private void CleanupTwain() private void CleanupTwain()
{
if (_twain != null)
{ {
if (_twain.State == 4) if (_twain.State == 4)
{ {
@@ -122,7 +123,6 @@ namespace Tester.Winform
_twain.ForceStepDown(2); _twain.ForceStepDown(2);
} }
} }
}
#endregion #endregion
@@ -245,7 +245,7 @@ namespace Tester.Winform
// use this for internal msg loop // use this for internal msg loop
_twain.Open(); _twain.Open();
// use this to hook into current app loop // use this to hook into current app loop
//_twain.Open(new WinformMessageLoopHook(this.Handle)); //_twain.Open(new WindowsFormsMessageLoopHook(this.Handle));
} }
if (_twain.State >= 3) if (_twain.State >= 3)