-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathExampleDoc.cs
More file actions
84 lines (82 loc) · 2.62 KB
/
Copy pathExampleDoc.cs
File metadata and controls
84 lines (82 loc) · 2.62 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
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace JayDataExamples.App_Code
{
[XmlRoot("MainPage")]
public class ExampleDoc
{
private static ExampleDoc _instance;
internal static ExampleDoc Instnace
{
get
{
//ExampleDoc._instance = null;
if (ExampleDoc._instance == null)
{
using (XmlReader reader = XmlReader.Create(HttpContext.Current.Server.MapPath("~/ExampleList.xml")))
{
reader.MoveToContent();
ExampleDoc._instance = new XmlSerializer(typeof(ExampleDoc)).Deserialize(reader) as ExampleDoc;
}
}
return ExampleDoc._instance;
}
}
[XmlAnyElement]
public XmlNode IncludeGroups { get; set; }
[XmlAnyElement("Includes")]
public XmlNode GlobalInclude { get; set; }
[XmlArray("Examples")]
[XmlArrayItem(typeof(Example))]
public List<Example> Examples { get; set; }
internal IEnumerable<XmlNode> GetIncludes(string name)
{
var list = new List<XmlNode>();
foreach (XmlNode node in this.IncludeGroups.SelectNodes(string.Format("/Group[@name='{0}']/*", name))) {
list.Add(node);
}
return list;
}
[XmlIgnore]
public List<XmlNode> ResolvedIncludes
{
get
{
var list = new List<XmlNode>();
if (this.GlobalInclude != null)
{
foreach (XmlNode node in this.GlobalInclude.SelectNodes("*"))
{
if (node.Name != "group")
{
list.Add(node);
}
else
{
var nodeList = this.GetIncludes(node.Attributes["name"].Value);
list = new List<XmlNode>(list.Concat(nodeList));
}
}
}
return list;
}
}
[XmlIgnore]
public string GlobalIncludesString
{
get
{
var sb = new StringBuilder();
foreach (XmlNode node in this.ResolvedIncludes)
{
sb.AppendLine(node.OuterXml);
}
return sb.ToString();
}
}
}
}