-
Notifications
You must be signed in to change notification settings - Fork 0
/
Components.cs
79 lines (67 loc) · 2.11 KB
/
Components.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;
namespace UnfuddleBackupParser
{
class Components
{
struct Component
{
public string id;
public string name;
}
SortedDictionary<int, Component> m_components;
public Components(XmlElement element)
{
m_components= new SortedDictionary<int, Component>();
parse(element);
}
public void AddAllAreas(StringBuilder sb)
{
addArea(sb, "id", "name");
foreach (KeyValuePair<int, Component> pair in m_components)
{
Component component = pair.Value;
addArea(sb, component.id, component.name);
}
}
public string GetComponentName(string id)
{
if (string.IsNullOrEmpty(id))
return null;
int nameId = Convert.ToInt32(id);
Component c = m_components[nameId];
return c.name;
}
private static void addArea(StringBuilder sb, string id, string name)
{
sb.Append(id);
sb.Append(',');
sb.Append(name);
sb.Append('\n');
}
private void parse(XmlElement element)
{
foreach (XmlNode node in element.ChildNodes)
{
Component component = new Component();
foreach (XmlNode child in node.ChildNodes)
{
string value = HttpUtility.HtmlDecode(child.InnerText);
switch (child.Name)
{
case "id":
component.id = value;
break;
case "name":
component.name = value;
break;
}
}
m_components.Add(Convert.ToInt32(component.id), component);
}
}
}
}