diff --git a/src/NTwain/Resources/MsgText.Designer.cs b/src/NTwain/Resources/MsgText.Designer.cs index cf617b5..022a7ed 100644 --- a/src/NTwain/Resources/MsgText.Designer.cs +++ b/src/NTwain/Resources/MsgText.Designer.cs @@ -68,5 +68,32 @@ namespace NTwain.Resources { return ResourceManager.GetString("MaxStringLengthExceeded", resourceCulture); } } + + /// + /// Looks up a localized string similar to No data type specified.. + /// + internal static string NoDataTypesSpecified { + get { + return ResourceManager.GetString("NoDataTypesSpecified", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This platform ({0}) is not supported.. + /// + internal static string PlatformNotSupported { + get { + return ResourceManager.GetString("PlatformNotSupported", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Source is not from this session.. + /// + internal static string SourceNotThisSession { + get { + return ResourceManager.GetString("SourceNotThisSession", resourceCulture); + } + } } } diff --git a/src/NTwain/Resources/MsgText.resx b/src/NTwain/Resources/MsgText.resx index e400ebd..090a54b 100644 --- a/src/NTwain/Resources/MsgText.resx +++ b/src/NTwain/Resources/MsgText.resx @@ -120,4 +120,13 @@ The string value has exceeded the maximum length of {0}. + + No data type specified. + + + This platform ({0}) is not supported. + + + Source is not from this session. + \ No newline at end of file diff --git a/src/NTwain/TwainConfigBuilder.cs b/src/NTwain/TwainConfigBuilder.cs index d8b3a76..60ecb03 100644 --- a/src/NTwain/TwainConfigBuilder.cs +++ b/src/NTwain/TwainConfigBuilder.cs @@ -1,5 +1,6 @@ using NTwain.Data; using NTwain.Internals; +using NTwain.Resources; using System; using System.Diagnostics; using System.Reflection; @@ -57,7 +58,7 @@ namespace NTwain if (image) dg |= DataGroups.Image; if (audio) dg |= DataGroups.Audio; - if (dg == DataGroups.None) throw new InvalidOperationException("No data type specified."); + if (dg == DataGroups.None) throw new InvalidOperationException(MsgText.NoDataTypesSpecified); _dg = dg; return this; } @@ -138,7 +139,7 @@ namespace NTwain case PlatformID.Unix: case PlatformID.MacOSX: default: - throw new PlatformNotSupportedException($"This platform {_platform} is not supported."); + throw new PlatformNotSupportedException(string.Format(MsgText.PlatformNotSupported, _platform)); } return config; } diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainSession.cs index d25d551..0670a9d 100644 --- a/src/NTwain/TwainSession.cs +++ b/src/NTwain/TwainSession.cs @@ -1,4 +1,5 @@ using NTwain.Data; +using NTwain.Resources; using NTwain.Threading; using NTwain.Triplets; using System; @@ -24,7 +25,7 @@ namespace NTwain readonly Dictionary _ownedSources = new Dictionary(); // need to keep delegate around to prevent GC? readonly Callback32 _callback32Delegate; - + // for windows only readonly WinMsgLoop _winMsgLoop; @@ -32,9 +33,10 @@ namespace NTwain /// Constructs a new . /// /// + /// public TwainSession(TwainConfig config) { - Config = config; + Config = config ?? throw new ArgumentNullException(nameof(config)); switch (config.Platform) { case PlatformID.MacOSX: @@ -46,15 +48,28 @@ namespace NTwain } } - + /// + /// Synchronously invokes an action on the internal thread if possible. + /// + /// + /// public void Invoke(Action action) { + if (action == null) throw new ArgumentNullException(nameof(action)); + if (_winMsgLoop != null) _winMsgLoop.Invoke(action); else action(); } + /// + /// Asynchronously invokes an action on the internal thread if possible. + /// + /// + /// public void BeginInvoke(Action action) { + if (action == null) throw new ArgumentNullException(nameof(action)); + if (_winMsgLoop != null) _winMsgLoop.BeginInvoke(action); else action(); } @@ -116,6 +131,14 @@ namespace NTwain rc = DGControl.Identity.CloseDS(CurrentSource.Identity32); if (rc != ReturnCode.Success) return rc; break; + case TwainState.SourceEnabled: + rc = DGControl.UserInterface.DisableDS(ref _lastEnableUI, false); + if (rc != ReturnCode.Success) return rc; + break; + case TwainState.TransferReady: + case TwainState.Transferring: + _disableDSNow = true; + break; } } return rc; @@ -210,7 +233,7 @@ namespace NTwain { if (value.Session != this) { - throw new InvalidOperationException("Source is not from this session."); + throw new InvalidOperationException(MsgText.SourceNotThisSession); } var rc = DGControl.Identity.Set(value); RaisePropertyChanged(nameof(DefaultSource)); @@ -274,7 +297,7 @@ namespace NTwain /// public override string ToString() { - return $"Session: {State}"; + return State.ToString() } } }