-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleModule1.cs
More file actions
83 lines (64 loc) · 2.85 KB
/
SampleModule1.cs
File metadata and controls
83 lines (64 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Infinity.Toolkit.FeatureModules;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Routing;
using System.Reflection;
using System.Runtime.InteropServices;
namespace FeatureModulesSample.Module1;
public class SampleModule1 : WebFeatureModule
{
public override IModuleInfo ModuleInfo { get; } = new FeatureModuleInfo("SampleModule1", "1.0.0");
public override void MapEndpoints(WebApplication app)
{
var group = app.MapGroup("/info")
.WithTags("Info");
group.MapGet("/systeminfo", GetSystemInfo)
.WithName("SystemInfo")
.WithDisplayName("Get system info");
}
private static JsonHttpResult<Response> GetSystemInfo(IWebHostEnvironment webHostEnvironment)
{
var processorArchitecture = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "64-bit",
Architecture.X86 => "32-bit",
Architecture.Arm => "ARM",
Architecture.Arm64 => "ARM64",
_ => "Unknown"
};
return TypedResults.Json<Response>(new Response
{
Name = Assembly.GetEntryAssembly()?.GetName().Name ?? webHostEnvironment.ApplicationName ?? "Name",
Version = Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "0.0.0",
DateTime = DateTimeOffset.Now.UtcDateTime,
Environment = webHostEnvironment.EnvironmentName,
FrameworkVersion = Environment.Version.ToString(),
OSVersion = Environment.OSVersion.ToString(),
BuildDate = File.GetLastWriteTime(Assembly.GetEntryAssembly()!.Location).ToString("yyyy-MM-dd HH:mm:ss"),
Host = Environment.MachineName,
ProcessorArchitecture = processorArchitecture,
FrameworkDescription = RuntimeInformation.FrameworkDescription,
RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier,
OSArchitecture = RuntimeInformation.OSArchitecture.ToString(),
OSDescription = RuntimeInformation.OSDescription
});
}
private record Response()
{
public string? Name { get; init; }
public string? Version { get; init; }
public DateTimeOffset DateTime { get; init; }
public string? Environment { get; init; }
public string? FrameworkVersion { get; init; }
public string? OSVersion { get; init; }
public string? BuildDate { get; init; }
public string? Host { get; init; }
public string? ProcessorArchitecture { get; init; }
public string? FrameworkDescription { get; init; }
public string? RuntimeIdentifier { get; init; }
public string? OSArchitecture { get; init; }
public string? OSDescription { get; init; }
}
}