Skip to content

Commit fa160fe

Browse files
Merge pull request #10 from KristofferStrube/feature/upgrade-for-newest-webidl-and-file-api
Upgraded project to target the newest Blazor.FileAPI version.
2 parents 718d8d3 + d763cb8 commit fa160fe

35 files changed

Lines changed: 1035 additions & 254 deletions

.EditorConfig

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
[*]
2+
# All files
3+
dotnet_style_qualification_for_field = false
4+
dotnet_style_qualification_for_property = false
5+
dotnet_style_qualification_for_method = false
6+
dotnet_style_qualification_for_event = false
7+
dotnet_diagnostic.IDE0003.severity = warning
8+
dotnet_style_predefined_type_for_locals_parameters_members = true
9+
dotnet_style_predefined_type_for_member_access = true
10+
dotnet_diagnostic.IDE0049.severity = suggestion
11+
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
12+
dotnet_diagnostic.IDE0036.severity = error
13+
dotnet_style_require_accessibility_modifiers = always
14+
dotnet_diagnostic.IDE0040.severity = warning
15+
dotnet_style_readonly_field = true
16+
dotnet_diagnostic.IDE0044.severity = error
17+
csharp_prefer_static_local_function = true
18+
dotnet_diagnostic.IDE0062.severity = warning
19+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
20+
dotnet_diagnostic.IDE0047.severity = warning
21+
dotnet_diagnostic.IDE0048.severity = warning
22+
dotnet_diagnostic.IDE0010.severity = error
23+
dotnet_style_object_initializer = true
24+
dotnet_diagnostic.IDE0017.severity = suggestion
25+
csharp_style_inlined_variable_declaration = true
26+
dotnet_diagnostic.IDE0018.severity = suggestion
27+
dotnet_style_collection_initializer = true
28+
dotnet_diagnostic.IDE0028.severity = warning
29+
dotnet_style_prefer_auto_properties = true
30+
dotnet_diagnostic.IDE0032.severity = suggestion
31+
dotnet_style_explicit_tuple_names = true
32+
dotnet_diagnostic.IDE0033.severity = warning
33+
csharp_prefer_simple_default_expression = false
34+
dotnet_diagnostic.IDE0034.severity = warning
35+
dotnet_style_prefer_inferred_tuple_names = true
36+
dotnet_style_prefer_inferred_anonymous_type_member_names = true
37+
dotnet_diagnostic.IDE0037.severity = suggestion
38+
csharp_style_prefer_local_over_anonymous_function = true
39+
dotnet_diagnostic.IDE0039.severity = warning
40+
csharp_style_deconstructed_variable_declaration = true
41+
dotnet_diagnostic.IDE0042.severity = suggestion
42+
dotnet_style_prefer_conditional_expression_over_assignment = true
43+
dotnet_diagnostic.IDE0045.severity = warning
44+
dotnet_style_prefer_conditional_expression_over_return = true
45+
dotnet_diagnostic.IDE0046.severity = warning
46+
dotnet_style_prefer_compound_assignment = true
47+
dotnet_diagnostic.IDE0054.severity = warning
48+
dotnet_diagnostic.IDE0074.severity = warning
49+
csharp_style_prefer_index_operator = true
50+
dotnet_diagnostic.IDE0056.severity = warning
51+
csharp_style_prefer_range_operator = true
52+
dotnet_diagnostic.IDE0057.severity = warning
53+
dotnet_diagnostic.IDE0070.severity = error
54+
dotnet_style_prefer_simplified_interpolation = true
55+
dotnet_diagnostic.IDE0071.severity = warning
56+
dotnet_diagnostic.IDE0072.severity = error
57+
dotnet_style_prefer_simplified_boolean_expressions = true
58+
dotnet_diagnostic.IDE0075.severity = warning
59+
dotnet_diagnostic.IDE0082.severity = error
60+
csharp_style_implicit_object_creation_when_type_is_apparent = true
61+
dotnet_diagnostic.IDE0090.severity = error
62+
dotnet_diagnostic.IDE0180.severity = warning
63+
csharp_style_namespace_declarations = file_scoped
64+
dotnet_diagnostic.IDE0160.severity = error
65+
dotnet_diagnostic.IDE0161.severity = error
66+
csharp_style_throw_expression = true
67+
dotnet_diagnostic.IDE0016.severity = warning
68+
dotnet_style_coalesce_expression = true
69+
dotnet_diagnostic.IDE0029.severity = warning
70+
dotnet_diagnostic.IDE0030.severity = warning
71+
dotnet_style_null_propagation = true
72+
dotnet_diagnostic.IDE0031.severity = warning
73+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
74+
dotnet_diagnostic.IDE0041.severity = warning
75+
csharp_style_prefer_null_check_over_type_check = true
76+
dotnet_diagnostic.IDE0150.severity = warning
77+
csharp_style_conditional_delegate_call = false
78+
dotnet_diagnostic.IDE1005.severity = warning
79+
csharp_style_var_for_built_in_types = false
80+
csharp_style_var_when_type_is_apparent = true
81+
csharp_style_var_elsewhere = false
82+
dotnet_diagnostic.IDE0007.severity = warning
83+
dotnet_diagnostic.IDE0008.severity = warning
84+
dotnet_diagnostic.IDE0001.severity = error
85+
dotnet_diagnostic.IDE0002.severity = error
86+
dotnet_diagnostic.IDE0004.severity = error
87+
dotnet_diagnostic.IDE0005.severity = error
88+
dotnet_diagnostic.IDE0035.severity = warning
89+
dotnet_diagnostic.IDE0051.severity = warning
90+
dotnet_diagnostic.IDE0052.severity = warning
91+
csharp_style_unused_value_expression_statement_preference = discard_variable
92+
dotnet_diagnostic.IDE0058.severity = warning
93+
csharp_style_unused_value_assignment_preference = discard_variable
94+
dotnet_diagnostic.IDE0059.severity = warning
95+
# Ignore namespace mismatch as this is a library
96+
dotnet_diagnostic.IDE0130.severity = none
97+
# We don't want to adopt primary constructors yet
98+
dotnet_diagnostic.IDE0290.severity = none

samples/KristofferStrube.Blazor.FileSystem.WasmExample.Benchmarks/KristofferStrube.Blazor.FileSystem.WasmExample.Benchmarks.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="BenchmarkDotNet" Version="0.13.4" />
12-
13-
<PackageReference Include="KristofferStrube.ActivityStreams" Version="0.1.0" />
1412
</ItemGroup>
1513

1614
<ItemGroup>
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
11-
<PackageReference Include="KristofferStrube.ActivityStreams" Version="0.1.0" />
12-
<PackageReference Include="MessagePack" Version="2.5.64-alpha" />
13-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.2" />
14-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
10+
<PackageReference Include="HtmlAgilityPack" Version="1.12.2" />
11+
<PackageReference Include="KristofferStrube.ActivityStreams" Version="0.2.4" />
12+
<PackageReference Include="MessagePack" Version="3.1.4" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.20" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.20" PrivateAssets="all" />
1515
<PackageReference Include="TG.Blazor.IndexedDB" Version="1.5.0-preview" />
1616
<PackageReference Include="System.Reactive.Linq" Version="5.0.0" />
1717
</ItemGroup>
@@ -20,15 +20,4 @@
2020
<ProjectReference Include="..\..\src\KristofferStrube.Blazor.FileSystem\KristofferStrube.Blazor.FileSystem.csproj" />
2121
</ItemGroup>
2222

23-
<ItemGroup>
24-
<Content Update="wwwroot\css\app.css">
25-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
26-
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
27-
</Content>
28-
<Content Update="wwwroot\index.html">
29-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
30-
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
31-
</Content>
32-
</ItemGroup>
33-
3423
</Project>

samples/KristofferStrube.Blazor.FileSystem.WasmExample/Pages/Status.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ dictionary FileSystemRemoveOptions {
103103
104104
[Exposed=(Window,Worker), SecureContext, Serializable]
105105
interface FileSystemDirectoryHandle : FileSystemHandle {
106-
async iterable<USVString, FileSystemHandle>;
106+
async_iterable<USVString, FileSystemHandle>;
107107
108108
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {});
109109
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {});
Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,61 @@
11
using KristofferStrube.Blazor.FileSystem.Extensions;
2+
using KristofferStrube.Blazor.WebIDL;
23
using Microsoft.JSInterop;
34

45
namespace KristofferStrube.Blazor.FileSystem;
56

6-
public abstract class BaseJSWrapper : IAsyncDisposable
7+
/// <summary>
8+
/// Base class for wrapping objects in the Blazor.FileSystem library.
9+
/// </summary>
10+
public abstract class BaseJSWrapper : IAsyncDisposable, IJSWrapper
711
{
12+
/// <summary>
13+
/// A lazily evaluated JS module that gives access to helper methods for the File System API.
14+
/// </summary>
815
protected readonly Lazy<Task<IJSObjectReference>> helperTask;
9-
protected readonly IJSRuntime jSRuntime;
10-
protected readonly FileSystemOptions options;
1116

1217
/// <summary>
13-
/// Constructs a wrapper instance for an equivalent JS instance.
18+
/// Options for where the helper JS module is located.
1419
/// </summary>
15-
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
16-
/// <param name="jSReference">A JS reference to an existing JS instance that should be wrapped.</param>
17-
internal BaseJSWrapper(IJSRuntime jSRuntime, IJSObjectReference jSReference, FileSystemOptions options)
20+
protected readonly FileSystemOptions fileSystemOptions;
21+
22+
/// <summary>
23+
/// Options for where the helper JS module is located.
24+
/// </summary>
25+
[Obsolete("This is here for backwards compatibility. It was replaced by 'fileSystemOptions' as 'options' was ambiguous.")]
26+
protected readonly FileSystemOptions options;
27+
28+
/// <inheritdoc/>
29+
public IJSRuntime JSRuntime { get; }
30+
31+
/// <inheritdoc/>
32+
public IJSObjectReference JSReference { get; }
33+
34+
/// <inheritdoc/>
35+
public bool DisposesJSReference { get; }
36+
37+
/// <inheritdoc cref="IJSCreatable{T}.CreateAsync(IJSRuntime, IJSObjectReference, CreationOptions)"/>
38+
internal BaseJSWrapper(IJSRuntime jSRuntime, IJSObjectReference jSReference, FileSystemOptions fileSystemOptions, CreationOptions options)
1839
{
19-
this.options = options;
20-
helperTask = new(async () => await jSRuntime.GetHelperAsync(options));
40+
this.fileSystemOptions = fileSystemOptions;
41+
#pragma warning disable CS0618 // Type or member is obsolete
42+
this.options = fileSystemOptions;
43+
#pragma warning restore CS0618 // Type or member is obsolete
44+
helperTask = new(async () => await jSRuntime.GetHelperAsync(fileSystemOptions));
2145
JSReference = jSReference;
22-
this.jSRuntime = jSRuntime;
46+
JSRuntime = jSRuntime;
47+
DisposesJSReference = options.DisposesJSReference;
2348
}
2449

25-
public IJSObjectReference JSReference { get; }
26-
50+
/// <inheritdoc/>
2751
public async ValueTask DisposeAsync()
2852
{
2953
if (helperTask.IsValueCreated)
3054
{
3155
IJSObjectReference module = await helperTask.Value;
3256
await module.DisposeAsync();
3357
}
58+
await IJSWrapper.DisposeJSReference(this);
3459
GC.SuppressFinalize(this);
3560
}
3661
}

src/KristofferStrube.Blazor.FileSystem/Converters/BlobConverter.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
namespace KristofferStrube.Blazor.FileSystem.Converters;
5+
6+
internal class FileSystemHandleKindConverter : JsonConverter<FileSystemHandleKind>
7+
{
8+
public override FileSystemHandleKind Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
9+
{
10+
return reader.GetString() switch
11+
{
12+
"file" => FileSystemHandleKind.File,
13+
"directory" => FileSystemHandleKind.Directory,
14+
var value => throw new ArgumentException($"Value '{value}' was not a valid {nameof(FileSystemHandleKind)}."),
15+
};
16+
}
17+
18+
public override void Write(Utf8JsonWriter writer, FileSystemHandleKind value, JsonSerializerOptions options)
19+
{
20+
writer.WriteStringValue(value switch
21+
{
22+
FileSystemHandleKind.File => "file",
23+
FileSystemHandleKind.Directory => "directory",
24+
_ => throw new ArgumentException($"Value '{value}' was not a valid {nameof(FileSystemHandleKind)}.")
25+
});
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
namespace KristofferStrube.Blazor.FileSystem.Converters;
5+
6+
internal class WriteCommandTypeConverter : JsonConverter<WriteCommandType>
7+
{
8+
public override WriteCommandType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
9+
{
10+
return reader.GetString() switch
11+
{
12+
"write" => WriteCommandType.Write,
13+
"seek" => WriteCommandType.Seek,
14+
"truncate" => WriteCommandType.Truncate,
15+
var value => throw new ArgumentException($"Value '{value}' was not a valid {nameof(WriteCommandType)}."),
16+
};
17+
}
18+
19+
public override void Write(Utf8JsonWriter writer, WriteCommandType value, JsonSerializerOptions options)
20+
{
21+
writer.WriteStringValue(value switch
22+
{
23+
WriteCommandType.Write => "write",
24+
WriteCommandType.Seek => "seek",
25+
WriteCommandType.Truncate => "truncate",
26+
_ => throw new ArgumentException($"Value '{value}' was not a valid {nameof(WriteCommandType)}.")
27+
});
28+
}
29+
}

src/KristofferStrube.Blazor.FileSystem/EnumDescriptionConverter.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/KristofferStrube.Blazor.FileSystem/Enums/FileSystemCreateWritableOptions.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)