forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealDataRepo.cs
More file actions
152 lines (119 loc) · 4.58 KB
/
RealDataRepo.cs
File metadata and controls
152 lines (119 loc) · 4.58 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Hosting;
using System.Xml.Serialization;
using DynamicLinqWebDocs.Models;
namespace DynamicLinqWebDocs.Infrastructure.Data
{
public class DynLINQDoc
{
public List<Class> Classes { get; set; }
public List<Expression> Expressions { get; set; }
public List<Keyword> Keywords { get; set; }
}
class RealDataRepo : IDataRepo
{
static DynLINQDoc _doc;
static RealDataRepo()
{
LoadData();
}
public RealDataRepo()
{
#if DEBUG
//reload data in debug mode so we can see xml changes without recycling IIS.
LoadData();
#endif
}
static void LoadData()
{
var serializer = new XmlSerializer(typeof(DynLINQDoc), "http://schemas.plainlogic.net/dynamiclinqdocs/2014");
var docFolder = HostingEnvironment.MapPath(@"~/App_Data/");
var docFolderInfo = new DirectoryInfo(docFolder);
var docFiles = docFolderInfo.GetFiles("*.xml", SearchOption.AllDirectories);
//var filePath = HostingEnvironment.MapPath(@"~/App_Data/DynLINQDoc.xml");
_doc = new DynLINQDoc()
{
Classes = new List<Class>(),
Expressions = new List<Expression>(),
Keywords = new List<Keyword>()
};
foreach (var docFile in docFiles)
{
using (var file = File.Open(docFile.FullName, FileMode.Open))
{
var tempDoc = (DynLINQDoc)serializer.Deserialize(file);
if (tempDoc.Classes != null) _doc.Classes.AddRange(tempDoc.Classes);
if (tempDoc.Expressions != null) _doc.Expressions.AddRange(tempDoc.Expressions);
if (tempDoc.Keywords != null) _doc.Keywords.AddRange(tempDoc.Keywords);
}
}
}
public IEnumerable<Class> GetClasses()
{
return _doc.Classes;
}
public Class GetClass(string className)
{
return _doc.Classes
.Where(x => className.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();
}
public Method GetMethod(string className, string methodName, Frameworks framework, out Class @class, int overload)
{
@class = GetClass(className);
if (@class == null) return null;
if (overload < 0) return null;
IEnumerable<Method> methodFinder = @class.Methods
.Where(x => methodName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase));
if (framework == Frameworks.NotSet)
{
methodFinder = methodFinder.OrderByDescending(x => x.Frameworks);
}
else
{
methodFinder = methodFinder.Where(x => x.Frameworks.HasFlag(framework));
}
if( overload > 0 ) methodFinder = methodFinder.Skip(overload);
return methodFinder.FirstOrDefault();
}
public Property GetProperty(string className, string propertyName, Frameworks framework, out Class @class)
{
@class = GetClass(className);
if (@class == null) return null;
IEnumerable<Property> propertyFinder = @class.Properties
.Where(x => propertyName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase));
if (framework == Frameworks.NotSet)
{
propertyFinder = propertyFinder.OrderByDescending(x => x.Frameworks);
}
else
{
propertyFinder = propertyFinder.Where(x => x.Frameworks.HasFlag(framework));
}
return propertyFinder.FirstOrDefault();
}
public Expression GetExpression(string expressionName)
{
return _doc.Expressions
.Where(x => expressionName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();
}
public IEnumerable<Expression> GetExpressions()
{
return _doc.Expressions;
}
public IEnumerable<Keyword> GetKeywords()
{
return _doc.Keywords;
}
public Keyword GetKeyword(string keywordName)
{
return _doc.Keywords
.Where(x => keywordName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();
}
}
}