Some quality of life improvements.

This commit is contained in:
Eugene Wang 2023-04-10 19:47:01 -04:00
parent 88458c0d7d
commit b89c186987
5 changed files with 41 additions and 3 deletions

View File

@ -227,6 +227,16 @@ namespace NTwain.Data
// return new STS { RC = rc };
//}
/// <summary>
/// Quick check if the RC is success.
/// </summary>
public bool IsSuccess => RC == TWRC.SUCCESS;
/// <summary>
/// Quick access to condition code.
/// </summary>
public TWCC ConditionCode => STATUS.ConditionCode;
public override string ToString()
{
return $"{RC} - {STATUS.ConditionCode}";
@ -647,10 +657,16 @@ namespace NTwain.Data
}
partial struct TW_IDENTITY_LEGACY
{
/// <summary>
/// A simplified check on whether this has valid data from DSM.
/// </summary>
public bool HasValue => Id == 0 && ProtocolMajor == 0 && ProtocolMinor == 0;
public override string ToString()
{
return $"{Manufacturer} - {ProductName} v{Version.MajorNum}.{Version.MinorNum} (TWAIN {ProtocolMajor}.{ProtocolMinor})";
}
public static implicit operator TW_IDENTITY(TW_IDENTITY_LEGACY value) => new()
{
Id = value.Id,
@ -820,6 +836,7 @@ namespace NTwain.Data
// provide casted versions over raw value
public TWDE Event { get { return (TWDE)_Event; } }
public TWFL FlashUsed2 { get { return (TWFL)_FlashUsed2; } }
}

View File

@ -287,6 +287,20 @@ namespace NTwain
return WrapInSTS(rc);
}
/// <summary>
/// A simpler cap value setter for common one-value scenarios
/// that's easier to use. Not for other container type sets.
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="cap"></param>
/// <param name="value"></param>
/// <returns></returns>
public STS SetCap<TValue>(CAP cap, TValue value) where TValue : struct
{
var twcap = ValueWriter.CreateOneValueCap(cap, this, value);
return SetCap(ref twcap);
}
/// <summary>
/// Sets a CAP's constraint values.
/// An easy way to create a value is to use the

View File

@ -134,10 +134,15 @@ namespace NTwain
public event TwainEventDelegate<TW_IDENTITY_LEGACY>? DefaultSourceChanged;
/// <summary>
/// Fires when <see cref="CurrentSource"/> changes.
/// Fires when <see cref="CurrentSource"/> changes (opened and closed).
/// </summary>
public event TwainEventDelegate<TW_IDENTITY_LEGACY>? CurrentSourceChanged;
/// <summary>
/// Fires when source has moved from enabled to disabled state.
/// </summary>
public event TwainEventDelegate<TW_IDENTITY_LEGACY>? SourceDisabled;
/// <summary>
/// Fires when the source has some device event happening.
/// </summary>

View File

@ -142,6 +142,7 @@ namespace NTwain
if (rc == TWRC.SUCCESS)
{
State = STATE.S4;
SourceDisabled?.Invoke(this, _currentDS);
}
return WrapInSTS(rc);
}

View File

@ -228,12 +228,13 @@ namespace NTwain
}
/// <summary>
/// Wraps return code with additional status if not successful.
/// Wraps a return code with additional status if not successful.
/// Use this right after an API call to get its condition code.
/// </summary>
/// <param name="rc"></param>
/// <param name="dsmOnly">true to get status for dsm operation error, false to get status for ds operation error,</param>
/// <returns></returns>
protected STS WrapInSTS(TWRC rc, bool dsmOnly = false)
public STS WrapInSTS(TWRC rc, bool dsmOnly = false)
{
if (rc != TWRC.FAILURE) return new STS { RC = rc };
var sts = new STS { RC = rc, STATUS = GetLastStatus(dsmOnly) };