mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Moved wrapped capabilities into its own class to reduce DataSource complexity.
This commit is contained in:
parent
59e8b996de
commit
b757cc4a42
@ -46,15 +46,15 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\NTwain\Capabilities.cs">
|
||||
<Link>Capabilities.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\CapabilityReader.cs">
|
||||
<Link>CapabilityReader.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\CapWrapper.cs">
|
||||
<Link>CapWrapper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\DataSource.Caps.cs">
|
||||
<Link>DataSource.Caps.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\DataSource.cs">
|
||||
<Link>DataSource.cs</Link>
|
||||
</Compile>
|
||||
@ -79,9 +79,6 @@
|
||||
<Compile Include="..\NTwain\DeviceEventArgs.cs">
|
||||
<Link>DeviceEventArgs.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\ICapControl.cs">
|
||||
<Link>ICapControl.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\NTwain\ICapWrapper.cs">
|
||||
<Link>ICapWrapper.cs</Link>
|
||||
</Compile>
|
||||
|
@ -114,7 +114,7 @@ namespace NTwain
|
||||
var srcVersion = _source.ProtocolVersion;
|
||||
if (srcVersion >= ProtocolVersions.GetMinimumVersion(Capability))
|
||||
{
|
||||
_supports = _source.CapQuerySupport(Capability);
|
||||
_supports = _source.Capabilities.QuerySupport(Capability);
|
||||
|
||||
if (!_supports.HasValue)
|
||||
{
|
||||
@ -275,7 +275,7 @@ namespace NTwain
|
||||
{
|
||||
if (CanGetDefault)
|
||||
{
|
||||
return _getConvertRoutine(_source.CapGetDefault(Capability));
|
||||
return _getConvertRoutine(_source.Capabilities.GetDefault(Capability));
|
||||
}
|
||||
return default(TValue);
|
||||
}
|
||||
@ -288,7 +288,7 @@ namespace NTwain
|
||||
{
|
||||
if (CanGetCurrent)
|
||||
{
|
||||
return _getConvertRoutine(_source.CapGetCurrent(Capability));
|
||||
return _getConvertRoutine(_source.Capabilities.GetCurrent(Capability));
|
||||
}
|
||||
return default(TValue);
|
||||
}
|
||||
@ -299,7 +299,7 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public IList<TValue> GetValues()
|
||||
{
|
||||
return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList();
|
||||
return _source.Capabilities.GetValues(Capability).Select(o => _getConvertRoutine(o)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -384,7 +384,7 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public ReturnCode Reset()
|
||||
{
|
||||
return _source.CapReset(Capability);
|
||||
return _source.Capabilities.Reset(Capability);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -55,10 +55,10 @@ namespace NTwain
|
||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId));
|
||||
|
||||
rc = _session.DGControl.Identity.CloseDS();
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
SupportedCaps = null;
|
||||
}
|
||||
//if (rc == ReturnCode.Success)
|
||||
//{
|
||||
// SupportedCaps = null;
|
||||
//}
|
||||
_session.UpdateCallback();
|
||||
});
|
||||
return rc;
|
||||
@ -158,34 +158,48 @@ namespace NTwain
|
||||
/// </value>
|
||||
public bool IsOpen { get { return _session.IsSourceOpen; } }
|
||||
|
||||
static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];
|
||||
//static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];
|
||||
|
||||
//private IList<CapabilityId> _supportedCapsList;
|
||||
///// <summary>
|
||||
///// Gets the list of supported caps for this source.
|
||||
///// </summary>
|
||||
///// <value>
|
||||
///// The supported caps.
|
||||
///// </value>
|
||||
//[Obsolete("Use CapSupportedCaps.Get() instead.")]
|
||||
//public IList<CapabilityId> SupportedCaps
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (_supportedCapsList == null && _session.State > 3)
|
||||
// {
|
||||
// _supportedCapsList = CapSupportedCaps.GetValues();
|
||||
// }
|
||||
// return _supportedCapsList ?? _emptyCapList;
|
||||
// }
|
||||
// private set
|
||||
// {
|
||||
// _supportedCapsList = value;
|
||||
// //OnPropertyChanged("SupportedCaps");
|
||||
// }
|
||||
//}
|
||||
|
||||
private Capabilities _caps;
|
||||
|
||||
private IList<CapabilityId> _supportedCapsList;
|
||||
/// <summary>
|
||||
/// Gets the list of supported caps for this source.
|
||||
/// Gets the capabilities for this data source.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The supported caps.
|
||||
/// The capabilities.
|
||||
/// </value>
|
||||
[Obsolete("Use CapSupportedCaps.Get() instead.")]
|
||||
public IList<CapabilityId> SupportedCaps
|
||||
public Capabilities Capabilities
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_supportedCapsList == null && _session.State > 3)
|
||||
{
|
||||
_supportedCapsList = CapSupportedCaps.GetValues();
|
||||
}
|
||||
return _supportedCapsList ?? _emptyCapList;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_supportedCapsList = value;
|
||||
//OnPropertyChanged("SupportedCaps");
|
||||
}
|
||||
get { return _caps ?? (_caps = new Capabilities(this)); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for control data group.
|
||||
/// </summary>
|
||||
|
Binary file not shown.
@ -1,54 +0,0 @@
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace NTwain
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for providing basic functions at controlling caps.
|
||||
/// </summary>
|
||||
public interface ICapControl : ITripletControl
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the possible values for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
IList<object> CapGet(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
object CapGetCurrent(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default value for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
object CapGetDefault(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported operations for a capability.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
QuerySupports? CapQuerySupport(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the current value to power-on default.
|
||||
/// </summary>
|
||||
/// <param name="capabilityId">The capability identifier.</param>
|
||||
/// <returns></returns>
|
||||
ReturnCode CapReset(CapabilityId capabilityId);
|
||||
|
||||
/// <summary>
|
||||
/// Resets all values and constraints to power-on defaults.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ReturnCode CapResetAll();
|
||||
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace NTwain
|
||||
/// <summary>
|
||||
/// Represents a TWAIN data source.
|
||||
/// </summary>
|
||||
public interface IDataSource : ICapControl
|
||||
public interface IDataSource : ITripletControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the source's product name.
|
||||
@ -48,14 +48,6 @@ namespace NTwain
|
||||
/// </value>
|
||||
Version ProtocolVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported caps for this source.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The supported caps.
|
||||
/// </value>
|
||||
IList<CapabilityId> SupportedCaps { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source's version information.
|
||||
/// </summary>
|
||||
@ -72,6 +64,14 @@ namespace NTwain
|
||||
/// </value>
|
||||
bool IsOpen { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the capabilities for this data source.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The capabilities.
|
||||
/// </value>
|
||||
Capabilities Capabilities { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Opens the source for capability negotiation.
|
||||
/// </summary>
|
||||
|
@ -68,7 +68,7 @@ namespace NTwain.Internals
|
||||
// some DS end up getting none but we will assume it's image
|
||||
if (xferImage)
|
||||
{
|
||||
var mech = session.CurrentSource.ICapXferMech.GetCurrent();
|
||||
var mech = session.CurrentSource.Capabilities.ICapXferMech.GetCurrent();
|
||||
|
||||
switch (mech)
|
||||
{
|
||||
@ -90,7 +90,7 @@ namespace NTwain.Internals
|
||||
}
|
||||
if (xferAudio)
|
||||
{
|
||||
var mech = session.CurrentSource.ACapXferMech.GetCurrent();
|
||||
var mech = session.CurrentSource.Capabilities.ACapXferMech.GetCurrent();
|
||||
switch (mech)
|
||||
{
|
||||
case XferMech.File:
|
||||
|
@ -63,7 +63,6 @@
|
||||
<Compile Include="DeviceEventArgs.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="IDataSource.cs" />
|
||||
<Compile Include="ICapControl.cs" />
|
||||
<Compile Include="Internals\Extensions.cs" />
|
||||
<Compile Include="DataTransferredEventArgs.cs" />
|
||||
<Compile Include="IMemoryManager.cs" />
|
||||
@ -108,7 +107,7 @@
|
||||
<Compile Include="Triplets\Dsm.WinOld.cs" />
|
||||
<Compile Include="Triplets\Dsm.WinNew.cs" />
|
||||
<Compile Include="TwainSessionInternal.cs" />
|
||||
<Compile Include="DataSource.Caps.cs" />
|
||||
<Compile Include="Capabilities.cs" />
|
||||
<Compile Include="TwainSession.cs" />
|
||||
<Compile Include="DataSource.cs" />
|
||||
<Compile Include="TwainStateException.cs" />
|
||||
|
@ -87,7 +87,7 @@ myDS.DGImage...;
|
||||
|
||||
```
|
||||
|
||||
Additionally, the DataSource class itself has some handy pre-defined wrappers for common capability
|
||||
Additionally, the DataSource class has a Capabilities property with pre-defined wrappers for capability
|
||||
negotiation. You can use the wrapper properties to see what capabilities or their operations are
|
||||
supported. You also won't have to keep track of what value types to use since the wrapper defines it
|
||||
for you. Most capabilities only require a simple single value to set
|
||||
@ -107,10 +107,10 @@ and the wrapper makes it easy to do that (see example below):
|
||||
// (note: the name of the wrapper property is the same as the CapabilityId enum)
|
||||
PixelType myValue = PixelType.BlackWhite;
|
||||
|
||||
if (myDS.ICapPixelType.CanSet &&
|
||||
myDS.ICapPixelType.GetValues().Contains(myValue))
|
||||
if (myDS.Capabilities.ICapPixelType.CanSet &&
|
||||
myDS.Capabilities.ICapPixelType.GetValues().Contains(myValue))
|
||||
{
|
||||
myDS.ICapPixelType.SetValue(myValue);
|
||||
myDS.Capabilities.ICapPixelType.SetValue(myValue);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,17 +24,17 @@ namespace Tester.WPF
|
||||
|
||||
|
||||
var capName = cap.ToString();
|
||||
var wrapProperty = ds.GetType().GetProperty(capName);
|
||||
var wrapProperty = ds.Capabilities.GetType().GetProperty(capName);
|
||||
if (wrapProperty != null)
|
||||
{
|
||||
_wrapper = wrapProperty.GetGetMethod().Invoke(ds, null);
|
||||
_wrapper = wrapProperty.GetGetMethod().Invoke(ds.Capabilities, null);
|
||||
var wrapperType = _wrapper.GetType();
|
||||
_getMethod = wrapperType.GetMethod("GetValues");
|
||||
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");
|
||||
_setMethod = wrapperType.GetMethods().FirstOrDefault(m => m.Name == "SetValue");
|
||||
}
|
||||
|
||||
var supportTest = ds.CapQuerySupport(cap);
|
||||
var supportTest = ds.Capabilities.QuerySupport(cap);
|
||||
if (supportTest.HasValue)
|
||||
{
|
||||
Supports = supportTest.Value;
|
||||
@ -55,7 +55,7 @@ namespace Tester.WPF
|
||||
{
|
||||
if (_getMethod == null)
|
||||
{
|
||||
return _ds.CapGet(Cap);
|
||||
return _ds.Capabilities.GetValues(Cap);
|
||||
}
|
||||
return _getMethod.Invoke(_wrapper, null) as IEnumerable;
|
||||
}
|
||||
@ -63,7 +63,7 @@ namespace Tester.WPF
|
||||
{
|
||||
if (_getMethod == null)
|
||||
{
|
||||
return _ds.CapGetCurrent(Cap);
|
||||
return _ds.Capabilities.GetCurrent(Cap);
|
||||
}
|
||||
return _getCurrentMethod.Invoke(_wrapper, null);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace Tester.WPF
|
||||
//rc = DGControl.Status.Get(dsId, ref stat);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
foreach (var c in DS.CapSupportedCaps.GetValues().Select(o => new CapVM(DS, o)))
|
||||
foreach (var c in DS.Capabilities.CapSupportedCaps.GetValues().Select(o => new CapVM(DS, o)))
|
||||
{
|
||||
Caps.Add(c);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ namespace Tester.WPF
|
||||
}
|
||||
}, () =>
|
||||
{
|
||||
return _session.State == 4 && _session.CurrentSource.CapEnableDSUIOnly.GetCurrent() == BoolType.True;
|
||||
return _session.State == 4 && _session.CurrentSource.Capabilities.CapEnableDSUIOnly.GetCurrent() == BoolType.True;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -246,9 +246,9 @@ namespace Tester.WPF
|
||||
|
||||
void _session_TransferReady(object sender, TransferReadyEventArgs e)
|
||||
{
|
||||
if (_session.CurrentSource.ICapXferMech.GetCurrent() == XferMech.File)
|
||||
if (_session.CurrentSource.Capabilities.ICapXferMech.GetCurrent() == XferMech.File)
|
||||
{
|
||||
var formats = _session.CurrentSource.ICapImageFileFormat.GetValues();
|
||||
var formats = _session.CurrentSource.Capabilities.ICapImageFileFormat.GetValues();
|
||||
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
|
||||
|
||||
var fileSetup = new TWSetupFileXfer
|
||||
|
@ -230,7 +230,7 @@ namespace Tester.Winform
|
||||
|
||||
_stopScan = false;
|
||||
|
||||
if (_twain.CurrentSource.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
|
||||
if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
|
||||
{
|
||||
// hide scanner ui if possible
|
||||
if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
|
||||
@ -301,26 +301,26 @@ namespace Tester.Winform
|
||||
var src = _twain.CurrentSource;
|
||||
_loadingCaps = true;
|
||||
|
||||
var test = src.SupportedCaps;
|
||||
//var test = src.SupportedCaps;
|
||||
|
||||
if (groupDepth.Enabled = src.ICapPixelType.IsSupported)
|
||||
if (groupDepth.Enabled = src.Capabilities.ICapPixelType.IsSupported)
|
||||
{
|
||||
LoadDepth(src.ICapPixelType);
|
||||
LoadDepth(src.Capabilities.ICapPixelType);
|
||||
}
|
||||
if (groupDPI.Enabled = src.ICapXResolution.IsSupported && src.ICapYResolution.IsSupported)
|
||||
if (groupDPI.Enabled = src.Capabilities.ICapXResolution.IsSupported && src.Capabilities.ICapYResolution.IsSupported)
|
||||
{
|
||||
LoadDPI(src.ICapXResolution);
|
||||
LoadDPI(src.Capabilities.ICapXResolution);
|
||||
}
|
||||
// TODO: find out if this is how duplex works or also needs the other option
|
||||
if (groupDuplex.Enabled = src.CapDuplexEnabled.IsSupported)
|
||||
if (groupDuplex.Enabled = src.Capabilities.CapDuplexEnabled.IsSupported)
|
||||
{
|
||||
LoadDuplex(src.CapDuplexEnabled);
|
||||
LoadDuplex(src.Capabilities.CapDuplexEnabled);
|
||||
}
|
||||
if (groupSize.Enabled = src.ICapSupportedSizes.IsSupported)
|
||||
if (groupSize.Enabled = src.Capabilities.ICapSupportedSizes.IsSupported)
|
||||
{
|
||||
LoadPaperSize(src.ICapSupportedSizes);
|
||||
LoadPaperSize(src.Capabilities.ICapSupportedSizes);
|
||||
}
|
||||
btnAllSettings.Enabled = src.CapEnableDSUIOnly.IsSupported;
|
||||
btnAllSettings.Enabled = src.Capabilities.CapEnableDSUIOnly.IsSupported;
|
||||
_loadingCaps = false;
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ namespace Tester.Winform
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (SupportedSize)comboSize.SelectedItem;
|
||||
_twain.CurrentSource.ICapSupportedSizes.SetValue(sel);
|
||||
_twain.CurrentSource.Capabilities.ICapSupportedSizes.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ namespace Tester.Winform
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (PixelType)comboDepth.SelectedItem;
|
||||
_twain.CurrentSource.ICapPixelType.SetValue(sel);
|
||||
_twain.CurrentSource.Capabilities.ICapPixelType.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,8 +398,8 @@ namespace Tester.Winform
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (TWFix32)comboDPI.SelectedItem;
|
||||
_twain.CurrentSource.ICapXResolution.SetValue(sel);
|
||||
_twain.CurrentSource.ICapYResolution.SetValue(sel);
|
||||
_twain.CurrentSource.Capabilities.ICapXResolution.SetValue(sel);
|
||||
_twain.CurrentSource.Capabilities.ICapYResolution.SetValue(sel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -407,7 +407,7 @@ namespace Tester.Winform
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
_twain.CurrentSource.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False);
|
||||
_twain.CurrentSource.Capabilities.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user