Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,200 @@ build/
/XmlResolverData/Data
/XmlResolverData/XmlResolverData.csproj
/DataTests/DataTest.cs


# User-specific files
*.suo
*.user
*.userprefs
*.sln.docstates
*.svclog
.vs/
.vscode/settings.json

# Build results
[Aa]rtifacts/
[Dd]ebug/
[Rr]elease/
[Bb]inaries/
[Bb]in/
[Oo]bj/
.dotnet/
.tools/
.packages/
.nuget/
.complog/
/MSBuild_Logs/

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

# Debug artifacts
launchSettings.json

# Prevent accidental re-checkin of NuGet.exe
NuGet.exe

# NuGet restore semaphore
build/ToolsetPackages/toolsetpackages.semaphore

# NuGet package
src/Tools/UploadNugetZip/*.zip

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
UnitTestResults.html

# NuGet V3 artifacts
*-packages.config
*.nuget.props
*.nuget.targets
project.lock.json
*.binlog
*.project.lock.json

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.wrn
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual Studio cache files
*.sln.ide/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
*.VC.opendb
*.VC.db

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# 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
*.Publish.xml

# NuGet Packages Directory
packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# 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

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf


#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# JetBrains Rider
.idea/

# WPF temp projects
*wpftmp.*

17 changes: 13 additions & 4 deletions XmlResolver/ResourceAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri
status = resp.StatusCode;
if (seen.Contains(resolvedUri))
{
throw new HttpRequestException("Redirect loop", null, status);
throw CreateHttpRequestException("Redirect loop", status);
}

seen.Add(resolvedUri);
Expand All @@ -204,7 +204,7 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri
if (resp.StatusCode == HttpStatusCode.Moved || resp.StatusCode == HttpStatusCode.Redirect)
{
resolvedUri = resp.Content.Headers.ContentLocation
?? throw new HttpRequestException("Redirect without location", null, status);
?? throw CreateHttpRequestException("Redirect without location", status);
}
else
{
Expand All @@ -214,10 +214,19 @@ private static (Uri resolvedUri, HttpResponseMessage resp) _getHttpResponse(Uri

if (count <= 0)
{
throw new HttpRequestException("Too many redirects", null, status);
throw CreateHttpRequestException("Too many redirects", status);
}

throw new HttpRequestException("Failed to read resource", null, status);
throw CreateHttpRequestException("Failed to read resource", status);

HttpRequestException CreateHttpRequestException(string text, HttpStatusCode statusCode)
{
#if NETSTANDARD2_0
return new HttpRequestException($"{text} ({statusCode})");
#else
return new HttpRequestException(text, null, statusCode);
#endif
}
}

private static IResourceResponse _getFileResource(IResourceRequest request, Uri uri)
Expand Down
48 changes: 48 additions & 0 deletions XmlResolver/Utils/NetStandardExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

#if NETSTANDARD2_0
namespace XmlResolver.Utils
{
internal static class NetStandardExtensions
{
public static int IndexOf(this string s, char value, StringComparison comparisonType)
{
return s.IndexOf($"{value}", comparisonType);
}

public static Span<string> Split(this string s, string sep, StringSplitOptions stringSplitOptions = StringSplitOptions.None)
{
char[] sepChars = [.. s];
return s.Split(sepChars, stringSplitOptions);
}

public static bool StartsWith(this string s, char c)
{
if (s.Length > 0)
{
if (s[0] == c)
{
return true;
}
}
return false;
}

public static HttpResponseMessage Send(this HttpClient client, HttpRequestMessage message)
{
return client.SendAsync(message).Result;
}

public static Stream ReadAsStream(this HttpContent content)
{
return content.ReadAsStreamAsync().Result;
}
}
}
#endif
1 change: 0 additions & 1 deletion XmlResolver/Utils/UriUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.IO;
using System.IO.Compression;
Expand Down
20 changes: 17 additions & 3 deletions XmlResolver/XmlResolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
<LangVersion>14</LangVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Norman Walsh</Authors>
<Description>The xmlresolver project provides an implementation of the System.Xml.XmlResolver. It uses the OASIS XML Catalogs V1.1 Standard to provide a mapping from external identifiers and URIs to local resources.</Description>
Expand All @@ -22,11 +23,24 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="10.0.1" />
<PackageReference Include="NLog" Version="6.0.7" />
<PackageReference Include="NuGet.Frameworks" Version="7.0.1" />
<PackageReference Include="System.IO.Packaging" Version="10.0.1" />
</ItemGroup>

<Choose>
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="10.0.1" />
<PackageReference Include="IndexRange" Version="1.1.0" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="NuGet.Frameworks" Version="7.0.1" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath=""/>
<None Include="readme.md" Pack="true" PackagePath="" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions XmlResolver/XmlResolverConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void LoadPropertiesConfiguration(Uri propertyFile, IConfigurationSection

property = section.GetSection("catalogs");
if (property.Value != null) {
String[] tokens = property.Value.Split(";");
var tokens = property.Value.Split(";");
catalogs.Clear();
if (showConfigChanges) {
logger.Debug("Catalog list cleared");
Expand All @@ -429,7 +429,7 @@ private void LoadPropertiesConfiguration(Uri propertyFile, IConfigurationSection

property = section.GetSection("catalogAdditions");
if (property.Value != null) {
String[] tokens = property.Value.Split(";");
var tokens = property.Value.Split(";");
foreach (var token in tokens) {
if (!"".Equals(token)) {
string caturi = token;
Expand Down
2 changes: 1 addition & 1 deletion tools/make-csproj.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<xsl:template match="/">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Norman Walsh</Authors>
<Description>This package provides a common set of XML resources and an XML Catalog that resolves them. It’s most commonly used with the xmlresolver package.</Description>
Expand Down