public void SaveStat() //сохранение статистики
{
try
{
var data = new List<Statistcs>();
string filePath = "stats.xml";
data = Serializer.GetData(filePath);
data.Add(new Statistcs()
{
Date = DateTime.Now,
Result = state,
StepCounter = stepCounter,
UserFirst = true
});
Serializer.SetData(filePath, data);
data = Serializer.GetData(filePath);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
transportList = new List<ITransport>();
BinaryFormatter formatter = new BinaryFormatter();
FileStream transportFile = new FileStream("transport.tdt", FileMode.OpenOrCreate);
if (transportFile.Length>0)
{
transportList = (List<ITransport>)formatter.Deserialize(transportFile);
}
transportFile.Close();
transportListBindingSource.DataSource = transportList;
BinaryFormatter formatter = new BinaryFormatter();
FileStream transporFileStream = new FileStream("transport.tdt", FileMode.OpenOrCreate);
formatter.Serialize(transporFileStream, transportList);
transporFileStream.Close();