mirror of
https://github.com/soukoku/ntwain.git
synced 2025-06-28 15:28:06 +08:00
More cleanup for v1.
This commit is contained in:
parent
31f77edb40
commit
108fde6fe7
@ -43,15 +43,12 @@
|
|||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="..\NTwain\CapabilityReadout.cs">
|
||||||
|
<Link>CapabilityReadout.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\NTwain\DataTransferredEventArgs.cs">
|
<Compile Include="..\NTwain\DataTransferredEventArgs.cs">
|
||||||
<Link>DataTransferredEventArgs.cs</Link>
|
<Link>DataTransferredEventArgs.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\NTwain\Data\CapReadOut.cs">
|
|
||||||
<Link>Data\CapReadOut.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\NTwain\Data\SourceEnableMode.cs">
|
|
||||||
<Link>Data\SourceEnableMode.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\NTwain\Data\TwainTypes.cs">
|
<Compile Include="..\NTwain\Data\TwainTypes.cs">
|
||||||
<Link>Data\TwainTypes.cs</Link>
|
<Link>Data\TwainTypes.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -64,8 +61,8 @@
|
|||||||
<Compile Include="..\NTwain\Data\TypeReader.cs">
|
<Compile Include="..\NTwain\Data\TypeReader.cs">
|
||||||
<Link>Data\TypeReader.cs</Link>
|
<Link>Data\TypeReader.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\NTwain\Data\ValueConverter.cs">
|
<Compile Include="..\NTwain\Data\ValueExtensions.cs">
|
||||||
<Link>Data\ValueConverter.cs</Link>
|
<Link>Data\ValueExtensions.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\NTwain\DeviceEventArgs.cs">
|
<Compile Include="..\NTwain\DeviceEventArgs.cs">
|
||||||
<Link>DeviceEventArgs.cs</Link>
|
<Link>DeviceEventArgs.cs</Link>
|
||||||
@ -109,9 +106,6 @@
|
|||||||
<Compile Include="..\NTwain\ITwainSession.cs">
|
<Compile Include="..\NTwain\ITwainSession.cs">
|
||||||
<Link>ITwainSession.cs</Link>
|
<Link>ITwainSession.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\NTwain\ITwainState.cs">
|
|
||||||
<Link>ITwainState.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\NTwain\Platform.cs">
|
<Compile Include="..\NTwain\Platform.cs">
|
||||||
<Link>Platform.cs</Link>
|
<Link>Platform.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -127,6 +121,9 @@
|
|||||||
<Compile Include="..\NTwain\Properties\VersionInfo.cs">
|
<Compile Include="..\NTwain\Properties\VersionInfo.cs">
|
||||||
<Link>Properties\VersionInfo.cs</Link>
|
<Link>Properties\VersionInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\NTwain\SourceEnableMode.cs">
|
||||||
|
<Link>SourceEnableMode.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\NTwain\TransferErrorEventArgs.cs">
|
<Compile Include="..\NTwain\TransferErrorEventArgs.cs">
|
||||||
<Link>TransferErrorEventArgs.cs</Link>
|
<Link>TransferErrorEventArgs.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -16,7 +16,7 @@ EndProject
|
|||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{4CE0B9ED-2CD1-440F-B4EC-35ECA6D61EFE}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
LICENSE.txt = LICENSE.txt
|
LICENSE.txt = LICENSE.txt
|
||||||
README.markdown = README.markdown
|
README.md = README.md
|
||||||
Spec\twain2.3.h = Spec\twain2.3.h
|
Spec\twain2.3.h = Spec\twain2.3.h
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
using NTwain.Properties;
|
using NTwain.Data;
|
||||||
|
using NTwain.Properties;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace NTwain.Data
|
namespace NTwain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The one-stop class for reading TWAIN cap values.
|
/// The one-stop class for reading TWAIN cap values.
|
||||||
/// This contains all the properties for the 4 container types.
|
/// This contains all the properties for the 4 container types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CapReadOut
|
public class CapabilityReadOut
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the value from a <see cref="TWCapability"/> that was returned
|
/// Reads the value from a <see cref="TWCapability"/> that was returned
|
||||||
@ -24,7 +25,7 @@ namespace NTwain.Data
|
|||||||
/// or
|
/// or
|
||||||
/// capability
|
/// capability
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public static CapReadOut ReadValue(TWCapability capability)
|
public static CapabilityReadOut ReadValue(TWCapability capability)
|
||||||
{
|
{
|
||||||
if (capability == null) { throw new ArgumentNullException("capability"); }
|
if (capability == null) { throw new ArgumentNullException("capability"); }
|
||||||
if (capability.Container == IntPtr.Zero) { throw new ArgumentException(Resources.CapHasNoData, "capability"); }
|
if (capability.Container == IntPtr.Zero) { throw new ArgumentException(Resources.CapHasNoData, "capability"); }
|
||||||
@ -36,22 +37,22 @@ namespace NTwain.Data
|
|||||||
switch (capability.ContainerType)
|
switch (capability.ContainerType)
|
||||||
{
|
{
|
||||||
case ContainerType.Array:
|
case ContainerType.Array:
|
||||||
return new CapReadOut
|
return new CapabilityReadOut
|
||||||
{
|
{
|
||||||
ContainerType = capability.ContainerType,
|
ContainerType = capability.ContainerType,
|
||||||
}.ReadArrayValue(baseAddr);
|
}.ReadArrayValue(baseAddr);
|
||||||
case ContainerType.Enum:
|
case ContainerType.Enum:
|
||||||
return new CapReadOut
|
return new CapabilityReadOut
|
||||||
{
|
{
|
||||||
ContainerType = capability.ContainerType,
|
ContainerType = capability.ContainerType,
|
||||||
}.ReadEnumValue(baseAddr);
|
}.ReadEnumValue(baseAddr);
|
||||||
case ContainerType.OneValue:
|
case ContainerType.OneValue:
|
||||||
return new CapReadOut
|
return new CapabilityReadOut
|
||||||
{
|
{
|
||||||
ContainerType = capability.ContainerType,
|
ContainerType = capability.ContainerType,
|
||||||
}.ReadOneValue(baseAddr);
|
}.ReadOneValue(baseAddr);
|
||||||
case ContainerType.Range:
|
case ContainerType.Range:
|
||||||
return new CapReadOut
|
return new CapabilityReadOut
|
||||||
{
|
{
|
||||||
ContainerType = capability.ContainerType,
|
ContainerType = capability.ContainerType,
|
||||||
}.ReadRangeValue(baseAddr);
|
}.ReadRangeValue(baseAddr);
|
||||||
@ -160,7 +161,7 @@ namespace NTwain.Data
|
|||||||
|
|
||||||
#region reader methods
|
#region reader methods
|
||||||
|
|
||||||
CapReadOut ReadOneValue(IntPtr baseAddr)
|
CapabilityReadOut ReadOneValue(IntPtr baseAddr)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
@ -169,7 +170,7 @@ namespace NTwain.Data
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CapReadOut ReadArrayValue(IntPtr baseAddr)
|
CapabilityReadOut ReadArrayValue(IntPtr baseAddr)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
@ -187,7 +188,7 @@ namespace NTwain.Data
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CapReadOut ReadEnumValue(IntPtr baseAddr)
|
CapabilityReadOut ReadEnumValue(IntPtr baseAddr)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
||||||
@ -209,7 +210,7 @@ namespace NTwain.Data
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CapReadOut ReadRangeValue(IntPtr baseAddr)
|
CapabilityReadOut ReadRangeValue(IntPtr baseAddr)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
|
@ -486,10 +486,12 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Channel-specific transform parameters.
|
/// Channel-specific transform parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWDecodeFunction[] Decode { get { return _decode; } }//set { _decode = value; } }
|
public TWDecodeFunction[] Decode { get { return _decode; } }//set { _decode = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Flattened 3x3 matrix that specifies how channels are mixed in.
|
/// Flattened 3x3 matrix that specifies how channels are mixed in.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWFix32[] Mix { get { return _mix; } }//set { _mix = value; } }
|
public TWFix32[] Mix { get { return _mix; } }//set { _mix = value; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -527,6 +529,7 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Array of ItemType values starts here.
|
/// Array of ItemType values starts here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public object[] ItemList
|
public object[] ItemList
|
||||||
{
|
{
|
||||||
get { return _itemList; }
|
get { return _itemList; }
|
||||||
@ -1060,6 +1063,7 @@ namespace NTwain.Data
|
|||||||
/// Optional table look-up values used by the decode function. Samples
|
/// Optional table look-up values used by the decode function. Samples
|
||||||
/// are ordered sequentially and end-to-end as A, B, C, L, M, and N.
|
/// are ordered sequentially and end-to-end as A, B, C, L, M, and N.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWFix32[] Samples { get { return _samples; } }
|
public TWFix32[] Samples { get { return _samples; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1251,6 +1255,7 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The enumerated list: one value resides within each array element.
|
/// The enumerated list: one value resides within each array element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public object[] ItemList
|
public object[] ItemList
|
||||||
{
|
{
|
||||||
get { return _itemList; }
|
get { return _itemList; }
|
||||||
@ -1352,6 +1357,7 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Array of information.
|
/// Array of information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWInfo[] Info { get { return _info; } }
|
public TWInfo[] Info { get { return _info; } }
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
@ -1493,6 +1499,7 @@ namespace NTwain.Data
|
|||||||
/// Transfer curve descriptors. All three channels (Channel1, Channel2
|
/// Transfer curve descriptors. All three channels (Channel1, Channel2
|
||||||
/// and Channel3) must contain the same value for every entry.
|
/// and Channel3) must contain the same value for every entry.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWElement8[] Response { get { return _response; } set { _response = value; } }
|
public TWElement8[] Response { get { return _response; } set { _response = value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1772,6 +1779,7 @@ namespace NTwain.Data
|
|||||||
/// bits. However, both the application and Source must simultaneously
|
/// bits. However, both the application and Source must simultaneously
|
||||||
/// support sample sizes greater than 8 bits per color.
|
/// support sample sizes greater than 8 bits per color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public short[] BitsPerSample { get { return _bitsPerSample; } }
|
public short[] BitsPerSample { get { return _bitsPerSample; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The number of bits in each image pixel (or bit depth). This value is
|
/// The number of bits in each image pixel (or bit depth). This value is
|
||||||
@ -1969,23 +1977,28 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mapping of components to Quantization tables.
|
/// Mapping of components to Quantization tables.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public ushort[] QuantMap { get { return _quantMap; } set { _quantMap = value; } }
|
public ushort[] QuantMap { get { return _quantMap; } set { _quantMap = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quantization tables.
|
/// Quantization tables.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWMemory[] QuantTable { get { return _quantTable; } set { _quantTable = value; } }
|
public TWMemory[] QuantTable { get { return _quantTable; } set { _quantTable = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mapping of components to Huffman tables. Null entries signify
|
/// Mapping of components to Huffman tables. Null entries signify
|
||||||
/// selection of the default tables.
|
/// selection of the default tables.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public ushort[] HuffmanMap { get { return _huffmanMap; } set { _huffmanMap = value; } }
|
public ushort[] HuffmanMap { get { return _huffmanMap; } set { _huffmanMap = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DC Huffman tables. Null entries signify selection of the default tables.
|
/// DC Huffman tables. Null entries signify selection of the default tables.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWMemory[] HuffmanDC { get { return _huffmanDC; } set { _huffmanDC = value; } }
|
public TWMemory[] HuffmanDC { get { return _huffmanDC; } set { _huffmanDC = value; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AC Huffman tables. Null entries signify selection of the default tables.
|
/// AC Huffman tables. Null entries signify selection of the default tables.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWMemory[] HuffmanAC { get { return _huffmanAC; } set { _huffmanAC = value; } }
|
public TWMemory[] HuffmanAC { get { return _huffmanAC; } set { _huffmanAC = value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2023,6 +2036,7 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Array of palette values.
|
/// Array of palette values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWElement8[] Colors { get { return _colors; } set { _colors = value; } }
|
public TWElement8[] Colors { get { return _colors; } set { _colors = value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2134,6 +2148,7 @@ namespace NTwain.Data
|
|||||||
/// Transfer curve descriptors. To minimize color shift problems, writing the
|
/// Transfer curve descriptors. To minimize color shift problems, writing the
|
||||||
/// same values into each channel is desirable.
|
/// same values into each channel is desirable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public TWElement8[] Response { get { return _response; } set { _response = value; } }
|
public TWElement8[] Response { get { return _response; } set { _response = value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace NTwain.Data
|
namespace NTwain.Data
|
||||||
@ -67,7 +68,7 @@ namespace NTwain.Data
|
|||||||
val = ReadString(baseAddress, offset, TwainConst.String64 - 2);
|
val = ReadString(baseAddress, offset, TwainConst.String64 - 2);
|
||||||
break;
|
break;
|
||||||
case ItemType.Handle:
|
case ItemType.Handle:
|
||||||
val = new IntPtr(baseAddress.ToInt64() + offset);
|
val = Marshal.ReadIntPtr(baseAddress, offset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset += GetItemTypeSize(type);
|
offset += GetItemTypeSize(type);
|
||||||
@ -93,6 +94,28 @@ namespace NTwain.Data
|
|||||||
//return sb.ToString();
|
//return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly Dictionary<ItemType, int> __sizes = GenerateSizes();
|
||||||
|
|
||||||
|
private static Dictionary<ItemType, int> GenerateSizes()
|
||||||
|
{
|
||||||
|
var sizes = new Dictionary<ItemType, int>();
|
||||||
|
sizes[ItemType.Int8] = 1;
|
||||||
|
sizes[ItemType.UInt8] = 1;
|
||||||
|
sizes[ItemType.Int16] = 2;
|
||||||
|
sizes[ItemType.UInt16] = 2;
|
||||||
|
sizes[ItemType.Bool] = 2;
|
||||||
|
sizes[ItemType.Int32] = 4;
|
||||||
|
sizes[ItemType.UInt32] = 4;
|
||||||
|
sizes[ItemType.Fix32] = 4;
|
||||||
|
sizes[ItemType.Frame] = 16;
|
||||||
|
sizes[ItemType.String32] = TwainConst.String32;
|
||||||
|
sizes[ItemType.String64] = TwainConst.String64;
|
||||||
|
sizes[ItemType.String128] = TwainConst.String128;
|
||||||
|
sizes[ItemType.String255] = TwainConst.String255;
|
||||||
|
sizes[ItemType.Handle] = IntPtr.Size;
|
||||||
|
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the byte size of the item type.
|
/// Gets the byte size of the item type.
|
||||||
@ -101,31 +124,9 @@ namespace NTwain.Data
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GetItemTypeSize(ItemType type)
|
public static int GetItemTypeSize(ItemType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
if (__sizes.ContainsKey(type))
|
||||||
{
|
{
|
||||||
case ItemType.Int8:
|
return __sizes[type];
|
||||||
case ItemType.UInt8:
|
|
||||||
return 1;
|
|
||||||
case ItemType.UInt16:
|
|
||||||
case ItemType.Int16:
|
|
||||||
case ItemType.Bool:
|
|
||||||
return 2;
|
|
||||||
case ItemType.Int32:
|
|
||||||
case ItemType.UInt32:
|
|
||||||
case ItemType.Fix32:
|
|
||||||
return 4;
|
|
||||||
case ItemType.Frame:
|
|
||||||
return 16;
|
|
||||||
case ItemType.String32:
|
|
||||||
return TwainConst.String32;
|
|
||||||
case ItemType.String64:
|
|
||||||
return TwainConst.String64;
|
|
||||||
case ItemType.String128:
|
|
||||||
return TwainConst.String128;
|
|
||||||
case ItemType.String255:
|
|
||||||
return TwainConst.String255;
|
|
||||||
case ItemType.Handle:
|
|
||||||
return IntPtr.Size;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,24 +8,50 @@ namespace NTwain.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utility on converting (possibly bad) integer values to enum values.
|
/// Utility on converting (possibly bad) integer values to enum values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ValueConverter
|
public static class ValueExtensions
|
||||||
{
|
{
|
||||||
public static IList<T> CastToEnum<T>(this IEnumerable<object> list) where T : struct,IConvertible
|
/// <summary>
|
||||||
|
/// Casts a list of objects to a list of specified enum.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
|
/// <param name="list">The list.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list) where TEnum : struct,IConvertible
|
||||||
{
|
{
|
||||||
return list.CastToEnum<T>(true);
|
return list.CastToEnum<TEnum>(true);
|
||||||
}
|
}
|
||||||
public static IList<T> CastToEnum<T>(this IEnumerable<object> list, bool tryUpperWord) where T : struct,IConvertible
|
/// <summary>
|
||||||
|
/// Casts a list of objects to a list of specified enum.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
|
/// <param name="list">The list.</param>
|
||||||
|
/// <param name="tryUpperWord">set to <c>true</c> for working with bad values.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list, bool tryUpperWord) where TEnum : struct,IConvertible
|
||||||
{
|
{
|
||||||
return list.Select(o => o.ConvertToEnum<T>(tryUpperWord)).ToList();
|
return list.Select(o => o.ConvertToEnum<TEnum>(tryUpperWord)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T ConvertToEnum<T>(this object value) where T : struct,IConvertible
|
/// <summary>
|
||||||
|
/// Casts an objects to the specified enum.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static TEnum ConvertToEnum<TEnum>(this object value) where TEnum : struct,IConvertible
|
||||||
{
|
{
|
||||||
return ConvertToEnum<T>(value, true);
|
return ConvertToEnum<TEnum>(value, true);
|
||||||
}
|
}
|
||||||
public static T ConvertToEnum<T>(this object value, bool tryUpperWord) where T : struct,IConvertible
|
/// <summary>
|
||||||
|
/// Casts an objects to the specified enum.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <param name="tryUpperWord">if set to <c>true</c> [try upper word].</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static TEnum ConvertToEnum<TEnum>(this object value, bool tryUpperWord) where TEnum : struct,IConvertible
|
||||||
{
|
{
|
||||||
var returnType = typeof(T);
|
var returnType = typeof(TEnum);
|
||||||
|
|
||||||
// standard int values
|
// standard int values
|
||||||
if (returnType.IsEnum)
|
if (returnType.IsEnum)
|
||||||
@ -41,22 +67,22 @@ namespace NTwain.Data
|
|||||||
var enumVal = GetLowerWord(intVal);
|
var enumVal = GetLowerWord(intVal);
|
||||||
if (!Enum.IsDefined(returnType, enumVal))
|
if (!Enum.IsDefined(returnType, enumVal))
|
||||||
{
|
{
|
||||||
return (T)Enum.ToObject(returnType, GetUpperWord(intVal));
|
return (TEnum)Enum.ToObject(returnType, GetUpperWord(intVal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// this may work better?
|
// this may work better?
|
||||||
return (T)Enum.ToObject(returnType, value);
|
return (TEnum)Enum.ToObject(returnType, value);
|
||||||
//// cast to underlying type first then to the enum
|
//// cast to underlying type first then to the enum
|
||||||
//return (T)Convert.ChangeType(value, rawType);
|
//return (T)Convert.ChangeType(value, rawType);
|
||||||
}
|
}
|
||||||
else if (typeof(IConvertible).IsAssignableFrom(returnType))
|
else if (typeof(IConvertible).IsAssignableFrom(returnType))
|
||||||
{
|
{
|
||||||
// for regular integers and whatnot
|
// for regular integers and whatnot
|
||||||
return (T)Convert.ChangeType(value, returnType, CultureInfo.InvariantCulture);
|
return (TEnum)Convert.ChangeType(value, returnType, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
// return as-is from cap. if caller made a mistake then there should be exceptions
|
// return as-is from cap. if caller made a mistake then there should be exceptions
|
||||||
return (T)value;
|
return (TEnum)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ushort GetLowerWord(uint value)
|
static ushort GetLowerWord(uint value)
|
@ -12,7 +12,8 @@ namespace NTwain
|
|||||||
/// Gets pointer to the complete data if the transfer was native.
|
/// Gets pointer to the complete data if the transfer was native.
|
||||||
/// The data will be freed once the event handler ends
|
/// The data will be freed once the event handler ends
|
||||||
/// so consumers must complete whatever processing before then.
|
/// so consumers must complete whatever processing before then.
|
||||||
/// For image type this data is DIB (Windows), PICT (old Mac), and TIFF (Linux/OSX).
|
/// For image type this data is DIB (Windows) or TIFF (Linux).
|
||||||
|
/// This pointer is already locked for the duration of this event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The data pointer.</value>
|
/// <value>The data pointer.</value>
|
||||||
public IntPtr NativeData { get; internal set; }
|
public IntPtr NativeData { get; internal set; }
|
||||||
@ -33,6 +34,7 @@ namespace NTwain
|
|||||||
/// <value>
|
/// <value>
|
||||||
/// The memory data.
|
/// The memory data.
|
||||||
/// </value>
|
/// </value>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||||
public byte[] MemData { get; internal set; }
|
public byte[] MemData { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
using NTwain.Triplets;
|
using NTwain.Data;
|
||||||
|
using NTwain.Triplets;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for providing TWAIN triplet operations.
|
/// Interface for TWAIN triplet operations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITwainOperation
|
public interface ITwainOperation
|
||||||
{
|
{
|
||||||
@ -21,5 +23,52 @@ namespace NTwain
|
|||||||
/// Gets the triplet operations defined for image data group.
|
/// Gets the triplet operations defined for image data group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DGImage DGImage { get; }
|
DGImage DGImage { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the data source manager. This must be the first method used
|
||||||
|
/// before using other TWAIN functions. Calls to this must be followed by <see cref="CloseManager"/> when done with a TWAIN session.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
ReturnCode OpenManager();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes the data source manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
ReturnCode CloseManager();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the specified source into main memory and causes its initialization.
|
||||||
|
/// Calls to this must be followed by
|
||||||
|
/// <see cref="CloseSource" /> when not using it anymore.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sourceProductName">Name of the source.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
ReturnCode OpenSource(string sourceProductName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// application (many desktop scanners will behave this way). A Source such as this cannot be
|
||||||
|
/// accessed by other applications until its current session is terminated
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
ReturnCode CloseSource();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enables the source to start transferring.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mode">The mode.</param>
|
||||||
|
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
|
||||||
|
/// <param name="windowHandle">The window handle if modal.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
ReturnCode EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Forces the stepping down of an opened source when things gets out of control.
|
||||||
|
/// Used when session state and source state become out of sync.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="targetState">State of the target.</param>
|
||||||
|
void ForceStepDown(int targetState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -9,8 +10,20 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// General interface for a TWAIN session.
|
/// General interface for a TWAIN session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITwainSession : ITwainState, ITwainOperation
|
public interface ITwainSession : INotifyPropertyChanged, ITwainOperation
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the source id used for the session.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The source id.</value>
|
||||||
|
TWIdentity SourceId { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current state number as defined by the TWAIN spec.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The state.</value>
|
||||||
|
int State { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the supported caps for the currently open source.
|
/// Gets the supported caps for the currently open source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
using NTwain.Data;
|
|
||||||
using System.ComponentModel;
|
|
||||||
namespace NTwain
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Interface for keeping track of current TWAIN state with current app and source ids.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITwainState : INotifyPropertyChanged
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the source id used for the session.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The source id.</value>
|
|
||||||
TWIdentity SourceId { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the current state number as defined by the TWAIN spec.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The state.</value>
|
|
||||||
int State { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides methods for managing memory on data exchanged with twain sources using old win32 methods.
|
/// Provides methods for managing memory on data exchanged with twain sources using old win32 methods.
|
||||||
/// This should only be used after the DSM has been opened.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class WinMemoryManager : IMemoryManager
|
class WinMemoryManager : IMemoryManager
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Data\CapReadOut.cs" />
|
<Compile Include="CapabilityReadout.cs" />
|
||||||
<Compile Include="Data\TypeReader.cs" />
|
<Compile Include="Data\TypeReader.cs" />
|
||||||
<Compile Include="Data\TwainTypesExtended.cs" />
|
<Compile Include="Data\TwainTypesExtended.cs" />
|
||||||
<Compile Include="DeviceEventArgs.cs" />
|
<Compile Include="DeviceEventArgs.cs" />
|
||||||
@ -66,7 +66,6 @@
|
|||||||
<Compile Include="Internals\WrappedManualResetEvent.cs" />
|
<Compile Include="Internals\WrappedManualResetEvent.cs" />
|
||||||
<Compile Include="ITwainOperation.cs" />
|
<Compile Include="ITwainOperation.cs" />
|
||||||
<Compile Include="ITwainSession.cs" />
|
<Compile Include="ITwainSession.cs" />
|
||||||
<Compile Include="ITwainState.cs" />
|
|
||||||
<Compile Include="Internals\WinMemoryManager.cs" />
|
<Compile Include="Internals\WinMemoryManager.cs" />
|
||||||
<Compile Include="Internals\MessageLoop.cs" />
|
<Compile Include="Internals\MessageLoop.cs" />
|
||||||
<Compile Include="Internals\UnsafeNativeMethods.cs" />
|
<Compile Include="Internals\UnsafeNativeMethods.cs" />
|
||||||
@ -130,8 +129,8 @@
|
|||||||
<Compile Include="Triplets\Dsm.cs" />
|
<Compile Include="Triplets\Dsm.cs" />
|
||||||
<Compile Include="TwainException.cs" />
|
<Compile Include="TwainException.cs" />
|
||||||
<Compile Include="Data\TwainValues.cs" />
|
<Compile Include="Data\TwainValues.cs" />
|
||||||
<Compile Include="Data\SourceEnableMode.cs" />
|
<Compile Include="SourceEnableMode.cs" />
|
||||||
<Compile Include="Data\ValueConverter.cs" />
|
<Compile Include="Data\ValueExtensions.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="NTwain.nuspec" />
|
<None Include="NTwain.nuspec" />
|
||||||
|
@ -11,14 +11,6 @@ namespace NTwain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Platform
|
public static class Platform
|
||||||
{
|
{
|
||||||
// Change pinvoke base on where running in 64bit mode.
|
|
||||||
// Theoretically [DllImport("twaindsm", EntryPoint = "#1")]
|
|
||||||
// works on both 32 and 64 bit
|
|
||||||
// but it's not installed on either system by default.
|
|
||||||
// A proper 64 bit twain driver would've installed it so
|
|
||||||
// in essence it only exists in 64 bit systems and thus
|
|
||||||
// the 2 sets of identical pinvokes for windows :(
|
|
||||||
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
|
||||||
static Platform()
|
static Platform()
|
||||||
{
|
{
|
||||||
@ -69,6 +61,7 @@ namespace NTwain
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="IMemoryManager"/> for communicating with data sources.
|
/// Gets the <see cref="IMemoryManager"/> for communicating with data sources.
|
||||||
|
/// This should only be used after the DSM has been opened.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The memory manager.
|
/// The memory manager.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace NTwain.Data
|
namespace NTwain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates how the source should be enabled in a TWAIN session.
|
/// Indicates how the source should be enabled in a TWAIN session.
|
@ -16,6 +16,16 @@ namespace NTwain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TwainException() { }
|
public TwainException() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TwainException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message that describes the error.</param>
|
||||||
|
public TwainException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TwainException" /> class.
|
/// Initializes a new instance of the <see cref="TwainException" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,6 +34,17 @@ namespace NTwain
|
|||||||
public TwainException(ReturnCode returnCode, string message)
|
public TwainException(ReturnCode returnCode, string message)
|
||||||
: this(returnCode, message, null) { }
|
: this(returnCode, message, null) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TwainException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||||
|
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
|
||||||
|
public TwainException(string message, Exception innerException)
|
||||||
|
: base(message, innerException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TwainException" /> class.
|
/// Initializes a new instance of the <see cref="TwainException" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -39,32 +39,6 @@ namespace NTwain
|
|||||||
TWIdentity _appId;
|
TWIdentity _appId;
|
||||||
TWUserInterface _twui;
|
TWUserInterface _twui;
|
||||||
|
|
||||||
static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];
|
|
||||||
|
|
||||||
private IList<CapabilityId> _supportedCaps;
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the supported caps for the currently open source.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The supported caps.
|
|
||||||
/// </value>
|
|
||||||
public IList<CapabilityId> SupportedCaps
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_supportedCaps == null && State > 3)
|
|
||||||
{
|
|
||||||
_supportedCaps = this.GetCapabilities();
|
|
||||||
}
|
|
||||||
return _supportedCaps ?? _emptyCapList;
|
|
||||||
}
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
_supportedCaps = value;
|
|
||||||
OnPropertyChanged("SupportedCaps");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the optional synchronization context.
|
/// Gets or sets the optional synchronization context.
|
||||||
/// This allows events to be raised on the thread
|
/// This allows events to be raised on the thread
|
||||||
@ -129,7 +103,7 @@ namespace NTwain
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ITwainState Members
|
#region ITwainSession Members
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the source id used for the session.
|
/// Gets the source id used for the session.
|
||||||
@ -149,7 +123,7 @@ namespace NTwain
|
|||||||
public int State
|
public int State
|
||||||
{
|
{
|
||||||
get { return _state; }
|
get { return _state; }
|
||||||
internal protected set
|
private set
|
||||||
{
|
{
|
||||||
if (value > 0 && value < 8)
|
if (value > 0 && value < 8)
|
||||||
{
|
{
|
||||||
@ -160,6 +134,33 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];
|
||||||
|
|
||||||
|
private IList<CapabilityId> _supportedCaps;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the supported caps for the currently open source.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The supported caps.
|
||||||
|
/// </value>
|
||||||
|
public IList<CapabilityId> SupportedCaps
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_supportedCaps == null && State > 3)
|
||||||
|
{
|
||||||
|
_supportedCaps = this.GetCapabilities();
|
||||||
|
}
|
||||||
|
return _supportedCaps ?? _emptyCapList;
|
||||||
|
}
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
_supportedCaps = value;
|
||||||
|
OnPropertyChanged("SupportedCaps");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ITwainOperation Members
|
#region ITwainOperation Members
|
||||||
@ -218,7 +219,8 @@ 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)
|
||||||
{
|
{
|
||||||
if (SynchronizationContext == null)
|
var syncer = SynchronizationContext;
|
||||||
|
if (syncer == null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -229,7 +231,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SynchronizationContext.Post(o =>
|
syncer.Post(o =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -292,6 +294,10 @@ namespace NTwain
|
|||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
|
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
|
||||||
|
|
||||||
rc = DGControl.Parent.CloseDsm(MessageLoop.Instance.LoopHandle);
|
rc = DGControl.Parent.CloseDsm(MessageLoop.Instance.LoopHandle);
|
||||||
|
if (rc == ReturnCode.Success)
|
||||||
|
{
|
||||||
|
Platform.MemoryManager = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -313,8 +319,10 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
|
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
|
||||||
|
|
||||||
var source = new TWIdentity();
|
var source = new TWIdentity
|
||||||
source.ProductName = sourceProductName;
|
{
|
||||||
|
ProductName = sourceProductName
|
||||||
|
};
|
||||||
|
|
||||||
rc = DGControl.Identity.OpenDS(source);
|
rc = DGControl.Identity.OpenDS(source);
|
||||||
});
|
});
|
||||||
@ -351,7 +359,6 @@ namespace NTwain
|
|||||||
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
|
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
|
||||||
/// <param name="windowHandle">The window handle if modal.</param>
|
/// <param name="windowHandle">The window handle if modal.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ArgumentNullException">context</exception>
|
|
||||||
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle)
|
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle)
|
||||||
{
|
{
|
||||||
var rc = ReturnCode.Failure;
|
var rc = ReturnCode.Failure;
|
||||||
@ -398,6 +405,11 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
rc = DGControl.UserInterface.EnableDS(_twui);
|
rc = DGControl.UserInterface.EnableDS(_twui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rc != ReturnCode.Success)
|
||||||
|
{
|
||||||
|
_callbackObj = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -501,7 +513,6 @@ namespace NTwain
|
|||||||
/// Occurs when data has been transferred.
|
/// Occurs when data has been transferred.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<DataTransferredEventArgs> DataTransferred;
|
public event EventHandler<DataTransferredEventArgs> DataTransferred;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when an error has been encountered during transfer.
|
/// Occurs when an error has been encountered during transfer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -509,7 +520,8 @@ namespace NTwain
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raises event and if applicable marshal it asynchronously to the <see cref="SynchronizationContext"/> thread.
|
/// Raises event and if applicable marshal it asynchronously to the <see cref="SynchronizationContext"/> thread
|
||||||
|
/// without exceptions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="onEventFunc">The on event function.</param>
|
/// <param name="onEventFunc">The on event function.</param>
|
||||||
/// <param name="handler">The handler.</param>
|
/// <param name="handler">The handler.</param>
|
||||||
@ -540,7 +552,8 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raises event and if applicable marshal it synchronously to the <see cref="SynchronizationContext" /> thread.
|
/// Raises event and if applicable marshal it synchronously to the <see cref="SynchronizationContext" /> thread
|
||||||
|
/// without exceptions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
|
/// <typeparam name="TEventArgs">The type of the event arguments.</typeparam>
|
||||||
/// <param name="onEventFunc">The on event function.</param>
|
/// <param name="onEventFunc">The on event function.</param>
|
||||||
@ -597,19 +610,19 @@ namespace NTwain
|
|||||||
/// Called when a data transfer is ready.
|
/// Called when a data transfer is ready.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">The <see cref="TransferReadyEventArgs"/> instance containing the event data.</param>
|
/// <param name="e">The <see cref="TransferReadyEventArgs"/> instance containing the event data.</param>
|
||||||
internal protected virtual void OnTransferReady(TransferReadyEventArgs e) { }
|
protected virtual void OnTransferReady(TransferReadyEventArgs e) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when data has been transferred.
|
/// Called when data has been transferred.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">The <see cref="DataTransferredEventArgs"/> instance containing the event data.</param>
|
/// <param name="e">The <see cref="DataTransferredEventArgs"/> instance containing the event data.</param>
|
||||||
internal protected virtual void OnDataTransferred(DataTransferredEventArgs e) { }
|
protected virtual void OnDataTransferred(DataTransferredEventArgs e) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when an error has been encountered during transfer.
|
/// Called when an error has been encountered during transfer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">The <see cref="TransferErrorEventArgs"/> instance containing the event data.</param>
|
/// <param name="e">The <see cref="TransferErrorEventArgs"/> instance containing the event data.</param>
|
||||||
internal protected virtual void OnTransferError(TransferErrorEventArgs e) { }
|
protected virtual void OnTransferError(TransferErrorEventArgs e) { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -661,7 +674,7 @@ namespace NTwain
|
|||||||
return ReturnCode.Failure;
|
return ReturnCode.Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
// method that handles msg from the source, whether it's from wndproc or callbacks
|
// final method that handles msg from the source, whether it's from wndproc or callbacks
|
||||||
void HandleSourceMsg(Message msg)
|
void HandleSourceMsg(Message msg)
|
||||||
{
|
{
|
||||||
switch (msg)
|
switch (msg)
|
||||||
|
@ -74,7 +74,7 @@ namespace NTwain
|
|||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="capId">The cap identifier.</param>
|
/// <param name="capId">The cap identifier.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static QuerySupport GetCapSupport(this ITwainOperation session, CapabilityId capId)
|
public static QuerySupport GetCapabilitySupport(this ITwainOperation session, CapabilityId capId)
|
||||||
{
|
{
|
||||||
if (session == null) { throw new ArgumentNullException("session"); }
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ namespace NTwain
|
|||||||
var rc = session.DGControl.Capability.QuerySupport(cap);
|
var rc = session.DGControl.Capability.QuerySupport(cap);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
var read = CapReadOut.ReadValue(cap);
|
var read = CapabilityReadOut.ReadValue(cap);
|
||||||
|
|
||||||
if (read.ContainerType == ContainerType.OneValue)
|
if (read.ContainerType == ContainerType.OneValue)
|
||||||
{
|
{
|
||||||
@ -110,7 +110,7 @@ namespace NTwain
|
|||||||
var rc = session.DGControl.Capability.GetCurrent(cap);
|
var rc = session.DGControl.Capability.GetCurrent(cap);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
var read = CapReadOut.ReadValue(cap);
|
var read = CapabilityReadOut.ReadValue(cap);
|
||||||
|
|
||||||
switch (read.ContainerType)
|
switch (read.ContainerType)
|
||||||
{
|
{
|
||||||
@ -149,7 +149,7 @@ namespace NTwain
|
|||||||
|
|
||||||
if (toPopulate == null) { toPopulate = new List<object>(); }
|
if (toPopulate == null) { toPopulate = new List<object>(); }
|
||||||
|
|
||||||
var read = CapReadOut.ReadValue(capability);
|
var read = CapabilityReadOut.ReadValue(capability);
|
||||||
|
|
||||||
switch (read.ContainerType)
|
switch (read.ContainerType)
|
||||||
{
|
{
|
||||||
@ -224,6 +224,8 @@ namespace NTwain
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IList<XferMech> CapGetImageXferMech(this ITwainOperation session)
|
public static IList<XferMech> CapGetImageXferMech(this ITwainOperation session)
|
||||||
{
|
{
|
||||||
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
|
|
||||||
return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
|
return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +241,8 @@ namespace NTwain
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IList<CompressionType> CapGetCompression(this ITwainOperation session)
|
public static IList<CompressionType> CapGetCompression(this ITwainOperation session)
|
||||||
{
|
{
|
||||||
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
|
|
||||||
return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<CompressionType>(true);
|
return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<CompressionType>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,6 +254,8 @@ namespace NTwain
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetImageCompression(this ITwainOperation session, CompressionType compression)
|
public static ReturnCode CapSetImageCompression(this ITwainOperation session, CompressionType compression)
|
||||||
{
|
{
|
||||||
|
if (session == null) { throw new ArgumentNullException("session"); }
|
||||||
|
|
||||||
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);
|
||||||
@ -500,7 +506,7 @@ namespace NTwain
|
|||||||
/// Change the auto deskew flag for the current source.
|
/// Change the auto deskew flag for the current source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="useIt">if set to <c>true</c> [use it].</param>
|
/// <param name="useIt">if set to <c>true</c> use it.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetAutoDeskew(this TwainSession session, bool useIt)
|
public static ReturnCode CapSetAutoDeskew(this TwainSession session, bool useIt)
|
||||||
{
|
{
|
||||||
@ -542,7 +548,7 @@ namespace NTwain
|
|||||||
/// Change the auto rotate flag for the current source.
|
/// Change the auto rotate flag for the current source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="useIt">if set to <c>true</c> [use it].</param>
|
/// <param name="useIt">if set to <c>true</c> use it.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetAutoRotate(this ITwainSession session, bool useIt)
|
public static ReturnCode CapSetAutoRotate(this ITwainSession session, bool useIt)
|
||||||
{
|
{
|
||||||
@ -582,7 +588,7 @@ namespace NTwain
|
|||||||
/// Change the auto border detection flag for the current source.
|
/// Change the auto border detection flag for the current source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="useIt">if set to <c>true</c> [use it].</param>
|
/// <param name="useIt">if set to <c>true</c> use it.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetBorderDetection(this ITwainSession session, bool useIt)
|
public static ReturnCode CapSetBorderDetection(this ITwainSession session, bool useIt)
|
||||||
{
|
{
|
||||||
@ -632,7 +638,7 @@ namespace NTwain
|
|||||||
/// Change the duplex flag for the current source.
|
/// Change the duplex flag for the current source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="useIt">if set to <c>true</c> [use it].</param>
|
/// <param name="useIt">if set to <c>true</c> to use it.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetDuplex(this ITwainSession session, bool useIt)
|
public static ReturnCode CapSetDuplex(this ITwainSession session, bool useIt)
|
||||||
{
|
{
|
||||||
@ -668,7 +674,7 @@ namespace NTwain
|
|||||||
/// Change the use feeder flag for the current source.
|
/// Change the use feeder flag for the current source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The session.</param>
|
/// <param name="session">The session.</param>
|
||||||
/// <param name="useIt">if set to <c>true</c> [use it].</param>
|
/// <param name="useIt">if set to <c>true</c> use it.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ReturnCode CapSetFeeder(this ITwainSession session, bool useIt)
|
public static ReturnCode CapSetFeeder(this ITwainSession session, bool useIt)
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,7 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an exception from calling a TWAIN triplet operation in the wrong state.
|
/// Represents an exception from calling a TWAIN triplet operation in the wrong state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class TwainStateException : TwainException
|
public class TwainStateException : TwainException
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ namespace Tester.WPF
|
|||||||
var caps = _twainVM.SupportedCaps.Select(o => new CapVM
|
var caps = _twainVM.SupportedCaps.Select(o => new CapVM
|
||||||
{
|
{
|
||||||
Cap = o,
|
Cap = o,
|
||||||
Supports = _twainVM.GetCapSupport(o)
|
Supports = _twainVM.GetCapabilitySupport(o)
|
||||||
}).OrderBy(o => o.Name).ToList();
|
}).OrderBy(o => o.Name).ToList();
|
||||||
CapList.ItemsSource = caps;
|
CapList.ItemsSource = caps;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\packages\CommonWin32.2.0.5\lib\net35-Client\CommonWin32.dll</HintPath>
|
<HintPath>..\..\packages\CommonWin32.2.0.5.2\lib\net35-Client\CommonWin32.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="GalaSoft.MvvmLight.Extras.WPF4">
|
<Reference Include="GalaSoft.MvvmLight.Extras.WPF4">
|
||||||
<HintPath>..\..\packages\MvvmLightLibs.4.3.31.1\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll</HintPath>
|
<HintPath>..\..\packages\MvvmLightLibs.4.3.31.1\lib\net40\GalaSoft.MvvmLight.Extras.WPF4.dll</HintPath>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ModernWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
<Reference Include="ModernWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\packages\ModernWPF.1.1.41.3\lib\net40-Client\ModernWPF.dll</HintPath>
|
<HintPath>..\..\packages\ModernWPF.1.1.43\lib\net40-Client\ModernWPF.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonServiceLocator" version="1.2" targetFramework="net40-Client" />
|
<package id="CommonServiceLocator" version="1.2" targetFramework="net40-Client" />
|
||||||
<package id="CommonWin32" version="2.0.5" targetFramework="net40-Client" />
|
<package id="CommonWin32" version="2.0.5.2" targetFramework="net40-Client" />
|
||||||
<package id="ModernWPF" version="1.1.41.3" targetFramework="net40-Client" />
|
<package id="ModernWPF" version="1.1.43" targetFramework="net40-Client" />
|
||||||
<package id="MvvmLightLibs" version="4.3.31.1" targetFramework="net40-Client" />
|
<package id="MvvmLightLibs" version="4.3.31.1" targetFramework="net40-Client" />
|
||||||
</packages>
|
</packages>
|
@ -37,7 +37,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\packages\CommonWin32.2.0.5\lib\net35-Client\CommonWin32.dll</HintPath>
|
<HintPath>..\..\packages\CommonWin32.2.0.5.2\lib\net35-Client\CommonWin32.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonWin32" version="2.0.5" targetFramework="net35-Client" />
|
<package id="CommonWin32" version="2.0.5.2" targetFramework="net35-Client" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue
Block a user