|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Reflection; |
4 | | -using System.Threading; |
5 | | -using System.Threading.Tasks; |
6 | | -using MediatR; |
7 | | -using NetEvent.Shared.Dto; |
8 | | - |
9 | | -namespace NetEvent.Server.Modules.System.Endpoints |
10 | | -{ |
11 | | - public static class GetSystemInfo |
12 | | - { |
13 | | - public sealed class Handler : IRequestHandler<Request, Response> |
14 | | - { |
15 | | - public Handler() |
16 | | - { |
17 | | - } |
18 | | - |
19 | | - public Task<Response> Handle(Request request, CancellationToken cancellationToken) |
20 | | - { |
21 | | - var systeminfocomponents = new List<SystemInfoComponentEntryDto>(); |
22 | | - var systeminfohealth = new List<SystemInfoHealthEntryDto>(); |
23 | | - var systeminfoversions = new List<SystemInfoVersionEntryDto>(); |
24 | | - |
25 | | - AppDomain currentDomain = AppDomain.CurrentDomain; |
26 | | - Assembly[] assems = currentDomain.GetAssemblies(); |
27 | | - foreach (Assembly assem in assems) |
28 | | - { |
29 | | - systeminfocomponents.Add(new SystemInfoComponentEntryDto(assem.ManifestModule.Name, assem.ToString())); |
30 | | - } |
31 | | - |
32 | | - systeminfoversions.Add(new SystemInfoVersionEntryDto("NETEVENT", Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion)); |
33 | | - systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDNODE")); |
34 | | - systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDID")); |
35 | | - systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDNUMBER")); |
36 | | - systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("SOURCE_COMMIT")); |
37 | | - |
38 | | - // TODO: think about healthchecks and healthcheck modularity (to perform checks on various services like game servers, the mail server, payment apis ...) and remove dummy services |
39 | | - systeminfohealth.Add(new SystemInfoHealthEntryDto("NETEVENT Server", string.Empty, true)); |
40 | | - systeminfohealth.Add(new SystemInfoHealthEntryDto("Email Service", "servername", false)); |
41 | | - |
42 | | - var systeminfo = new SystemInfoDto(systeminfocomponents, systeminfohealth, systeminfoversions); |
43 | | - |
44 | | - return Task.FromResult(new Response(systeminfo)); |
45 | | - } |
46 | | - |
47 | | - private static SystemInfoVersionEntryDto CreateSystemInfoVersionEntryFromEnv(string envName) |
48 | | - { |
49 | | - return new SystemInfoVersionEntryDto(envName, string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName)) ? "dev" : Environment.GetEnvironmentVariable(envName)); |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - public sealed class Request : IRequest<Response> |
54 | | - { |
55 | | - public Request() |
56 | | - { |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - public sealed class Response : ResponseBase<SystemInfoDto> |
61 | | - { |
62 | | - public Response(SystemInfoDto value) : base(value) |
63 | | - { |
64 | | - } |
65 | | - |
66 | | - public Response(ReturnType returnType, string error) : base(returnType, error) |
67 | | - { |
68 | | - } |
69 | | - } |
70 | | - } |
71 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Reflection; |
| 4 | +using System.Threading; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using MediatR; |
| 7 | +using NetEvent.Shared.Dto; |
| 8 | +using Microsoft.AspNetCore.Components; |
| 9 | +using Microsoft.Extensions.Localization; |
| 10 | +using NetEvent.Server; |
| 11 | + |
| 12 | +namespace NetEvent.Server.Modules.System.Endpoints |
| 13 | +{ |
| 14 | + public static class GetSystemInfo |
| 15 | + { |
| 16 | + public sealed class Handler : IRequestHandler<Request, Response> |
| 17 | + { |
| 18 | + // TODO: remove localizer as soon as it is implemented somewhere where it makes sense |
| 19 | + private IStringLocalizer<Localize> _Localizer { get; set; } |
| 20 | + |
| 21 | + // TODO: remove localizer as soon as it is implemented somewhere where it makes sense |
| 22 | + public Handler(IStringLocalizer<Localize> localizer) |
| 23 | + { |
| 24 | + _Localizer = localizer; |
| 25 | + } |
| 26 | + |
| 27 | + public Task<Response> Handle(Request request, CancellationToken cancellationToken) |
| 28 | + { |
| 29 | + var systeminfocomponents = new List<SystemInfoComponentEntryDto>(); |
| 30 | + var systeminfohealth = new List<SystemInfoHealthEntryDto>(); |
| 31 | + var systeminfoversions = new List<SystemInfoVersionEntryDto>(); |
| 32 | + |
| 33 | + AppDomain currentDomain = AppDomain.CurrentDomain; |
| 34 | + Assembly[] assems = currentDomain.GetAssemblies(); |
| 35 | + foreach (Assembly assem in assems) |
| 36 | + { |
| 37 | + systeminfocomponents.Add(new SystemInfoComponentEntryDto(assem.ManifestModule.Name, assem.ToString())); |
| 38 | + } |
| 39 | + |
| 40 | + systeminfoversions.Add(new SystemInfoVersionEntryDto("NETEVENT", Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion)); |
| 41 | + systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDNODE")); |
| 42 | + systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDID")); |
| 43 | + systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("BUILDNUMBER")); |
| 44 | + systeminfoversions.Add(CreateSystemInfoVersionEntryFromEnv("SOURCE_COMMIT")); |
| 45 | + |
| 46 | + // TODO: think about healthchecks and healthcheck modularity (to perform checks on various services like game servers, the mail server, payment apis ...) and remove dummy services |
| 47 | + systeminfohealth.Add(new SystemInfoHealthEntryDto("NETEVENT Server", string.Empty, true)); |
| 48 | + systeminfohealth.Add(new SystemInfoHealthEntryDto("Email Service", "servername", false)); |
| 49 | + |
| 50 | + var systeminfo = new SystemInfoDto(systeminfocomponents, systeminfohealth, systeminfoversions); |
| 51 | + |
| 52 | + // TODO: remove localizer as soon as it is implemented somewhere where it makes sense |
| 53 | + Console.WriteLine(_Localizer["test.test"]); |
| 54 | + |
| 55 | + return Task.FromResult(new Response(systeminfo)); |
| 56 | + } |
| 57 | + |
| 58 | + private static SystemInfoVersionEntryDto CreateSystemInfoVersionEntryFromEnv(string envName) |
| 59 | + { |
| 60 | + return new SystemInfoVersionEntryDto(envName, string.IsNullOrEmpty(Environment.GetEnvironmentVariable(envName)) ? "dev" : Environment.GetEnvironmentVariable(envName)); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + public sealed class Request : IRequest<Response> |
| 65 | + { |
| 66 | + public Request() |
| 67 | + { |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public sealed class Response : ResponseBase<SystemInfoDto> |
| 72 | + { |
| 73 | + public Response(SystemInfoDto value) : base(value) |
| 74 | + { |
| 75 | + } |
| 76 | + |
| 77 | + public Response(ReturnType returnType, string error) : base(returnType, error) |
| 78 | + { |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments