1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
#endregion
|
23
|
|
|
24
|
|
using System;
|
25
|
|
using System.IO;
|
26
|
|
using System.Reflection;
|
27
|
|
using System.Collections;
|
28
|
|
using System.Text.RegularExpressions;
|
29
|
|
using System.Xml;
|
30
|
|
using ShowX.Model;
|
31
|
|
using ShowX.Model.XmlModel;
|
32
|
|
using log4net;
|
33
|
|
|
34
|
|
namespace ShowX.Session
|
35
|
|
{
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
public class XmlSession : ISession
|
40
|
|
{
|
41
|
|
private static readonly ILog log = LogManager.GetLogger(
|
42
|
|
typeof(XmlSession));
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
|
47
|
|
protected IObjectHandlerMethodCaller activeMethodCaller;
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
|
protected IMappingHandler activeMappingHandler;
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
protected Hashtable classXmlFilesMappingInfo;
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
protected Hashtable classMappingInfo;
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
23
|
public XmlSession()
|
71
|
|
{
|
72
|
23
|
activeMethodCaller = new XmlObjectHandlerMethodCaller();
|
73
|
23
|
activeMappingHandler = new XmlMappingHandler();
|
74
|
23
|
classMappingInfo = new Hashtable();
|
75
|
|
}
|
76
|
|
|
77
|
|
#region ISession Members
|
78
|
|
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
public ShowX.Model.IObjectHandlerMethodCaller MethodCaller
|
83
|
|
{
|
84
|
142
|
get
|
85
|
|
{
|
86
|
142
|
return activeMethodCaller;
|
87
|
|
}
|
88
|
|
}
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
public ShowX.Model.IMappingHandler MappingHandler
|
94
|
|
{
|
95
|
2757
|
get
|
96
|
|
{
|
97
|
2757
|
return activeMappingHandler;
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|
101
|
|
#endregion
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
29
|
public void RegisterClass(Type t)
|
109
|
|
{
|
110
|
|
|
111
|
29
|
if (classMappingInfo[t] != null) return;
|
112
|
|
|
113
|
28
|
XmlDocument mappingFile = new XmlDocument();
|
114
|
|
|
115
|
28
|
if (classXmlFilesMappingInfo[t.FullName] != null) {
|
116
|
|
|
117
|
0
|
mappingFile.Load(classXmlFilesMappingInfo[t.FullName] as string);
|
118
|
|
}
|
119
|
|
else {
|
120
|
|
|
121
|
|
|
122
|
28
|
Assembly asm = t.UnderlyingSystemType.Assembly;
|
123
|
|
|
124
|
28
|
string[] resources = asm.GetManifestResourceNames();
|
125
|
28
|
Regex regex = new Regex(t.Name + "\\.xml",RegexOptions.Compiled);
|
126
|
28
|
int index = -1;
|
127
|
|
|
128
|
85
|
for(int i = 0; i < resources.Length; i++) {
|
129
|
|
|
130
|
84
|
if (regex.IsMatch(resources[i])) {
|
131
|
|
|
132
|
27
|
index = i;
|
133
|
27
|
break;
|
134
|
|
}
|
135
|
|
}
|
136
|
|
|
137
|
28
|
if (index == -1) throw new SessionException(
|
138
|
|
string.Format("Unable to load (embedded) mapping file '{0}.xml' "
|
139
|
|
+ " for type '{1}' in assembly '{2}'",t.Name,
|
140
|
|
t.FullName,asm.FullName));
|
141
|
|
|
142
|
27
|
Stream xmlFile = asm.GetManifestResourceStream(
|
143
|
|
resources[index]);
|
144
|
|
|
145
|
27
|
XmlTextReader xtr = new XmlTextReader(xmlFile);
|
146
|
27
|
mappingFile.Load(xtr);
|
147
|
|
}
|
148
|
|
|
149
|
27
|
classMappingInfo.Add(t,new XmlClassMap(t,mappingFile));
|
150
|
|
}
|
151
|
|
|
152
|
|
|
153
|
|
|
154
|
|
|
155
|
|
public XmlClassMap this [Type t]
|
156
|
|
{
|
157
|
5479
|
get
|
158
|
|
{
|
159
|
5479
|
return classMappingInfo[t] as XmlClassMap;
|
160
|
|
}
|
161
|
|
}
|
162
|
|
|
163
|
|
|
164
|
|
|
165
|
|
|
166
|
|
public Hashtable XmlMappingFiles
|
167
|
|
{
|
168
|
1
|
get { return this.classXmlFilesMappingInfo; }
|
169
|
23
|
set
|
170
|
|
{
|
171
|
23
|
if (value == null) {
|
172
|
|
|
173
|
0
|
string errorMsg = "Cannot assign a null Hashtable to "
|
174
|
|
+" property XmlSession.XmlMappingFiles.";
|
175
|
0
|
log.Error(errorMsg);
|
176
|
0
|
throw new SessionException(errorMsg);
|
177
|
|
}
|
178
|
|
|
179
|
23
|
this.classXmlFilesMappingInfo = value;
|
180
|
|
}
|
181
|
|
}
|
182
|
|
}
|
183
|
|
}
|
184
|
|
|