Skip to content

Commit

Permalink
aot发布支持
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Sep 20, 2022
1 parent ef4ebf7 commit bd70867
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions FastGithub.Configuration/TypeConverterBinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace FastGithub.Configuration
Expand All @@ -18,7 +19,7 @@ static class TypeConverterBinder
/// <typeparam name="T"></typeparam>
/// <param name="reader"></param>
/// <param name="writer"></param>
public static void Bind<T>(Func<string, T?> reader, Func<T?, string?> writer)
public static void Bind<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(Func<string, T?> reader, Func<T?, string?> writer)
{
binders[typeof(T)] = new Binder<T>(reader, writer);

Expand All @@ -37,7 +38,7 @@ private abstract class Binder
}


private class Binder<T> : Binder
private class Binder<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : Binder
{
private readonly Func<string, T?> reader;
private readonly Func<T?, string?> writer;
Expand All @@ -60,7 +61,7 @@ public Binder(Func<string, T?> reader, Func<T?, string?> writer)
}


private class TypeConverter<T> : TypeConverter
private class TypeConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
Expand Down
9 changes: 9 additions & 0 deletions FastGithub.FlowAnalyze/FlowStatisticsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace FastGithub.FlowAnalyze
{
[JsonSerializable(typeof(FlowStatistics))]
public partial class FlowStatisticsContext : JsonSerializerContext
{
}
}
6 changes: 3 additions & 3 deletions FastGithub/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/// <summary>
/// app选项
/// </summary>
public class AppOptions
public record AppOptions
{
/// <summary>
/// 父进程id
/// </summary>
public int ParentProcessId { get; set; }
public int ParentProcessId { get; init; }

/// <summary>
/// udp日志服务器端口
/// </summary>
public int UdpLoggerPort { get; set; }
public int UdpLoggerPort { get; init; }
}
}
7 changes: 6 additions & 1 deletion FastGithub/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
using Serilog;
using Serilog.Sinks.Network;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Text.Json;

namespace FastGithub
{
Expand Down Expand Up @@ -87,6 +90,7 @@ public static void ConfigureConfiguration(this WebApplicationBuilder builder)
/// 配置服务
/// </summary>
/// <param name="builder"></param>
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary<string, DomainConfig>))]
public static void ConfigureServices(this WebApplicationBuilder builder)
{
var services = builder.Services;
Expand Down Expand Up @@ -124,7 +128,8 @@ public static void ConfigureApp(this WebApplication app)
app.MapGet("/flowStatistics", context =>
{
var flowStatistics = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowStatistics();
return context.Response.WriteAsJsonAsync(flowStatistics);
var json = JsonSerializer.Serialize(flowStatistics, FlowStatisticsContext.Default.FlowStatistics);
return context.Response.WriteAsync(json);
});
}
}
Expand Down

0 comments on commit bd70867

Please sign in to comment.