mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Moved wrapped capabilities into its own class to reduce DataSource complexity.
This commit is contained in:
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user