serializer

This commit is contained in:
Hendrik Schutter 2019-06-07 16:55:53 +02:00
parent dba3c5c2e1
commit fb3640e999
32 changed files with 107 additions and 13 deletions

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using ClassLibraryStandard;
namespace EntitiesStandard
{
public static class XMLhelper
{
public static void serializeToXML<T>(T list )
{
XmlSerializer ser = new XmlSerializer(typeof(List<Participant>));
FileStream file = File.OpenWrite(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\data.xml");
ser.Serialize(file, list);
file.Close();
}
public static T xmlToDeserialize<T>()
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
FileStream file = File.OpenRead(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\data.xml");
T blogList = (T) serializer.Deserialize(file);
//T value = (T) Convert.ChangeType(serializer.Deserialize(file));
file.Close();
return blogList;
}
}
}

View File

@ -1 +1 @@
56bcca95c23602acb987d5b18a78659a4b87bf01
2b405998b147ec7745f71929a99418b4b119d093

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using ClassLibraryStandard;
using EntitiesStandard;
namespace Service
{
@ -33,8 +34,6 @@ namespace Service
pr4.lastname = "Wurst4";
parlis.Add(pr4);
while (true)
{
Thread.Sleep(500);
@ -44,6 +43,9 @@ namespace Service
int tmp = ran.Next(0, 3);
Console.WriteLine(parlis[tmp]);
XMLhelper.serializeToXML<List<Participant>>(parlis);
}
}
}

View File

@ -8,5 +8,6 @@
Title="MainWindow" Height="450" Width="800">
<Grid>
<DataGrid x:Name="datagrid1" HorizontalAlignment="Left" Height="231" Margin="184,94,0,0" VerticalAlignment="Top" Width="384"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="328,365,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>

View File

@ -1,9 +1,12 @@
using ClassLibraryStandard;
using EntitiesStandard;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@ -26,22 +29,52 @@ namespace UI
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
BindingList<Participant> list01 = new BindingList<Participant>();
Participant pr3 = new Participant();
pr3.name = "Hans3";
pr3.lastname = "Wurst3";
List<Participant> par = new List<Participant>();
BindingList<Participant> list01 = new BindingList<Participant>();
list01.Add(pr3);
datagrid1.ItemsSource = list01;
Participant pr4 = new Participant();
pr3.name = "Hans4";
pr3.lastname = "Wurst4";
list01.Add(pr4);
List<Participant> listpar = new List<Participant>();
// Thread.Sleep(2000);
try
{
listpar = XMLhelper.xmlToDeserialize<List<Participant>>();
}
catch (Exception exception)
{
Console.WriteLine(exception);
//throw;
Thread.Sleep(200);
}
}
foreach (var par in listpar)
{
list01.Add(par);
datagrid1.ItemsSource = list01;
}
}
}
}

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "795417AB8F41B49EC74B26B9A1C1A059CA80E3679169B674EC266D4C35E9AE25"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6640988C6F05A6430030B2C234F217E83431DDB1C2C7CEFBBFF353D38FC55D39"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@ -81,6 +81,14 @@ namespace UI {
case 1:
this.datagrid1 = ((System.Windows.Controls.DataGrid)(target));
return;
case 2:
#line 11 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}

View File

@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "795417AB8F41B49EC74B26B9A1C1A059CA80E3679169B674EC266D4C35E9AE25"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6640988C6F05A6430030B2C234F217E83431DDB1C2C7CEFBBFF353D38FC55D39"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@ -81,6 +81,14 @@ namespace UI {
case 1:
this.datagrid1 = ((System.Windows.Controls.DataGrid)(target));
return;
case 2:
#line 11 "..\..\MainWindow.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Button_Click);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}