Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Synchronic SAM-SE Key Store #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin
obj
*.user
/KeyManager.Setup/packages
/KeyManager.Library.KeyStore.SAM_SE/DLL/Debug
30 changes: 30 additions & 0 deletions KeyManager.Library.KeyStore.SAM_SE.UI/Domain/SAM_SEConverters.cs
Maxhy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
** File Name: SAM_SEConverters.cs
** Author: s_eva
** Creation date: January 2024
** Description: This file regroups all the converters for XAML Files.
** Licence: LGPLv3
** Copyright (c) 2023-Present Synchronic
*/

using System.Globalization;
using System.Windows.Data;
using System.Windows;

namespace Leosac.KeyManager.Library.KeyStore.SAM_SE.UI.Domain
{
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolValue = (bool)value;
boolValue = (parameter != null) ? !boolValue : boolValue;
return boolValue ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
** File Name: SAM_SEKeyStorePropertiesControlViewModel.cs
** Author: s_eva
** Creation date: January 2024
** Description: This file is the MVVM component of the KeyStore Properties.
** Licence: LGPLv3
** Copyright (c) 2023-Present Synchronic
*/

using Leosac.KeyManager.Library.KeyStore.SAM_SE.DLL;
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace Leosac.KeyManager.Library.KeyStore.SAM_SE.UI.Domain
{
public class SAM_SEKeyStorePropertiesControlViewModel : KeyStorePropertiesControlViewModel
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType);

public SAM_SEKeyStorePropertiesControlViewModel()
{
_properties = new SAM_SEKeyStoreProperties();
SAM_SEReaders = new ObservableCollection<string>();
SAM_SEDll = new SAM_SEDllProgrammingStation();
}

public SAM_SEKeyStoreProperties? SAM_SEProperties
{
get { return Properties as SAM_SEKeyStoreProperties; }
}

public ObservableCollection<string> SAM_SEReaders { get; set; }
public SAM_SEDllProgrammingStation SAM_SEDll { get; set; }

private int stationIndex = 0;
public int SAM_SEStationIndex
{
get => stationIndex;
set
{
if (SetProperty(ref stationIndex, value))
{
try
{
//Stopping all the blinking leds
for (uint i = 0; i < SAM_SEDll.GetNumberSAM_SE(); i++)
{
SAM_SEDll.BlinkLedId(i, 0);
}
//XAML can make stationIndex == -1 if nothing is selected
if (stationIndex > 0)
{
//And making blink the selected one
SAM_SEDll.BlinkLedId((uint)stationIndex, 1);
}
}
//Catch do nothing, since we just want to catch the exception and .. do nothing about it
catch (Exception e)
{
//Well, at least let's log the error
log.Error(e);
}
}
}
}

private bool refreshList = true;
public bool RefreshList
{
get => refreshList;
set => SetProperty(ref refreshList, value);
}

private bool keystorePropertiesErrorEnable = false;
public bool KeyStorePropertiesErrorEnable
{
get => keystorePropertiesErrorEnable;
set => SetProperty(ref keystorePropertiesErrorEnable, value);
}

private string programmingStation = string.Empty;
public string ProgrammingStation
{
get => programmingStation;
set
{
if (SetProperty(ref programmingStation, value))
{
if (ProgrammingStation != null)
{
//Extraction of MAC to identify the SAM-SE
SAM_SEProperties!.SAM_SEMac = ProgrammingStation.Split('\t')[1];
}
else
{
SAM_SEProperties!.SAM_SEMac = string.Empty;
}
}
}
}

public async Task RefreshStationProgrammationList()
{
try
{
RefreshList = false;
KeyStorePropertiesErrorEnable = false;
string prevru = ProgrammingStation;
SAM_SEReaders.Clear();
Mouse.OverrideCursor = Cursors.Wait;
await SAM_SEDll.DetectSAM_SE();
uint nb = SAM_SEDll.GetNumberSAM_SE();
for (uint i = 0; i < nb; i++)
{
SAM_SEDll.BlinkLedId(i, 0);

String version = SAM_SEDll.GetVersion(i);
String mac = SAM_SEDll.GetMac(i);
String type = SAM_SEDll.GetType(i);

SAM_SEReaders.Add(type + '\t' + mac + '\t' + version + '\t');
}
//If we find the old element which was selected before the refresh
if (SAM_SEReaders.Contains(prevru))
{
//We select it back and make the Led blink to notify the user
ProgrammingStation = prevru;
SAM_SEDll.BlinkLedId((uint)SAM_SEStationIndex, 1);
}
//If we don't find the old element, and if there is at least one programming station
else if (SAM_SEReaders.Count != 0)
{
//We select the first one of the list, and we make its Led blink
ProgrammingStation = SAM_SEReaders.First();
SAM_SEDll.BlinkLedId(0, 1);
}
//If there is no programming station, we put the string as empty
else
{
ProgrammingStation = string.Empty;
}
}
catch (Exception ex)
{
KeyStorePropertiesErrorEnable = true;
log.Error(ex);
}
finally
{
RefreshList = true;
Mouse.OverrideCursor = null;
}
}
}
}
Loading
Loading