Skip to content

Commit ca36c2f

Browse files
author
linzhijun
committed
添加 ToolGood.Algorithm.WebAssembly 项目
1 parent f7f90d1 commit ca36c2f

File tree

437 files changed

+10286
-0
lines changed

Some content is hidden

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

437 files changed

+10286
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace ToolGood.Algorithm.WebAssembly
2+
{
3+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
4+
using Microsoft.JSInterop;
5+
using ToolGood.Algorithm;
6+
public class Program
7+
{
8+
private static async Task Main(string[] args)
9+
{
10+
}
11+
12+
13+
///// <summary>
14+
///// 给js调用的函数
15+
///// </summary>
16+
///// <param name="i"></param>
17+
///// <param name="j"></param>
18+
///// <returns></returns>
19+
//[JSInvokable]
20+
//public static byte[] Add(int i, int j)
21+
//{
22+
// return new byte[] { (byte)i, (byte)j };
23+
//}
24+
25+
[JSInvokable]
26+
public static string TryEvaluate(string exp)
27+
{
28+
var ae = new AlgorithmEngine();
29+
return ae.TryEvaluate(exp, null);
30+
}
31+
}
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"ToolGood.Algorithm.WebAssembly": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:51417;http://localhost:51418"
10+
}
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" />
12+
<!--<PackageReference Include="SkiaSharp.Views.Blazor" Version="2.88.8" />-->
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\ToolGood.Algorithm2\ToolGood.Algorithm2.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace ToolGood.Algorithm2.WebTest.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
Layout = null;
5+
}
6+
<html lang="en">
7+
<head>
8+
<meta charset="UTF-8" />
9+
</head>
10+
<body>
11+
编译ToolGood.Algorithm.WebAssembly项目,生成文件夹下的wwwroot文件夹中的_framework文件夹中就是生成的WebAssembly和相关文件
12+
<br />
13+
我们运行前端项目. 由于Blazor会生成blat、dll等不被Web服务器默认接受的文件类型,所以请确保在Web服务器上为如下格式的文件配置MimeType:.pdb、.blat、.dat、.dll、.json、.wasm、.woff、.woff2。
14+
15+
16+
<pre>
17+
window.onload = async function () {
18+
await Blazor.start();
19+
constr = await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluate', '1+1');
20+
alert(constr);
21+
};
22+
</pre>
23+
</body>
24+
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
25+
<script>
26+
window.onload = async function () {
27+
await Blazor.start();
28+
constr = await DotNet.invokeMethodAsync('ToolGood.Algorithm.WebAssembly', 'TryEvaluate', '1+1');
29+
alert(constr);
30+
};
31+
</script>
32+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace ToolGood.Algorithm2.WebTest.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace ToolGood.Algorithm2.WebTest.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
20+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - ToolGood.Algorithm2.WebTest</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/ToolGood.Algorithm2.WebTest.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container">
15+
<a class="navbar-brand" asp-area="" asp-page="/Index">ToolGood.Algorithm2.WebTest</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
30+
</div>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
37+
</div>
38+
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2024 - ToolGood.Algorithm2.WebTest - <a asp-area="" asp-page="/Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
45+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
46+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
47+
<script src="~/js/site.js" asp-append-version="true"></script>
48+
49+
@await RenderSectionAsync("Scripts", required: false)
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)