From eb600def1d9d84e1d77ce599cda2fa993cd2b82c Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Sun, 26 Mar 2023 09:16:47 +0800 Subject: [PATCH] add GlobalVariable --- src/Application/Constants/GlobalVariable.cs | 5 +++++ .../Components/Common/PickUserAutocomplete.cs | 4 ++-- src/Blazor.Server.UI/Pages/Customers/Customers.razor | 2 +- .../Pages/Documents/_UploadFilesFormDialog.razor | 5 ++--- src/Blazor.Server.UI/Pages/Identity/Users/Profile.razor | 2 +- src/Blazor.Server.UI/Pages/Identity/Users/Users.razor | 2 +- src/Blazor.Server.UI/Pages/Identity/Users/_UserForm.razor | 2 +- src/Blazor.Server.UI/Pages/Products/Products.razor | 2 +- src/Blazor.Server.UI/Pages/Products/_ProductFormDialog.razor | 2 +- .../Pages/SystemManagement/Dictionaries.razor | 2 +- src/Blazor.Server.UI/Shared/MainLayout.razor.cs | 3 +-- 11 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 src/Application/Constants/GlobalVariable.cs diff --git a/src/Application/Constants/GlobalVariable.cs b/src/Application/Constants/GlobalVariable.cs new file mode 100644 index 000000000..33f3f7bc7 --- /dev/null +++ b/src/Application/Constants/GlobalVariable.cs @@ -0,0 +1,5 @@ +namespace CleanArchitecture.Blazor.Application.Constants; +public static class GlobalVariable +{ + public static long maxAllowedSize => 512000 * 100; +} diff --git a/src/Blazor.Server.UI/Components/Common/PickUserAutocomplete.cs b/src/Blazor.Server.UI/Components/Common/PickUserAutocomplete.cs index 0b3d34794..979319f02 100644 --- a/src/Blazor.Server.UI/Components/Common/PickUserAutocomplete.cs +++ b/src/Blazor.Server.UI/Components/Common/PickUserAutocomplete.cs @@ -26,7 +26,7 @@ public override Task SetParametersAsync(ParameterView parameters) return base.SetParametersAsync(parameters); } - private async Task> searchKeyValues(string value, CancellationToken cancellation) + private Task> searchKeyValues(string value, CancellationToken cancellation) { // if text is null or empty, show complete list _userList = _dataProvider.DataSource.Where(x => x.TenantId == TenantId).ToList(); @@ -39,7 +39,7 @@ private async Task> searchKeyValues(string value, Cancellati { result = _userList.Where(x => x.UserName.Contains(value, StringComparison.OrdinalIgnoreCase) || x.Email.Contains(value, StringComparison.OrdinalIgnoreCase)).Select(x => x.UserName).ToList(); } - return result; + return Task.FromResult(result.AsEnumerable()); } private string toString(string str) diff --git a/src/Blazor.Server.UI/Pages/Customers/Customers.razor b/src/Blazor.Server.UI/Pages/Customers/Customers.razor index 2babbccfb..7cb870b6e 100644 --- a/src/Blazor.Server.UI/Pages/Customers/Customers.razor +++ b/src/Blazor.Server.UI/Pages/Customers/Customers.razor @@ -378,7 +378,7 @@ { _uploading = true; var stream = new MemoryStream(); - await file.OpenReadStream().CopyToAsync(stream); + await file.OpenReadStream(GlobalVariable.maxAllowedSize).CopyToAsync(stream); var command = new ImportCustomersCommand(file.Name, stream.ToArray()); var result = await _mediator.Send(command); if (result.Succeeded) diff --git a/src/Blazor.Server.UI/Pages/Documents/_UploadFilesFormDialog.razor b/src/Blazor.Server.UI/Pages/Documents/_UploadFilesFormDialog.razor index 2d67495d9..7046ce274 100644 --- a/src/Blazor.Server.UI/Pages/Documents/_UploadFilesFormDialog.razor +++ b/src/Blazor.Server.UI/Pages/Documents/_UploadFilesFormDialog.razor @@ -64,7 +64,6 @@ private ISender _mediator { get; set; } = default!; [Inject] private IUploadService _uploadService { get; set; } = default!; List uploadedFiles = new(); - const long MAXALLOWEDSIZE = 5242880; private async ValueTask LoadFiles(InputFileChangeEventArgs e) { try @@ -90,7 +89,7 @@ { foreach (var file in files) { - using var stream = file.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); + using var stream = file.OpenReadStream(GlobalVariable.maxAllowedSize); while (await stream.ReadAsync(buffer) is int read && read > 0) { uploadedFiles[startIndex].UploadedBytes += read; @@ -141,7 +140,7 @@ { try { - var filestream = uploaded.File.OpenReadStream(MAXALLOWEDSIZE); + var filestream = uploaded.File.OpenReadStream(GlobalVariable.maxAllowedSize); var imgstream = new MemoryStream(); await filestream.CopyToAsync(imgstream); imgstream.Position = 0; diff --git a/src/Blazor.Server.UI/Pages/Identity/Users/Profile.razor b/src/Blazor.Server.UI/Pages/Identity/Users/Profile.razor index d953d079b..875e84e1c 100644 --- a/src/Blazor.Server.UI/Pages/Identity/Users/Profile.razor +++ b/src/Blazor.Server.UI/Pages/Identity/Users/Profile.razor @@ -226,7 +226,7 @@ } private async Task UploadPhoto(InputFileChangeEventArgs e) { - var filestream = e.File.OpenReadStream(); + var filestream = e.File.OpenReadStream(GlobalVariable.maxAllowedSize); var imgstream = new MemoryStream(); await filestream.CopyToAsync(imgstream); imgstream.Position = 0; diff --git a/src/Blazor.Server.UI/Pages/Identity/Users/Users.razor b/src/Blazor.Server.UI/Pages/Identity/Users/Users.razor index 042c94888..d07c74b02 100644 --- a/src/Blazor.Server.UI/Pages/Identity/Users/Users.razor +++ b/src/Blazor.Server.UI/Pages/Identity/Users/Users.razor @@ -749,7 +749,7 @@ { _uploading = true; var stream = new MemoryStream(); - await file.OpenReadStream().CopyToAsync(stream); + await file.OpenReadStream(GlobalVariable.maxAllowedSize).CopyToAsync(stream); var result = await _excelService.ImportAsync(stream.ToArray(), mappers: new Dictionary> { { L["User Name"], (row, item) => item.UserName = row[L["User Name"]]?.ToString() }, diff --git a/src/Blazor.Server.UI/Pages/Identity/Users/_UserForm.razor b/src/Blazor.Server.UI/Pages/Identity/Users/_UserForm.razor index 4741a32fa..572b3fb61 100644 --- a/src/Blazor.Server.UI/Pages/Identity/Users/_UserForm.razor +++ b/src/Blazor.Server.UI/Pages/Identity/Users/_UserForm.razor @@ -168,7 +168,7 @@ private async Task UploadPhoto(InputFileChangeEventArgs e) { - var filestream = e.File.OpenReadStream(); + var filestream = e.File.OpenReadStream(GlobalVariable.maxAllowedSize); var imgstream = new MemoryStream(); await filestream.CopyToAsync(imgstream); imgstream.Position = 0; diff --git a/src/Blazor.Server.UI/Pages/Products/Products.razor b/src/Blazor.Server.UI/Pages/Products/Products.razor index 548cc2df6..6c777e174 100644 --- a/src/Blazor.Server.UI/Pages/Products/Products.razor +++ b/src/Blazor.Server.UI/Pages/Products/Products.razor @@ -436,7 +436,7 @@ { _uploading = true; var stream = new MemoryStream(); - await file.OpenReadStream().CopyToAsync(stream); + await file.OpenReadStream(GlobalVariable.maxAllowedSize).CopyToAsync(stream); var command = new ImportProductsCommand(file.Name, stream.ToArray()); var result = await _mediator.Send(command); diff --git a/src/Blazor.Server.UI/Pages/Products/_ProductFormDialog.razor b/src/Blazor.Server.UI/Pages/Products/_ProductFormDialog.razor index 073008dc6..a67392d5c 100644 --- a/src/Blazor.Server.UI/Pages/Products/_ProductFormDialog.razor +++ b/src/Blazor.Server.UI/Pages/Products/_ProductFormDialog.razor @@ -135,7 +135,7 @@ { try { - var filestream = file.OpenReadStream(MAXALLOWEDSIZE); + var filestream = file.OpenReadStream(GlobalVariable.maxAllowedSize); var imgstream = new MemoryStream(); await filestream.CopyToAsync(imgstream); imgstream.Position = 0; diff --git a/src/Blazor.Server.UI/Pages/SystemManagement/Dictionaries.razor b/src/Blazor.Server.UI/Pages/SystemManagement/Dictionaries.razor index 6d38e2e28..4790fc35d 100644 --- a/src/Blazor.Server.UI/Pages/SystemManagement/Dictionaries.razor +++ b/src/Blazor.Server.UI/Pages/SystemManagement/Dictionaries.razor @@ -398,7 +398,7 @@ { _uploading = true; var stream = new MemoryStream(); - await e.File.OpenReadStream().CopyToAsync(stream); + await e.File.OpenReadStream(GlobalVariable.maxAllowedSize).CopyToAsync(stream); var command = new ImportKeyValuesCommand(e.File.Name, stream.ToArray()); var result = await _mediator.Send(command); if(result.Succeeded){ diff --git a/src/Blazor.Server.UI/Shared/MainLayout.razor.cs b/src/Blazor.Server.UI/Shared/MainLayout.razor.cs index 24528cb7e..4ab220abe 100644 --- a/src/Blazor.Server.UI/Shared/MainLayout.razor.cs +++ b/src/Blazor.Server.UI/Shared/MainLayout.razor.cs @@ -40,14 +40,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } private async Task ApplyUserPreferences() { - + _defaultDarkMode =await _mudThemeProvider.GetSystemPreference(); UserPreferences = await _layoutService.ApplyUserPreferences(_defaultDarkMode); } protected override async Task OnInitializedAsync() { _layoutService.MajorUpdateOccured += LayoutServiceOnMajorUpdateOccured; _layoutService.SetBaseTheme(Theme.ApplicationTheme()); - _layoutService.SetDarkMode(_defaultDarkMode); _hotKeysContext = _hotKeys.CreateContext().Add(ModKey.Ctrl, Key.K, async () => await OpenCommandPalette(), "Open command palette."); await base.OnInitializedAsync();