Skip to content

Commit

Permalink
Merge pull request #69 from ramondeklein/net7.0
Browse files Browse the repository at this point in the history
Implement proper .NET Core support
  • Loading branch information
ramondeklein authored Jan 20, 2024
2 parents 015fb59 + 8a00601 commit 319c2cb
Show file tree
Hide file tree
Showing 160 changed files with 7,555 additions and 8,127 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches:
- net7.0
pull_request:
branches:
- net7.0

jobs:
build:
env:
BUILD_CONFIG: 'Release'
VERSION: '0.0.0'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Version Variable
if: ${{ github.ref_type == 'tag' }}
env:
TAG: ${{ github.ref_name }}
run: echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration $BUILD_CONFIG --no-restore /p:Version=$VERSION
- name: Create NuGet package
run: dotnet pack --output nupkgs --configuration $BUILD_CONFIG --no-restore --no-build /p:PackageVersion=$VERSION
- name: Publish NuGet package
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
run: nuget push nupkgs\*.nupkg -s 'https://api.nuget.org/v3/index.json' -k ${{secrets.NUGET_API_KEY}}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
.idea
.vs
.vscode
nuget.apikey
packages/
Certificates/
*/obj/
*/bin/
*.suo
*.nupkg
**/*.lock.json
**/*.user
**/*.userprefs
.vscode
Help/
13 changes: 13 additions & 0 deletions .idea/.idea.NWebDav/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Clean.ps1

This file was deleted.

14 changes: 11 additions & 3 deletions Directory.build.props → Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<Project>
<PropertyGroup>
<VersionPrefix>0.1.36</VersionPrefix>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.2.0</VersionPrefix>
<Product>NWebDav</Product>
<Company></Company>
<Authors>Ramon de Klein &lt;mail@ramondeklein.nl&gt;</Authors>
<Copyright>Copyright (C) 2016-2021 Ramon de Klein</Copyright>
<Copyright>Copyright (C) 2016-2024 Ramon de Klein</Copyright>
<PackageProjectUrl>https://github.com/ramondeklein/nwebdav</PackageProjectUrl>
<RepositoryUrl>https://github.com/ramondeklein/nwebdav.git</RepositoryUrl>
<PackageLicenseUrl>https://github.com/ramondeklein/nwebdav/blob/master/LICENSE</PackageLicenseUrl>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
<PublishSingleFile>true</PublishSingleFile>

<DebugType>portable</DebugType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
19 changes: 19 additions & 0 deletions GenerateCert.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$DAYS=3650
$PASSWORD='nwebdav'
$OPENSSL_CMD="docker"
$OPENSSL_ARG=@("run","--rm","-v","$(Get-Location)/Certificates:/data","alpine/openssl")

New-Item -ItemType Directory -Force certificates

Write-Host "Generate CA"
& $OPENSSL_CMD ($OPENSSL_ARG+@("req","-x509","-nodes","-new","-sha256","-days","$DAYS","-newkey","rsa:2048","-keyout","data/RootCA.key","-out","data/RootCA.pem","-subj","/C=NL/CN=NWebDAV-Development-CA"))
& $OPENSSL_CMD ($OPENSSL_ARG+@("x509","-outform","pem","-in","data/RootCA.pem","-out","data/RootCA.crt"))

Write-Host "Generate localhost certificate"
Copy-Item domains.ext certificates
& $OPENSSL_CMD ($OPENSSL_ARG+@("req","-new","-nodes","-newkey","rsa:2048","-keyout","data/localhost.key","-out","data/localhost.csr","-subj","/C=NL/ST=Overijssel/L=Enschede/O=Localhost/CN=localhost"))
& $OPENSSL_CMD ($OPENSSL_ARG+@("x509","-req","-sha256","-days","$DAYS","-in","data/localhost.csr","-CA","data/RootCA.pem","-CAkey","data/RootCA.key","-CAcreateserial","-extfile","/data/domains.ext","-out","data/localhost.crt"))
& $OPENSSL_CMD ($OPENSSL_ARG+@("pkcs12","-export","-out","data/localhost.pfx","-inkey","data/localhost.key","-in","data/localhost.crt","-certfile","data/RootCA.crt","-passout","pass:$PASSWORD"))

Write-Host "Import certificate (run as administrator if this fails)"
Import-Certificate -FilePath certificates/RootCA.pem -CertStoreLocation Cert:\LocalMachine\Root
48 changes: 0 additions & 48 deletions NWebDav.Sample.AspNet/DebugOutputAdapter.cs

This file was deleted.

30 changes: 0 additions & 30 deletions NWebDav.Sample.AspNet/DiskWebDavHandlerFactory.cs

This file was deleted.

44 changes: 0 additions & 44 deletions NWebDav.Sample.AspNet/NWebDav.Sample.AspNet.csproj

This file was deleted.

3 changes: 0 additions & 3 deletions NWebDav.Sample.AspNet/Web.Debug.config

This file was deleted.

6 changes: 0 additions & 6 deletions NWebDav.Sample.AspNet/Web.Release.config

This file was deleted.

15 changes: 0 additions & 15 deletions NWebDav.Sample.AspNet/Web.config

This file was deleted.

86 changes: 86 additions & 0 deletions NWebDav.Sample.AzureBlob/AzureBlob/AzureBlobBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using NWebDav.Server.Props;

namespace NWebDav.Sample.AzureBlob.AzureBlob;

internal abstract class AzureBlobBase
{
protected AzureBlobBase(AzureBlobStore store, BlobContainerClient blobContainerClient, IPropertyManager propertyManager, IStoreItemMetadata storeItemMetadata)
{
StoreItemMetadata = storeItemMetadata;
Store = store;
BlobContainerClient = blobContainerClient;
PropertyManager = propertyManager;
}

internal IStoreItemMetadata StoreItemMetadata { get; }

protected AzureBlobStore Store { get; }
protected BlobContainerClient BlobContainerClient { get; }
protected string Path => StoreItemMetadata.Path;
protected BlobClient BlobClient => BlobContainerClient.GetBlobClient(Path);

public string Name => !string.IsNullOrEmpty(Path) ? System.IO.Path.GetFileName(Path) : BlobContainerClient.Name;
public string UniqueKey => BlobContainerClient.Name + '/' + Path;

public IPropertyManager? PropertyManager { get; }
}

internal interface IStoreItemMetadata
{
string Path { get; }
bool IsFolder { get; }
DateTime CreatedOn { get; }
long ContentLength { get; }
string ContentType { get; }
string ETag { get; }

}

// We need this to bridge the difference between BlobProperties and BlobItemProperties
internal sealed class StoreItemMetadata : IStoreItemMetadata
{
public static StoreItemMetadata Root { get; } = new();

private StoreItemMetadata()
{
Path = string.Empty;
IsFolder = true;
CreatedOn = DateTime.UnixEpoch;
ContentLength = 0;
ContentType = string.Empty;
ETag = string.Empty;
}

private static bool DetermineIsFolder(IDictionary<string, string> metadata) => metadata.TryGetValue("Folder", out _);

public StoreItemMetadata(string path, BlobProperties blobProperties)
{
Path = path;
IsFolder = DetermineIsFolder(blobProperties.Metadata);
CreatedOn = blobProperties.CreatedOn.DateTime;
ContentLength = blobProperties.ContentLength;
ContentType = blobProperties.ContentType ?? string.Empty;
ETag = blobProperties.ETag.ToString();
}

public StoreItemMetadata(string path, BlobItemProperties blobItemProperties, IDictionary<string, string> metadata)
{
Path = path;
IsFolder = DetermineIsFolder(metadata);
CreatedOn = blobItemProperties.CreatedOn?.DateTime ?? DateTime.UnixEpoch;
ContentLength = blobItemProperties.ContentLength ?? 0L;
ContentType = blobItemProperties.ContentType ?? string.Empty;
ETag = blobItemProperties.ETag?.ToString() ?? string.Empty;
}

public string Path { get; }
public bool IsFolder { get; }
public DateTime CreatedOn { get; }
public long ContentLength { get; }
public string ContentType { get; }
public string ETag { get; }
}
Loading

0 comments on commit 319c2cb

Please sign in to comment.