Skip to content

Commit b0e79a7

Browse files
Initial preparation for next major version.
1 parent 9b8793d commit b0e79a7

59 files changed

Lines changed: 997 additions & 981 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.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 = silent
93+
csharp_style_unused_value_assignment_preference = discard_variable
94+
dotnet_diagnostic.IDE0059.severity = silent
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Then you can use `IFileSystemAccessService` to open one of the three dialogs ava
7171
FileSystemFileHandle? fileHandle = null;
7272
try
7373
{
74-
OpenFilePickerOptionsStartInWellKnownDirectory options = new()
74+
OpenFilePickerOptions options = new()
7575
{
7676
Multiple = false,
7777
StartIn = WellKnownDirectory.Downloads
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
@@ -12,13 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<ProjectReference Include="..\..\..\Blazor.Streams\src\KristofferStrube.Blazor.Streams\KristofferStrube.Blazor.Streams.csproj" />
1516
<ProjectReference Include="..\..\src\KristofferStrube.Blazor.FileSystemAccess\KristofferStrube.Blazor.FileSystemAccess.csproj" />
1617
</ItemGroup>
1718

18-
<ItemGroup>
19-
<Content Update="Shared\NavMenu.razor">
20-
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
21-
</Content>
22-
</ItemGroup>
23-
2419
</Project>

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/AppendOnly.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else
3131
{
3232
try
3333
{
34-
var options = new OpenFilePickerOptionsStartInWellKnownDirectory() { Multiple = false, StartIn = WellKnownDirectory.Downloads };
34+
OpenFilePickerOptions options = new() { Multiple = false, StartIn = WellKnownDirectory.Downloads };
3535
var fileHandles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
3636
fileHandle = fileHandles.Single();
3737
}

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/IndexedDB.razor

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ In this sample we store the references to files that we have previously opened i
4242
StoredFileHandles = (await Task.WhenAll(Enumerable
4343
.Range(0, length)
4444
.Select(async i => {
45-
var fileHandle = FileSystemFileHandle.Create(JSRuntime, await entries.InvokeAsync<IJSObjectReference>("at", i));
45+
var fileHandle = await FileSystemFileHandle.CreateAsync(JSRuntime, await entries.InvokeAsync<IJSObjectReference>("at", i));
4646
return (false, fileHandle, await fileHandle.GetNameAsync());
4747
})
4848
)).ToList();
@@ -53,10 +53,7 @@ In this sample we store the references to files that we have previously opened i
5353
{
5454
try
5555
{
56-
var options = new OpenFilePickerOptionsStartInWellKnownDirectory()
57-
{
58-
Multiple = false
59-
};
56+
OpenFilePickerOptions options = new() { Multiple = false };
6057
var handles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
6158
FileHandle = handles.Single();
6259
}

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/InputFileExample.razor

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
11
@page "/InputFileExample"
22
@inject IFileSystemAccessService FileSystemAccessService
3+
@inject IJSRuntime JSRuntime
34

45
<PageTitle>File System Access - InputFile Example</PageTitle>
56

67
We can read the bytes from a <code>IBrowserFile</code> from the native <code>InputFile</code> component and write these to the <code>FileSystemWritableFileStream</code>.
78
<br />
89
<br />
9-
@if (readFile is not null)
10+
11+
@if (done)
1012
{
11-
<h3>Currently streaming...</h3>
13+
<h3>Done streaming file</h3>
14+
return;
1215
}
13-
else if (SaveFileHandle is not null)
16+
17+
@if (SaveFileHandle is null)
1418
{
15-
<text>Choose file to Stream From</text>
16-
<br />
17-
<InputFile OnChange="OnChange" />
19+
<button class="btn btn-primary" @onclick=Save>Choose File to Stream To</button>
20+
return;
1821
}
19-
else
22+
23+
@if (readFile is not null)
2024
{
21-
<button class="btn btn-primary" @onclick=Save>Choose File to Stream To</button>
25+
<h3>Currently streaming...</h3>
26+
return;
2227
}
2328

29+
<text>Choose file to Stream From</text>
30+
<br />
31+
<InputFile OnChange="OnChange" />
32+
2433
@code {
2534
FileSystemFileHandle? SaveFileHandle;
2635
IBrowserFile? readFile;
36+
bool done = false;
2737

2838
public async Task OnChange(InputFileChangeEventArgs args)
2939
{
30-
if (SaveFileHandle is not null)
40+
if (SaveFileHandle is null) return;
41+
42+
readFile = args.File;
43+
44+
using MemoryStream tempBuffer = new();
45+
46+
using (var stream = readFile.OpenReadStream(maxAllowedSize: 10000000000))
3147
{
32-
readFile = args.File;
33-
34-
using var stream = readFile.OpenReadStream(maxAllowedSize: 10000000000);
35-
await using var writable = await SaveFileHandle.CreateWritableAsync(new() { KeepExistingData = false });
36-
await stream.CopyToAsync(writable);
37-
SaveFileHandle = null;
38-
readFile = null;
39-
Console.WriteLine("Done streaming!");
48+
await stream.CopyToAsync(tempBuffer);
4049
}
50+
51+
await using var writable = await SaveFileHandle.CreateWritableAsync(new() { KeepExistingData = false });
52+
53+
tempBuffer.Position = 0;
54+
await tempBuffer.CopyToAsync(writable);
55+
56+
SaveFileHandle = null;
57+
readFile = null;
58+
Console.WriteLine("Done streaming!");
59+
done = true;
4160
}
4261

4362
public async Task Save()

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/MemeGenerator.razor

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@
5757
{
5858
try
5959
{
60-
var options = new OpenFilePickerOptionsStartInWellKnownDirectory()
61-
{
62-
Types = new FilePickerAcceptType[] {
60+
OpenFilePickerOptions options = new()
61+
{
62+
Types = new FilePickerAcceptType[] {
6363
new FilePickerAcceptType() {
6464
Description = "Images",
6565
Accept = new() { { "image/*", new string[] { ".png", ".gif", ".jpeg", ".jpg" } } }
6666
}
6767
},
68-
Multiple = false,
69-
StartIn = WellKnownDirectory.Pictures
70-
};
68+
Multiple = false,
69+
StartIn = WellKnownDirectory.Pictures
70+
};
7171
var fileHandles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
7272
fileHandle = fileHandles.Single();
7373
}
@@ -151,11 +151,11 @@
151151
try
152152
{
153153
var suggestedName = fileHandle is null ? "meme" : "meme_" + await fileHandle.GetNameAsync();
154-
var options = new SaveFilePickerOptionsStartInWellKnownDirectory()
155-
{
156-
StartIn = WellKnownDirectory.Pictures,
157-
SuggestedName = suggestedName
158-
};
154+
SaveFilePickerOptions options = new()
155+
{
156+
StartIn = WellKnownDirectory.Pictures,
157+
SuggestedName = suggestedName
158+
};
159159
saveFileHandle = await FileSystemAccessService.ShowSaveFilePickerAsync(options);
160160
}
161161
catch (JSException ex)
@@ -166,45 +166,36 @@
166166
{
167167
if (saveFileHandle != null && jSCanvas != null)
168168
{
169-
var blobCallback = new BlobCallback(jSRuntime);
170-
blobCallback.Callback = async (Blob blob) =>
169+
var blobCallback = new BlobCallback(jSRuntime, async (Blob blob) =>
171170
{
172171
var writable = await saveFileHandle.CreateWritableAsync();
173172
await writable.WriteAsync(blob);
174173
await writable.CloseAsync();
175-
};
176-
await blobCallback.ToBlobAsync(jSCanvas);
174+
});
175+
await jSRuntime.InvokeVoidAsync("toBlob", jSCanvas, blobCallback.ObjRef);
177176
}
178177
}
179178
}
180179

181180
public class BlobCallback
182181
{
183-
private IJSObjectReference? blobWrapper;
184182
private IJSRuntime jSRuntime;
183+
private readonly Func<Blob, Task> callback;
185184

186-
public BlobCallback(IJSRuntime jSRuntime)
185+
public BlobCallback(IJSRuntime jSRuntime, Func<Blob, Task> callback)
187186
{
188187
this.jSRuntime = jSRuntime;
189-
objRef = DotNetObjectReference.Create(this);
188+
this.callback = callback;
189+
ObjRef = DotNetObjectReference.Create(this);
190190
}
191191

192-
public DotNetObjectReference<BlobCallback> objRef { get; init; }
193-
194-
[JsonIgnore]
195-
public Action<Blob>? Callback { get; set; }
192+
public DotNetObjectReference<BlobCallback> ObjRef { get; init; }
196193

197194
[JSInvokable("Callback")]
198-
public async Task InvokeCallback()
199-
{
200-
var jSBlob = await jSRuntime.InvokeAsync<IJSObjectReference>("getAttribute", blobWrapper, "blob");
201-
var blob = Blob.Create(jSRuntime, jSBlob);
202-
Callback?.Invoke(blob);
203-
}
204-
205-
public async Task ToBlobAsync(IJSObjectReference jSCanvas)
195+
public async Task InvokeCallback(IJSObjectReference jsBlob)
206196
{
207-
blobWrapper = await jSRuntime.InvokeAsync<IJSObjectReference>("toBlob", jSCanvas, this);
197+
var blob = await Blob.CreateAsync(jSRuntime, jsBlob, new() { DisposesJSReference = true });
198+
await callback.Invoke(blob);
208199
}
209200
}
210201
}

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/MultipleFiles.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{
2424
try
2525
{
26-
var options = new OpenFilePickerOptionsStartInWellKnownDirectory() { Multiple = true, StartIn = WellKnownDirectory.Downloads };
26+
OpenFilePickerOptions options = new() { Multiple = true, StartIn = WellKnownDirectory.Downloads };
2727
var fileHandles = await FileSystemAccessService.ShowOpenFilePickerAsync(options);
2828
filesRead = (await Task.WhenAll(fileHandles.Select(async x => await x.GetNameAsync()))).ToList();
2929
}

0 commit comments

Comments
 (0)