mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 04:12:44 +08:00
Toying around with a signalr server sample.
This commit is contained in:
parent
4d8da799c0
commit
9467bb5409
15
NTwain.sln
15
NTwain.sln
@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm64", "samples\WinFor
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csizes", "csizes\csizes.vcxproj", "{1AABD2DC-3F81-4301-938B-3EC2EDEF38D4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleServer", "samples\SampleServer\SampleServer.csproj", "{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -86,6 +88,18 @@ Global
|
||||
{1AABD2DC-3F81-4301-938B-3EC2EDEF38D4}.Release|x64.Build.0 = Release|x64
|
||||
{1AABD2DC-3F81-4301-938B-3EC2EDEF38D4}.Release|x86.ActiveCfg = Release|Win32
|
||||
{1AABD2DC-3F81-4301-938B-3EC2EDEF38D4}.Release|x86.Build.0 = Release|Win32
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -93,6 +107,7 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{7792A94E-D0B4-440D-8BD5-CA1CA548782C} = {707B4313-8EF8-4D0F-A95E-590783422187}
|
||||
{C9666CB2-C9A6-48C8-AB51-D616A48058A7} = {707B4313-8EF8-4D0F-A95E-590783422187}
|
||||
{0BA3FBF4-E105-46E9-AAA5-283FD9D9940B} = {707B4313-8EF8-4D0F-A95E-590783422187}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7459323B-44F6-4E07-8574-E1B4B525086B}
|
||||
|
38
samples/SampleServer/DsmLoader.cs
Normal file
38
samples/SampleServer/DsmLoader.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
/// <summary>
|
||||
/// For demoing loading dsm from custom path in case
|
||||
/// it's not installed on system and don't want to be
|
||||
/// placed besides the exe.
|
||||
/// </summary>
|
||||
static class DsmLoader
|
||||
{
|
||||
static IntPtr __dllPtr;
|
||||
|
||||
public static bool TryUseCustomDSM()
|
||||
{
|
||||
if (__dllPtr == IntPtr.Zero)
|
||||
{
|
||||
var dll = Path.Combine(
|
||||
Path.GetDirectoryName(Environment.ProcessPath ?? Assembly.GetExecutingAssembly().Location)!,
|
||||
$@"runtimes\win-{(TWPlatform.Is32bit ? "x86" : "x64")}\native\TWAINDSM.dll");
|
||||
|
||||
__dllPtr = LoadLibraryW(dll);
|
||||
}
|
||||
return __dllPtr != IntPtr.Zero;
|
||||
}
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
static extern IntPtr LoadLibraryW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
|
||||
}
|
||||
}
|
21
samples/SampleServer/ITwainClient.cs
Normal file
21
samples/SampleServer/ITwainClient.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
public interface ITwainClient
|
||||
{
|
||||
// mirrors the twain session events
|
||||
Task StateChanged(STATE state);
|
||||
Task DefaultSourceChanged(string? source);
|
||||
Task CurrentSourceChanged(string? source);
|
||||
Task SourceDisabled(string source);
|
||||
Task DeviceEvent(TW_DEVICEEVENT evt);
|
||||
Task TransferError();
|
||||
Task<CancelType> TransferReady(int pending, TWEJ eojType);
|
||||
Task TransferCanceled();
|
||||
Task Transferred();
|
||||
}
|
||||
}
|
22
samples/SampleServer/Program.cs
Normal file
22
samples/SampleServer/Program.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddSignalR();
|
||||
builder.Services.AddHostedService<WinformHost>();
|
||||
builder.Services.AddSingleton<TwainForm>();
|
||||
|
||||
var app = builder.Build();
|
||||
app.MapHub<TwainHub>("/twain");
|
||||
app.MapGet("/about", (TwainForm form) => form.Text);
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
30
samples/SampleServer/SampleServer.csproj
Normal file
30
samples/SampleServer/SampleServer.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\NTwain\NTwain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="runtimes\win-x86\native\TWAINDSM.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
59
samples/SampleServer/TwainForm.Designer.cs
generated
Normal file
59
samples/SampleServer/TwainForm.Designer.cs
generated
Normal file
@ -0,0 +1,59 @@
|
||||
namespace SampleServer
|
||||
{
|
||||
partial class TwainForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
button1 = new System.Windows.Forms.Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Location = new System.Drawing.Point(63, 29);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new System.Drawing.Size(315, 37);
|
||||
button1.TabIndex = 0;
|
||||
button1.Text = "Start a test run";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += button1_Click;
|
||||
//
|
||||
// TwainForm
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(447, 102);
|
||||
Controls.Add(button1);
|
||||
Name = "TwainForm";
|
||||
Text = "TWAIN Server";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button button1;
|
||||
}
|
||||
}
|
118
samples/SampleServer/TwainForm.cs
Normal file
118
samples/SampleServer/TwainForm.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
public partial class TwainForm : Form
|
||||
{
|
||||
private readonly IHubContext<TwainHub, ITwainClient> _hub;
|
||||
private int _count;
|
||||
|
||||
public TwainAppSession Session { get; }
|
||||
// dont really care about value
|
||||
public ConcurrentDictionary<string, bool> KnownClients { get; } = new ConcurrentDictionary<string, bool>();
|
||||
|
||||
public TwainForm(IHubContext<TwainHub, ITwainClient> hub)
|
||||
{
|
||||
InitializeComponent();
|
||||
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).ProductVersion;
|
||||
Text += $"{(TWPlatform.Is32bit ? " 32bit" : " 64bit")} on NTwain {libVer}";
|
||||
_hub = hub;
|
||||
|
||||
Session = new TwainAppSession(SynchronizationContext.Current!, Environment.ProcessPath!);
|
||||
Session.StateChanged += Session_StateChanged;
|
||||
Session.DefaultSourceChanged += Session_DefaultSourceChanged;
|
||||
Session.CurrentSourceChanged += Session_CurrentSourceChanged;
|
||||
Session.SourceDisabled += Session_SourceDisabled;
|
||||
Session.TransferReady += Session_TransferReady;
|
||||
Session.Transferred += Session_Transferred;
|
||||
Session.TransferCanceled += Session_TransferCanceled;
|
||||
Session.TransferError += Session_TransferError;
|
||||
}
|
||||
|
||||
private void Session_TransferError(TwainAppSession sender, TransferErrorEventArgs e)
|
||||
{
|
||||
_hub.Clients.All.TransferError();
|
||||
}
|
||||
|
||||
private void Session_TransferCanceled(TwainAppSession sender, TransferCanceledEventArgs e)
|
||||
{
|
||||
_hub.Clients.All.TransferCanceled();
|
||||
}
|
||||
|
||||
private void Session_DefaultSourceChanged(TwainAppSession sender, TW_IDENTITY_LEGACY e)
|
||||
{
|
||||
_hub.Clients.All.DefaultSourceChanged(e.HasValue ? e.ProductName.ToString() : null);
|
||||
}
|
||||
|
||||
private void Session_CurrentSourceChanged(TwainAppSession sender, TW_IDENTITY_LEGACY e)
|
||||
{
|
||||
_hub.Clients.All.CurrentSourceChanged(e.HasValue ? e.ProductName.ToString() : null);
|
||||
}
|
||||
|
||||
private void Session_SourceDisabled(TwainAppSession sender, TW_IDENTITY_LEGACY e)
|
||||
{
|
||||
Debug.WriteLine("Ended");
|
||||
_hub.Clients.All.SourceDisabled(e.ProductName.ToString());
|
||||
}
|
||||
|
||||
private async void Session_TransferReady(TwainAppSession sender, TransferReadyEventArgs e)
|
||||
{
|
||||
foreach (var c in KnownClients.Keys)
|
||||
{
|
||||
var test = await _hub.Clients.Client(c).TransferReady(e.PendingCount, e.EndOfJobFlag);
|
||||
if (test != CancelType.None)
|
||||
{
|
||||
e.Cancel = test;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Session_StateChanged(TwainAppSession sender, STATE e)
|
||||
{
|
||||
_hub.Clients.All.StateChanged(e);
|
||||
}
|
||||
|
||||
private void Session_Transferred(TwainAppSession sender, TransferredEventArgs e)
|
||||
{
|
||||
_count++;
|
||||
Debug.WriteLine("Transferred " + _count);
|
||||
e.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
Session.OpenDSM(Handle);
|
||||
Session.AddWinformFilter();
|
||||
base.OnHandleCreated(e);
|
||||
}
|
||||
|
||||
protected override void OnHandleDestroyed(EventArgs e)
|
||||
{
|
||||
Session.RemoveWinformFilter();
|
||||
Session.CloseDSM();
|
||||
Session.Dispose();
|
||||
base.OnHandleDestroyed(e);
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Session.State == STATE.S3)
|
||||
{
|
||||
var sts = Session.OpenSource(Session.DefaultSource);
|
||||
}
|
||||
if (Session.State == STATE.S4)
|
||||
{
|
||||
_count = 0;
|
||||
var sts = Session.EnableSource(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
samples/SampleServer/TwainForm.resx
Normal file
60
samples/SampleServer/TwainForm.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
67
samples/SampleServer/TwainHub.cs
Normal file
67
samples/SampleServer/TwainHub.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
public class TwainHub : Hub<ITwainClient>
|
||||
{
|
||||
private readonly TwainForm twain;
|
||||
|
||||
public TwainHub(TwainForm twain)
|
||||
{
|
||||
this.twain = twain;
|
||||
}
|
||||
|
||||
public override Task OnConnectedAsync()
|
||||
{
|
||||
Debug.WriteLine("Server hub got connected by " + Context.ConnectionId);
|
||||
twain.KnownClients.TryAdd(Context.ConnectionId, true);
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public override Task OnDisconnectedAsync(Exception? exception)
|
||||
{
|
||||
Debug.WriteLine("Server hub got disconnected by " + Context.ConnectionId);
|
||||
twain.KnownClients.TryRemove(Context.ConnectionId, out _);
|
||||
return base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetSources()
|
||||
{
|
||||
return twain.Session.GetSources().Select(s => s.ProductName.ToString());
|
||||
}
|
||||
|
||||
public STS OpenSource(string source)
|
||||
{
|
||||
if (twain.Session.State == STATE.S3)
|
||||
{
|
||||
var hit = twain.Session.GetSources()
|
||||
.FirstOrDefault(s => s.ProductName.ToString() == source);
|
||||
|
||||
if (hit.HasValue) return twain.Session.OpenSource(hit);
|
||||
|
||||
return new STS { RC = TWRC.FAILURE, STATUS = new TW_STATUS { ConditionCode = TWCC.BADDEST } };
|
||||
}
|
||||
return new STS { RC = TWRC.FAILURE, STATUS = new TW_STATUS { ConditionCode = TWCC.SEQERROR } };
|
||||
}
|
||||
public STS CloseSource(string source)
|
||||
{
|
||||
if (twain.Session.State == STATE.S4)
|
||||
{
|
||||
return twain.Session.CloseSource();
|
||||
}
|
||||
return new STS { RC = TWRC.FAILURE, STATUS = new TW_STATUS { ConditionCode = TWCC.SEQERROR } };
|
||||
}
|
||||
public STS EnableSource(bool showUI, bool uiOnly)
|
||||
{
|
||||
if (twain.Session.State == STATE.S4)
|
||||
return twain.Invoke(new Func<STS>(() => twain.Session.EnableSource(showUI, uiOnly)));
|
||||
return new STS { RC = TWRC.FAILURE, STATUS = new TW_STATUS { ConditionCode = TWCC.SEQERROR } };
|
||||
}
|
||||
}
|
||||
}
|
71
samples/SampleServer/WinformHost.cs
Normal file
71
samples/SampleServer/WinformHost.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SampleServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Hosts the winform UI message loop.
|
||||
/// </summary>
|
||||
internal class WinformHost : IHostedService
|
||||
{
|
||||
private readonly IServiceProvider services;
|
||||
private readonly IHostApplicationLifetime lifetime;
|
||||
ManualResetEvent _threadEnded;
|
||||
TwainForm? _mainWindow;
|
||||
|
||||
public WinformHost(IServiceProvider services, IHostApplicationLifetime lifetime)
|
||||
{
|
||||
_threadEnded = new ManualResetEvent(false);
|
||||
this.services = services;
|
||||
this.lifetime = lifetime;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Thread t = new(RunWinform);
|
||||
t.SetApartmentState(ApartmentState.STA);
|
||||
t.Start();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_mainWindow != null && _mainWindow.IsHandleCreated)
|
||||
{
|
||||
_mainWindow.BeginInvoke(Application.ExitThread);
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_threadEnded.WaitOne();
|
||||
});
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
void RunWinform()
|
||||
{
|
||||
if (DsmLoader.TryUseCustomDSM())
|
||||
{
|
||||
Debug.WriteLine("Using our own dsm now :)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("Will attempt to use default dsm :(");
|
||||
}
|
||||
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
_mainWindow = services.GetRequiredService<TwainForm>();
|
||||
Application.Run(_mainWindow);
|
||||
|
||||
_threadEnded.Set();
|
||||
lifetime.StopApplication();
|
||||
}
|
||||
}
|
||||
}
|
8
samples/SampleServer/appsettings.Development.json
Normal file
8
samples/SampleServer/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
samples/SampleServer/appsettings.json
Normal file
9
samples/SampleServer/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
BIN
samples/SampleServer/runtimes/win-x86/native/TWAINDSM.dll
Normal file
BIN
samples/SampleServer/runtimes/win-x86/native/TWAINDSM.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user