Moved identities to propevents file.

This commit is contained in:
Eugene Wang 2023-04-01 08:01:20 -04:00
parent 003edcccce
commit 260ae9fdef
4 changed files with 31 additions and 27 deletions

View File

@ -8,6 +8,12 @@ namespace SampleConsole
static void Main(string[] args)
{
var twain = new TwainSession(Environment.ProcessPath ?? Assembly.GetExecutingAssembly().Location);
twain.StateChanged += Twain_StateChanged;
}
private static void Twain_StateChanged(TwainSession session, TWAINWorkingGroup.STATE state)
{
Console.WriteLine($"State changed to {state}");
}
}
}

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<PackageId>NTwain</PackageId>
<Description>Library containing the TWAIN API for dotnet.</Description>
<TargetFrameworks>net462;net6.0;net7.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View File

@ -13,6 +13,27 @@ namespace NTwain
partial class TwainSession
{
// really legacy version is the one to be used (except on mac) or
// until it doesn't work (special linux)
/// <summary>
/// Gets the app identity.
/// </summary>
public TW_IDENTITY_LEGACY AppIdentity => _appIdentityLegacy;
internal TW_IDENTITY_LEGACY _appIdentityLegacy;
internal TW_IDENTITY _appIdentity;
internal TW_IDENTITY_MACOSX _appIdentityOSX;
/// <summary>
/// Gets the current data source.
/// </summary>
public TW_IDENTITY_LEGACY DSIdentity => _dsIdentityLegacy;
internal TW_IDENTITY_LEGACY _dsIdentityLegacy;
internal TW_IDENTITY _dsIdentity;
internal TW_IDENTITY_MACOSX _dsIdentityOSX;
private STATE _state = STATE.S1;
/// <summary>
@ -20,13 +41,13 @@ namespace NTwain
/// </summary>
public STATE State
{
get { return _state; }
get => _state;
private set
{
if (_state != value)
{
_state = value;
StateChanged?.Invoke(this, value);
StateChanged?.Invoke(this, value); // TODO: should care about thread
}
}
}

View File

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TWAINWorkingGroup;
namespace NTwain
@ -77,26 +73,7 @@ namespace NTwain
}
};
if (TwainPlatform.IsLinux) _appIdentity = _appIdentityLegacy;
if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentityLegacy;
else if (TwainPlatform.IsMacOSX) _appIdentityOSX = _appIdentityLegacy;
}
// really legacy version is the one to be used (except on mac) or
// until it doesn't work (special linux)
/// <summary>
/// Gets the app identity.
/// </summary>
public TW_IDENTITY_LEGACY AppIdentity => _appIdentityLegacy;
internal TW_IDENTITY_LEGACY _appIdentityLegacy;
internal TW_IDENTITY _appIdentity;
internal TW_IDENTITY_MACOSX _appIdentityOSX;
/// <summary>
/// Gets the current data source.
/// </summary>
public TW_IDENTITY_LEGACY DSIdentity => _dsIdentityLegacy;
internal TW_IDENTITY_LEGACY _dsIdentityLegacy;
internal TW_IDENTITY _dsIdentity;
internal TW_IDENTITY_MACOSX _dsIdentityOSX;
}
}