Skip to content

Commit afc0234

Browse files
committed
Prepare to modernize
1 parent 4c93570 commit afc0234

File tree

7 files changed

+60
-178
lines changed

7 files changed

+60
-178
lines changed

Help/SimpleFeedReaderHelp.shfbproj

Lines changed: 0 additions & 87 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 - 2020 Rob Janssen
3+
Copyright (c) 2014 - 2025 Devcorner.nl
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

SimpleFeedReader.sln

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30011.22
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35825.156 d17.13
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{35CEBD40-E6BE-4671-B270-89C7E72CA980}"
77
ProjectSection(SolutionItems) = preProject
@@ -13,11 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleFeedReader", "SimpleF
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleFeedReaderTests", "SimpleFeedReaderTests\SimpleFeedReaderTests.csproj", "{F89D25D8-DDE6-4533-85BE-EBF105269C31}"
1515
EndProject
16-
Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "SimpleFeedReaderHelp", "Help\SimpleFeedReaderHelp.shfbproj", "{D6A78785-3434-4544-A495-B201AFBD0964}"
17-
ProjectSection(ProjectDependencies) = postProject
18-
{B057867D-0D85-4EEC-87C2-FBA8020ED31D} = {B057867D-0D85-4EEC-87C2-FBA8020ED31D}
19-
EndProjectSection
20-
EndProject
2116
Global
2217
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2318
Debug|Any CPU = Debug|Any CPU
@@ -32,9 +27,6 @@ Global
3227
{F89D25D8-DDE6-4533-85BE-EBF105269C31}.Debug|Any CPU.Build.0 = Debug|Any CPU
3328
{F89D25D8-DDE6-4533-85BE-EBF105269C31}.Release|Any CPU.ActiveCfg = Release|Any CPU
3429
{F89D25D8-DDE6-4533-85BE-EBF105269C31}.Release|Any CPU.Build.0 = Release|Any CPU
35-
{D6A78785-3434-4544-A495-B201AFBD0964}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36-
{D6A78785-3434-4544-A495-B201AFBD0964}.Release|Any CPU.ActiveCfg = Release|Any CPU
37-
{D6A78785-3434-4544-A495-B201AFBD0964}.Release|Any CPU.Build.0 = Release|Any CPU
3830
EndGlobalSection
3931
GlobalSection(SolutionProperties) = preSolution
4032
HideSolutionNode = FALSE

SimpleFeedReader/DefaultFeedItemNormalizer.cs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace SimpleFeedReader
2020
/// </remarks>
2121
public class DefaultFeedItemNormalizer : IFeedItemNormalizer
2222
{
23-
private static Regex _htmlRegex = new Regex(@"<[^>]*>", RegexOptions.Compiled); //@"<(.|\n)*?>"
24-
private static Regex _controlCodesRegex = new Regex(@"[\x00-\x1F\x7f]", RegexOptions.Compiled);
25-
private static Regex _whiteSpaceRegex = new Regex(@"\s{2,}", RegexOptions.Compiled);
23+
private static readonly Regex _htmlregex = new Regex(@"<[^>]*>", RegexOptions.Compiled); //@"<(.|\n)*?>"
24+
private static readonly Regex _controlcodesregex = new Regex(@"[\x00-\x1F\x7f]", RegexOptions.Compiled);
25+
private static readonly Regex _whitespaceregex = new Regex(@"\s{2,}", RegexOptions.Compiled);
2626

2727
/// <summary>
2828
/// Normalizes a SyndicationItem into a FeedItem.
@@ -34,16 +34,7 @@ public virtual FeedItem Normalize(SyndicationFeed feed, SyndicationItem item)
3434
{
3535
var alternatelink = item.Links.FirstOrDefault(l => l.RelationshipType == null || l.RelationshipType.Equals("alternate", StringComparison.OrdinalIgnoreCase));
3636

37-
Uri itemuri = null;
38-
if (alternatelink == null && !Uri.TryCreate(item.Id, UriKind.Absolute, out Uri parsed))
39-
{
40-
itemuri = parsed;
41-
}
42-
else
43-
{
44-
itemuri = alternatelink.GetAbsoluteUri();
45-
}
46-
37+
var itemuri = alternatelink == null && !Uri.TryCreate(item.Id, UriKind.Absolute, out var parsed) ? parsed : alternatelink.GetAbsoluteUri();
4738
return new FeedItem
4839
{
4940
Id = string.IsNullOrEmpty(item.Id) ? null : item.Id.Trim(),
@@ -58,20 +49,19 @@ public virtual FeedItem Normalize(SyndicationFeed feed, SyndicationItem item)
5849
};
5950
}
6051

61-
private static IEnumerable<Uri> GetFeedItemImages(SyndicationItem item)
62-
{
63-
return item.ElementExtensions
52+
private static IEnumerable<Uri> GetFeedItemImages(SyndicationItem item) => item.ElementExtensions
6453
.Where(p => p.OuterName.Equals("image"))
6554
.Select(p => new Uri(p.GetObject<XElement>().Value));
66-
}
6755

6856
private static string Normalize(string value)
6957
{
7058
if (!string.IsNullOrEmpty(value))
7159
{
7260
value = HtmlDecode(value);
7361
if (string.IsNullOrEmpty(value))
62+
{
7463
return value;
64+
}
7565

7666
value = StripHTML(value);
7767
value = StripDoubleOrMoreWhiteSpace(RemoveControlChars(value));
@@ -80,35 +70,23 @@ private static string Normalize(string value)
8070
return value;
8171
}
8272

83-
private static string RemoveControlChars(string value)
84-
{
85-
return _controlCodesRegex.Replace(value, " ");
86-
}
73+
private static string RemoveControlChars(string value) => _controlcodesregex.Replace(value, " ");
8774

88-
private static string StripDoubleOrMoreWhiteSpace(string value)
89-
{
90-
return _whiteSpaceRegex.Replace(value, " ");
91-
}
75+
private static string StripDoubleOrMoreWhiteSpace(string value) => _whitespaceregex.Replace(value, " ");
9276

93-
private static string StripHTML(string value)
94-
{
95-
return _htmlRegex.Replace(value, " ");
96-
}
77+
private static string StripHTML(string value) => _htmlregex.Replace(value, " ");
9778

9879
private static string HtmlDecode(string value, int threshold = 5)
9980
{
100-
int c = 0;
101-
string newvalue = WebUtility.HtmlDecode(value);
81+
var c = 0;
82+
var newvalue = WebUtility.HtmlDecode(value);
10283
while (!newvalue.Equals(value) && c < threshold) //Keep decoding (if a string is double/triple/... encoded; we want the original)
10384
{
10485
c++;
10586
value = newvalue;
10687
newvalue = WebUtility.HtmlDecode(value);
10788
}
108-
if (c >= threshold) //Decoding threshold exceeded?
109-
return null;
110-
111-
return newvalue;
89+
return c >= threshold ? null : newvalue;
11290
}
11391
}
11492
}

SimpleFeedReader/FeedItem.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class FeedItem
4949
/// The Date of the <see cref="FeedItem"/>.
5050
/// </summary>
5151
[Obsolete("Split into PublishDate and LastUpdatedDate")]
52-
public DateTimeOffset Date { get { return new[] { PublishDate, LastUpdatedDate }.Max(); } }
52+
public DateTimeOffset Date => new[] { PublishDate, LastUpdatedDate }.Max();
5353

5454
/// <summary>
5555
/// The publication date of the <see cref="FeedItem"/>.
@@ -93,19 +93,13 @@ public FeedItem(FeedItem item)
9393
/// </summary>
9494
/// <returns>Returns content, if any, otherwise returns the summary as content.</returns>
9595
/// <remarks>This method is intended as conveinience-method.</remarks>
96-
public string GetContent()
97-
{
98-
return !string.IsNullOrEmpty(Content) ? Content : Summary;
99-
}
96+
public string GetContent() => !string.IsNullOrEmpty(Content) ? Content : Summary;
10097

10198
/// <summary>
10299
/// Returns the summary, if any, otherwise returns the content as the summary.
103100
/// </summary>
104101
/// <returns>Returns the summary, if any, otherwise returns the content as the summary.</returns>
105102
/// <remarks>This method is intended as conveinience-method.</remarks>
106-
public string GetSummary()
107-
{
108-
return !string.IsNullOrEmpty(Summary) ? Summary : Content;
109-
}
103+
public string GetSummary() => !string.IsNullOrEmpty(Summary) ? Summary : Content;
110104
}
111105
}

SimpleFeedReader/FeedReader.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public FeedReader(IFeedItemNormalizer defaultFeedItemNormalizer, bool throwOnErr
7272
/// Returns an <see cref="IEnumerable&lt;FeedItem&gt;"/> of retrieved <see cref="FeedItem"/>s.
7373
/// </returns>
7474
/// <remarks>This is a convenience method.</remarks>
75-
public IEnumerable<FeedItem> RetrieveFeeds(IEnumerable<string> uris)
76-
{
77-
return RetrieveFeeds(uris, DefaultNormalizer);
78-
}
75+
public IEnumerable<FeedItem> RetrieveFeeds(IEnumerable<string> uris) => RetrieveFeeds(uris, DefaultNormalizer);
7976

8077
/// <summary>
8178
/// Retrieves the specified feeds.
@@ -90,9 +87,12 @@ public IEnumerable<FeedItem> RetrieveFeeds(IEnumerable<string> uris)
9087
/// <remarks>This is a convenience method.</remarks>
9188
public IEnumerable<FeedItem> RetrieveFeeds(IEnumerable<string> uris, IFeedItemNormalizer normalizer)
9289
{
93-
List<FeedItem> items = new List<FeedItem>();
90+
var items = new List<FeedItem>();
9491
foreach (var u in uris)
92+
{
9593
items.AddRange(RetrieveFeed(u, normalizer));
94+
}
95+
9696
return items;
9797
}
9898

@@ -103,10 +103,7 @@ public IEnumerable<FeedItem> RetrieveFeeds(IEnumerable<string> uris, IFeedItemNo
103103
/// <returns>
104104
/// Returns an <see cref="IEnumerable&lt;FeedItem&gt;"/> of retrieved <see cref="FeedItem"/>s.
105105
/// </returns>
106-
public IEnumerable<FeedItem> RetrieveFeed(string uri)
107-
{
108-
return RetrieveFeed(uri, DefaultNormalizer);
109-
}
106+
public IEnumerable<FeedItem> RetrieveFeed(string uri) => RetrieveFeed(uri, DefaultNormalizer);
110107

111108
/// <summary>
112109
/// Retrieves the specified feed.
@@ -127,7 +124,9 @@ public IEnumerable<FeedItem> RetrieveFeed(string uri, IFeedItemNormalizer normal
127124
catch
128125
{
129126
if (ThrowOnError)
127+
{
130128
throw;
129+
}
131130
}
132131
return Enumerable.Empty<FeedItem>();
133132
}
@@ -139,10 +138,7 @@ public IEnumerable<FeedItem> RetrieveFeed(string uri, IFeedItemNormalizer normal
139138
/// <returns>
140139
/// Returns an <see cref="IEnumerable&lt;FeedItem&gt;"/> of retrieved <see cref="FeedItem"/>s.
141140
/// </returns>
142-
public IEnumerable<FeedItem> RetrieveFeed(XmlReader xmlReader)
143-
{
144-
return RetrieveFeed(xmlReader, DefaultNormalizer);
145-
}
141+
public IEnumerable<FeedItem> RetrieveFeed(XmlReader xmlReader) => RetrieveFeed(xmlReader, DefaultNormalizer);
146142

147143
/// <summary>
148144
/// Retrieves the specified feed.
@@ -157,21 +153,30 @@ public IEnumerable<FeedItem> RetrieveFeed(XmlReader xmlReader)
157153
public IEnumerable<FeedItem> RetrieveFeed(XmlReader xmlReader, IFeedItemNormalizer normalizer)
158154
{
159155
if (xmlReader == null)
156+
{
160157
throw new ArgumentNullException("xmlReader");
158+
}
159+
161160
if (normalizer == null)
161+
{
162162
throw new ArgumentNullException("normalizer");
163+
}
163164

164165
var items = new List<FeedItem>();
165166
try
166167
{
167168
var feed = SyndicationFeed.Load(xmlReader);
168169
foreach (var item in feed.Items)
170+
{
169171
items.Add(normalizer.Normalize(feed, item));
172+
}
170173
}
171174
catch
172175
{
173176
if (ThrowOnError)
177+
{
174178
throw;
179+
}
175180
}
176181
return items;
177182
}

0 commit comments

Comments
 (0)