Skip to content

Commit ae56f92

Browse files
committed
Add RSS reader web application example
1 parent 81515c5 commit ae56f92

File tree

73 files changed

+74708
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+74708
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Greetings from Cairo, Egypt. You can [sponsor](https://github.com/sponsors/dodyg
4848
| [Request](/projects/request) | 15 | Form, Cookies, Query String, Headers |
4949
| [Request Timeouts Middleware](/projets/request-timeouts-middleware) | 6 | |
5050
| [Response](/projects/response) | 3 | |
51+
| [RSS](/projects/rss-reader) | 1 | |
5152
| [SignalR](/projects/signalr) | 1 | |
5253
| [Security](/projects/security) | 7 | |
5354
| [Single File Application](/projects/sfa) | 2 | |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RssReaderWebApplication", "RssReaderWebApplication\RssReaderWebApplication.csproj", "{18C926DB-958A-4FDA-962B-23F336D68900}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{18C926DB-958A-4FDA-962B-23F336D68900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{18C926DB-958A-4FDA-962B-23F336D68900}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{18C926DB-958A-4FDA-962B-23F336D68900}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{18C926DB-958A-4FDA-962B-23F336D68900}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace RssReaderWebApplication.Controllers;
4+
5+
public class HomeController : Controller
6+
{
7+
public IActionResult Index()
8+
{
9+
const string rssUrl = "https://www.newyorker.com/feed/everything";
10+
var rssItems = RssFeedService.GetRssFeedItems(rssUrl);
11+
return View(rssItems);
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace RssReaderWebApplication.Models;
2+
3+
public class RssItem
4+
{
5+
public string? Title { get; set; }
6+
public string? Link { get; set; }
7+
public string? Description { get; set; }
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
builder.Services.AddControllersWithViews();
4+
5+
var app = builder.Build();
6+
7+
if (!app.Environment.IsDevelopment())
8+
{
9+
app.UseExceptionHandler("/Home/Error");
10+
app.UseHsts();
11+
}
12+
13+
app.UseHttpsRedirection();
14+
app.UseStaticFiles();
15+
16+
app.UseRouting();
17+
18+
app.UseAuthorization();
19+
20+
app.MapControllerRoute(
21+
name: "default",
22+
pattern: "{controller=Home}/{action=Index}/{id?}");
23+
24+
app.Run();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Xml;
2+
using RssReaderWebApplication.Models;
3+
4+
namespace RssReaderWebApplication;
5+
6+
public class RssFeedService
7+
{
8+
public static List<RssItem> GetRssFeedItems(string rssUrl)
9+
{
10+
var rssItems = new List<RssItem>();
11+
var rssXmlDoc = new XmlDocument();
12+
13+
rssXmlDoc.Load(rssUrl);
14+
var rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");
15+
16+
if (rssNodes == null)
17+
return rssItems;
18+
19+
rssItems.AddRange(
20+
from XmlNode rssNode in rssNodes
21+
select new RssItem
22+
{
23+
Title = rssNode.SelectSingleNode("title").InnerText,
24+
Link = rssNode.SelectSingleNode("link").InnerText,
25+
Description = rssNode.SelectSingleNode("description").InnerText
26+
});
27+
28+
return rssItems;
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<_ContentIncludedByDefault Remove="Views\RssFeed\Index.cshtml" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
@model List<RssReaderWebApplication.Models.RssItem>
6+
7+
<h2>RSS Feed</h2>
8+
<ul>
9+
@foreach (var item in Model)
10+
{
11+
<li>
12+
<a href="@item.Link">@item.Title</a>
13+
<p>@item.Description</p>
14+
</li>
15+
}
16+
</ul>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<title>@ViewData["Title"] - RssReaderWebApplication</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
9+
<link rel="stylesheet" href="~/RssReaderWebApplication.styles.css" asp-append-version="true"/>
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container-fluid">
15+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">RssReaderWebApplication</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
24+
</li>
25+
</ul>
26+
</div>
27+
</div>
28+
</nav>
29+
</header>
30+
<div class="container">
31+
<main role="main" class="pb-3">
32+
@RenderBody()
33+
</main>
34+
</div>
35+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
36+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
37+
<script src="~/js/site.js" asp-append-version="true"></script>
38+
@await RenderSectionAsync("Scripts", required: false)
39+
</body>
40+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}

0 commit comments

Comments
 (0)