From 146808d0599221256f824339a57471b1d2dc8dc9 Mon Sep 17 00:00:00 2001 From: Maxhy Date: Thu, 11 Apr 2024 14:46:46 +0200 Subject: [PATCH] Fix PC/SC reader selection --- .../Domain/LLAReaderViewModel.cs | 36 ------------------ .../SAMKeyStoreToolsControlViewModel.cs | 2 +- .../LLAReaderControl.xaml | 5 +-- .../LLAReaderControl.xaml.cs | 37 ++++++++++++++----- .../SAMKeyStorePropertiesControl.xaml | 2 +- .../SAMKeyStoreToolsControl.xaml | 8 ++-- 6 files changed, 37 insertions(+), 53 deletions(-) delete mode 100644 KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/LLAReaderViewModel.cs diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/LLAReaderViewModel.cs b/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/LLAReaderViewModel.cs deleted file mode 100644 index 36e5291..0000000 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/LLAReaderViewModel.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.ObjectModel; - -namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Domain -{ - public class LLAReaderViewModel - { - private readonly LibLogicalAccess.LibraryManager _lla; - - public LLAReaderViewModel() - { - _lla = LibLogicalAccess.LibraryManager.getInstance(); - ReaderProviders = new ObservableCollection(_lla.getAvailableReaders().ToArray()); - ReaderUnits = new ObservableCollection(); - } - - public ObservableCollection ReaderProviders { get; set; } - - public ObservableCollection ReaderUnits { get; set; } - - public void RefreshReaderList(LLAReaderControl config) - { - var prevru = config!.ReaderUnit; - ReaderUnits.Clear(); - var rp = _lla.getReaderProvider(config.ReaderProvider); - var ruList = rp.getReaderList(); - foreach (var ru in ruList) - { - ReaderUnits.Add(ru.getName()); - } - if (ReaderUnits.Contains(prevru)) - { - config.ReaderUnit = prevru; - } - } - } -} diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/SAMKeyStoreToolsControlViewModel.cs b/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/SAMKeyStoreToolsControlViewModel.cs index bb4578a..14077bd 100644 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/SAMKeyStoreToolsControlViewModel.cs +++ b/KeyManager.Library.KeyStore.NXP_SAM.UI/Domain/SAMKeyStoreToolsControlViewModel.cs @@ -409,7 +409,7 @@ private void DESFireAuthenticate() throw new KeyStoreException("Unexpected commands type for the inserted RFID card."); } - uint aid = BitConverter.ToUInt32(DESFireAID); + uint aid = (uint)(DESFireAID[0] << 16 | DESFireAID[1] << 8 | DESFireAID[2]); ev1cmd.selectApplication(aid); var key = new DESFireKey(); diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml b/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml index 2d3b65b..b562191 100644 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml +++ b/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml @@ -10,17 +10,16 @@ xmlns:properties="clr-namespace:Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Properties" xmlns:wpfappctrls="clr-namespace:Leosac.WpfApp.Controls;assembly=WpfApp" mc:Ignorable="d" - d:DataContext="{d:DesignInstance domain:LLAReaderViewModel}" d:DesignHeight="250" d:DesignWidth="400"> - - diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml.cs b/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml.cs index 3bbf0d0..878c6bc 100644 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml.cs +++ b/KeyManager.Library.KeyStore.NXP_SAM.UI/LLAReaderControl.xaml.cs @@ -1,4 +1,5 @@ using Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI.Domain; +using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; @@ -9,11 +10,15 @@ namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM.UI /// public partial class LLAReaderControl : UserControl { + private readonly LibLogicalAccess.LibraryManager _lla; + public LLAReaderControl() { - InitializeComponent(); + _lla = LibLogicalAccess.LibraryManager.getInstance(); + ReaderProviders = new ObservableCollection(_lla.getAvailableReaders().ToArray()); + ReaderUnits = new ObservableCollection(); - DataContext = new LLAReaderViewModel(); + InitializeComponent(); } public string ReaderProvider @@ -32,20 +37,34 @@ public string ReaderUnit public static readonly DependencyProperty ReaderUnitProperty = DependencyProperty.Register(nameof(ReaderUnit), typeof(string), typeof(LLAReaderControl), new FrameworkPropertyMetadata("")); - private void cbReaderProvider_SelectionChanged(object sender, SelectionChangedEventArgs e) + public ObservableCollection ReaderProviders { get; set; } + + public ObservableCollection ReaderUnits { get; set; } + + public void RefreshReaderList() { - if (DataContext is LLAReaderViewModel model) + var prevru = ReaderUnit; + ReaderUnits.Clear(); + var rp = _lla.getReaderProvider(ReaderProvider); + var ruList = rp.getReaderList(); + foreach (var ru in ruList) + { + ReaderUnits.Add(ru.getName()); + } + if (ReaderUnits.Contains(prevru)) { - model.RefreshReaderList(this); + ReaderUnit = prevru; } } + private void cbReaderProvider_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + RefreshReaderList(); + } + private void btnRefreshReaderUnits_Click(object sender, RoutedEventArgs e) { - if (DataContext is LLAReaderViewModel model) - { - model.RefreshReaderList(this); - } + RefreshReaderList(); } } } diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStorePropertiesControl.xaml b/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStorePropertiesControl.xaml index 3786266..7b9874c 100644 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStorePropertiesControl.xaml +++ b/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStorePropertiesControl.xaml @@ -13,7 +13,7 @@ d:DataContext="{d:DesignInstance domain:SAMKeyStorePropertiesControlViewModel}" d:DesignHeight="200" d:DesignWidth="500"> - + diff --git a/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStoreToolsControl.xaml b/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStoreToolsControl.xaml index 55e0020..4304edb 100644 --- a/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStoreToolsControl.xaml +++ b/KeyManager.Library.KeyStore.NXP_SAM.UI/SAMKeyStoreToolsControl.xaml @@ -81,7 +81,7 @@ - + + materialDesign:HintAssist.Hint="{x:Static properties:Resources.DivInput}" + IsEnabled="{Binding DESFireUseDiversification}" /> @@ -111,7 +112,8 @@ + Hint="{x:Static properties:Resources.DESFireFileNo}" + IsEnabled="{Binding DESFireReadFile}" />