-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZespolSerializacja.cs
123 lines (110 loc) · 4.01 KB
/
ZespolSerializacja.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace ZespolLib
{
public partial class Zespol
{
public static Zespol OdczytajBinStatic(string sciezka)
{
var path = Path.GetFullPath(sciezka);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(path, FileMode.Open);
Zespol zespol = (Zespol)formatter.Deserialize(stream);
stream.Close();
return zespol;
}
public Zespol OdczytajBin(string sciezka)
{
return OdczytajBinStatic(sciezka);
}
public void ZapiszBin(string sciezka)
{
var path = Path.GetFullPath(sciezka);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(path, FileMode.Create);
formatter.Serialize(stream, this);
stream.Flush();
stream.Close();
}
public Zespol OdczytajXML(string sciezka)
{
return OdczytajXMLStatic(sciezka);
}
public static Zespol OdczytajXMLStatic(string sciezka)
{
var path = Path.GetFullPath(sciezka);
XmlSerializer serializer = new XmlSerializer(typeof(Zespol));
Stream stream = new FileStream(path, FileMode.Open);
Zespol zespol = (Zespol) serializer.Deserialize(stream);
stream.Close();
return zespol;
}
public void ZapiszXML(string sciezka)
{
var path = Path.GetFullPath(sciezka);
XmlSerializer serializer = new XmlSerializer(typeof(Zespol));
Stream stream = new FileStream(path, FileMode.Create);
serializer.Serialize(stream, this);
stream.Flush();
stream.Close();
}
public Zespol OdczytajJSON(string sciezka)
{
return OdczytajJSONStatic(sciezka);
}
public static Zespol OdczytajJSONStatic(string sciezka)
{
var path = Path.GetFullPath(sciezka);
StreamReader sr = File.OpenText(path);
Zespol zespol = JsonSerializer.Deserialize<Zespol>(sr.ReadToEnd());
sr.Close();
return zespol;
}
public void ZapiszJSON(string sciezka)
{
var path = Path.GetFullPath(sciezka);
StreamWriter sw = File.CreateText(path);
string output = GetJSONString();
sw.Write(output);
sw.Flush();
sw.Close();
}
public string GetJSONString()
{
return JsonSerializer.Serialize<Zespol>(this);
}
public Zespol OdczytajYaml(string sciezka)
{
return OdczytajYamlStatic(sciezka);
}
public static Zespol OdczytajYamlStatic(string sciezka)
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(new PascalCaseNamingConvention())
.Build();
var path = Path.GetFullPath(sciezka);
StreamReader sr = File.OpenText(path);
Zespol zespol = deserializer.Deserialize<Zespol>(sr.ReadToEnd());
sr.Close();
return zespol;
}
public void ZapiszYaml(string sciezka)
{
var serializer = new SerializerBuilder()
.WithNamingConvention(new PascalCaseNamingConvention())
.Build();
var path = Path.GetFullPath(sciezka);
StreamWriter sw = File.CreateText(path);
string output = serializer.Serialize(this);
sw.Write(output);
sw.Flush();
sw.Close();
}
}
}