[dotnet] Add dotnet projects and examples

+ Sitemap generator I created while learning the dispose pattern
+ Testing project for learning general C#
This commit is contained in:
Shaun Reed 2022-05-04 12:55:23 -04:00
parent 6dbac7559a
commit d1fb33c58e
26 changed files with 2927 additions and 0 deletions

View File

@ -7,6 +7,7 @@ github.com/shaunrd0/klips/
├── ansible # Ansible roles, playbooks, and examples
├── blockchain # Blockchain related project templates and examples
├── cpp # C++ programs, datastructures, and other examples
├── dotnet # .NET projects and examples
├── figlet # Figlet fonts I like :)
├── javascript # Javascript projects and examples
├── python # Python scripts or tools I've made

11
dotnet/README.md Normal file
View File

@ -0,0 +1,11 @@
# Dotnet
```bash
shaunrd0/klips/dotnet/
├── sitemap # Custom library to generate sitemaps
├── testing # General .NET practice
└── README.md
```
All of these projects were created with the `dotnet` CLI on Linux (Kubuntu 20.04).
They have not been tested on any other platform.

454
dotnet/sitemap/.gitignore vendored Normal file
View File

@ -0,0 +1,454 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# JetBrains Rider
.idea/
*.sln.iml
##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\SiteMapLibrary\SiteMapLibrary.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,12 @@
using SiteMapLibrary;
// Create an XmlManager to use for generating our sitemap; Provide a file path (and optional Xml settings; See ctor)
var mgr = new XmlManager("/home/kapper/Code/klips/dotnet/sitemap/ConsoleApp/TestFiles/sitemap.xml");
// If we want to output the sitemap to the console, instead of saving to a file
// var mgr = new XmlManager("Console.Out");
// Provide a base URL to start crawling, an XmlManager, and a Regex pattern to use for matching URLs while crawling
using SiteMap siteMap = new SiteMap("https://knoats.com", mgr,
new("(http?s://knoats.com(?!.*/dist/|.*/settings/|.*/register/|.*/login/|.*/uploads/|.*/export/|.*/search?).*?(?=\"))"));
// Start crawling; When this returns, we have visited all found URLs and wrote them to our sitemap
await siteMap.Crawl();

View File

@ -0,0 +1,9 @@
User-agent: *
Disallow:
Disallow: /dist/
Disallow: /settings/
Disallow: /register/
Disallow: /login/
Disallow: /uploads/
Disallow: /export/
Disallow: /search?

View File

@ -0,0 +1,975 @@
<?xml version="1.0" encoding="utf-8"?>
<urlset>
<url>
<loc>https://knoats.com</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/tags</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/login</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/shelves</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/register</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/ansible</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/password/email</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/user/shaun-reed</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c?shelf=2</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/javascript</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/blockchain</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim?shelf=2</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git?shelf=2</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/shelves/containers</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c/page/basics</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/shelves/programming</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker?shelf=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c/page/classes</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim/page/notes</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/ansible?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/page/basics</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack?shelf=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/chapter/usage</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking?shelf=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker/page/gitlab</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker/page/shlink</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin?shelf=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin?shelf=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/page/submodules</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/i3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/dns</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker/page/heimdall</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi/page/installation</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c-s68/page/dotnet-cli</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c/page/multithreading</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/grub</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/javascript/page/webgl</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/arch</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/tcpip</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/nginx</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/link/30#bkmrk-configure-ssl</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/fail2ban</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/apache</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker/page/dockerfile</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/page/authentication</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/debian</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/tcp-udp</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated?page=2</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated?page=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated?page=4</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated?page=5</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi/chapter/magic-mirror</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/pages/recently-updated?page=1</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/blockchain/page/solidity</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/c/page/building-projects</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim/page/configuring-vim</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/bash</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/crontab</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/yakuake</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/chapter/knoats</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/examples</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/xps-9310</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/wireless</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/ossec-rules</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/osi-model</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi/chapter/backup-scripts</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/tunneling</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/subnetting</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/bluetooth</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/ansible/page/creating-roles</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/virtualbox</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/chapter/monitoring</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/chapter/protocols</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi/page/magic-mirror-modules</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/page/software-development</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/boot-process</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/shelves/linux-server-administration</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/prefabs</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/proxy-servers</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/chapter/development</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/chapter/unity</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/bash-profiles</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/configure-ftp</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/interfaces</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/audio-devices</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/server-checklist</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/devsec-baselines</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/chapter/web-servers</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/chapter/installation</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/scripting</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/shortcuts</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/ansible/page/creating-playbooks</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/system-sensors</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications?shelf=3</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/swap-allocation</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/getting-started</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/system-admin</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/server-hostname</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/disk-management</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/pi/page/staging-configs-to-a-usb</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/linux-setup</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/git/page/pushing-merging-branches</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/systemd-services</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/distributions</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/customization</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/installing-fonts</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/virtualbox-networks</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/page/ossec-ubuntu-server</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/security/chapter/server-hardening</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/kernel-management</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/ansible/page/managing-remote-hosts</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/configure-postfix</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/page/hexo</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/mount-google-drive</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/page/gitea</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/enabling-google-2fa</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/user-administration</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/unattended-upgrades</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/page/jekyll</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/welcome-to-knoats-432</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/linux-on-chromebooks</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/post-processing</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/chapter/ssh-configuration</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/exploring-the-database</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/project-settings</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/new-input-system</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/bookstack-configuration</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/docker/chapter/docker-compose-services</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/chapter/unreal-engine-4</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/networking/page/certbot-ssl-certificates</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/yubikey-ssh-authentication</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/page/read-the-docs</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/backup-bookstack-using-docker</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/gameplay-ability-system</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/synchronizing-time-using-ntp</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/bookstack-using-docker-compose</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/chapter/url-shortners</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/bookstack/page/updating-bookstack-using-docker</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/configuring-sshd-authentication</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/chapter/site-generators</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/vim/page/configuring-vim#bkmrk-unicode.vim-plugin</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/game-development/page/retarget-skeleton-animations</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/page/mame-web-application</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/linux-admin/page/configuring-multi-boot-filesystems</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://knoats.com/books/self-hosted-applications/chapter/documentation-generators</loc>
<lastmod>2022-5-4</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
</urlset>

45
dotnet/sitemap/README.md Normal file
View File

@ -0,0 +1,45 @@
Sitemap generator I created while learning some C#.
Example of using the library is in `ConsoleApp/Program.cs`, files used for testing are in `ConsoleApp/TestFiles/`
`ConsoleApp/TestFiles/sitemap.xml` currently contains the sitemap for my website.
If we run the console application with a different URL that targets this same file, the file will be overwritten with the new sitemap.
There is no need to delete or recreate files manually.
I plan to check for a `robots.txt` while generating sitemaps to prevent crawling pages that aren't useful.
For now there is no use for a `robots.txt`, the `SiteMap.Crawl()` function visits the URL provided to the `SiteMap` constructor.
Regex is used to check the visited page and match URLs with the same base domain, the URLS found are logged for the crawler to visit.
Each time we finish collecting URLS on a page, we move to the next URL in the queue and repeat this process.
Once we finish crawling all URLs, an XML sitemap is generated where the URLs are sorted by their length.
I used [sitemaps.org - XML Format](https://www.sitemaps.org/protocol.html) to determine the proper formatting for the sitemap.
For now, since the web application I used for testing does not respond with [Last-Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) in the HTTP header, the last modified time is set to the date the sitemap was generated.
The `priority` fields are all set to the default value indicated on sitemaps.org, which is `0.5`.
This is to avoid confusing crawlers with a huge list of 'top-priority' pages to crawl.
All `changefreq` fields of the sitemap are marked as `daily`.
The primary motivation for this project was learning about unmanaged resources in C#, and trying out the [Dispose Pattern](https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose?redirectedfrom=MSDN#implement-the-dispose-pattern) for myself.
If someone reading this were to find a problem with the way I handled disposing of the `HttpClient` in the `SiteMap` class, feel free to let me know :) Creating an issue, PR, or sending an email is all acceptable.
### Future plans
* Parse `robots.txt` to avoid crawling pages that are not desired
* Test the generator with an application that serves `LastModified` date; Use it if available
* Set `priority` in a more useful way, or allow some form of customization of the way this is handled.
* Set `changefreq` in a more useful way, or allow some form of customization of the way this is handled.
* Generate a regex pattern to match, if one is not provided
For now, the general use of this library is seen in the example below.
```C#
using SiteMapLibrary;
// Create an XmlManager to use for generating our sitemap; Provide a file path (and optional Xml settings; See ctor)
var mgr = new XmlManager("/home/kapper/Code/klips/dotnet/sitemap/ConsoleApp/TestFiles/sitemap.xml");
// If we want to output the sitemap to the console, instead of saving to a file
// var mgr = new XmlManager("Console.Out");
// Provide a base URL to start crawling, an XmlManager, and a Regex pattern to use for matching URLs while crawling
using SiteMap siteMap = new SiteMap("https://knoats.com", mgr,
new("(http?s://knoats.com(?!.*/dist/|.*/settings/|.*/register/|.*/login/|.*/uploads/|.*/export/|.*/search?).*?(?=\"))"));
// Start crawling; When this returns, we have visited all found URLs and wrote them to our sitemap
await siteMap.Crawl();
```

View File

@ -0,0 +1,114 @@
using System.Text.RegularExpressions;
namespace SiteMapLibrary;
public class SiteMap : IDisposable
{
private HttpClient _client;
private HashSet<string> _foundUrls;
private HashSet<string> _visitedUrls;
private Queue<string> _visitQueue;
private bool _disposed = false;
private XmlManager XmlManager { get; set; }
public string? Url { get; private set; }
public Regex Regexp { get; set; }
public SiteMap(string url, string savepath, Regex pattern)
{
Url = url;
_client = new HttpClient();
_foundUrls = new HashSet<string>();
_visitedUrls = new HashSet<string>();
_visitQueue = new Queue<string>();
Regexp = pattern;
XmlManager = new XmlManager(savepath);
}
public SiteMap(string url, XmlManager mgr, Regex pattern)
{
_client = new HttpClient();
_foundUrls = new HashSet<string>();
_visitedUrls = new HashSet<string>();
_visitQueue = new Queue<string>();
Regexp = pattern;
Url = url;
XmlManager = mgr;
}
public async Task Crawl()
{
while (Url != null)
{
_visitedUrls.Add(Url);
using var content = await _client.GetAsync(Url);
if (!content.IsSuccessStatusCode)
{
Console.WriteLine($"{content.StatusCode} on url: {Url}");
NextUrl();
continue;
}
var m = Regexp.Match(await content.Content.ReadAsStringAsync());
while (m.Success)
{
foreach (Group group in m.Groups)
{
if (_foundUrls.Add(group.Value))
{
Console.WriteLine(group.Value);
// Console.WriteLine(content.Content.Headers.LastModified);
if (!_visitedUrls.Contains(group.Value) && !_visitQueue.Contains(group.Value))
{
_visitQueue.Enqueue(group.Value);
}
}
}
m = m.NextMatch();
}
NextUrl();
content.Dispose();
}
WriteXml();
}
private void WriteXml()
{
List<string> urls = new List<string>(_visitedUrls.OrderBy(k => k.Length).ToArray());
foreach (string url in urls)
{
XmlManager.AddUrl(url);
}
XmlManager.Save();
}
private void NextUrl()
{
if (_visitQueue.Count == 0)
{
Url = null;
return;
}
Url = _visitQueue.Dequeue();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_client.Dispose();
}
_disposed = true;
}
}
}

View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>SiteMap</RootNamespace>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,59 @@
using System.Xml;
namespace SiteMapLibrary;
public class XmlManager
{
private XmlDocument XmlDocument { get; set; }
private XmlDeclaration XmlDeclaration { get; set; }
private XmlElement XmlUrlset { get; set; }
private string Path { get; set; }
public XmlManager(string path,
string version="1.0", string encoding="utf-8", string standalone="")
{
XmlDocument = new XmlDocument();
XmlDeclaration = XmlDocument.CreateXmlDeclaration(version, encoding, standalone);
XmlDocument.AppendChild(XmlDeclaration);
XmlUrlset = XmlDocument.CreateElement("urlset");
XmlDocument.AppendChild(XmlUrlset);
Path = path;
}
~XmlManager()
{
Save();
}
<