mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Trying to resurrect my old cap wrapper.
This commit is contained in:
91
src/NTwain/Caps/CapReader.cs
Normal file
91
src/NTwain/Caps/CapReader.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
public class CapReader<TValue> where TValue : struct
|
||||||
|
{
|
||||||
|
readonly TwainAppSession _twain;
|
||||||
|
|
||||||
|
public CapReader(TwainAppSession twain, CAP cap)
|
||||||
|
{
|
||||||
|
_twain = twain;
|
||||||
|
Cap = cap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CAP Cap { get; }
|
||||||
|
|
||||||
|
public STS LastSTS { get; private set; }
|
||||||
|
|
||||||
|
TWQC? _qc;
|
||||||
|
public TWQC Supports
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_qc.HasValue) _qc = _twain.QueryCapSupport(Cap);
|
||||||
|
return _qc.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IList<TValue> Get()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapValues(Cap, out IList<TValue> values);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return values;
|
||||||
|
};
|
||||||
|
return Array.Empty<TValue>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TValue GetCurrent()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapCurrent(Cap, out TValue value);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TValue GetDefault()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapDefault(Cap, out TValue value);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? GetLabel()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapLabel(Cap, out string? value);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? GetHelp()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapHelp(Cap, out string? value);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IList<string> GetLabelEnum()
|
||||||
|
{
|
||||||
|
LastSTS = _twain.GetCapLabelEnum(Cap, out IList<string> value);
|
||||||
|
if (LastSTS.IsSuccess)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
return Array.Empty<string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/NTwain/Caps/CapWriter.cs
Normal file
16
src/NTwain/Caps/CapWriter.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
public class CapWriter<TValue> : CapReader<TValue> where TValue : struct
|
||||||
|
{
|
||||||
|
public CapWriter(TwainAppSession twain, CAP cap) : base(twain, cap)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/NTwain/Caps/KnownCaps.Audio.cs
Normal file
14
src/NTwain/Caps/KnownCaps.Audio.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
partial class KnownCaps
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/NTwain/Caps/KnownCaps.General.cs
Normal file
14
src/NTwain/Caps/KnownCaps.General.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
partial class KnownCaps
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/NTwain/Caps/KnownCaps.Image.cs
Normal file
14
src/NTwain/Caps/KnownCaps.Image.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
partial class KnownCaps
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/NTwain/Caps/KnownCaps.cs
Normal file
23
src/NTwain/Caps/KnownCaps.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NTwain.Caps
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides reader/writer wrapper of known <see cref="CAP"/>s.
|
||||||
|
/// </summary>
|
||||||
|
public partial class KnownCaps
|
||||||
|
{
|
||||||
|
private readonly TwainAppSession _twain;
|
||||||
|
|
||||||
|
public KnownCaps(TwainAppSession twain)
|
||||||
|
{
|
||||||
|
_twain = twain;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Caps;
|
||||||
|
using NTwain.Data;
|
||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -10,20 +12,16 @@ namespace NTwain
|
|||||||
|
|
||||||
partial class TwainAppSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
///// <summary>
|
private KnownCaps? _knownCaps;
|
||||||
///// Gets all the supported caps for the current source.
|
|
||||||
///// </summary>
|
/// <summary>
|
||||||
///// <returns></returns>
|
/// Access the known and pre-defined caps as properties.
|
||||||
//public IList<CAP> GetAllCaps()
|
/// </summary>
|
||||||
//{
|
public KnownCaps Caps
|
||||||
// // just as a sample of how to read cap values
|
{
|
||||||
|
get { return _knownCaps ??= new KnownCaps(this); }
|
||||||
|
}
|
||||||
|
|
||||||
// if (GetCapValues(CAP.CAP_SUPPORTEDCAPS, out TW_CAPABILITY value).RC == TWRC.SUCCESS)
|
|
||||||
// {
|
|
||||||
// return value.ReadArray<CAP>(this);
|
|
||||||
// }
|
|
||||||
// return Array.Empty<CAP>();
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a CAP's actual supported operations.
|
/// Gets a CAP's actual supported operations.
|
||||||
@@ -251,9 +249,9 @@ namespace NTwain
|
|||||||
/// <param name="cap"></param>
|
/// <param name="cap"></param>
|
||||||
/// <param name="labels"></param>
|
/// <param name="labels"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public STS GetCapLabelEnum(CAP cap, out IList<string>? labels)
|
public STS GetCapLabelEnum(CAP cap, out IList<string> labels)
|
||||||
{
|
{
|
||||||
labels = null;
|
labels = Array.Empty<string>();
|
||||||
var value = new TW_CAPABILITY(cap);
|
var value = new TW_CAPABILITY(cap);
|
||||||
var rc = DGControl.Capability.GetLabelEnum(ref _appIdentity, ref _currentDS, ref value);
|
var rc = DGControl.Capability.GetLabelEnum(ref _appIdentity, ref _currentDS, ref value);
|
||||||
if (rc == TWRC.SUCCESS)
|
if (rc == TWRC.SUCCESS)
|
||||||
|
|||||||
Reference in New Issue
Block a user