-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceConfig.cs
More file actions
91 lines (81 loc) · 2.61 KB
/
Copy pathDeviceConfig.cs
File metadata and controls
91 lines (81 loc) · 2.61 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
namespace AndroidDeviceConfig
{
/// <summary>
/// Holds a complete device config with versions, name, vendor etc.
/// </summary>
[Serializable]
public class DeviceConfig
{
static XmlSerializer serializer;
private string _Name = String.Empty;
private string _Vendor = String.Empty;
public string ADCVersion = "0.2";
/// <summary>
/// Holds the different versions of the device model available
/// </summary>
public List<DeviceVersion> Versions = new List<DeviceVersion>();
/// <summary>
/// The name of the device
/// </summary>
[XmlAttribute]
public string Name
{
get { return _Name; }
set { if(!Equals(Name, value)) _Name = value; }
}
/// <summary>
/// The vendor of the device
/// </summary>
[XmlAttribute]
public string Vendor
{
get { return _Vendor; }
set { if(!Vendor.Equals(value))_Vendor = value; }
}
/// <summary>
/// Derializises a file into a DeviceConfig object
/// </summary>
/// <param name="file">the file to deserialize</param>
/// <returns>a new DeviceConfig object</returns>
public static DeviceConfig LoadConfig(string file)
{
if (serializer == null)
{
serializer = new XmlSerializer(typeof (DeviceConfig));
}
using (FileStream stream = File.OpenRead(file))
{
return serializer.Deserialize(stream) as DeviceConfig;
}
}
/// <summary>
/// Serializes a DeviceConfig object into a file
/// </summary>
/// <param name="file">the destination file</param>
/// <param name="config">the config to serialize</param>
public static void SaveConfig(string file, DeviceConfig config)
{
if (serializer == null)
{
serializer = new XmlSerializer(typeof(DeviceConfig));
}
using (FileStream stream = File.Create(file))
{
serializer.Serialize(stream, config);
}
}
/// <summary>
/// Serializes the current Deviceconfig object into a file
/// </summary>
/// <param name="file">the destination file</param>
public void SaveConfig(string file)
{
DeviceConfig.SaveConfig(file, this);
}
}
}