master
wanggang 4 years ago
parent a7c0652a34
commit c15c81d0b1

@ -1,16 +1,12 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
public class CVRHelper : IDisposable
{
private CancellationTokenSource _cts = new CancellationTokenSource();
private bool disposedValue;
private bool connetctd;
public Action<bool> OnConnect { get; set; }
public Action<IdCardModel> OnRead { get; set; }
@ -38,13 +34,25 @@ public class CVRHelper : IDisposable
break;
}
}
this.OnConnect?.Invoke(cvrStatus == 1);
if (cvrStatus == 1 && CVRSDK.CVR_Authenticate() == 1 && CVRSDK.CVR_Read_FPContent() == 1)
if(cvrStatus == 1)
{
this.OnRead?.Invoke(this.Read());
if (!connetctd)
{
connetctd = true;
this.OnConnect?.Invoke(true);
}
if (CVRSDK.CVR_Authenticate() == 1 && CVRSDK.CVR_Read_FPContent() == 1)
{
this.OnRead?.Invoke(this.Read());
}
}
else
{
connetctd = false;
this.OnConnect?.Invoke(false);
}
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
@ -57,6 +65,7 @@ public class CVRHelper : IDisposable
}
return null;
}
private IdCardModel Read()
{
try

@ -1,5 +1,6 @@
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
using Serilog;
using System.Security.Cryptography;
using System.Text.Encodings.Web;
using System.Text.Json;
@ -21,7 +22,7 @@ namespace PhotoCollector
InitializeComponent();
}
private async void MainForm_Shown(object sender, EventArgs e)
private void MainForm_Shown(object sender, EventArgs e)
{
InitCVR();
InitWebViewAsync();
@ -37,7 +38,7 @@ namespace PhotoCollector
await this.webView21.EnsureCoreWebView2Async(env);
}
private void CoreWebView2_PermissionRequested(object? sender, CoreWebView2PermissionRequestedEventArgs e)
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e)
{
if (e.PermissionKind == CoreWebView2PermissionKind.Camera)
{
@ -45,22 +46,25 @@ namespace PhotoCollector
}
}
private void WebView21_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
private void WebView21_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
var webView = sender as WebView2;
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
webView.CoreWebView2.Settings.IsPinchZoomEnabled = false;
webView.CoreWebView2.Settings.IsBuiltInErrorPageEnabled = false;
if(webView!=null)
{
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
webView.CoreWebView2.Settings.IsPinchZoomEnabled = false;
webView.CoreWebView2.Settings.IsBuiltInErrorPageEnabled = false;
#if !DEBUG
webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
#endif
webView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
webView.CoreWebView2.Settings.UserAgent = $"{webView.CoreWebView2.Settings.UserAgent}|{AppContext.BaseDirectory}";
webView.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived;
AddEventHandler();
webView.CoreWebView2.AddHostObjectToScript("dotnet", new WebView2Interop());
webView.CoreWebView2.Navigate("https://localhost:7235/");
webView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
webView.CoreWebView2.Settings.UserAgent = $"{webView.CoreWebView2.Settings.UserAgent}|{AppContext.BaseDirectory}";
webView.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived;
AddEventHandler();
webView.CoreWebView2.AddHostObjectToScript("dotnet", new WebView2Interop());
webView.CoreWebView2.Navigate("https://localhost:7235/");
}
}
private void AddEventHandler()
@ -152,17 +156,20 @@ namespace PhotoCollector
});
}
private void CoreWebView2_WebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs e)
private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(e.WebMessageAsJson);
var command = dict["command"];
if (command == "setStatus")
if(dict != null)
{
this.toolStripStatusLabel1.Text = dict["message"];
var command = dict["command"];
if (command == "setStatus")
{
this.toolStripStatusLabel1.Text = dict["message"];
}
}
}
private void WebView21_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
private void WebView21_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
if (!e.IsSuccess)
{
@ -183,6 +190,7 @@ namespace PhotoCollector
try
{
var msg = o ? "读卡器已连接" : "读卡器未连接";
Log.Information(msg);
if (this.toolStripStatusLabel1.Text != msg)
{
this.toolStripStatusLabel1.Text = msg;
@ -204,6 +212,7 @@ namespace PhotoCollector
}
try
{
Log.Information($"read idcard: {o.Name}|{o.Sex}|{o.IdCardNo} ");
this.toolStripStatusLabel1.Text = o.Name;
var param = JsonSerializer.Serialize(o, jsonSerializerOptions);
this.webView21.ExecuteScriptAsync($"onIdCardRead({param})");

@ -3,30 +3,54 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PlatformTarget>x64</PlatformTarget>
<DebugType>embedded</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>full</DebugType>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="6.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1020.30" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="license.dat">
<None Update="x64\license.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\sdtapi.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\Termb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\WltRS.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x86\license.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="sdtapi.dll">
<None Update="x86\sdtapi.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Termb.dll">
<None Update="x86\Termb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="WltRS.dll">
<None Update="x86\WltRS.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

@ -1,16 +1,57 @@
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace PhotoCollector
{
internal static class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDllDirectory(string path);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
private static void Main()
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
using var mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var result);
if (!result)
{
MessageBox.Show($"当前程序只允许运行一个实例");
return;
}
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Debug()
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.log.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Information))
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.err.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Error))
.CreateLogger();
try
{
Log.Information("application start");
var path = Path.Combine(AppContext.BaseDirectory, IntPtr.Size == 8 ? "x64" : "x86");
Log.Information($"SetDllDirectory:{path}");
SetDllDirectory(path);
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler((s, e) => MessageBox.Show(e.Exception.Message));
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) => MessageBox.Show(e.ExceptionObject.ToString()));
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
Log.Information("application exit");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Log.Error(ex.ToString());
}
finally
{
Log.CloseAndFlush();
}
}
}
}

@ -9,7 +9,11 @@ namespace PhotoCollector
public string Action(string message)
{
var json = JsonSerializer.Deserialize<Dictionary<string, string>>(message);
return FuncList[json["command"]].Invoke(json);
if(json != null)
{
return FuncList[json["command"]].Invoke(json);
}
return null;
}
}
}

Binary file not shown.

Binary file not shown.

@ -0,0 +1 @@
0744e088ca453d89bdc6eb2ff732c9b161033baeb37cc56d9f77d8694bd1eb0d05f4cebc33fe3b148820af747e4377bb00f20e536674a66fa7380590ca7792c99e14b055abc74aae687aaf40aff3a1966db4a8e29e1fad4279dec343e78248a43a6a2d5c1ce792ddc59d969b722d6dc81211b36242c7ff707b31bc6a8a3c349541c0eed86da73a2cee520a8daf3803db56d0d4dc3ab2c78117f9956a9beb7fab1bdc9ad1864f6b20975fb31f4e5d8c57a0bbb5576e282bfbb4fdf9ee03d8506e3186da4f4f273043db8c3b5837e430c25a98fedbc6735368b9068e1ea84bd065e988565bb076061c3ca34741521516a6eb3057712ada68db90dcfc01738b2718aca9b5fc9186c033236a82e08837678abb4b661f82319239a047ec9f4ce27c0fe3b0a03bda9da311f6ab913fbf944af732b1d6efb61af8ad510f06011c96f7d3f466be1e7304d73d1e2c1f66e072e874b8294de9ae84c3330bfbf12ec9f0c2eb4993b8b04403833f04b6d25bd41a6989b5da7314522a1a5336d4562e3d3802df48ff35f635e1cfa00f10522881d4f4be9172f2788b5326963a62dc0a5eb6e2385b71defa2fe8e4e7a63248d5d1e8b19cb4d36f1d3f480f83806d2cc916b2887de9b25bc3185eea9c33585c68ab9dc9aa8667950c5752fca36ebded734c731c365a8b5359da8c08481dd535ebf63c647070f6094cbcb7157c6d19bb11e842c7eb15c16ec55bba6772cc437c659c0da977d84776e554bf8498e64b65aad167b025841f550e85302fa2a86ad8df8458c146272382e009b46e7f3f196b46f12a016b0e6cb0313e3587601911f2609665d466c652d544c2dcfeb7e24c83ed2fd2df461b6f265870129735870271f0ba7b095d1b9c1819678159ca35ac54a873a9743d13f16068021088a85a03fe97d8e488b590c9f367dfe9aa40a200aa7ea5f5e8d85fba0677dc758242fadd415ed8e67af58ca00d37145c179f8f12c378aeff639f6592bf8ae689ac89cf58e14ca2cacaa677ea0f90ed24c87166a8b19d740f0c1b8e4133ab08962f07423b876a1fd8564fb86fa07b5288e63d8e8bf8f5e06d0bd3428e0be12ae23344b950dabf35579078b9f769ff2bcf998c6f834188da60314fea43ef3534b6dfc79d5d8353cd91dcaae14a1224604208e57157345f4b31aed3ec2686ad0e5a5b18572b292ed0cc636b982f42f2da295cd0fcd178811929a1b5b2007954a016d0bf4d82755924514c464670a1727fccbcd578b7b6f62e8e8baea2986f2fd3326644e9290fdbb368c0c053d3d8ab3872517d4dd295c770a8938c26b811488d31443092ea9ebc6358e76328218fa5ee64434fe3eabefbc9c1e2d6a52607a6b7a9930baf8bca041e6be8b62b216d6987ebb9d4a3c7d89a201f9f1487abf8513a947a5baad53dbccbe73441c59d1bfeed4ddb92f3308cad5c0bf3cf

Binary file not shown.

@ -88,7 +88,7 @@
document.getElementById("saveFile").onclick = function () {
var response = window.chrome.webview.hostObjects.sync.dotnet.Action(JSON.stringify({
command: 'saveFile',
file: appBasePath + "test.webp",
file: appBasePath + "asserts/test.webp",
base64: canvas.toDataURL('image/webp')
}));
var result = JSON.parse(response);
@ -100,7 +100,7 @@
document.getElementById("readFile").onclick = function () {
var response = window.chrome.webview.hostObjects.sync.dotnet.Action(JSON.stringify({
command: 'readFile',
file: appBasePath + "test.webp"
file: appBasePath + "asserts/test.webp"
}));
var result = JSON.parse(response);
if (result.code) {

Loading…
Cancel
Save