mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-24 16:53:24 +08:00
Updated exception message texts and more cases on stepdown().
This commit is contained in:
27
src/NTwain/Resources/MsgText.Designer.cs
generated
27
src/NTwain/Resources/MsgText.Designer.cs
generated
@@ -68,5 +68,32 @@ namespace NTwain.Resources {
|
|||||||
return ResourceManager.GetString("MaxStringLengthExceeded", resourceCulture);
|
return ResourceManager.GetString("MaxStringLengthExceeded", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to No data type specified..
|
||||||
|
/// </summary>
|
||||||
|
internal static string NoDataTypesSpecified {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("NoDataTypesSpecified", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to This platform ({0}) is not supported..
|
||||||
|
/// </summary>
|
||||||
|
internal static string PlatformNotSupported {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("PlatformNotSupported", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Source is not from this session..
|
||||||
|
/// </summary>
|
||||||
|
internal static string SourceNotThisSession {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("SourceNotThisSession", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,4 +120,13 @@
|
|||||||
<data name="MaxStringLengthExceeded" xml:space="preserve">
|
<data name="MaxStringLengthExceeded" xml:space="preserve">
|
||||||
<value>The string value has exceeded the maximum length of {0}.</value>
|
<value>The string value has exceeded the maximum length of {0}.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NoDataTypesSpecified" xml:space="preserve">
|
||||||
|
<value>No data type specified.</value>
|
||||||
|
</data>
|
||||||
|
<data name="PlatformNotSupported" xml:space="preserve">
|
||||||
|
<value>This platform ({0}) is not supported.</value>
|
||||||
|
</data>
|
||||||
|
<data name="SourceNotThisSession" xml:space="preserve">
|
||||||
|
<value>Source is not from this session.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
using NTwain.Internals;
|
using NTwain.Internals;
|
||||||
|
using NTwain.Resources;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -57,7 +58,7 @@ namespace NTwain
|
|||||||
if (image) dg |= DataGroups.Image;
|
if (image) dg |= DataGroups.Image;
|
||||||
if (audio) dg |= DataGroups.Audio;
|
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;
|
_dg = dg;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ namespace NTwain
|
|||||||
case PlatformID.Unix:
|
case PlatformID.Unix:
|
||||||
case PlatformID.MacOSX:
|
case PlatformID.MacOSX:
|
||||||
default:
|
default:
|
||||||
throw new PlatformNotSupportedException($"This platform {_platform} is not supported.");
|
throw new PlatformNotSupportedException(string.Format(MsgText.PlatformNotSupported, _platform));
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
|
using NTwain.Resources;
|
||||||
using NTwain.Threading;
|
using NTwain.Threading;
|
||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
@@ -24,7 +25,7 @@ namespace NTwain
|
|||||||
readonly Dictionary<string, DataSource> _ownedSources = new Dictionary<string, DataSource>();
|
readonly Dictionary<string, DataSource> _ownedSources = new Dictionary<string, DataSource>();
|
||||||
// need to keep delegate around to prevent GC?
|
// need to keep delegate around to prevent GC?
|
||||||
readonly Callback32 _callback32Delegate;
|
readonly Callback32 _callback32Delegate;
|
||||||
|
// for windows only
|
||||||
readonly WinMsgLoop _winMsgLoop;
|
readonly WinMsgLoop _winMsgLoop;
|
||||||
|
|
||||||
|
|
||||||
@@ -32,9 +33,10 @@ namespace NTwain
|
|||||||
/// Constructs a new <see cref="TwainSession"/>.
|
/// Constructs a new <see cref="TwainSession"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public TwainSession(TwainConfig config)
|
public TwainSession(TwainConfig config)
|
||||||
{
|
{
|
||||||
Config = config;
|
Config = config ?? throw new ArgumentNullException(nameof(config));
|
||||||
switch (config.Platform)
|
switch (config.Platform)
|
||||||
{
|
{
|
||||||
case PlatformID.MacOSX:
|
case PlatformID.MacOSX:
|
||||||
@@ -46,15 +48,28 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Synchronously invokes an action on the internal thread if possible.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public void Invoke(Action action)
|
public void Invoke(Action action)
|
||||||
{
|
{
|
||||||
|
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||||
|
|
||||||
if (_winMsgLoop != null) _winMsgLoop.Invoke(action);
|
if (_winMsgLoop != null) _winMsgLoop.Invoke(action);
|
||||||
else action();
|
else action();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously invokes an action on the internal thread if possible.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public void BeginInvoke(Action action)
|
public void BeginInvoke(Action action)
|
||||||
{
|
{
|
||||||
|
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||||
|
|
||||||
if (_winMsgLoop != null) _winMsgLoop.BeginInvoke(action);
|
if (_winMsgLoop != null) _winMsgLoop.BeginInvoke(action);
|
||||||
else action();
|
else action();
|
||||||
}
|
}
|
||||||
@@ -116,6 +131,14 @@ namespace NTwain
|
|||||||
rc = DGControl.Identity.CloseDS(CurrentSource.Identity32);
|
rc = DGControl.Identity.CloseDS(CurrentSource.Identity32);
|
||||||
if (rc != ReturnCode.Success) return rc;
|
if (rc != ReturnCode.Success) return rc;
|
||||||
break;
|
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;
|
return rc;
|
||||||
@@ -210,7 +233,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
if (value.Session != this)
|
if (value.Session != this)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Source is not from this session.");
|
throw new InvalidOperationException(MsgText.SourceNotThisSession);
|
||||||
}
|
}
|
||||||
var rc = DGControl.Identity.Set(value);
|
var rc = DGControl.Identity.Set(value);
|
||||||
RaisePropertyChanged(nameof(DefaultSource));
|
RaisePropertyChanged(nameof(DefaultSource));
|
||||||
@@ -274,7 +297,7 @@ namespace NTwain
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Session: {State}";
|
return State.ToString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user