From 472fe4e0f2d4c2abd1fd7e17a318ec632bd00b0e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 22 Feb 2024 18:24:41 +0100 Subject: [PATCH] Rename componente + testing --- .../EgwCoreLib.BlazorTest.csproj | 2 +- .../Pages/TestPdfViewer.razor | 14 ++- .../Pages/TestPdfViewer.razor.cs | 87 +++++++++++++++++++ EgwCoreLib.BlazorTest/Pages/_Layout.cshtml | 2 + EgwCoreLib.BlazorTest/Program.cs | 2 + EgwCoreLib.Razor/EgwCoreLib.Razor.csproj | 5 +- .../{PdfViewer.razor => PdfDisplay.razor} | 0 ...PdfViewer.razor.cs => PdfDisplay.razor.cs} | 4 +- ...PdfViewer.razor.js => PdfDisplay.razor.js} | 0 9 files changed, 110 insertions(+), 6 deletions(-) rename EgwCoreLib.Razor/{PdfViewer.razor => PdfDisplay.razor} (100%) rename EgwCoreLib.Razor/{PdfViewer.razor.cs => PdfDisplay.razor.cs} (92%) rename EgwCoreLib.Razor/{PdfViewer.razor.js => PdfDisplay.razor.js} (100%) diff --git a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj index dba1f64..7d3d910 100644 --- a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj +++ b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor b/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor index ed1ef69..ad92c78 100644 --- a/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor +++ b/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor @@ -24,12 +24,24 @@ + @* Compo + *@
- + + @* @if (CompoSel == 1) + { + } + else + { + + } *@

Selezione: @FileSel

diff --git a/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor.cs b/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor.cs index f3e1884..47fb4ef 100644 --- a/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor.cs +++ b/EgwCoreLib.BlazorTest/Pages/TestPdfViewer.razor.cs @@ -1,7 +1,29 @@ +#if false +using CA.Blazor.Pdf; +using CA.Blazor.Pdf.Extensions; +#endif + +using Microsoft.AspNetCore.Components; +using System.Net.Http.Headers; + namespace EgwCoreLib.BlazorTest.Pages { public partial class TestPdfViewer { + #region Public Fields + + public int CompoSel = 1; + + #endregion Public Fields + + #region Public Properties + + public string PdfBase64 { get; set; } = ""; + + #endregion Public Properties + + #region Protected Properties + protected string FileSel { get => fileSel; @@ -10,10 +32,12 @@ namespace EgwCoreLib.BlazorTest.Pages if (fileSel != value) { fileSel = value; + ReloadData().ConfigureAwait(false); StateHasChanged(); } } } + protected string HeightSel { get => heightSel; @@ -26,7 +50,70 @@ namespace EgwCoreLib.BlazorTest.Pages } } } + + [Inject] + protected NavigationManager NavMan { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + await Task.Delay(1); + } + + #endregion Protected Methods + + #region Private Properties + private string fileSel { get; set; } = "File01.pdf"; private string heightSel { get; set; } = "400px"; + + private string baseUri = ""; + private string fileUrl = ""; + + #endregion Private Properties + + #region Private Methods + + private async Task GetBase64Pdf(string apiUrl) + { + using (var httpClient = new HttpClient()) + { + httpClient.BaseAddress = new Uri(NavMan.BaseUri); + + // Make the API request to get the PDF content + var response = await httpClient.GetAsync(apiUrl); + + if (response.IsSuccessStatusCode) + { + // Convert the response content to Base64 + var pdfBytes = await response.Content.ReadAsByteArrayAsync(); + var base64String = Convert.ToBase64String(pdfBytes); + return $"data:application/pdf;base64,{base64String}"; + } + else + { + // Handle error scenarios based on your application needs For simplicity, we + // return an empty string in case of an error + return string.Empty; + } + } + } + + private async Task ReloadData() + { + baseUri = NavMan.BaseUri; + fileUrl = $"{baseUri}/test/{FileSel}"; + +#if false + // Call the helper method to retrieve the Base64-encoded PDF content + PdfBase64 = await GetBase64Pdf(apiUrl); +#endif + } + + #endregion Private Methods } } \ No newline at end of file diff --git a/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml b/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml index 48d1302..09d3a05 100644 --- a/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml +++ b/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml @@ -60,5 +60,7 @@ + + diff --git a/EgwCoreLib.BlazorTest/Program.cs b/EgwCoreLib.BlazorTest/Program.cs index d9bdc27..d254c51 100644 --- a/EgwCoreLib.BlazorTest/Program.cs +++ b/EgwCoreLib.BlazorTest/Program.cs @@ -1,3 +1,5 @@ + +using EgwCoreLib.BlazorTest; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; diff --git a/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj b/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj index 06ac4f4..b5c09af 100644 --- a/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj +++ b/EgwCoreLib.Razor/EgwCoreLib.Razor.csproj @@ -53,7 +53,7 @@ true PreserveNewest - + @@ -66,7 +66,8 @@ - + + diff --git a/EgwCoreLib.Razor/PdfViewer.razor b/EgwCoreLib.Razor/PdfDisplay.razor similarity index 100% rename from EgwCoreLib.Razor/PdfViewer.razor rename to EgwCoreLib.Razor/PdfDisplay.razor diff --git a/EgwCoreLib.Razor/PdfViewer.razor.cs b/EgwCoreLib.Razor/PdfDisplay.razor.cs similarity index 92% rename from EgwCoreLib.Razor/PdfViewer.razor.cs rename to EgwCoreLib.Razor/PdfDisplay.razor.cs index cd56f7b..660d9bb 100644 --- a/EgwCoreLib.Razor/PdfViewer.razor.cs +++ b/EgwCoreLib.Razor/PdfDisplay.razor.cs @@ -7,7 +7,7 @@ using ZXingBlazor.Components; namespace EgwCoreLib.Razor { - public partial class PdfViewer + public partial class PdfDisplay { /// /// URL del documento da mostrare @@ -43,7 +43,7 @@ namespace EgwCoreLib.Razor { if (!firstRender) return; - module = await JS.InvokeAsync("import", "./_content/EgwCoreLib.Razor/PdfViewer.razor.js"); + module = await JS.InvokeAsync("import", "./_content/EgwCoreLib.Razor/PdfDisplay.razor.js"); isMobile = await JS.InvokeAsync("isDevice"); } catch diff --git a/EgwCoreLib.Razor/PdfViewer.razor.js b/EgwCoreLib.Razor/PdfDisplay.razor.js similarity index 100% rename from EgwCoreLib.Razor/PdfViewer.razor.js rename to EgwCoreLib.Razor/PdfDisplay.razor.js