serializer
This commit is contained in:
parent
dba3c5c2e1
commit
fb3640e999
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
56bcca95c23602acb987d5b18a78659a4b87bf01
|
||||
2b405998b147ec7745f71929a99418b4b119d093
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue