mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-08 10:34:47 +08:00
Some refactor ideas
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using NTwain.Properties;
|
using NTwain.Properties;
|
||||||
using NTwain.Values;
|
using NTwain.Values;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Permissions;
|
using System.Security.Permissions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -663,7 +665,7 @@ namespace NTwain.Data
|
|||||||
var value = new TWOneValue();
|
var value = new TWOneValue();
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = MemoryManager.Global.MemLock(_hContainer);
|
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@@ -672,7 +674,7 @@ namespace NTwain.Data
|
|||||||
value.Item = (uint)ReadValue(baseAddr, ref offset, ItemType.UInt32);
|
value.Item = (uint)ReadValue(baseAddr, ref offset, ItemType.UInt32);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
MemoryManager.Global.MemUnlock(_hContainer);
|
MemoryManager.Instance.MemUnlock(_hContainer);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -686,7 +688,7 @@ namespace NTwain.Data
|
|||||||
// since one value can only house UInt32 we will not allow type size > 4
|
// since one value can only house UInt32 we will not allow type size > 4
|
||||||
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid one value type"); }
|
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid one value type"); }
|
||||||
|
|
||||||
_hContainer = MemoryManager.Global.MemAllocate((uint)Marshal.SizeOf(value));
|
_hContainer = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(value));
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Marshal.StructureToPtr(value, _hContainer, false);
|
Marshal.StructureToPtr(value, _hContainer, false);
|
||||||
@@ -705,7 +707,7 @@ namespace NTwain.Data
|
|||||||
var value = new TWArray();
|
var value = new TWArray();
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = MemoryManager.Global.MemLock(_hContainer);
|
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
@@ -719,7 +721,7 @@ namespace NTwain.Data
|
|||||||
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
|
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MemoryManager.Global.MemUnlock(_hContainer);
|
MemoryManager.Instance.MemUnlock(_hContainer);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -736,7 +738,7 @@ namespace NTwain.Data
|
|||||||
var value = new TWEnumeration();
|
var value = new TWEnumeration();
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = MemoryManager.Global.MemLock(_hContainer);
|
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
@@ -754,7 +756,7 @@ namespace NTwain.Data
|
|||||||
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
|
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MemoryManager.Global.MemUnlock(_hContainer);
|
MemoryManager.Instance.MemUnlock(_hContainer);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -768,8 +770,8 @@ namespace NTwain.Data
|
|||||||
Int32 valueSize = value.ItemOffset + value.ItemList.Length * GetItemTypeSize(value.ItemType);
|
Int32 valueSize = value.ItemOffset + value.ItemList.Length * GetItemTypeSize(value.ItemType);
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
_hContainer = MemoryManager.Global.MemAllocate((uint)valueSize);
|
_hContainer = MemoryManager.Instance.MemAllocate((uint)valueSize);
|
||||||
IntPtr baseAddr = MemoryManager.Global.MemLock(_hContainer);
|
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
|
||||||
|
|
||||||
// can't safely use StructureToPtr here so write it our own
|
// can't safely use StructureToPtr here so write it our own
|
||||||
WriteValue(baseAddr, ref offset, ItemType.UInt16, value.ItemType);
|
WriteValue(baseAddr, ref offset, ItemType.UInt16, value.ItemType);
|
||||||
@@ -780,7 +782,7 @@ namespace NTwain.Data
|
|||||||
{
|
{
|
||||||
WriteValue(baseAddr, ref offset, value.ItemType, item);
|
WriteValue(baseAddr, ref offset, value.ItemType, item);
|
||||||
}
|
}
|
||||||
MemoryManager.Global.MemUnlock(_hContainer);
|
MemoryManager.Instance.MemUnlock(_hContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -795,7 +797,7 @@ namespace NTwain.Data
|
|||||||
var value = new TWRange();
|
var value = new TWRange();
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = MemoryManager.Global.MemLock(_hContainer);
|
IntPtr baseAddr = MemoryManager.Instance.MemLock(_hContainer);
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
@@ -810,7 +812,7 @@ namespace NTwain.Data
|
|||||||
offset += 4;
|
offset += 4;
|
||||||
value.CurrentValue = (uint)Marshal.ReadInt32(baseAddr, offset);
|
value.CurrentValue = (uint)Marshal.ReadInt32(baseAddr, offset);
|
||||||
|
|
||||||
MemoryManager.Global.MemUnlock(_hContainer);
|
MemoryManager.Instance.MemUnlock(_hContainer);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -823,7 +825,7 @@ namespace NTwain.Data
|
|||||||
// since range value can only house UInt32 we will not allow type size > 4
|
// since range value can only house UInt32 we will not allow type size > 4
|
||||||
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid range value type"); }
|
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid range value type"); }
|
||||||
|
|
||||||
_hContainer = MemoryManager.Global.MemAllocate((uint)Marshal.SizeOf(value));
|
_hContainer = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(value));
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Marshal.StructureToPtr(value, _hContainer, false);
|
Marshal.StructureToPtr(value, _hContainer, false);
|
||||||
@@ -1123,7 +1125,7 @@ namespace NTwain.Data
|
|||||||
{
|
{
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
MemoryManager.Global.MemFree(_hContainer);
|
MemoryManager.Instance.MemFree(_hContainer);
|
||||||
_hContainer = IntPtr.Zero;
|
_hContainer = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
@@ -1136,7 +1138,7 @@ namespace NTwain.Data
|
|||||||
{
|
{
|
||||||
if (_hContainer != IntPtr.Zero)
|
if (_hContainer != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
MemoryManager.Global.MemFree(_hContainer);
|
MemoryManager.Instance.MemFree(_hContainer);
|
||||||
_hContainer = IntPtr.Zero;
|
_hContainer = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1857,12 +1859,24 @@ namespace NTwain.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ProductName { get { return _productName; } set { value.VerifyLengthUnder(TwainConst.String32 - 1); _productName = value; } }
|
public string ProductName { get { return _productName; } set { value.VerifyLengthUnder(TwainConst.String32 - 1); _productName = value; } }
|
||||||
|
|
||||||
//public static TWIdentity CreateFromAssembly(DataGroups supportedGroups)
|
|
||||||
//{
|
|
||||||
// return Create(supportedGroups);
|
|
||||||
//}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="TWIdentity"/> specified values.
|
/// Creates a <see cref="TWIdentity"/> from assembly values.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="supportedGroups">The supported groups.</param>
|
||||||
|
/// <param name="assembly">The assembly.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentNullException">assembly</exception>
|
||||||
|
public static TWIdentity CreateFromAssembly(DataGroups supportedGroups, Assembly assembly)
|
||||||
|
{
|
||||||
|
if (assembly == null) { throw new ArgumentNullException("assembly"); }
|
||||||
|
|
||||||
|
var info = FileVersionInfo.GetVersionInfo(assembly.Location);
|
||||||
|
|
||||||
|
return Create(supportedGroups, assembly.GetName().Version, info.CompanyName, info.ProductName, info.ProductName, info.FileDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="TWIdentity"/> from specified values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="supportedGroups">The supported groups.</param>
|
/// <param name="supportedGroups">The supported groups.</param>
|
||||||
/// <param name="version">The version.</param>
|
/// <param name="version">The version.</param>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
@@ -6,7 +7,7 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for keeping track of current TWAIN state with current app and source ids.
|
/// Interface for keeping track of current TWAIN state with current app and source ids.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITwainSession : INotifyPropertyChanged
|
public interface ITwainState : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the app id used for the session.
|
/// Gets the app id used for the session.
|
||||||
@@ -27,10 +28,11 @@ namespace NTwain
|
|||||||
int State { get; }
|
int State { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal interface for state management.
|
/// Internal interface for state management.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
interface ITwainSessionInternal : ITwainSession
|
interface ITwainStateInternal : ITwainState
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
|
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
|
||||||
@@ -54,6 +56,8 @@ namespace NTwain
|
|||||||
/// <param name="newState">The new state.</param>
|
/// <param name="newState">The new state.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
ICommitable GetPendingStateChanger(int newState);
|
ICommitable GetPendingStateChanger(int newState);
|
||||||
|
|
||||||
|
void ChangeSourceId(TWIdentity sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICommitable : IDisposable
|
interface ICommitable : IDisposable
|
||||||
@@ -9,15 +9,14 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides methods for managing memory on data exchanged with twain sources.
|
/// Provides methods for managing memory on data exchanged with twain sources.
|
||||||
/// This should only be used after the DSM has been opened in <see cref="TwainSession"/>
|
/// This should only be used after the DSM has been opened.
|
||||||
/// via <see cref="TwainSession.OpenManager"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MemoryManager
|
public class MemoryManager : IMemoryManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the global <see cref="MemoryManager"/> instance.
|
/// Gets the singleton <see cref="MemoryManager"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly MemoryManager Global = new MemoryManager();
|
public static readonly MemoryManager Instance = new MemoryManager();
|
||||||
|
|
||||||
private MemoryManager() { }
|
private MemoryManager() { }
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ namespace NTwain
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 0x0040 is GPTR
|
// 0x0040 is GPTR
|
||||||
return GlobalAlloc(0x0040, new UIntPtr(size));
|
return WinGlobalAlloc(0x0040, new UIntPtr(size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalFree(handle);
|
WinGlobalFree(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return GlobalLock(handle);
|
return WinGlobalLock(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,24 +94,25 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalUnlock(handle);
|
WinGlobalUnlock(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region old mem stuff for twain 1.x
|
#region old mem stuff for twain 1.x
|
||||||
|
|
||||||
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
|
|
||||||
static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes);
|
|
||||||
|
|
||||||
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
|
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalAlloc")]
|
||||||
static extern IntPtr GlobalFree(IntPtr hMem);
|
static extern IntPtr WinGlobalAlloc(uint uFlags, UIntPtr dwBytes);
|
||||||
|
|
||||||
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
|
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalFree")]
|
||||||
static extern IntPtr GlobalLock(IntPtr handle);
|
static extern IntPtr WinGlobalFree(IntPtr hMem);
|
||||||
|
|
||||||
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
|
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalLock")]
|
||||||
|
static extern IntPtr WinGlobalLock(IntPtr handle);
|
||||||
|
|
||||||
|
[DllImport("kernel32", SetLastError = true, EntryPoint = "GlobalUnlock")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool GlobalUnlock(IntPtr handle);
|
static extern bool WinGlobalUnlock(IntPtr handle);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
@@ -60,7 +57,9 @@
|
|||||||
<Compile Include="DeviceEventArgs.cs" />
|
<Compile Include="DeviceEventArgs.cs" />
|
||||||
<Compile Include="Extensions.cs" />
|
<Compile Include="Extensions.cs" />
|
||||||
<Compile Include="DataTransferredEventArgs.cs" />
|
<Compile Include="DataTransferredEventArgs.cs" />
|
||||||
<Compile Include="ITwainSession.cs" />
|
<Compile Include="IMemoryManager.cs" />
|
||||||
|
<Compile Include="ITwainOperation.cs" />
|
||||||
|
<Compile Include="ITwainState.cs" />
|
||||||
<Compile Include="MemoryManager.cs" />
|
<Compile Include="MemoryManager.cs" />
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
@@ -68,6 +67,7 @@
|
|||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\VersionInfo.cs" />
|
<Compile Include="Properties\VersionInfo.cs" />
|
||||||
|
<Compile Include="TentativeStateCommitable.cs" />
|
||||||
<Compile Include="TransferReadyEventArgs.cs" />
|
<Compile Include="TransferReadyEventArgs.cs" />
|
||||||
<Compile Include="Triplets\DGControl\DGControl.Callback2.cs" />
|
<Compile Include="Triplets\DGControl\DGControl.Callback2.cs" />
|
||||||
<Compile Include="Triplets\DGImage\DGImage.Filter.cs" />
|
<Compile Include="Triplets\DGImage\DGImage.Filter.cs" />
|
||||||
@@ -75,6 +75,7 @@
|
|||||||
<Compile Include="Triplets\PInvokes.32bit.cs" />
|
<Compile Include="Triplets\PInvokes.32bit.cs" />
|
||||||
<Compile Include="Triplets\PInvokes.64bit.cs" />
|
<Compile Include="Triplets\PInvokes.64bit.cs" />
|
||||||
<Compile Include="TwainSessionExtensions.cs" />
|
<Compile Include="TwainSessionExtensions.cs" />
|
||||||
|
<Compile Include="TwainSessionBase.cs" />
|
||||||
<Compile Include="TwainStateException.cs" />
|
<Compile Include="TwainStateException.cs" />
|
||||||
<Compile Include="Data\Types.cs" />
|
<Compile Include="Data\Types.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
47
NTwain/TentativeStateCommitable.cs
Normal file
47
NTwain/TentativeStateCommitable.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
class TentativeStateCommitable : ICommitable
|
||||||
|
{
|
||||||
|
bool _commit;
|
||||||
|
ITwainStateInternal _session;
|
||||||
|
int _origState;
|
||||||
|
int _newState;
|
||||||
|
public TentativeStateCommitable(ITwainStateInternal session, int newState)
|
||||||
|
{
|
||||||
|
_session = session;
|
||||||
|
_origState = session.State;
|
||||||
|
_newState = newState;
|
||||||
|
_session.ChangeState(newState, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region ICommitable Members
|
||||||
|
|
||||||
|
public void Commit()
|
||||||
|
{
|
||||||
|
if (_session.State == _newState)
|
||||||
|
{
|
||||||
|
_session.ChangeState(_newState, true);
|
||||||
|
}
|
||||||
|
_commit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable Members
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (!_commit && _session.State == _newState)
|
||||||
|
{
|
||||||
|
_session.ChangeState(_origState, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class AudioFileXfer : OpBase
|
sealed class AudioFileXfer : OpBase
|
||||||
{
|
{
|
||||||
internal AudioFileXfer(ITwainSessionInternal session) : base(session) { }
|
internal AudioFileXfer(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation is used to initiate the transfer of audio from the Source to the application via the
|
/// This operation is used to initiate the transfer of audio from the Source to the application via the
|
||||||
/// disk-file transfer mechanism. It causes the transfer to begin.
|
/// disk-file transfer mechanism. It causes the transfer to begin.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class AudioInfo : OpBase
|
public sealed class AudioInfo : OpBase
|
||||||
{
|
{
|
||||||
internal AudioInfo(ITwainSessionInternal session) : base(session) { }
|
internal AudioInfo(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to get the information of the current audio data ready to transfer.
|
/// Used to get the information of the current audio data ready to transfer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class AudioNativeXfer : OpBase
|
sealed class AudioNativeXfer : OpBase
|
||||||
{
|
{
|
||||||
internal AudioNativeXfer(ITwainSessionInternal session) : base(session) { }
|
internal AudioNativeXfer(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes the transfer of an audio data from the Source to the application, via the Native
|
/// Causes the transfer of an audio data from the Source to the application, via the Native
|
||||||
/// transfer mechanism, to begin. The resulting data is stored in main memory in a single block.
|
/// transfer mechanism, to begin. The resulting data is stored in main memory in a single block.
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DGAudio
|
public sealed class DGAudio
|
||||||
{
|
{
|
||||||
ITwainSessionInternal _session;
|
ITwainStateInternal _session;
|
||||||
internal DGAudio(ITwainSessionInternal session)
|
internal DGAudio(ITwainStateInternal session)
|
||||||
{
|
{
|
||||||
if (session == null) { throw new ArgumentNullException("session"); }
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
_session = session;
|
_session = session;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class Callback : OpBase
|
sealed class Callback : OpBase
|
||||||
{
|
{
|
||||||
internal Callback(ITwainSessionInternal session) : base(session) { }
|
internal Callback(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This triplet is sent to the DSM by the Application to register the application’s entry point with
|
/// This triplet is sent to the DSM by the Application to register the application’s entry point with
|
||||||
/// the DSM, so that the DSM can use callbacks to inform the application of events generated by the
|
/// the DSM, so that the DSM can use callbacks to inform the application of events generated by the
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class Callback2 : OpBase
|
sealed class Callback2 : OpBase
|
||||||
{
|
{
|
||||||
internal Callback2(ITwainSessionInternal session) : base(session) { }
|
internal Callback2(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This triplet is sent to the DSM by the Application to register the application’s entry point with
|
/// This triplet is sent to the DSM by the Application to register the application’s entry point with
|
||||||
/// the DSM, so that the DSM can use callbacks to inform the application of events generated by the
|
/// the DSM, so that the DSM can use callbacks to inform the application of events generated by the
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Capability : OpBase
|
public sealed class Capability : OpBase
|
||||||
{
|
{
|
||||||
internal Capability(ITwainSessionInternal session) : base(session) { }
|
internal Capability(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Source’s Current, Default and Available Values for a specified capability.
|
/// Returns the Source’s Current, Default and Available Values for a specified capability.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class CustomDSData : OpBase
|
public sealed class CustomDSData : OpBase
|
||||||
{
|
{
|
||||||
internal CustomDSData(ITwainSessionInternal session) : base(session) { }
|
internal CustomDSData(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation is used by the application to query the data source for its current settings, e.g.
|
/// This operation is used by the application to query the data source for its current settings, e.g.
|
||||||
/// DPI, paper size, color format. The actual format of the data is data source dependent and not
|
/// DPI, paper size, color format. The actual format of the data is data source dependent and not
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DeviceEvent : OpBase
|
public sealed class DeviceEvent : OpBase
|
||||||
{
|
{
|
||||||
internal DeviceEvent(ITwainSessionInternal session) : base(session) { }
|
internal DeviceEvent(ITwainStateInternal session) : base(session) { }
|
||||||
public ReturnCode Get(out TWDeviceEvent sourceDeviceEvent)
|
public ReturnCode Get(out TWDeviceEvent sourceDeviceEvent)
|
||||||
{
|
{
|
||||||
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get);
|
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.DeviceEvent, Message.Get);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class EntryPoint : OpBase
|
sealed class EntryPoint : OpBase
|
||||||
{
|
{
|
||||||
internal EntryPoint(ITwainSessionInternal session) : base(session) { }
|
internal EntryPoint(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the function entry points for twain 2.0 or higher.
|
/// Gets the function entry points for twain 2.0 or higher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class Event : OpBase
|
sealed class Event : OpBase
|
||||||
{
|
{
|
||||||
internal Event(ITwainSessionInternal session) : base(session) { }
|
internal Event(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation supports the distribution of events from the application to Sources so that the
|
/// This operation supports the distribution of events from the application to Sources so that the
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class FileSystem : OpBase
|
public sealed class FileSystem : OpBase
|
||||||
{
|
{
|
||||||
internal FileSystem(ITwainSessionInternal session) : base(session) { }
|
internal FileSystem(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation selects the destination directory within the Source (camera, storage, etc), where
|
/// This operation selects the destination directory within the Source (camera, storage, etc), where
|
||||||
/// images captured using CapAutomaticCapture will be stored. This command only selects
|
/// images captured using CapAutomaticCapture will be stored. This command only selects
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Identity : OpBase
|
public sealed class Identity : OpBase
|
||||||
{
|
{
|
||||||
internal Identity(ITwainSessionInternal session) : base(session) { }
|
internal Identity(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When an application is finished with a Source, it must formally close the session between them
|
/// When an application is finished with a Source, it must formally close the session between them
|
||||||
/// using this operation. This is necessary in case the Source only supports connection with a single
|
/// using this operation. This is necessary in case the Source only supports connection with a single
|
||||||
@@ -23,6 +23,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = PInvoke.DsmEntry(Session.AppId, Message.CloseDS, Session.SourceId);
|
var rc = PInvoke.DsmEntry(Session.AppId, Message.CloseDS, Session.SourceId);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
|
Session.ChangeSourceId(null);
|
||||||
Session.ChangeState(3, true);
|
Session.ChangeState(3, true);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@@ -78,6 +79,7 @@ namespace NTwain.Triplets
|
|||||||
var rc = PInvoke.DsmEntry(Session.AppId, Message.OpenDS, source);
|
var rc = PInvoke.DsmEntry(Session.AppId, Message.OpenDS, source);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
|
Session.ChangeSourceId(source);
|
||||||
Session.ChangeState(4, true);
|
Session.ChangeState(4, true);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class Parent : OpBase
|
sealed class Parent : OpBase
|
||||||
{
|
{
|
||||||
internal Parent(ITwainSessionInternal session) : base(session) { }
|
internal Parent(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When the application has closed all the Sources it had previously opened, and is finished with
|
/// When the application has closed all the Sources it had previously opened, and is finished with
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class PassThru : OpBase
|
public sealed class PassThru : OpBase
|
||||||
{
|
{
|
||||||
internal PassThru(ITwainSessionInternal session) : base(session) { }
|
internal PassThru(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// PASSTHRU is intended for the use of Source writers writing diagnostic applications. It allows
|
/// PASSTHRU is intended for the use of Source writers writing diagnostic applications. It allows
|
||||||
/// raw communication with the currently selected device in the Source.
|
/// raw communication with the currently selected device in the Source.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class PendingXfers : OpBase
|
sealed class PendingXfers : OpBase
|
||||||
{
|
{
|
||||||
internal PendingXfers(ITwainSessionInternal session) : base(session) { }
|
internal PendingXfers(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This triplet is used to cancel or terminate a transfer. Issued in state 6, this triplet cancels the next
|
/// This triplet is used to cancel or terminate a transfer. Issued in state 6, this triplet cancels the next
|
||||||
/// pending transfer, discards the transfer data, and decrements the pending transfers count. In
|
/// pending transfer, discards the transfer data, and decrements the pending transfers count. In
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SetupFileXfer : OpBase
|
public sealed class SetupFileXfer : OpBase
|
||||||
{
|
{
|
||||||
internal SetupFileXfer(ITwainSessionInternal session) : base(session) { }
|
internal SetupFileXfer(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns information about the file into which the Source has or will put the acquired image
|
/// Returns information about the file into which the Source has or will put the acquired image
|
||||||
/// or audio data.
|
/// or audio data.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SetupMemXfer : OpBase
|
public sealed class SetupMemXfer : OpBase
|
||||||
{
|
{
|
||||||
internal SetupMemXfer(ITwainSessionInternal session) : base(session) { }
|
internal SetupMemXfer(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Source’s preferred, minimum, and maximum allocation sizes for transfer memory
|
/// Returns the Source’s preferred, minimum, and maximum allocation sizes for transfer memory
|
||||||
/// buffers.
|
/// buffers.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Status : OpBase
|
public sealed class Status : OpBase
|
||||||
{
|
{
|
||||||
internal Status(ITwainSessionInternal session) : base(session) { }
|
internal Status(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the current Condition Code for the Source Manager.
|
/// Returns the current Condition Code for the Source Manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class StatusUtf8 : OpBase
|
public sealed class StatusUtf8 : OpBase
|
||||||
{
|
{
|
||||||
internal StatusUtf8(ITwainSessionInternal session) : base(session) { }
|
internal StatusUtf8(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Translate the contents of a TW_STATUS structure received from a Source into a localized UTF-8
|
/// Translate the contents of a TW_STATUS structure received from a Source into a localized UTF-8
|
||||||
/// encoded string.
|
/// encoded string.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class UserInterface : OpBase
|
sealed class UserInterface : OpBase
|
||||||
{
|
{
|
||||||
internal UserInterface(ITwainSessionInternal session) : base(session) { }
|
internal UserInterface(ITwainStateInternal session) : base(session) { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation causes the Source’s user interface, if displayed during the
|
/// This operation causes the Source’s user interface, if displayed during the
|
||||||
/// EnableDS operation, to be lowered. The Source is returned to
|
/// EnableDS operation, to be lowered. The Source is returned to
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class XferGroup : OpBase
|
public sealed class XferGroup : OpBase
|
||||||
{
|
{
|
||||||
internal XferGroup(ITwainSessionInternal session) : base(session) { }
|
internal XferGroup(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to
|
/// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DGControl
|
public sealed class DGControl
|
||||||
{
|
{
|
||||||
ITwainSessionInternal _session;
|
ITwainStateInternal _session;
|
||||||
internal DGControl(ITwainSessionInternal session)
|
internal DGControl(ITwainStateInternal session)
|
||||||
{
|
{
|
||||||
if (session == null) { throw new ArgumentNullException("session"); }
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
_session = session;
|
_session = session;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class CieColor : OpBase
|
public sealed class CieColor : OpBase
|
||||||
{
|
{
|
||||||
internal CieColor(ITwainSessionInternal session) : base(session) { }
|
internal CieColor(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation causes the Source to report the currently active parameters to be used in
|
/// This operation causes the Source to report the currently active parameters to be used in
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ExtImageInfo : OpBase
|
public sealed class ExtImageInfo : OpBase
|
||||||
{
|
{
|
||||||
internal ExtImageInfo(ITwainSessionInternal session) : base(session) { }
|
internal ExtImageInfo(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode Get(TWExtImageInfo info)
|
public ReturnCode Get(TWExtImageInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Filter : OpBase
|
public sealed class Filter : OpBase
|
||||||
{
|
{
|
||||||
internal Filter(ITwainSessionInternal session) : base(session) { }
|
internal Filter(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class GrayResponse : OpBase
|
public sealed class GrayResponse : OpBase
|
||||||
{
|
{
|
||||||
internal GrayResponse(ITwainSessionInternal session) : base(session) { }
|
internal GrayResponse(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Reset operation causes the Source to use its "identity response curve." The identity
|
/// The Reset operation causes the Source to use its "identity response curve." The identity
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class IccProfile : OpBase
|
public sealed class IccProfile : OpBase
|
||||||
{
|
{
|
||||||
internal IccProfile(ITwainSessionInternal session) : base(session) { }
|
internal IccProfile(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation provides the application with the ICC profile associated with the image which is
|
/// This operation provides the application with the ICC profile associated with the image which is
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class ImageFileXfer : OpBase
|
sealed class ImageFileXfer : OpBase
|
||||||
{
|
{
|
||||||
internal ImageFileXfer(ITwainSessionInternal session) : base(session) { }
|
internal ImageFileXfer(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ImageInfo : OpBase
|
public sealed class ImageInfo : OpBase
|
||||||
{
|
{
|
||||||
internal ImageInfo(ITwainSessionInternal session) : base(session) { }
|
internal ImageInfo(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode Get(out TWImageInfo info)
|
public ReturnCode Get(out TWImageInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ImageLayout : OpBase
|
public sealed class ImageLayout : OpBase
|
||||||
{
|
{
|
||||||
internal ImageLayout(ITwainSessionInternal session) : base(session) { }
|
internal ImageLayout(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
public ReturnCode Get(out TWImageLayout layout)
|
public ReturnCode Get(out TWImageLayout layout)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class ImageMemFileXfer : OpBase
|
sealed class ImageMemFileXfer : OpBase
|
||||||
{
|
{
|
||||||
internal ImageMemFileXfer(ITwainSessionInternal session) : base(session) { }
|
internal ImageMemFileXfer(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class ImageMemXfer : OpBase
|
sealed class ImageMemXfer : OpBase
|
||||||
{
|
{
|
||||||
internal ImageMemXfer(ITwainSessionInternal session) : base(session) { }
|
internal ImageMemXfer(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
/// This operation is used to initiate the transfer of an image from the Source to the application via
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace NTwain.Triplets
|
|||||||
{
|
{
|
||||||
sealed class ImageNativeXfer : OpBase
|
sealed class ImageNativeXfer : OpBase
|
||||||
{
|
{
|
||||||
internal ImageNativeXfer(ITwainSessionInternal session) : base(session) { }
|
internal ImageNativeXfer(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes the transfer of an image’s data from the Source to the application, via the Native transfer
|
/// Causes the transfer of an image’s data from the Source to the application, via the Native transfer
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class JpegCompression : OpBase
|
public sealed class JpegCompression : OpBase
|
||||||
{
|
{
|
||||||
internal JpegCompression(ITwainSessionInternal session) : base(session) { }
|
internal JpegCompression(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes the Source to return the parameters that will be used during the compression of data
|
/// Causes the Source to return the parameters that will be used during the compression of data
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Palette8 : OpBase
|
public sealed class Palette8 : OpBase
|
||||||
{
|
{
|
||||||
internal Palette8(ITwainSessionInternal session) : base(session) { }
|
internal Palette8(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This operation causes the Source to report its current palette information.
|
/// This operation causes the Source to report its current palette information.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class RgbResponse : OpBase
|
public sealed class RgbResponse : OpBase
|
||||||
{
|
{
|
||||||
internal RgbResponse(ITwainSessionInternal session) : base(session) { }
|
internal RgbResponse(ITwainStateInternal session) : base(session) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes the Source to use its "identity" response curves for future RGB transfers. The identity
|
/// Causes the Source to use its "identity" response curves for future RGB transfers. The identity
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DGImage
|
public sealed class DGImage
|
||||||
{
|
{
|
||||||
ITwainSessionInternal _session;
|
ITwainStateInternal _session;
|
||||||
internal DGImage(ITwainSessionInternal session)
|
internal DGImage(ITwainStateInternal session)
|
||||||
{
|
{
|
||||||
if (session == null) { throw new ArgumentNullException("session"); }
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
_session = session;
|
_session = session;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace NTwain.Triplets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <exception cref="System.ArgumentNullException"></exception>
|
/// <exception cref="System.ArgumentNullException"></exception>
|
||||||
internal OpBase(ITwainSessionInternal session)
|
internal OpBase(ITwainStateInternal session)
|
||||||
{
|
{
|
||||||
if (session == null) { throw new ArgumentNullException("session"); }
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
Session = session;
|
Session = session;
|
||||||
@@ -28,6 +28,6 @@ namespace NTwain.Triplets
|
|||||||
/// <value>
|
/// <value>
|
||||||
/// The session.
|
/// The session.
|
||||||
/// </value>
|
/// </value>
|
||||||
internal ITwainSessionInternal Session { get; private set; }
|
internal ITwainStateInternal Session { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a session for working with TWAIN api in an application.
|
/// Provides a session for working with TWAIN api in an application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TwainSession : ITwainSessionInternal, IMessageFilter, INotifyPropertyChanged
|
public class TwainSession : ITwainStateInternal, IMessageFilter, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TwainSession" /> class.
|
/// Initializes a new instance of the <see cref="TwainSession" /> class.
|
||||||
@@ -29,7 +29,7 @@ namespace NTwain
|
|||||||
public TwainSession(TWIdentity appId)
|
public TwainSession(TWIdentity appId)
|
||||||
{
|
{
|
||||||
if (appId == null) { throw new ArgumentNullException("appId"); }
|
if (appId == null) { throw new ArgumentNullException("appId"); }
|
||||||
_appId = appId;
|
AppId = appId;
|
||||||
State = 1;
|
State = 1;
|
||||||
EnforceState = true;
|
EnforceState = true;
|
||||||
}
|
}
|
||||||
@@ -40,27 +40,17 @@ namespace NTwain
|
|||||||
SynchronizationContext _syncer;
|
SynchronizationContext _syncer;
|
||||||
|
|
||||||
|
|
||||||
TWIdentity _appId;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the app id used for the session.
|
/// Gets the app id used for the session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The app id.</value>
|
/// <value>The app id.</value>
|
||||||
public TWIdentity AppId { get { return _appId; } }
|
public TWIdentity AppId { get; private set; }
|
||||||
|
|
||||||
TWIdentity _sourceId;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the source id used for the session.
|
/// Gets the source id used for the session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The source id.</value>
|
/// <value>The source id.</value>
|
||||||
public TWIdentity SourceId
|
public TWIdentity SourceId { get; private set; }
|
||||||
{
|
|
||||||
get { return _sourceId; }
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
_sourceId = value;
|
|
||||||
RaisePropertyChanged("SourceId");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current state number as defined by the TWAIN spec.
|
/// Gets the current state number as defined by the TWAIN spec.
|
||||||
@@ -157,15 +147,20 @@ namespace NTwain
|
|||||||
|
|
||||||
#region state transition calls
|
#region state transition calls
|
||||||
|
|
||||||
void ITwainSessionInternal.ChangeState(int newState, bool notifyChange)
|
void ITwainStateInternal.ChangeState(int newState, bool notifyChange)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("TWAIN State = " + newState);
|
Debug.WriteLine("TWAIN State = " + newState);
|
||||||
State = newState;
|
State = newState;
|
||||||
if (notifyChange) { RaisePropertyChanged("State"); }
|
if (notifyChange) { RaisePropertyChanged("State"); }
|
||||||
}
|
}
|
||||||
ICommitable ITwainSessionInternal.GetPendingStateChanger(int newState)
|
ICommitable ITwainStateInternal.GetPendingStateChanger(int newState)
|
||||||
{
|
{
|
||||||
return new TentativeStateChanger(this, newState);
|
return new TentativeStateCommitable(this, newState);
|
||||||
|
}
|
||||||
|
void ITwainStateInternal.ChangeSourceId(TWIdentity sourceId)
|
||||||
|
{
|
||||||
|
SourceId = sourceId;
|
||||||
|
RaisePropertyChanged("SourceId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,7 +188,7 @@ namespace NTwain
|
|||||||
rc = DGControl.EntryPoint.Get(out entry);
|
rc = DGControl.EntryPoint.Get(out entry);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
MemoryManager.Global.UpdateEntryPoint(entry);
|
MemoryManager.Instance.UpdateEntryPoint(entry);
|
||||||
Debug.WriteLine("Using TWAIN2 memory functions.");
|
Debug.WriteLine("Using TWAIN2 memory functions.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -218,7 +213,7 @@ namespace NTwain
|
|||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
_parentHandle = default(HandleRef);
|
_parentHandle = default(HandleRef);
|
||||||
MemoryManager.Global.UpdateEntryPoint(null);
|
MemoryManager.Instance.UpdateEntryPoint(null);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -258,7 +253,7 @@ namespace NTwain
|
|||||||
if (!DisableCallback)
|
if (!DisableCallback)
|
||||||
{
|
{
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
var cb = new TWCallback2(new CallbackDelegate(CallbackHandler));
|
var cb = new TWCallback2(new CallbackDelegate(CallbackHandler));
|
||||||
var rc2 = DGControl.Callback2.RegisterCallback(cb);
|
var rc2 = DGControl.Callback2.RegisterCallback(cb);
|
||||||
@@ -289,7 +284,7 @@ namespace NTwain
|
|||||||
ReturnCode CallbackHandler(TWIdentity origin, TWIdentity dest,
|
ReturnCode CallbackHandler(TWIdentity origin, TWIdentity dest,
|
||||||
DataGroups dg, DataArgumentType dat, Values.Message msg, IntPtr data)
|
DataGroups dg, DataArgumentType dat, Values.Message msg, IntPtr data)
|
||||||
{
|
{
|
||||||
if (origin != null && _sourceId != null && origin.Id == _sourceId.Id)
|
if (origin != null && SourceId != null && origin.Id == SourceId.Id)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format("Thread {0}: GOT TWAIN callback for msg {1}.", Thread.CurrentThread.ManagedThreadId, msg));
|
Debug.WriteLine(string.Format("Thread {0}: GOT TWAIN callback for msg {1}.", Thread.CurrentThread.ManagedThreadId, msg));
|
||||||
// spec says should handle this on the thread that enabled the DS,
|
// spec says should handle this on the thread that enabled the DS,
|
||||||
@@ -509,7 +504,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
if (dataPtr != IntPtr.Zero)
|
if (dataPtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
lockedPtr = MemoryManager.Global.MemLock(dataPtr);
|
lockedPtr = MemoryManager.Instance.MemLock(dataPtr);
|
||||||
}
|
}
|
||||||
dtHand(this, new DataTransferredEventArgs(lockedPtr, file));
|
dtHand(this, new DataTransferredEventArgs(lockedPtr, file));
|
||||||
}
|
}
|
||||||
@@ -528,7 +523,7 @@ namespace NTwain
|
|||||||
// var dtHand = DataTransferred;
|
// var dtHand = DataTransferred;
|
||||||
// if (dtHand != null)
|
// if (dtHand != null)
|
||||||
// {
|
// {
|
||||||
// lockedPtr = MemoryManager.Global.MemLock(dataPtr);
|
// lockedPtr = MemoryManager.Instance.MemLock(dataPtr);
|
||||||
// dtHand(this, new DataTransferredEventArgs(lockedPtr));
|
// dtHand(this, new DataTransferredEventArgs(lockedPtr));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -542,12 +537,12 @@ namespace NTwain
|
|||||||
// data here is allocated by source so needs to use shared mem calls
|
// data here is allocated by source so needs to use shared mem calls
|
||||||
if (lockedPtr != IntPtr.Zero)
|
if (lockedPtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
MemoryManager.Global.MemUnlock(lockedPtr);
|
MemoryManager.Instance.MemUnlock(lockedPtr);
|
||||||
lockedPtr = IntPtr.Zero;
|
lockedPtr = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
if (dataPtr != IntPtr.Zero)
|
if (dataPtr != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
MemoryManager.Global.MemFree(dataPtr);
|
MemoryManager.Instance.MemFree(dataPtr);
|
||||||
dataPtr = IntPtr.Zero;
|
dataPtr = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -723,14 +718,14 @@ namespace NTwain
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// no need to lock for marshal alloc
|
// no need to lock for marshal alloc
|
||||||
msgPtr = MemoryManager.Global.MemAllocate((uint)Marshal.SizeOf(winmsg));
|
msgPtr = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(winmsg));
|
||||||
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
||||||
return HandleLoopMsgEvent(ref msgPtr);
|
return HandleLoopMsgEvent(ref msgPtr);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (msgPtr != IntPtr.Zero)
|
if (msgPtr != IntPtr.Zero)
|
||||||
MemoryManager.Global.MemFree(msgPtr);
|
MemoryManager.Instance.MemFree(msgPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -762,14 +757,14 @@ namespace NTwain
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// no need to lock for marshal alloc
|
// no need to lock for marshal alloc
|
||||||
msgPtr = MemoryManager.Global.MemAllocate((uint)Marshal.SizeOf(winmsg));
|
msgPtr = MemoryManager.Instance.MemAllocate((uint)Marshal.SizeOf(winmsg));
|
||||||
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
||||||
handled = HandleLoopMsgEvent(ref msgPtr);
|
handled = HandleLoopMsgEvent(ref msgPtr);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (msgPtr != IntPtr.Zero)
|
if (msgPtr != IntPtr.Zero)
|
||||||
MemoryManager.Global.MemFree(msgPtr);
|
MemoryManager.Instance.MemFree(msgPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
@@ -791,44 +786,5 @@ namespace NTwain
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region nested stuff
|
|
||||||
|
|
||||||
class TentativeStateChanger : ICommitable
|
|
||||||
{
|
|
||||||
bool _commit;
|
|
||||||
ITwainSessionInternal _session;
|
|
||||||
int _origState;
|
|
||||||
int _newState;
|
|
||||||
public TentativeStateChanger(ITwainSessionInternal session, int newState)
|
|
||||||
{
|
|
||||||
_session = session;
|
|
||||||
_origState = session.State;
|
|
||||||
_newState = newState;
|
|
||||||
_session.ChangeState(newState, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Commit()
|
|
||||||
{
|
|
||||||
if (_session.State == _newState)
|
|
||||||
{
|
|
||||||
_session.ChangeState(_newState, true);
|
|
||||||
}
|
|
||||||
_commit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (!_commit && _session.State == _newState)
|
|
||||||
{
|
|
||||||
_session.ChangeState(_origState, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace NTwain
|
|||||||
/// <param name="dataArgumentType">The triplet data argument type.</param>
|
/// <param name="dataArgumentType">The triplet data argument type.</param>
|
||||||
/// <param name="message">The triplet message.</param>
|
/// <param name="message">The triplet message.</param>
|
||||||
/// <exception cref="TwainStateException"></exception>
|
/// <exception cref="TwainStateException"></exception>
|
||||||
internal static void VerifyState(this ITwainSessionInternal session, int allowedMinimum, int allowedMaximum, DataGroups group, DataArgumentType dataArgumentType, NTwain.Values.Message message)
|
internal static void VerifyState(this ITwainStateInternal session, int allowedMinimum, int allowedMaximum, DataGroups group, DataArgumentType dataArgumentType, NTwain.Values.Message message)
|
||||||
{
|
{
|
||||||
if (session.EnforceState && (session.State < allowedMinimum || session.State > allowedMaximum))
|
if (session.EnforceState && (session.State < allowedMinimum || session.State > allowedMaximum))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ namespace NTwain.Values
|
|||||||
/// CapClearBuffers values.
|
/// CapClearBuffers values.
|
||||||
/// Corresponds to TWCB_* values.
|
/// Corresponds to TWCB_* values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum ClearBuffers : ushort
|
public enum ClearBuffer : ushort
|
||||||
{
|
{
|
||||||
Auto = 0,
|
Auto = 0,
|
||||||
Clear = 1,
|
Clear = 1,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace NTwain.Tests
|
|||||||
[ExpectedException(typeof(TwainStateException), "State check failed to throw.")]
|
[ExpectedException(typeof(TwainStateException), "State check failed to throw.")]
|
||||||
public void VerifyState_Throws_When_State_Is_Enforced()
|
public void VerifyState_Throws_When_State_Is_Enforced()
|
||||||
{
|
{
|
||||||
ITwainSessionInternal session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
ITwainStateInternal session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
||||||
session.EnforceState = true;
|
session.EnforceState = true;
|
||||||
session.ChangeState(4, false);
|
session.ChangeState(4, false);
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ namespace NTwain.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void VerifyState_No_Throws_When_State_Is_Not_Enforced()
|
public void VerifyState_No_Throws_When_State_Is_Not_Enforced()
|
||||||
{
|
{
|
||||||
ITwainSessionInternal session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
ITwainStateInternal session = new TwainSession(TWIdentity.Create(DataGroups.Image, new Version(1, 0), "test", "test", "test", "test"));
|
||||||
session.EnforceState = false;
|
session.EnforceState = false;
|
||||||
session.ChangeState(4, false);
|
session.ChangeState(4, false);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
@@ -40,10 +40,6 @@
|
|||||||
<HintPath>..\..\packages\CommonWin32.2.0.4\lib\net35-Client\CommonWin32.dll</HintPath>
|
<HintPath>..\..\packages\CommonWin32.2.0.4\lib\net35-Client\CommonWin32.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Deployment" />
|
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
|||||||
Reference in New Issue
Block a user