more :D
[GitHub/Stricted/SpeedportHybridControl.git] / SpeedportHybridControl.Implementations / Settings.cs
CommitLineData
a231311a
S
1using System;
2using System.IO;
3using System.Text;
4using System.Xml;
5
6namespace SpeedportHybridControl.Implementations {
7 public class Settings {
8 public static SettingsModel load () {
9 SettingsModel result = new SettingsModel();
10 try {
11 if (File.Exists("settings.xml").Equals(true)) {
12 XmlDocument xmlDocument = new XmlDocument();
13 xmlDocument.Load("settings.xml");
14 result = new SettingsModel {
15 ip = xmlDocument.DocumentElement["ip"].InnerText,
16 password = Cryptography.Decrypt(xmlDocument.DocumentElement["password"].InnerText)
17 };
18 }
19 }
20 catch (Exception ex) {
21 LogManager.WriteToLog(ex.Message);
22 }
23
24 return result;
25 }
26
27 public static bool save(SettingsModel settings) {
28 bool result;
29 try {
30 using (XmlTextWriter xmlTextWriter = new XmlTextWriter("settings.xml", Encoding.UTF8)) {
31 xmlTextWriter.Formatting = Formatting.Indented;
32 xmlTextWriter.Indentation = 4;
33 xmlTextWriter.WriteStartDocument();
34 xmlTextWriter.WriteStartElement("settings");
35 xmlTextWriter.WriteElementString("ip", settings.ip);
36 xmlTextWriter.WriteElementString("password", Cryptography.Encrypt(settings.password));
37 xmlTextWriter.WriteEndElement();
38 xmlTextWriter.WriteEndDocument();
39 }
40 result = true;
41 }
42 catch (Exception exception) {
43 LogManager.WriteToLog(exception.Message);
44
45 result = false;
46 }
47 return result;
48 }
49 }
50
51 public class SettingsModel {
52 private string _password;
53 private string _ip;
54
55 public string password {
56 get { return _password; }
57 set {
58 if (_password == value)
59 return;
60
61 _password = value;
62 }
63 }
64
65 public string ip {
66 get { return _ip; }
67 set {
68 if (_ip == value)
69 return;
70
71 _ip = value;
72 }
73 }
74
75 public SettingsModel () {
76 }
bd99ec80 77 }
a231311a 78}