Skip to content

Commit

Permalink
fix: Deserializer must be sync
Browse files Browse the repository at this point in the history
  • Loading branch information
c3rebro committed Jan 24, 2023
1 parent e841f36 commit 3433c90
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 64 deletions.
1 change: 0 additions & 1 deletion RFiDGear/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
xmlns:mainvm="clr-namespace:MefMvvm.SharedContracts.ViewModel;assembly=PluginSystem"
xmlns:pre="clr-namespace:MvvmDialogs.Presenters;assembly=MVVMDialogs"
xmlns:vm="clr-namespace:RFiDGear.ViewModel"

d1p1:Ignorable="d"
StartupUri="View/MainWindow.xaml">

Expand Down
17 changes: 6 additions & 11 deletions RFiDGear/DataAccessLayer/Remote/FromFile/DatabaseReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DatabaseReaderWriter()
{
try
{
AsyncRelayCommandLoadDB = new AsyncRelayCommand<TextReader>(LoadXMLAsync,AsyncRelayCommandOptions.AllowConcurrentExecutions);
//AsyncRelayCommandLoadDB = new AsyncRelayCommand<TextReader>(LoadXML,AsyncRelayCommandOptions.AllowConcurrentExecutions);

// Combine the base folder with the specific folder....
appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RFiDGear");
Expand Down Expand Up @@ -165,9 +165,8 @@ public bool ReadDatabase(string _fileName = "")

try
{
var serializer = new XmlSerializer(typeof(ChipTaskHandlerModel));
AsyncRelayCommandLoadDB.ExecuteAsync(reader);
SetupModel = (SetupModel as ChipTaskHandlerModel);
XmlSerializer serializer = new XmlSerializer(typeof(ChipTaskHandlerModel));
SetupModel = (serializer.Deserialize(reader) as ChipTaskHandlerModel);
}
catch (Exception e)
{
Expand Down Expand Up @@ -261,14 +260,12 @@ public void DeleteDatabase()
File.Delete(Path.Combine(appDataPath, chipDatabaseFileName));
}

private Task<object> LoadXMLAsync(TextReader reader)
private object LoadXML(TextReader reader)
{
try
{
var serializer = new XmlSerializer(typeof(ChipTaskHandlerModel));
SetupModel = (serializer.Deserialize(reader) as ChipTaskHandlerModel);

return Task.FromResult(SetupModel as object);
return (serializer.Deserialize(reader) as ChipTaskHandlerModel);
}
catch (Exception e)
{
Expand All @@ -277,9 +274,7 @@ private Task<object> LoadXMLAsync(TextReader reader)
try
{
var serializer = new XmlSerializer(typeof(ObservableCollection<RFiDChipParentLayerViewModel>));
TreeViewModel = serializer.Deserialize(reader) as ObservableCollection<RFiDChipParentLayerViewModel>;

return Task.FromResult(TreeViewModel as object);
return serializer.Deserialize(reader) as ObservableCollection<RFiDChipParentLayerViewModel>;
}

catch (Exception innerE)
Expand Down
3 changes: 3 additions & 0 deletions RFiDGear/RFiDGear.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@
<PackageReference Include="Portable.BouncyCastle">
<Version>1.9.0</Version>
</PackageReference>
<PackageReference Include="QuestPDF">
<Version>2022.12.1</Version>
</PackageReference>
<PackageReference Include="System.Buffers">
<Version>4.5.1</Version>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion RFiDGear/RFiDGear.csproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>REPORTTARGETPATH="C:\temp\test file.pdf" AUTORUN=0 %24JobNumber=1234 %24CardType=</StartArguments>
<StartArguments>REPORTTARGETPATH="C:\temp\test file.pdf" AUTORUN=1 %24JobNumber=1234 %24CardType=</StartArguments>
<StartWorkingDirectory>D:\Seafile\Dokumente Privat\Steven\Projekte\Software\Windows\RFIDGear\RFiDGear\bin\Debug\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup>
Expand Down
11 changes: 7 additions & 4 deletions RFiDGear/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
<Menu
HorizontalContentAlignment="Right"
VerticalAlignment="Top"
Margin="0,2,0,0"
Margin="2,2,0,0"
Background="{x:Null}"
DockPanel.Dock="Top">
<MenuItem
Expand Down Expand Up @@ -575,8 +575,8 @@
</Menu>
</DockPanel>
<DockPanel Grid.ColumnSpan="2" Grid.Row="2">
<StatusBar VerticalAlignment="Bottom" DockPanel.Dock="Bottom" Height="49" VerticalContentAlignment="Center">
<StatusBarItem Height="auto" VerticalAlignment="Center" Content="{Binding LocalizationResourceSet, Converter={StaticResource Localization}, ConverterParameter='labelSelectedReader'}" />
<StatusBar VerticalAlignment="Bottom" DockPanel.Dock="Bottom" Height="49" VerticalContentAlignment="Center" >
<StatusBarItem Margin="4,0,0,0" Height="auto" VerticalAlignment="Center" Content="{Binding LocalizationResourceSet, Converter={StaticResource Localization}, ConverterParameter='labelSelectedReader'}" />
<StatusBarItem>
<TextBlock Text="{Binding CurrentReader}" FontWeight="Bold"/>
</StatusBarItem>
Expand All @@ -587,7 +587,10 @@
Height="auto"/>
</StatusBarItem>
<StatusBarItem>
<TextBlock Text="{Binding ReaderStatus}" Height="auto" FontWeight="Bold"/>
<TextBlock Text="{Binding ReaderStatus}" Height="auto" FontWeight="Bold" HorizontalAlignment="Left"/>
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Right" Margin="0,0,12,0">
<TextBlock Text="{Binding DateTimeStatusBar, UpdateSourceTrigger=PropertyChanged}" Height="auto" FontWeight="Bold" HorizontalAlignment="Left"/>
</StatusBarItem>
<!--
<StatusBarItem>
Expand Down
5 changes: 2 additions & 3 deletions RFiDGear/View/SettingsView/SetupView.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Window
x:Class="RFiDGear.View.SetupView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dal="clr-namespace:RFiDGear.DataAccessLayer"
xmlns:v="clr-namespace:RFiDGear.View"
Expand All @@ -25,7 +24,7 @@
<TabControl
Grid.Row="0"
Grid.Column="0"
Margin="8,45,8,49"
Margin="8,8,8,49"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TabItem MinWidth="50" Header="{Binding LocalizationResourceSet, Converter={StaticResource Localization}, ConverterParameter='tabPageHeaderReaderSetup'}">
Expand Down
8 changes: 4 additions & 4 deletions RFiDGear/View/Splash.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Background="Transparent" BorderBrush="Black"
Background="Transparent"
mc:Ignorable="d">
<Window.Resources>
<dal:ResourceLoader x:Key="Localization"/>
Expand All @@ -28,9 +28,9 @@

<Label
x:Name="label"
Margin="238,286,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,0,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{Binding LocalizationResourceSet, Converter={StaticResource Localization}, ConverterParameter='labelContentSplashScreenLoadingData'}"
FontSize="14"
FontWeight="ExtraBold" />
Expand Down
2 changes: 1 addition & 1 deletion RFiDGear/View/UpdateNotifierView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<GroupBox
x:Name="groupBox"
Grid.ColumnSpan="3"
Margin="10,35,10,10"
Margin="10,10,10,10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Header="{Binding LocalizationResourceSet, Converter={StaticResource Localization}, ConverterParameter='groupBoxHeaderUpdateWindowVersionInfo'}">
Expand Down
74 changes: 41 additions & 33 deletions RFiDGear/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class MainWindowViewModel : ObservableObject
// set if task was completed; indicates greenlight to continue execution
// if programming takes too long; quit the process
private bool firstRun = true;
private bool _isLoadingProject = true;
private bool userIsNotifiedForAvailableUpdate = false;
private bool updateIsAvailable = false;
private protected Mutex mutex;
Expand Down Expand Up @@ -154,6 +155,7 @@ public MainWindowViewModel()
taskHandler = new ChipTaskHandlerModel();

ReaderStatus = CurrentReader == "None" ? "" : "ready";
DateTimeStatusBar = "";
databaseReaderWriter = new DatabaseReaderWriter();
resLoader = new ResourceLoader();

Expand Down Expand Up @@ -293,8 +295,7 @@ private void OpenLastProjectFile()
{
using (var settings = new SettingsReaderWriter())
{
Application.Current.Dispatcher.BeginInvoke((Action)(() => {
var autoLoadLastUsedDB = settings.DefaultSpecification.AutoLoadProjectOnStart;
var autoLoadLastUsedDB = settings.DefaultSpecification.AutoLoadProjectOnStart;
var lastUsedDBPath = settings.DefaultSpecification.LastUsedProjectPath;

culture = (settings.DefaultSpecification.DefaultLanguage == "german") ? new CultureInfo("de-DE") : new CultureInfo("en-US");
Expand All @@ -303,22 +304,21 @@ private void OpenLastProjectFile()
{
ChipTasks.TaskCollection.Clear();
}

databaseReaderWriter.ReadDatabase(lastUsedDBPath);

foreach (var vm in databaseReaderWriter.TreeViewModel)
{
TreeViewParentNodes.Add(vm);
}


foreach (var setup in databaseReaderWriter.SetupModel.TaskCollection)
{
ChipTasks.TaskCollection.Add(setup);
}

Dialogs.RemoveAt(0);
}));

foreach (var setup in databaseReaderWriter.SetupModel.TaskCollection)
{
ChipTasks.TaskCollection.Add(setup);
}

Dialogs.RemoveAt(0);

OnPropertyChanged(nameof(ChipTasks));
}
Expand Down Expand Up @@ -347,9 +347,12 @@ private void UpdateChip(object sender, EventArgs args)
//reader was ready - proceed
if (device != null)
{
ReaderStatus = "busy";
device.ReadChipPublic();

GenericChip = device.GenericChip;

ReaderStatus = "ready";
}
else
{
Expand Down Expand Up @@ -865,10 +868,10 @@ private void OnNewReadChipCommand()
triggerReadChip.IsEnabled = false;

Mouse.OverrideCursor = Cursors.Wait;
ReaderStatus = "busy";

using (var device = ReaderDevice.Instance)
{

foreach (var item in treeViewParentNodes)
{
item.IsExpanded = false;
Expand Down Expand Up @@ -985,6 +988,7 @@ private void OnNewReadChipCommand()
}

Mouse.OverrideCursor = null;
ReaderStatus = "ready";

triggerReadChip.IsEnabled = timerState;
}
Expand Down Expand Up @@ -1137,11 +1141,11 @@ private void OnNewWriteToChipOnceCommand()
{
device.ReadChipPublic();

GenericChip.CardType = device.GenericChip.CardType;
GenericChip.UID = device.GenericChip.UID;

if (GenericChip != null)
if (device.GenericChip != null)
{
GenericChip.CardType = device.GenericChip.CardType;
GenericChip.UID = device.GenericChip.UID;

if (GenericChip.CardType.ToString().ToLower(CultureInfo.CurrentCulture).Contains("desfire"))
{
device.GetMiFareDESFireChipAppIDs();
Expand Down Expand Up @@ -2019,6 +2023,20 @@ public string ReaderStatus
}
private string readerStatus;

/// <summary>
///
/// </summary>
public string DateTimeStatusBar
{
get => dateTimeStatusBar;
set
{
dateTimeStatusBar = value;
OnPropertyChanged(nameof(DateTimeStatusBar));
}
}
private string dateTimeStatusBar;

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -2167,9 +2185,9 @@ private void AskForUpdateNow()
//Only one instance is allowed due to the singleton pattern of the reader class
private void RunMutex(object sender, StartupEventArgs e)
{
mutex = new Mutex(true, "App", out var aIsNewInstance);
mutex = new Mutex(true, "App", out var isANewInstance);

if (!aIsNewInstance)
if (!isANewInstance)
{
Environment.Exit(0);
}
Expand All @@ -2187,7 +2205,6 @@ private void LoadCompleted(object sender, EventArgs e)

if (firstRun)
{
Task loadProjectOnStartThread;
Task refreshStatusBarThread;

firstRun = false;
Expand Down Expand Up @@ -2241,28 +2258,18 @@ private void LoadCompleted(object sender, EventArgs e)
{
Dialogs.Add(mySplash);
}

loadProjectOnStartThread = new Task(() =>
{
if (autoLoadLastUsedDB)
{
OpenLastProjectFile();
}
});

loadProjectOnStartThread.ContinueWith((x) =>
if (autoLoadLastUsedDB)
{
});


loadProjectOnStartThread.Start();
OpenLastProjectFile();
}

refreshStatusBarThread = new Task(() =>
{
while (true)
{
Thread.Sleep(500);
ReaderStatus = string.Format("{0}", DateTime.Now);
DateTimeStatusBar = string.Format("{0}", DateTime.Now);
}
});

Expand Down Expand Up @@ -2298,6 +2305,7 @@ private void LoadCompleted(object sender, EventArgs e)
case "AUTORUN":
if (arg.Split('=')[1] == "1")
{
_isLoadingProject = true;
OnNewWriteToChipOnceCommand();
}
break;
Expand Down
19 changes: 13 additions & 6 deletions RFiDGear/ViewModel/TaskSetupViewModels/CommonTaskViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,13 +1547,20 @@ private void OnNewExecuteProgramCommand()
info = new ProcessStartInfo()
{
FileName = Args[ProgramToExecute],
UseShellExecute =
ProgramToExecute.Contains("bat") ||
ProgramToExecute.Contains("exe") ||
UseShellExecute =
ProgramToExecute.Contains("bat") ||
ProgramToExecute.Contains("exe") ||
ProgramToExecute.Contains("msi") ? false : true
};
}

else if (ProgramToExecute.ToLower() == @"%exit%")
{
info = null;

Environment.Exit(0);
}

else
{
var fileName = ProgramToExecute.Split('\"')[1];
Expand Down Expand Up @@ -1600,9 +1607,9 @@ private void OnNewExecuteProgramCommand()
FileName = string.IsNullOrWhiteSpace(fileName) ? ProgramToExecute : fileName,
Arguments = string.IsNullOrWhiteSpace(args) ? "" : args,
UseShellExecute = (fileName != null) ? (
fileName.Contains("bat") ||
fileName.Contains("exe") ||
fileName.Contains("msi") ? false : true ) : false,
fileName.Contains("bat") ||
fileName.Contains("exe") ||
fileName.Contains("msi") ? false : true) : false,
};
}

Expand Down

0 comments on commit 3433c90

Please sign in to comment.