/
PersonalEvent.cs
117 lines (108 loc) · 2.73 KB
/
PersonalEvent.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
using System;
using System.Text;
using System.Xml;
using Waher.Content;
using Waher.Content.Xml;
namespace Waher.Networking.XMPP.PEP
{
/// <summary>
/// </summary>
public abstract class PersonalEvent : IPersonalEvent
{
/// <summary>
/// Node on which the personal event is published on.
/// </summary>
public virtual string Node => this.Namespace;
/// <summary>
/// Local name of the event element.
/// </summary>
public abstract string LocalName
{
get;
}
/// <summary>
/// Namespace of the event element.
/// </summary>
public abstract string Namespace
{
get;
}
/// <summary>
/// Optional Item ID of event. If null, a new will automatically be generated by the server.
/// </summary>
public virtual string ItemId
{
get { return null; }
}
/// <summary>
/// XML representation of the event.
/// </summary>
public abstract string PayloadXml
{
get;
}
/// <summary>
/// Parses a personal event from its XML representation
/// </summary>
/// <param name="E">XML representation of personal event.</param>
/// <returns>Personal event object.</returns>
public abstract IPersonalEvent Parse(XmlElement E);
/// <summary>
/// Serializes an optional decimal value.
/// </summary>
/// <param name="Xml">XML output.</param>
/// <param name="LocalName">Local name of element.</param>
/// <param name="Value">Optional value.</param>
protected void Append(StringBuilder Xml, string LocalName, decimal? Value)
{
if (Value.HasValue)
{
Xml.Append('<');
Xml.Append(LocalName);
Xml.Append('>');
Xml.Append(CommonTypes.Encode(Value.Value));
Xml.Append("</");
Xml.Append(LocalName);
Xml.Append('>');
}
}
/// <summary>
/// Serializes an optional date and time value.
/// </summary>
/// <param name="Xml">XML output.</param>
/// <param name="LocalName">Local name of element.</param>
/// <param name="Value">Optional value.</param>
protected void Append(StringBuilder Xml, string LocalName, DateTime? Value)
{
if (Value.HasValue)
{
Xml.Append('<');
Xml.Append(LocalName);
Xml.Append('>');
Xml.Append(XML.Encode(Value.Value));
Xml.Append("</");
Xml.Append(LocalName);
Xml.Append('>');
}
}
/// <summary>
/// Serializes an optional string value.
/// </summary>
/// <param name="Xml">XML output.</param>
/// <param name="LocalName">Local name of element.</param>
/// <param name="Value">Optional value.</param>
protected void Append(StringBuilder Xml, string LocalName, string Value)
{
if (!(Value is null))
{
Xml.Append('<');
Xml.Append(LocalName);
Xml.Append('>');
Xml.Append(XML.Encode(Value));
Xml.Append("</");
Xml.Append(LocalName);
Xml.Append('>');
}
}
}
}