From 59b5437ba01aa82d3cc1a5ea7b20b4c232466701 Mon Sep 17 00:00:00 2001 From: soukoku Date: Tue, 21 Apr 2015 06:23:33 -0400 Subject: [PATCH] Allow selecting/opening a source by id in case of duplicate names. --- src/NTwain/DataSource.cs | 8 ++++++++ src/NTwain/IDataSource.cs | 8 ++++++++ src/NTwain/ITwainSession.cs | 7 +++++++ src/NTwain/Properties/VersionInfo.cs | 2 +- src/NTwain/TwainSession.cs | 22 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/NTwain/DataSource.cs b/src/NTwain/DataSource.cs index 5991ab6..bb6cfa4 100644 --- a/src/NTwain/DataSource.cs +++ b/src/NTwain/DataSource.cs @@ -103,6 +103,14 @@ namespace NTwain internal TWIdentity Identity { get; private set; } + /// + /// Gets the id of the source. + /// + /// + /// The identifier. + /// + public int Id { get { return Identity.Id; } } + /// /// Gets the source's product name. /// diff --git a/src/NTwain/IDataSource.cs b/src/NTwain/IDataSource.cs index d10478b..6efc3d2 100644 --- a/src/NTwain/IDataSource.cs +++ b/src/NTwain/IDataSource.cs @@ -8,6 +8,14 @@ namespace NTwain /// public interface IDataSource : ITripletControl { + /// + /// Gets the id of the source. + /// + /// + /// The identifier. + /// + int Id { get; } + /// /// Gets the source's product name. /// diff --git a/src/NTwain/ITwainSession.cs b/src/NTwain/ITwainSession.cs index cdaf2a3..da7c88b 100644 --- a/src/NTwain/ITwainSession.cs +++ b/src/NTwain/ITwainSession.cs @@ -136,6 +136,13 @@ namespace NTwain /// ReturnCode OpenSource(string sourceName); + /// + /// Quick shortcut to open a source. + /// + /// Id of the source. + /// + ReturnCode OpenSource(int sourceId); + /// /// Gets the manager status. Only call this at state 2 or higher. /// diff --git a/src/NTwain/Properties/VersionInfo.cs b/src/NTwain/Properties/VersionInfo.cs index 9bf651d..a1f25a4 100644 --- a/src/NTwain/Properties/VersionInfo.cs +++ b/src/NTwain/Properties/VersionInfo.cs @@ -23,7 +23,7 @@ namespace NTwain /// /// The build release version number. /// - public const string Build = "3.3.2"; // change this for each nuget release + public const string Build = "3.3.3"; // change this for each nuget release } diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainSession.cs index dc8e68a..b8d5e45 100644 --- a/src/NTwain/TwainSession.cs +++ b/src/NTwain/TwainSession.cs @@ -309,6 +309,28 @@ namespace NTwain return ReturnCode.Failure; } + /// + /// Quick shortcut to open a source. + /// + /// Id of the source. + /// + public ReturnCode OpenSource(int sourceId) + { + var curSrc = CurrentSource; + if (curSrc != null) + { + // TODO: close any open sources first + + } + + var hit = this.Where(s => s.Id == sourceId).FirstOrDefault(); + if (hit != null) + { + return hit.Open(); + } + return ReturnCode.Failure; + } + /// /// Gets the manager status. Only call this at state 2 or higher. ///