-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadataReader.cs
122 lines (103 loc) · 4.35 KB
/
MetadataReader.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using FuryTech.OdataTypescriptServiceGenerator.Models;
namespace FuryTech.OdataTypescriptServiceGenerator
{
public class MetadataReader
{
public List<EntityType> EntityTypes { get; private set; }
public List<ComplexType> ComplexTypes { get; private set; }
public List<EnumType> EnumTypes { get; private set; }
public List<EntitySet> EntitySets { get; private set; }
public List<CustomAction> CustomActions { get; private set; }
public List<CustomFunction> CustomFunctions { get; private set; }
private void ReadEntityTypes(XDocument xdoc)
{
Logger.Log("Parsing entity types...");
var typeList = new List<EntityType>();
var elements = xdoc.Descendants().Where(a => a.Name.LocalName == "EntityType");
foreach (var xElement in elements)
{
var enT = new EntityType(xElement);
typeList.Add(enT);
Logger.Log($"Entity Type '{enT.NameSpace}.{enT.Name}' parsed");
}
EntityTypes = typeList;
}
private void ReadComplexTypes(XDocument xdoc)
{
Logger.Log("Parsing complex types...");
var typeList = new List<ComplexType>();
var elements = xdoc.Descendants().Where(a => a.Name.LocalName == "ComplexType");
foreach (var xElement in elements)
{
var enT = new ComplexType(xElement);
typeList.Add(enT);
Logger.Log($"Entity Type '{enT.NameSpace}.{enT.Name}' parsed");
}
ComplexTypes = typeList;
}
private void ReadEnums(XDocument xdoc)
{
Logger.Log("Parsing enums...");
var enumList = new List<EnumType>();
var elements = xdoc.Descendants().Where(a => a.Name.LocalName == "EnumType");
foreach (var xElement in elements)
{
var enT = new EnumType(xElement);
enumList.Add(enT);
Logger.Log($"Enum Type '{enT.NameSpace}.{enT.Name}' parsed");
}
EnumTypes = enumList;
}
private void ReadEntitySets(XDocument xdoc, List<CustomAction> actions, List<CustomFunction> functions)
{
Logger.Log("Parsing entity sets...");
var entitySetList = new List<EntitySet>();
var elements = xdoc.Descendants().Where(a => a.Name.LocalName == "EntitySet");
foreach (var xElement in elements)
{
var tContainer = new EntitySet(xElement, actions, functions);
entitySetList.Add(tContainer);
Logger.Log($"Entity set '{tContainer.Name}' parsed");
}
EntitySets = entitySetList;
}
private void ReadCustomActions(XDocument xDoc)
{
Logger.Log("Parsing custom actions...");
List<CustomAction> customActionList = new List<CustomAction>();
var elements = xDoc.Descendants().Where(a => a.Name.LocalName == "Action");
foreach (var xElement in elements)
{
var tCustomAction = new CustomAction(xElement);
customActionList.Add(tCustomAction);
Logger.Log($"Custom Action '{tCustomAction.Name}' parsed");
}
CustomActions = customActionList;
}
private void ReadCustomFunctions(XDocument xDoc)
{
Logger.Log("Parsing custom functions...");
List<CustomFunction> customFunctionList = new List<CustomFunction>();
var elements = xDoc.Descendants().Where(a => a.Name.LocalName == "Function");
foreach (var xElement in elements)
{
var tCustomAction = new CustomFunction(xElement);
customFunctionList.Add(tCustomAction);
Logger.Log($"Custom Action '{tCustomAction.Name}' parsed");
}
CustomFunctions = customFunctionList;
}
public MetadataReader(XDocument xdoc)
{
ReadEntityTypes(xdoc);
ReadComplexTypes(xdoc);
ReadEnums(xdoc);
ReadCustomActions(xdoc);
ReadCustomFunctions(xdoc);
ReadEntitySets(xdoc, CustomActions, CustomFunctions);
}
}
}