Skip to content

Commit

Permalink
Upgrade to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Nov 26, 2023
1 parent 357be35 commit 12d1b59
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test and Deploy
env:
PUBLISH_DIR: Nodexr/bin/Release/net7.0/publish/wwwroot
PUBLISH_DIR: Nodexr/bin/Release/net8.0/publish/wwwroot

# Controls when the action will run
on:
Expand Down Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: Install dependencies
run: dotnet restore
Expand Down
4 changes: 2 additions & 2 deletions BlazorNodes/BlazorNodes.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BlazorNodes/Core/NodeTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class NodeTree
{
private readonly List<INodeViewModel> nodes = new();
private readonly List<INodeViewModel> nodes = [];

public IEnumerable<INodeViewModel> Nodes => nodes.AsReadOnly();

Expand Down
8 changes: 4 additions & 4 deletions Nodexr.Tests/Nodexr.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand All @@ -11,12 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0">
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 7 additions & 5 deletions Nodexr/Components/NodeGraph/NodeGraph.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public partial class NodeGraph

private bool isLoadingNodeTree;

private static readonly JsonSerializerOptions jsonSerializerOptions = new()
{
ReferenceHandler = new CachePreservingReferenceHandler(),
Converters = { new RegexNodeJsonConverter() },
};

private static Type InputViewModelProvider(INodeInput input)
{
return input switch
Expand Down Expand Up @@ -78,11 +84,7 @@ private async Task LoadNodeTreeFromServer()
{
var nodeTree = await Http.GetFromJsonAsync<NodeTreePreviewDto>($"{Config["apiAddress"]}/nodetree/{NodeTreeId}");

var jsonOptions = new JsonSerializerOptions()
{
ReferenceHandler = new CachePreservingReferenceHandler(),
Converters = { new RegexNodeJsonConverter() },
};
var jsonOptions = jsonSerializerOptions;

var nodes = nodeTree?.Nodes.Deserialize<List<INodeViewModel>>(jsonOptions)
?? throw new JsonException();
Expand Down
2 changes: 1 addition & 1 deletion Nodexr/Components/OutputDisplay.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private async Task OnCreateLinkButtonClick(MouseEventArgs eventArgs)

private string GetBasicLink()
{
var urlParams = new Dictionary<string, string>
var urlParams = new Dictionary<string, string?>
{
{ "parse", NodeHandler.CachedOutput.Expression }
};
Expand Down
5 changes: 1 addition & 4 deletions Nodexr/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@

#pragma warning disable IDE0065 // Misplaced using directive
global using Nodexr.Nodes;
#pragma warning restore IDE0065 // Misplaced using directive
global using Nodexr.Nodes;
1 change: 1 addition & 0 deletions Nodexr/NodeInputs/InputCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BlazorNodes.Core;
using Nodexr.Nodes;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "<Pending>")]
public class InputCollection : NodeInputBase<IReadOnlyCollection<INodeViewModel>>
{
// TODO replace Inputs and refactor
Expand Down
4 changes: 1 addition & 3 deletions Nodexr/NodeTypes/IntegerNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class IntegerNode : RegexNodeViewModelBase
"\n\nWarning: this node is marked as 'Experimental' because it will not be preserved " +
"after using the 'Create Link' or 'Edit' buttons.";

private readonly IntegerRangeGenerator rangeGenerator = new();

[NodeInput]
public InputDropdown<LimitType> InputLimitBy { get; } = new InputDropdown<LimitType>()
{
Expand Down Expand Up @@ -133,7 +131,7 @@ private void AddSign(NodeResultBuilder builder)

private string GetIntegerRangeRegex(int min, int max)
{
var ranges = rangeGenerator.GenerateRegexRange(min, max);
var ranges = IntegerRangeGenerator.GenerateRegexRange(min, max);
if (InputPreferLongest.Checked)
{
ranges.Reverse();
Expand Down
2 changes: 1 addition & 1 deletion Nodexr/NodeTypes/QuantifierNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected override NodeResultBuilder GetValue()
/// </summary>
internal static bool RequiresGroupToQuantify(RegexNodeViewModelBase val)
{
if (val is null) throw new ArgumentNullException(nameof(val));
ArgumentNullException.ThrowIfNull(val);

//Any chain of 2 or more nodes will always need to be wrapped in a group to quantify properly.
if (val.PreviousNode is not null)
Expand Down
2 changes: 1 addition & 1 deletion Nodexr/NodeTypes/WhitespaceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private string ValueString()
return invert ? "\\S" : "\\s";
}

List<string> charsToAllow = new List<string>();
List<string> charsToAllow = [];

if (InputSpace.Checked) charsToAllow.Add(" ");
if (InputTab.Checked) charsToAllow.Add("\\t");
Expand Down
21 changes: 4 additions & 17 deletions Nodexr/Nodes/NodeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,19 @@ public class NodeResultBuilder

public NodeResultBuilder()
{
contents = new List<RegexSegment>();
contents = [];
}

public NodeResultBuilder(string expression, RegexNodeViewModelBase node)
{
contents = new List<RegexSegment>
{
new RegexSegment(expression, node)
};
contents = [new(expression, node)];
}

public NodeResultBuilder(NodeResult? contents)
{
if (contents is null)
{
this.contents = new List<RegexSegment>();
this.contents = [];
}
else
{
Expand Down Expand Up @@ -108,14 +105,4 @@ public NodeResult Build()
}
}

public class RegexSegment
{
public string Expression { get; }
public RegexNodeViewModelBase Node { get; }

public RegexSegment(string expression, RegexNodeViewModelBase node)
{
Expression = expression;
Node = node;
}
}
public record RegexSegment(string Expression, RegexNodeViewModelBase Node);
13 changes: 7 additions & 6 deletions Nodexr/Nodes/RegexNodeJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class RegexNodeJsonConverter : JsonConverter<INodeViewModel>
{
private class SerializedNode
private sealed class SerializedNode
{
[JsonPropertyName("$ref")]
public string? Ref { get; set; }
Expand All @@ -21,17 +21,18 @@ private class SerializedNode
public JsonObject? Inputs { get; set; }
}

//private static readonly Dictionary<string, Type> allowedNodeTypes = typeof(INodeViewModel).Assembly.;
private static readonly JsonSerializerOptions jsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true,
};

public override INodeViewModel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var referenceResolver = options.ReferenceHandler?.CreateResolver()
?? throw new InvalidOperationException("A ReferenceHandler must be provided to deserialize this object");

var props = JsonSerializer.Deserialize<SerializedNode>(ref reader, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
}) ?? throw new JsonException("Node should not be null");
var props = JsonSerializer.Deserialize<SerializedNode>(ref reader, jsonSerializerOptions)
?? throw new JsonException("Node should not be null");

if (!string.IsNullOrEmpty(props.Ref))
{
Expand Down
22 changes: 11 additions & 11 deletions Nodexr/Nodexr.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<DocumentationFile>Nodexr.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
Expand All @@ -21,28 +21,28 @@
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Blazored.Toast" Version="3.2.2" />

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.FeatureManagement" Version="2.5.1" />
<PackageReference Include="Pidgin" Version="3.2.0" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.8.4">
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.0" />
<PackageReference Include="Microsoft.FeatureManagement" Version="3.1.0" />
<PackageReference Include="Pidgin" Version="3.2.2" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.1.2">
<PackageReference Include="Roslynator.Analyzers" Version="4.6.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.1.2">
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.6.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.1.2">
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.6.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Nodexr/RegexParsers/NodeTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class NodeTreeBuilder
{
private readonly NodeTree tree;
private readonly RegexNodeViewModelBase endNode;
private readonly List<int> columnHeights = new();
private readonly List<int> columnHeights = [];
private const int SpacingX = 250;
private const int SpacingY = 20;
private static readonly Vector2 outputPos = new(1000, 300);
Expand Down
9 changes: 2 additions & 7 deletions Nodexr/Services/DragModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
/// <summary>
/// C# wrapper for the DragModule.js module.
/// </summary>
public sealed class DragModule : IAsyncDisposable
public sealed class DragModule(IJSRuntime jsRuntime) : IAsyncDisposable
{
private readonly JSModule module;

public DragModule(IJSRuntime jsRuntime)
{
module = jsRuntime.LoadJSModule("./js/GeneratedJS/DragModule.js");
}
private readonly JSModule module = jsRuntime.LoadJSModule("./js/GeneratedJS/DragModule.js");

public ValueTask StartDrag<T>(DotNetObjectReference<T> callbackObject, string methodName)
where T : class
Expand Down
11 changes: 1 addition & 10 deletions Nodexr/Services/NodeDragService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@ public interface INodeDragService
void CancelDrag();
}

public class NodeDragService : INodeDragService
public class NodeDragService(INodeHandler nodeHandler, IJSRuntime jsRuntime) : INodeDragService
{
private readonly INodeHandler nodeHandler;
private readonly IJSRuntime jsRuntime;

private INodeViewModel? nodeToDrag;
private Vector2 cursorStartPos;

public NodeDragService(INodeHandler nodeHandler, IJSRuntime jsRuntime)
{
this.nodeHandler = nodeHandler;
this.jsRuntime = jsRuntime;
}

public async Task OnStartCreateNodeDrag(INodeViewModel nodeToDrag, DragEventArgs e)
{
this.nodeToDrag = nodeToDrag;
Expand Down
18 changes: 9 additions & 9 deletions Nodexr/Services/NodeTreeBrowserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class NodeTreeBrowserService
private readonly string apiAddress;
private NodeTreePreviewDto? selectedNodeTree;

private static readonly JsonSerializerOptions jsonSerializerOptions = new()
{
ReferenceHandler = new CachePreservingReferenceHandler(),
Converters = { new RegexNodeJsonConverter() },
};

public event Action? SelectedNodeTreeChanged;
public NodeTreePreviewDto? SelectedNodeTree
{
Expand All @@ -43,7 +49,7 @@ public class NodeTreeBrowserService
this.nodeHandler = nodeHandler;
this.navManager = navManager;
this.regexReplaceHandler = regexReplaceHandler;
apiAddress = config["apiAddress"] ?? throw new Exception("apiAddress was not provided in config");
apiAddress = config["apiAddress"] ?? throw new InvalidOperationException("apiAddress was not provided in config");
}

public void LoadSelectedNodeTree()
Expand All @@ -64,14 +70,8 @@ public async Task PublishNodeTree(CreateNodeTreeCommand model)

public async Task<string?> PublishAnonymousNodeTree()
{
var jsonOptions = new JsonSerializerOptions()
{
ReferenceHandler = new CachePreservingReferenceHandler(),
Converters = { new RegexNodeJsonConverter() },
};

var nodes = JsonObject.Create(
JsonSerializer.SerializeToElement(nodeHandler.Tree.Nodes, jsonOptions)
JsonSerializer.SerializeToElement(nodeHandler.Tree.Nodes, jsonSerializerOptions)
)!;
var command = new CreateAnonymousNodeTreeCommand(nodes)
{
Expand All @@ -93,7 +93,7 @@ public async Task PublishNodeTree(CreateNodeTreeCommand model)

public async Task<Paged<NodeTreePreviewDto>> GetAllNodeTrees(CancellationToken cancellationToken, string? search = null, int start = 0, int limit = 50)
{
var queryParams = new Dictionary<string, string>
var queryParams = new Dictionary<string, string?>
{
{ "start", start.ToString(CultureInfo.InvariantCulture) },
{ "limit", limit.ToString(CultureInfo.InvariantCulture) },
Expand Down
11 changes: 1 addition & 10 deletions Nodexr/Services/NoodleDragService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ public interface INoodleDragService
void OnStartNoodleDrag(INodeOutput nodeToDrag, Vector2 noodleEndPos);
}

public class NoodleDragService : INoodleDragService
public class NoodleDragService(IToastService toastService, IJSRuntime jsRuntime) : INoodleDragService
{
private INodeOutput? nodeToDrag;
public NoodleDataCustom TempNoodle { get; } = new NoodleDataCustom() { Connected = false };

private readonly IToastService toastService;
private readonly IJSRuntime jsRuntime;

public NoodleDragService(IToastService toastService, IJSRuntime jsRuntime)
{
this.toastService = toastService;
this.jsRuntime = jsRuntime;
}

public void OnStartNoodleDrag(INodeOutput nodeToDrag)
{
OnStartNoodleDrag(nodeToDrag, nodeToDrag.OutputPos);
Expand Down
Loading

0 comments on commit 12d1b59

Please sign in to comment.