-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
99 lines (76 loc) · 2.79 KB
/
Settings.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
using System.Xml.Serialization;
using System.Collections.Generic;
namespace SimpleDBAdmin
{
public class Settings
{
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public bool SavePublicKeys { get; set; }
public bool SavePrivateKeys { get; set; }
public bool SaveDomainSchemas { get; set; }
public List<AwsCredentials> AwsCredentials { get; set; }
}
public class AwsCredentials
{
public string Name { get; set; }
public string Key { get; set; }
[XmlIgnore]
public string Secret { get; set; }
public string EncryptedSecret { get; set; }
public string ServiceUrl { get; set; }
}
public class DomainSchema : SerializableDictionary<string, string[]>
{
}
[XmlRoot( "dictionary" )]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
{
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml( System.Xml.XmlReader reader )
{
var keySerializer = new XmlSerializer( typeof( TKey ) );
var valueSerializer = new XmlSerializer( typeof( TValue ) );
var wasEmpty = reader.IsEmptyElement;
reader.Read();
if( wasEmpty )
return;
while( reader.NodeType != System.Xml.XmlNodeType.EndElement )
{
reader.ReadStartElement( "item" );
reader.ReadStartElement( "key" );
var key = (TKey)keySerializer.Deserialize( reader );
reader.ReadEndElement();
reader.ReadStartElement( "value" );
var value = (TValue)valueSerializer.Deserialize( reader );
reader.ReadEndElement();
this.Add( key, value );
reader.ReadEndElement();
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml( System.Xml.XmlWriter writer )
{
var keySerializer = new XmlSerializer( typeof( TKey ) );
var valueSerializer = new XmlSerializer( typeof( TValue ) );
foreach( var key in this.Keys )
{
writer.WriteStartElement( "item" );
writer.WriteStartElement( "key" );
keySerializer.Serialize( writer, key );
writer.WriteEndElement();
writer.WriteStartElement( "value" );
var value = this[key];
valueSerializer.Serialize( writer, value );
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
}