Skip to content

Commit b824a6d

Browse files
author
Anthony Rivera
committed
Added compatibility with net5 and net6 as well should be supported. fix #28
#31
1 parent 10b471c commit b824a6d

Some content is hidden

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

46 files changed

+2324
-183
lines changed

BlazorDownloadFile.Demo/BlazorDownloadFile.Demo.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-rc1.20223.4" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
12-
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-rc1.20217.1" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
12+
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
1313
</ItemGroup>
1414

1515
<ItemGroup>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Content Update="Pages\Index.razor">
9+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
10+
</Content>
11+
<Content Update="Shared\MainLayout.razor">
12+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
13+
</Content>
14+
<Content Update="Shared\NavMenu.razor">
15+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
16+
</Content>
17+
<Content Update="wwwroot\css\app.css">
18+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
19+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
20+
</Content>
21+
<Content Update="wwwroot\css\bootstrap\bootstrap.min.css">
22+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
23+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
24+
</Content>
25+
<Content Update="wwwroot\css\bootstrap\bootstrap.min.css.map">
26+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
27+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
28+
</Content>
29+
<Content Update="wwwroot\css\open-iconic\FONT-LICENSE">
30+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
31+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
32+
</Content>
33+
<Content Update="wwwroot\css\open-iconic\font\css\open-iconic-bootstrap.min.css">
34+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
35+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
36+
</Content>
37+
<Content Update="wwwroot\css\open-iconic\font\fonts\open-iconic.eot">
38+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
39+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
40+
</Content>
41+
<Content Update="wwwroot\css\open-iconic\font\fonts\open-iconic.otf">
42+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
43+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
44+
</Content>
45+
<Content Update="wwwroot\css\open-iconic\font\fonts\open-iconic.svg">
46+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
47+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
48+
</Content>
49+
<Content Update="wwwroot\css\open-iconic\font\fonts\open-iconic.ttf">
50+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
51+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
52+
</Content>
53+
<Content Update="wwwroot\css\open-iconic\font\fonts\open-iconic.woff">
54+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
55+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
56+
</Content>
57+
<Content Update="wwwroot\css\open-iconic\ICON-LICENSE">
58+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
59+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
60+
</Content>
61+
<Content Update="wwwroot\css\open-iconic\README.md">
62+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
63+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
64+
</Content>
65+
<Content Update="wwwroot\favicon.ico">
66+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
67+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
68+
</Content>
69+
<Content Update="wwwroot\sample-data\weather.json">
70+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
71+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
72+
</Content>
73+
</ItemGroup>
74+
75+
<ItemGroup>
76+
<UpToDateCheckInput Remove="Pages\DownloadFileFromText.razor" />
77+
</ItemGroup>
78+
79+
<ItemGroup>
80+
<_ContentIncludedByDefault Remove="Pages\DownloadFileFromText.razor" />
81+
</ItemGroup>
82+
83+
<ItemGroup>
84+
<ProjectReference Include="..\BlazorDownloadFile\BlazorDownloadFile.csproj" />
85+
</ItemGroup>
86+
87+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace BlazorDownloadFile.Server.Demo.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace BlazorDownloadFile.Server.Demo.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@page "/DownloadFileFromText"
2+
<h1>Download File From Text</h1>
3+
4+
<button @onclick=@(async () => await BlazorDownloadFileService.DownloadFileFromText("test.json", json, "application/octet-stream"))>Dowload json from text</button>
5+
<br />
6+
<br />
7+
<pre>@json</pre>
8+
9+
<button @onclick=@(async () => await BlazorDownloadFileService.DownloadFileFromText("test.csv", csv, "text/csv"))>Dowload csv from text</button>
10+
<br />
11+
<br />
12+
<pre>@csv</pre>
13+
14+
@code {
15+
[Inject] public IBlazorDownloadFileService BlazorDownloadFileService { get; set; }
16+
string csv = @"""Name"",""StreetAddress""
17+
""Customer 1"",""Sölfang""
18+
""Customer 2"",""Skärholmen""
19+
""Customer 3"",""Trömso""
20+
""Customer 4"",""Fårsta Strand""
21+
""Customer 5"",""Gullmarsplan""
22+
""Customer 6"",""Råcksta""
23+
""Customer 7"",""Vällingby""";
24+
string json = @"{
25+
TestData: [
26+
{
27+
Name: ""Customer 1"",
28+
StreetAddress: ""Sölfang""
29+
},
30+
{
31+
Name: ""Customer 2"",
32+
StreetAddress: ""Skärholmen""
33+
},
34+
{
35+
Name: ""Customer 3"",
36+
StreetAddress: ""Trömso""
37+
},
38+
{
39+
Name: ""Customer 4"",
40+
StreetAddress: ""Fårsta Strand""
41+
},
42+
{
43+
Name: ""Customer 5"",
44+
StreetAddress: ""Gullmarsplan""
45+
},
46+
{
47+
Name: ""Customer 6"",
48+
StreetAddress: ""Råcksta""
49+
},
50+
{
51+
Name: ""Customer 7"",
52+
StreetAddress: ""Vällingby""
53+
}
54+
]
55+
}";
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model BlazorDownloadFile.Server.Demo.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html>
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/app.css" rel="stylesheet" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace BlazorDownloadFile.Server.Demo.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
[IgnoreAntiforgeryToken]
14+
public class ErrorModel : PageModel
15+
{
16+
public string RequestId { get; set; }
17+
18+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
19+
20+
private readonly ILogger<ErrorModel> _logger;
21+
22+
public ErrorModel(ILogger<ErrorModel> logger)
23+
{
24+
_logger = logger;
25+
}
26+
27+
public void OnGet()
28+
{
29+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/fetchdata"
2+
3+
@using BlazorDownloadFile.Server.Demo.Data
4+
@inject WeatherForecastService ForecastService
5+
6+
<h1>Weather forecast</h1>
7+
8+
<p>This component demonstrates fetching data from a service.</p>
9+
10+
@if (forecasts == null)
11+
{
12+
<p><em>Loading...</em></p>
13+
}
14+
else
15+
{
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>Date</th>
20+
<th>Temp. (C)</th>
21+
<th>Temp. (F)</th>
22+
<th>Summary</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
@foreach (var forecast in forecasts)
27+
{
28+
<tr>
29+
<td>@forecast.Date.ToShortDateString()</td>
30+
<td>@forecast.TemperatureC</td>
31+
<td>@forecast.TemperatureF</td>
32+
<td>@forecast.Summary</td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
private WeatherForecast[] forecasts;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
45+
}
46+
}

BlazorDownloadFile.Server.Demo/Pages/Index.razor

+33
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@page "/"
2+
@namespace BlazorDownloadFile.Server.Demo.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = null;
6+
}
7+
8+
<!DOCTYPE html>
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
13+
<title>BlazorDownloadFile.Demo</title>
14+
<base href="/" />
15+
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
16+
<link href="css/app.css" rel="stylesheet" />
17+
</head>
18+
<body>
19+
<component type="typeof(App)" render-mode="ServerPrerendered" />
20+
21+
<div id="blazor-error-ui">
22+
<environment include="Staging,Production">
23+
An error has occurred. This application may no longer respond until reloaded.
24+
</environment>
25+
<environment include="Development">
26+
An unhandled exception has occurred. See browser dev tools for details.
27+
</environment>
28+
<a href="" class="reload">Reload</a>
29+
<a class="dismiss">🗙</a>
30+
</div>
31+
32+
<script src="_framework/blazor.server.js"></script>
33+
</body>
34+
</html>

0 commit comments

Comments
 (0)