From daa29c0fa600c0293eaec557b35f1060b0e1828a Mon Sep 17 00:00:00 2001 From: Takuya Takeuchi Date: Sat, 11 Aug 2018 17:39:08 +0900 Subject: [PATCH 01/21] add: support to cancel verify and capture callbacks --- ...inBioCaptureSampleWithCallbackViewModel.cs | 6 ++ .../WinBioVerifyWithCallbackViewModel.cs | 6 ++ .../Interfaces/IWinBiometricService.cs | 2 + .../Services/WinBiometricService.cs | 8 +++ ...inBioCaptureSampleWithCallbackViewModel.cs | 9 ++- .../IWinBioVerifyWithCallbackViewModel.cs | 6 ++ ...inBioCaptureSampleWithCallbackViewModel.cs | 60 ++++++++++++++++++- .../WinBioVerifyWithCallbackViewModel.cs | 60 ++++++++++++++++++- .../WinBioCaptureSampleWithCallback.xaml | 19 ++++-- .../Views/WinBioVerifyWithCallback.xaml | 19 ++++-- sources/WinBiometricDotNet/WinBiometric.cs | 21 +++++-- 11 files changed, 197 insertions(+), 19 deletions(-) diff --git a/examples/FrameworkTester/DesignTimes/WinBioCaptureSampleWithCallbackViewModel.cs b/examples/FrameworkTester/DesignTimes/WinBioCaptureSampleWithCallbackViewModel.cs index 1d72496..3a06110 100644 --- a/examples/FrameworkTester/DesignTimes/WinBioCaptureSampleWithCallbackViewModel.cs +++ b/examples/FrameworkTester/DesignTimes/WinBioCaptureSampleWithCallbackViewModel.cs @@ -1,5 +1,6 @@ using System.Windows.Media.Imaging; using FrameworkTester.ViewModels.Interfaces; +using GalaSoft.MvvmLight.Command; using WinBiometricDotNet; namespace FrameworkTester.DesignTimes @@ -8,6 +9,11 @@ namespace FrameworkTester.DesignTimes public sealed class WinBioCaptureSampleWithCallbackViewModel : WinBioViewModel, IWinBioCaptureSampleWithCallbackViewModel { + public RelayCommand CancelCommand + { + get; + } + public BitmapSource CaptureImage { get; diff --git a/examples/FrameworkTester/DesignTimes/WinBioVerifyWithCallbackViewModel.cs b/examples/FrameworkTester/DesignTimes/WinBioVerifyWithCallbackViewModel.cs index 8e58ef0..b6f47cb 100644 --- a/examples/FrameworkTester/DesignTimes/WinBioVerifyWithCallbackViewModel.cs +++ b/examples/FrameworkTester/DesignTimes/WinBioVerifyWithCallbackViewModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Windows.Media.Imaging; using FrameworkTester.ViewModels.Interfaces; +using GalaSoft.MvvmLight.Command; using WinBiometricDotNet; namespace FrameworkTester.DesignTimes @@ -9,6 +10,11 @@ namespace FrameworkTester.DesignTimes public sealed class WinBioVerifyWithCallbackViewModel : WinBioViewModel, IWinBioVerifyWithCallbackViewModel { + public RelayCommand CancelCommand + { + get; + } + public bool IsMatch { get; diff --git a/examples/FrameworkTester/Services/Interfaces/IWinBiometricService.cs b/examples/FrameworkTester/Services/Interfaces/IWinBiometricService.cs index 837219e..7792b9b 100644 --- a/examples/FrameworkTester/Services/Interfaces/IWinBiometricService.cs +++ b/examples/FrameworkTester/Services/Interfaces/IWinBiometricService.cs @@ -10,6 +10,8 @@ public interface IWinBiometricService void AcquireFocus(); + void Cancel(); + CaptureSampleResult CaptureSample(); void CaptureSampleWithCallback(); diff --git a/examples/FrameworkTester/Services/WinBiometricService.cs b/examples/FrameworkTester/Services/WinBiometricService.cs index d1d18fa..791ab24 100644 --- a/examples/FrameworkTester/Services/WinBiometricService.cs +++ b/examples/FrameworkTester/Services/WinBiometricService.cs @@ -36,6 +36,14 @@ public void AcquireFocus() WinBiometric.AcquireFocus(); } + public void Cancel() + { + if (this._Session == null) + throw new Exception("There is no opened session."); + + WinBiometric.Cancel(this._Session); + } + public CaptureSampleResult CaptureSample() { if (this._Session == null) diff --git a/examples/FrameworkTester/ViewModels/Interfaces/IWinBioCaptureSampleWithCallbackViewModel.cs b/examples/FrameworkTester/ViewModels/Interfaces/IWinBioCaptureSampleWithCallbackViewModel.cs index 012ab22..d8dba94 100644 --- a/examples/FrameworkTester/ViewModels/Interfaces/IWinBioCaptureSampleWithCallbackViewModel.cs +++ b/examples/FrameworkTester/ViewModels/Interfaces/IWinBioCaptureSampleWithCallbackViewModel.cs @@ -1,9 +1,16 @@ -namespace FrameworkTester.ViewModels.Interfaces +using GalaSoft.MvvmLight.Command; + +namespace FrameworkTester.ViewModels.Interfaces { public interface IWinBioCaptureSampleWithCallbackViewModel : IWinBioCaptureSampleViewModel { + RelayCommand CancelCommand + { + get; + } + bool Loop { get; diff --git a/examples/FrameworkTester/ViewModels/Interfaces/IWinBioVerifyWithCallbackViewModel.cs b/examples/FrameworkTester/ViewModels/Interfaces/IWinBioVerifyWithCallbackViewModel.cs index b22b892..2f6ed8d 100644 --- a/examples/FrameworkTester/ViewModels/Interfaces/IWinBioVerifyWithCallbackViewModel.cs +++ b/examples/FrameworkTester/ViewModels/Interfaces/IWinBioVerifyWithCallbackViewModel.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Windows.Media.Imaging; +using GalaSoft.MvvmLight.Command; using WinBiometricDotNet; namespace FrameworkTester.ViewModels.Interfaces @@ -8,6 +9,11 @@ namespace FrameworkTester.ViewModels.Interfaces public interface IWinBioVerifyWithCallbackViewModel : IWinBioViewModel { + RelayCommand CancelCommand + { + get; + } + bool IsMatch { get; diff --git a/examples/FrameworkTester/ViewModels/WinBioCaptureSampleWithCallbackViewModel.cs b/examples/FrameworkTester/ViewModels/WinBioCaptureSampleWithCallbackViewModel.cs index 4f3f423..09d9426 100644 --- a/examples/FrameworkTester/ViewModels/WinBioCaptureSampleWithCallbackViewModel.cs +++ b/examples/FrameworkTester/ViewModels/WinBioCaptureSampleWithCallbackViewModel.cs @@ -16,6 +16,8 @@ public sealed class WinBioCaptureSampleWithCallbackViewModel : WinBioViewModel, #region Fields + private readonly IDispatcherService _DispatcherService; + private readonly IWinBiometricService _Service; #endregion @@ -25,13 +27,41 @@ public sealed class WinBioCaptureSampleWithCallbackViewModel : WinBioViewModel, public WinBioCaptureSampleWithCallbackViewModel() { this._Service = SimpleIoc.Default.GetInstance(); + this._DispatcherService = SimpleIoc.Default.GetInstance(); + WinBiometric.SampleCaptured += this.WinBiometricOnSampleCaptured; + + this.WaitCallback = false; } #endregion #region Properties + private RelayCommand _CancelCommand; + + public RelayCommand CancelCommand + { + get + { + return this._CancelCommand ?? (this._CancelCommand = new RelayCommand(() => + { + try + { + this._Service.Cancel(); + + this.WaitCallback = false; + } + catch (Exception e) + { + MessageBox.Show(e.Message); + + this.WaitCallback = true; + } + }, () => this._WaitCallback)); + } + } + private BitmapSource _CaptureImage; public BitmapSource CaptureImage @@ -149,13 +179,17 @@ public override RelayCommand ExecuteCommand { this.Result = "WAIT"; this._Service.CaptureSampleWithCallback(); + + this.WaitCallback = true; } catch (Exception e) { MessageBox.Show(e.Message); this.Result = "FAIL"; + + this.WaitCallback = false; } - })); + }, () => !this._WaitCallback)); } } @@ -221,6 +255,25 @@ private set } } + private bool _WaitCallback; + + private bool WaitCallback + { + get + { + return this._WaitCallback; + } + set + { + this._WaitCallback = value; + + this.RaisePropertyChanged(); + + this.ExecuteCommand.RaiseCanExecuteChanged(); + this.CancelCommand.RaiseCanExecuteChanged(); + } + } + #endregion #region Methods @@ -229,6 +282,11 @@ private set private void WinBiometricOnSampleCaptured(object sender, CaptureSampleEventArgs e) { + this._DispatcherService.SafeAction(() => + { + this.WaitCallback = false; + }); + switch (e.Result.OperationStatus) { case OperationStatus.OK: diff --git a/examples/FrameworkTester/ViewModels/WinBioVerifyWithCallbackViewModel.cs b/examples/FrameworkTester/ViewModels/WinBioVerifyWithCallbackViewModel.cs index 22087f9..f5032fb 100644 --- a/examples/FrameworkTester/ViewModels/WinBioVerifyWithCallbackViewModel.cs +++ b/examples/FrameworkTester/ViewModels/WinBioVerifyWithCallbackViewModel.cs @@ -18,6 +18,8 @@ public sealed class WinBioVerifyWithCallbackViewModel : WinBioViewModel, IWinBio #region Fields + private readonly IDispatcherService _DispatcherService; + private readonly IWinBiometricService _Service; #endregion @@ -27,14 +29,42 @@ public sealed class WinBioVerifyWithCallbackViewModel : WinBioViewModel, IWinBio public WinBioVerifyWithCallbackViewModel() { this._Service = SimpleIoc.Default.GetInstance(); + this._DispatcherService = SimpleIoc.Default.GetInstance(); this._FingerPositions = Enum.GetValues(typeof(FingerPosition)).Cast().ToArray(); + WinBiometric.Verified += this.WinBiometricVerified; + + this.WaitCallback = false; } #endregion #region Properties + private RelayCommand _CancelCommand; + + public RelayCommand CancelCommand + { + get + { + return this._CancelCommand ?? (this._CancelCommand = new RelayCommand(() => + { + try + { + this._Service.Cancel(); + + this.WaitCallback = false; + } + catch (Exception e) + { + MessageBox.Show(e.Message); + + this.WaitCallback = true; + } + }, () => this._WaitCallback)); + } + } + private RelayCommand _ExecuteCommand; public override RelayCommand ExecuteCommand @@ -51,13 +81,17 @@ public override RelayCommand ExecuteCommand { this.Result = "WAIT"; this._Service.VerifyWithCallback(this.CurrentUnit, this.SelectedFingerPosition); + + this.WaitCallback = true; } catch (Exception e) { MessageBox.Show(e.Message); this.Result = "FAIL"; + + this.WaitCallback = false; } - })); + }, () => !this._WaitCallback)); } } @@ -108,6 +142,25 @@ private set } } + private bool _WaitCallback; + + private bool WaitCallback + { + get + { + return this._WaitCallback; + } + set + { + this._WaitCallback = value; + + this.RaisePropertyChanged(); + + this.ExecuteCommand.RaiseCanExecuteChanged(); + this.CancelCommand.RaiseCanExecuteChanged(); + } + } + private FingerPosition _SelectedFingerPosition; public FingerPosition SelectedFingerPosition @@ -146,6 +199,11 @@ private set private void WinBiometricVerified(object sender, VerifyEventArgs e) { + this._DispatcherService.SafeAction(() => + { + this.WaitCallback = false; + }); + switch (e.Result.OperationStatus) { case OperationStatus.OK: diff --git a/examples/FrameworkTester/Views/WinBioCaptureSampleWithCallback.xaml b/examples/FrameworkTester/Views/WinBioCaptureSampleWithCallback.xaml index 9247102..bae2b8d 100644 --- a/examples/FrameworkTester/Views/WinBioCaptureSampleWithCallback.xaml +++ b/examples/FrameworkTester/Views/WinBioCaptureSampleWithCallback.xaml @@ -41,13 +41,22 @@ -