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
6 changes: 1 addition & 5 deletions .github/workflows/dotnet-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: .\main
Expand All @@ -39,10 +39,6 @@ jobs:
- name: Test
run: dotnet test -c Release --no-build --verbosity normal .\test\ReCode.Cocoon.Proxy.Tests
working-directory: .\main
- name: BuildNet45
run: |
cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\"
.\MSBuild.exe $Env:GITHUB_WORKSPACE\main\Cocoon.sln -m /p:Configuration=Release
- name: ConsoleRunXUnitLegacyTests
run: |
~/.nuget/packages/xunit.runner.console/2.4.1/tools/net472/xunit.console.exe $Env:GITHUB_WORKSPACE\main\test\ReCode.Cocoon.Legacy.Tests\bin\Release\net45\ReCode.Cocoon.Legacy.Tests.dll
5 changes: 4 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,29 @@ jobs:
--output . src\ReCode.Cocoon.Legacy\ReCode.Cocoon.Legacy.csproj
working-directory: .\main
- name: PackProxy
working-directory: .\main
run: >
dotnet pack --configuration Release --no-build
-p:PackageVersion=${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }}
--output . src\ReCode.Cocoon.Proxy\ReCode.Cocoon.Proxy.csproj
- name: PackProxyBlazorServer
working-directory: .\main
run: >
dotnet pack --configuration Release --no-build
-p:PackageVersion=${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }}
--output . src\ReCode.Cocoon.Proxy.BlazorServer\ReCode.Cocoon.Proxy.BlazorServer.csproj
- name: PackProxyBlazorWasm
working-directory: .\main
run: >
dotnet pack --configuration Release --no-build
-p:PackageVersion=${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }}
--output . src\ReCode.Cocoon.Proxy.BlazorWasm\ReCode.Cocoon.Proxy.BlazorWasm.csproj
- name: PackProxyBlazorWasmAuth
working-directory: .\main
run: >
dotnet pack --configuration Release --no-build
-p:PackageVersion=${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }}
--output . src\ReCode.Cocoon.Proxy.BlazorWasmAuth\ReCode.Cocoon.Proxy.BlazorWasmAuth.csproj
working-directory: .\main
- name: Push
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
working-directory: .\main
1 change: 1 addition & 0 deletions main/Cocoon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{19C51172-6F93-479C-BF81-EDA51D6597AE}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{6AD14C47-2BE5-4428-AB83-641684162C8A}"
Expand Down
1 change: 1 addition & 0 deletions main/src/ReCode.Cocoon.Legacy/ReCode.Cocoon.Legacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal static class SessionValueDeserializer

public static object Deserialize(Type type, byte[] bytes)
{
if (bytes is not { Length: > 0 }) return null;

if (Deserializers.TryGetValue(type, out var deserializer))
{
return deserializer(bytes);
Expand Down
4 changes: 4 additions & 0 deletions main/src/ReCode.Cocoon.Legacy/Session/ValueSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace ReCode.Cocoon.Legacy.Session
{
public static class ValueSerializer
{
private static readonly byte[] Empty = new byte[0];

public static byte[] Serialize(object value)
{
switch (value)
{
case null:
return Empty;
case string str:
return Encoding.UTF8.GetBytes(str);
case short i16:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Text;

namespace ReCode.Cocoon.Proxy.BlazorCodeGen
{
public class IndentedStringBuilder
{
private readonly int _indentSpaces;
private readonly StringBuilder _builder = new();
private bool _newLine = true;

public IndentedStringBuilder(int indentSpaces = 4)
{
_indentSpaces = indentSpaces;
}

public int Indent { get; set; }

public IndentedStringBuilder Append(string value)
{
if (_newLine)
{
if (Indent > 0)
{
_builder.Append(new string(' ', _indentSpaces * Indent));
_newLine = false;
}
}

_builder.Append(value);

return this;
}

public IndentedStringBuilder AppendLine(string value)
{
Append(value);
_builder.AppendLine();
_newLine = true;
return this;
}

public IndentedStringBuilder AppendLine()
{
_builder.AppendLine();
_newLine = true;
return this;
}

public IDisposable OpenBrace() => new Block(this);

private class Block : IDisposable
{
private readonly IndentedStringBuilder _builder;

public Block(IndentedStringBuilder builder)
{
_builder = builder;
_builder.AppendLine("{");
_builder.Indent++;
}

public void Dispose()
{
_builder.Indent--;
_builder.AppendLine("}");
}
}

public override string ToString() => _builder.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
</ItemGroup>

</Project>
79 changes: 79 additions & 0 deletions main/src/ReCode.Cocoon.Proxy.BlazorCodeGen/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;

namespace ReCode.Cocoon.Proxy.BlazorCodeGen
{
internal class Route
{
private readonly Dictionary<char, Route> _routes = new();

public Route(bool isStart)
{
IsStart = isStart;
}

public bool IsStart { get; }

public bool IsEnd { get; private set; }
public bool IsWildcard { get; private set; }

public IEnumerable<char> GetValues() => _routes.Keys;
public Route GetRoute(char key) => _routes[key];

public void Add(Span<string> parts)
{
if (parts.Length == 0)
{
IsEnd = true;
return;
}
var part = parts[0];

if (parts[0].Length == 0)
{
if (parts.Length == 0)
{
IsEnd = true;
}
return;
}

if (part[0] == '{')
{
if (part.Length > 1 && part[1] == '*')
{
IsWildcard = true;
return;
}

char ch = '*';
if (!_routes.TryGetValue(ch, out var route))
{
route = new Route(part.Length == 1);
_routes.Add(ch, route);
}
route.Add(parts.Slice(1));
}
else
{
char ch = part[0];
if (!_routes.TryGetValue(ch, out var route))
{
route = new Route(part.Length == 1);
_routes.Add(ch, route);
}

if (part.Length == 1)
{
route.Add(parts.Slice(1));
}
else
{
parts[0] = part.Substring(1);
route.Add(parts);
}
}

}
}
}
Loading