|
1 | | -using AkazawaYun.PRO7; |
| 1 | +#pragma warning disable IDE1006,IL2026 |
| 2 | + |
| 3 | +using AkazawaYun.AOT; |
| 4 | +using AkazawaYun.PRO7; |
| 5 | +using AkazawaYun.PRO7.AkazawaYunWebFunctionAOP; |
2 | 6 | using AkazawaYun.PRO7.AkazawaYunWebInterceptor; |
3 | | -using System.Text.Json.Serialization; |
| 7 | +using System.Diagnostics.CodeAnalysis; |
4 | 8 |
|
5 | 9 | namespace AkazawaYun.FrameworkBenchmarks; |
6 | 10 |
|
7 | | -public class Program : IPostFunction |
| 11 | +class Program : IPostFunctionWrapper |
8 | 12 | { |
9 | | - static async Task Main() |
| 13 | + static readonly akzWebBuilder builder; |
| 14 | + static readonly akzDbFactory mysql; |
| 15 | + |
| 16 | + |
| 17 | + static Program() |
10 | 18 | { |
11 | | - akzJson.Config(null, Json.Default); |
12 | | - var server = await akzWebBuilder.Shared.Load().SetDefault().Build() |
| 19 | + akzJson.Config(null, AotJsonContext.Default); |
| 20 | + builder = akzWebBuilder.Shared.SetDefault() |
| 21 | + .Build() |
13 | 22 | .Config<IWebReceptor, akzWebInterceptor>(itc => |
14 | 23 | { |
| 24 | + itc.ClearInterceptor(); |
15 | 25 | itc.AddInterceptor(new akzWebInterceptorNotOnlyPost()); |
16 | | - }).Launch(); |
| 26 | + }); |
| 27 | + mysql = new akzDbBuilderII() |
| 28 | + .SetServer("tfb-database:3306") |
| 29 | + //.SetServer("localhost:3306") |
| 30 | + .SetUser("benchmarkdbuser") |
| 31 | + .SetPwd("benchmarkdbpass") |
| 32 | + .SetDatabase("hello_world") |
| 33 | + .SetCharset() |
| 34 | + .SetOtherset() |
| 35 | + .Build<Mysql>(); |
| 36 | + } |
| 37 | + static async Task Main() |
| 38 | + { |
| 39 | + await builder.Launch(); |
17 | 40 | akzLog.Default = akzLog.Output.None; |
18 | 41 | await Task.Delay(-1); |
19 | 42 | } |
20 | 43 |
|
21 | 44 |
|
22 | | - public static ValueTask<HttpRes> plaintext(HttpReq _) |
| 45 | + public static HttpRes plaintext() => HttpRes.HttpOK("Hello, World!", ".txt"); |
| 46 | + public static JsonModel json() => new() |
| 47 | + { |
| 48 | + message = "Hello, World!" |
| 49 | + }; |
| 50 | + |
| 51 | + //[WebFunctionAopTry] |
| 52 | + public static async Task<world> db() |
23 | 53 | { |
24 | | - return HttpRes.HttpOK("Hello, World!", ".txt"); |
| 54 | + await using IDb con = await mysql.Connect(); |
| 55 | + world obj = await WorldService.GetRandomWorld(con); |
| 56 | + return obj; |
25 | 57 | } |
26 | | - public static ValueTask<HttpRes> json(HttpReq _) |
| 58 | + //[WebFunctionAopTry] |
| 59 | + public static async Task<world[]> queries(string queries) |
27 | 60 | { |
28 | | - return HttpRes.HttpJson(new JsonResponse |
29 | | - { |
30 | | - message = "Hello, World!" |
31 | | - }); |
| 61 | + int count = ParseCount(queries); |
| 62 | + |
| 63 | + await using IDb con = await mysql.Connect(); |
| 64 | + world[] lst = await WorldService.GetWorlds(con, count); |
| 65 | + return lst; |
32 | 66 | } |
33 | | -} |
| 67 | + //[WebFunctionAopTry] |
| 68 | + public static async Task<world[]> updates(string queries) |
| 69 | + { |
| 70 | + int count = ParseCount(queries); |
34 | 71 |
|
35 | | -public class JsonResponse |
36 | | -{ |
37 | | - public string? message { get; set; } |
38 | | -} |
| 72 | + await using IDb con = await mysql.Connect(); |
| 73 | + world[] lst = await WorldService.GetWorlds(con, count); |
| 74 | + |
| 75 | + foreach (world obj in lst) |
| 76 | + obj.randomNumber = Random.Shared.Next(1, 10001); |
| 77 | + |
| 78 | + await WorldService.SaveWorlds(con, lst); |
| 79 | + |
| 80 | + return lst; |
| 81 | + } |
39 | 82 |
|
40 | | -[JsonSerializable(typeof(JsonResponse))] |
41 | | -public partial class Json : JsonSerializerContext { } |
| 83 | + |
| 84 | + static int ParseCount(string queries) |
| 85 | + { |
| 86 | + if (!int.TryParse(queries, out int count)) |
| 87 | + return 1; |
| 88 | + |
| 89 | + count = Math.Clamp(count, 1, 500); |
| 90 | + return count; |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments