OneMessageXmlParser.cs
11.7 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Xml.Serialization;
using Vrh.XmlProcessing;
namespace Vrh.OneMessage
{
/// <summary>
/// OneMessage üzenetküldő paraméterező XML fájl leképezése.
/// </summary>
public sealed class OneMessageXmlParser : XmlParser
{
private const string ELEMENT_NOTFOUND = "Element \"{0}\" not found where \"{1}\" attribute equals \"{2}\"!";
#region Private variables
private readonly XElement m_MessageXE = null;
#endregion Private variables
#region ElementNames private classes
private new class ElementNames : XmlLinqBase.ElementNames
{
/// <summary>
/// 'Attachment' elem név.
/// </summary>
public const string ATTACHMENT = "Attachment";
/// <summary>
/// 'Attachments' elem név.
/// </summary>
public const string ATTACHMENTS = "Attachments";
/// <summary>
/// 'DeliveryDefinition' elem név.
/// </summary>
public const string DELIVERYDEFINITION = "DeliveryDefinition";
/// <summary>
/// 'DeliveryDefinitions' elem név.
/// </summary>
public const string DELIVERYDEFINITIONS = "DeliveryDefinitions";
/// <summary>
/// 'MessageBody' elem név.
/// </summary>
public const string MESSAGEBODY = "MessageBody";
/// <summary>
/// 'OneMessage' elem név.
/// </summary>
public const string ONEMESSAGE = "OneMessage";
/// <summary>
/// 'OneMessageDefinitions' elem név.
/// </summary>
public const string ONEMESSAGEDEFINITIONS = "OneMessageDefinitions";
/// <summary>
/// 'SendTo' elem név.
/// </summary>
public const string SENDTO = "SendTo";
/// <summary>
/// 'Subject' elem név.
/// </summary>
public const string SUBJECT = "Subject";
}
#endregion ElementNames private classes
#region AttributeNames static class
/// <summary>
/// XML fájlokban ilyen attribútum nevek találhatóak egy MenuItem-ben.
/// </summary>
public static class AttributeNames
{
/// <summary>
/// 'DeleteAfterSend' attribútum név.
/// </summary>
public const string DELETEAFTERSEND = "DeleteAfterSend";
/// <summary>
/// 'Delivery' attribútum név.
/// </summary>
public const string DELIVERY = "Delivery";
/// <summary>
/// 'Folder' attribútum név.
/// </summary>
public const string FOLDER = "Folder";
/// <summary>
/// 'Id' attribútum név.
/// </summary>
public const string ID = "Id";
/// <summary>
/// 'LCID' attribútum név.
/// </summary>
public const string LCID = "LCID";
/// <summary>
/// 'Name' attribútum név.
/// </summary>
public const string NAME = "Name";
}
#endregion AttributeNames static class
#region Properties
/// <summary>
/// A már beazonosított (hozzárendelt) szállítási definició.
/// </summary>
public DeliveryDefinition Delivery { get; private set; }
#region SendTo property
/// <summary>
/// Címzettek vesszővel elválasztott listája.
/// </summary>
public string SendTo
{
get
{
if (m_SendTo == null)
{
m_SendTo = GetValue(m_MessageXE.Element(ElementNames.SENDTO), "");
}
return m_SendTo;
}
}
private string m_SendTo = null;
#endregion SendTo property
#region Subject property
/// <summary>
/// A levél tárgya.
/// </summary>
public string Subject
{
get
{
if (m_Subject == null)
{
m_Subject = GetValue(m_MessageXE.Element(ElementNames.SUBJECT), "");
}
return m_Subject;
}
}
private string m_Subject = null;
#endregion Subject property
#region MessageBody property
/// <summary>
/// Az üzenet tartalma.
/// </summary>
public string MessageBody
{
get
{
if (m_MessageBody == null)
{
m_MessageBody = GetValue(m_MessageXE.Element(ElementNames.MESSAGEBODY), "");
}
return m_MessageBody;
}
}
private string m_MessageBody = null;
#endregion MessageBody property
#region Attachments property
/// <summary>
/// A paraméterező fájlban megadott csatolmányok.
/// </summary>
public List<AttachmentElement> Attachments
{
get
{
if (m_Attachments == null)
{
m_Attachments = new List<AttachmentElement>();
XElement xe = m_MessageXE.Element(ElementNames.ATTACHMENTS);
if (xe != null)
{
string folder = GetValue(AttributeNames.FOLDER, xe, "");
m_IsDeleteAfterSend = GetValue(AttributeNames.DELETEAFTERSEND, xe, false);
m_IsInitializedDeleteAfterSend = true;
IEnumerable<XElement> attachmentsXE = xe.Elements(ElementNames.ATTACHMENT);
if (attachmentsXE != null && attachmentsXE.Any())
{
foreach (XElement attXE in attachmentsXE)
{
var ae = new AttachmentElement(attXE, folder);
if (!string.IsNullOrWhiteSpace(ae.File))
{ // Ha van érték is File tulajdonságokban, csak akkor adjuk hozzá
m_Attachments.Add(ae);
}
}
}
}
}
return m_Attachments;
}
}
private List<AttachmentElement> m_Attachments = null;
#endregion Attachments property
#region IsDeleteAfterSend property
/// <summary>
/// A csatolmányokat kell-e törölni a küldés után.
/// </summary>
public bool IsDeleteAfterSend
{
get
{
if (!m_IsInitializedDeleteAfterSend)
{
XElement xe = m_MessageXE.Element(ElementNames.ATTACHMENTS);
if (xe != null)
{
m_IsDeleteAfterSend = GetValue(AttributeNames.DELETEAFTERSEND, xe, false);
}
m_IsInitializedDeleteAfterSend = true;
}
return m_IsDeleteAfterSend;
}
}
private bool m_IsDeleteAfterSend = false;
private bool m_IsInitializedDeleteAfterSend = false;
#endregion IsDeleteAfterSend property
#endregion Properties
#region Constructor
/// <summary>
/// XML paraméterező fájl feldolgozásának konstruktora.
/// </summary>
/// <param name="xmlc">XmlParser kapcsolati sztring (connection string).</param>
/// <param name="appPath">Az alkalmazás alap mappája. Ez alatt van az App_Data.</param>
/// <param name="lcid">A környezetben érvényes nyelvi kód. Ha üres, akkor az XmlParser-ben beállított lesz érvényes.</param>
/// <param name="otherVars">A környezetben az XmlParser részére létrehozott változók.</param>
/// <param name="messageId"></param>
/// <param name="delivery"></param>
public OneMessageXmlParser(
XmlConnection xmlc,
string appPath,
string lcid,
Dictionary<string, string> otherVars,
string messageId,
string delivery = null)
: base(xmlc, appPath, lcid, otherVars)
{
try
{
#region Üzenetdefiníciós XElement megkeresése és megjegyzése
XElement defXE = this.RootElement.Element(ElementNames.ONEMESSAGEDEFINITIONS);
if (defXE == null)
{
throw new ApplicationException(string.Format(Messages.ERR_MISSINGELEMENT, ElementNames.ONEMESSAGEDEFINITIONS));
}
IEnumerable<XElement> messagesXE = defXE.Elements(ElementNames.ONEMESSAGE);
if (messagesXE == null || !messagesXE.Any())
{
throw new ApplicationException(string.Format(Messages.ERR_MISSINGELEMENT, ElementNames.ONEMESSAGE));
}
foreach (XElement messXE in messagesXE)
{
string messId = GetValue(AttributeNames.ID, messXE, "", true, true);
string messLCID = GetValue(AttributeNames.LCID, messXE, "");
if (messId == messageId && (string.IsNullOrWhiteSpace(messLCID) || messLCID == this.LCID))
{
m_MessageXE = messXE;
}
}
if (m_MessageXE == null)
{
throw new ApplicationException(string.Format(ELEMENT_NOTFOUND, ElementNames.ONEMESSAGE, AttributeNames.ID, messageId));
}
#endregion Üzenetdefiníciós XElement megkeresése és megjegyzése
#region Delivery megkeresése és beállítása
string deliveryName = delivery;
if (string.IsNullOrWhiteSpace(deliveryName))
{
deliveryName = GetValue(AttributeNames.DELIVERY, m_MessageXE, "", true, true);
}
XElement deliveryDefsXE = this.RootElement.Element(ElementNames.DELIVERYDEFINITIONS);
if (deliveryDefsXE == null)
{
throw new ApplicationException(string.Format(Messages.ERR_MISSINGELEMENT, ElementNames.DELIVERYDEFINITIONS));
}
IEnumerable<XElement> deliveriesXE = deliveryDefsXE.Elements(ElementNames.DELIVERYDEFINITION);
if (deliveriesXE == null || !deliveriesXE.Any())
{
throw new ApplicationException(string.Format(Messages.ERR_MISSINGELEMENT, ElementNames.DELIVERYDEFINITION));
}
foreach (XElement delXE in deliveriesXE)
{
string delName = GetValue(AttributeNames.NAME, delXE, "", true, true);
if (delName == deliveryName)
{
this.Delivery = new DeliveryDefinition(delXE);
}
}
if (this.Delivery == null)
{
throw new ApplicationException(string.Format(ELEMENT_NOTFOUND, ElementNames.DELIVERYDEFINITION, AttributeNames.NAME, deliveryName));
}
#endregion Delivery megkeresése és beállítása
}
catch (Exception ex)
{
throw new ApplicationException("Error occured when OneMessageXmlParser initialization!", ex);
}
}
#endregion Constructor
}
}