Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RssItem.cs
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Xml;
4
using
Waher.Runtime.Inventory
;
5
6
namespace
Waher.Content.Rss
7
{
16
public
class
RssItem
17
{
28
public
RssItem
(XmlElement Xml, Uri BaseUri)
29
{
30
if
(Xml is
null
)
31
throw
new
ArgumentNullException(nameof(Xml));
32
33
List<RssWarning>
Warnings
=
new
List<RssWarning>();
34
List<RssCategory>
Categories
=
new
List<RssCategory>();
35
List<IRssExtension>
Extensions
=
new
List<IRssExtension>();
36
37
foreach
(XmlNode N
in
Xml.ChildNodes)
38
{
39
if
(!(N is XmlElement E))
40
continue
;
41
42
if
(E.NamespaceURI == Xml.NamespaceURI)
43
{
44
switch
(E.LocalName)
45
{
46
case
"title"
:
47
this.Title = E.InnerText;
48
break
;
49
50
case
"link"
:
51
if
(Uri.TryCreate(BaseUri, E.InnerText, out Uri
Link
))
52
this.Link =
Link
;
53
else
54
Warnings
.Add(
new
RssWarning
(E,
"Invalid URI: "
+ E.InnerText));
55
break
;
56
57
case
"description"
:
58
this.Description = E.InnerText;
59
break
;
60
61
case
"author"
:
62
this.Author = E.InnerText;
63
break
;
64
65
case
"category"
:
66
RssCategory
Category =
new
RssCategory
(E, BaseUri);
67
Warnings
.AddRange(Category.
Warnings
);
68
Categories
.Add(Category);
69
break
;
70
71
case
"comments"
:
72
if
(Uri.TryCreate(BaseUri, E.InnerText, out Uri
Comments
))
73
this.Comments =
Comments
;
74
else
75
Warnings
.Add(
new
RssWarning
(E,
"Invalid URI: "
+ E.InnerText));
76
break
;
77
78
case
"enclosure"
:
79
if
(!(this.
Enclosure
is
null
))
80
Warnings
.Add(
new
RssWarning
(E,
"Enclosure already defined."
));
81
else
82
{
83
this.Enclosure =
new
RssEnclosure
(E, BaseUri);
84
Warnings
.AddRange(this.
Enclosure
.
Warnings
);
85
}
86
break
;
87
88
case
"guid"
:
89
this.Guid =
new
RssGuid
(E);
90
break
;
91
92
case
"pubDate"
:
93
if
(
CommonTypes
.
TryParseRfc822
(E.InnerText, out DateTimeOffset PubDate))
94
this.PublicationDate = PubDate;
95
else
96
Warnings
.Add(
new
RssWarning
(E,
"Unable to parse publication date: "
+ E.InnerText));
97
break
;
98
99
case
"source"
:
100
if
(!(this.
Source
is
null
))
101
Warnings
.Add(
new
RssWarning
(E,
"Source already defined."
));
102
else
103
{
104
this.Source =
new
RssSource
(E, BaseUri);
105
Warnings
.AddRange(this.
Source
.
Warnings
);
106
}
107
break
;
108
109
default
:
110
Warnings
.Add(
new
RssWarning
(E));
111
break
;
112
}
113
}
114
else
115
{
116
IRssExtension
Extension =
Types
.FindBest<
IRssExtension
, XmlElement>(E);
117
if
(Extension is
null
)
118
Warnings
.Add(
new
RssWarning
(E));
119
else
120
Extensions
.Add(Extension.
Create
(E, BaseUri));
121
}
122
}
123
124
this.Warnings =
Warnings
.ToArray();
125
this.Categories =
Categories
.ToArray();
126
this.Extensions =
Extensions
.ToArray();
127
}
128
132
public
RssWarning
[]
Warnings
{
get
; }
133
137
public
string
Title
{
get
; }
138
142
public
Uri
Link
{
get
; } =
null
;
143
147
public
string
Description
{
get
; } =
null
;
148
152
public
string
Author
{
get
; } =
null
;
153
157
public
RssCategory
[]
Categories
{
get
; } =
null
;
158
162
public
Uri
Comments
{
get
; } =
null
;
163
167
public
RssEnclosure
Enclosure
{
get
; } =
null
;
168
172
public
RssGuid
Guid
{
get
; } =
null
;
173
177
public
DateTimeOffset?
PublicationDate
{
get
; } =
null
;
178
182
public
RssSource
Source
{
get
; } =
null
;
183
187
public
IRssExtension
[]
Extensions
{
get
; } =
null
;
188
}
189
}
Waher.Content.CommonTypes
Helps with parsing of commong data types.
Definition:
CommonTypes.cs:13
Waher.Content.CommonTypes.TryParseRfc822
static bool TryParseRfc822(string s, out DateTimeOffset Value)
Parses a date and time value encoded according to RFC 822, §5.
Definition:
CommonTypes.cs:170
Waher.Content.Rss.RssCategory
Identifies a categorization taxonomy.
Definition:
RssCategory.cs:12
Waher.Content.Rss.RssCategory.Warnings
RssWarning[] Warnings
Any warning messages created during parsing.
Definition:
RssCategory.cs:44
Waher.Content.Rss.RssEnclosure
Describes content enclosed in an RSS item.
Definition:
RssEnclosure.cs:12
Waher.Content.Rss.RssEnclosure.Warnings
RssWarning[] Warnings
Any warning messages created during parsing.
Definition:
RssEnclosure.cs:45
Waher.Content.Rss.RssGuid
Globally unique identifier
Definition:
RssGuid.cs:11
Waher.Content.Rss.RssItem
A channel may contain any number of <item>s. An item may represent a "story" – much like a story in a...
Definition:
RssItem.cs:17
Waher.Content.Rss.RssItem.Comments
Uri Comments
URL of a page for comments relating to the item.
Definition:
RssItem.cs:162
Waher.Content.Rss.RssItem.Link
Uri Link
The URL of the item.
Definition:
RssItem.cs:142
Waher.Content.Rss.RssItem.Title
string Title
The title of the item.
Definition:
RssItem.cs:137
Waher.Content.Rss.RssItem.Description
string Description
The item synopsis.
Definition:
RssItem.cs:147
Waher.Content.Rss.RssItem.RssItem
RssItem(XmlElement Xml, Uri BaseUri)
A channel may contain any number of <item>s. An item may represent a "story" – much like a story in a...
Definition:
RssItem.cs:28
Waher.Content.Rss.RssItem.Warnings
RssWarning[] Warnings
Any warning messages created during parsing.
Definition:
RssItem.cs:132
Waher.Content.Rss.RssItem.Categories
RssCategory[] Categories
Includes the item in one or more categories.
Definition:
RssItem.cs:157
Waher.Content.Rss.RssItem.Guid
RssGuid Guid
A string that uniquely identifies the item.
Definition:
RssItem.cs:172
Waher.Content.Rss.RssItem.PublicationDate
DateTimeOffset? PublicationDate
Indicates when the item was published.
Definition:
RssItem.cs:177
Waher.Content.Rss.RssItem.Author
string Author
Email address of the author of the item.
Definition:
RssItem.cs:152
Waher.Content.Rss.RssItem.Extensions
IRssExtension[] Extensions
Extensions
Definition:
RssItem.cs:187
Waher.Content.Rss.RssItem.Enclosure
RssEnclosure Enclosure
Describes a media object that is attached to the item.
Definition:
RssItem.cs:167
Waher.Content.Rss.RssItem.Source
RssSource Source
The RSS channel that the item came from.
Definition:
RssItem.cs:182
Waher.Content.Rss.RssSource
RSS channel that the item came from.
Definition:
RssSource.cs:12
Waher.Content.Rss.RssSource.Warnings
RssWarning[] Warnings
Any warning messages created during parsing.
Definition:
RssSource.cs:44
Waher.Content.Rss.RssWarning
Contains a warning message.
Definition:
RssWarning.cs:9
Waher.Runtime.Inventory.Types
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition:
Types.cs:14
Waher.Content.Rss.IRssExtension
Interface for RSS extensions
Definition:
IRssExtension.cs:11
Waher.Content.Rss.IRssExtension.Create
IRssExtension Create(XmlElement Xml, Uri BaseUri)
Creates a new instance of the RSS extension.
Waher.Content.Rss
Definition:
IRssExtension.cs:6
Waher.Runtime.Inventory
Definition:
TypesLoader.cs:9
IoTGateway
Content
Waher.Content.Rss
RssItem.cs
Generated by
1.9.5