From e5a22ece90e20d0c3f6907319b2b098b0fcfd76b Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Sat, 9 Jul 2022 21:26:39 +0800 Subject: [PATCH] Use locally compiled new version of EmbedIO Remove backports Skip trimming of FilterOperator and FilterDefinition --- .../GC-local-server-rewrite.csproj | 4 +- .../backports/CustomResponseSerializer.cs | 74 ------------------- .../backports/JsonDataAttribute.cs | 41 ---------- GC-local-server-rewrite/server/Server.cs | 36 +++------ MudAdmin/ILLink.Descriptors.xml | 12 +++ MudAdmin/MudAdmin.csproj | 17 ++++- MudAdmin/Pages/User.razor | 2 +- SharedProject/models/Navigator.cs | 4 + 8 files changed, 42 insertions(+), 148 deletions(-) delete mode 100644 GC-local-server-rewrite/backports/CustomResponseSerializer.cs delete mode 100644 GC-local-server-rewrite/backports/JsonDataAttribute.cs create mode 100644 MudAdmin/ILLink.Descriptors.xml diff --git a/GC-local-server-rewrite/GC-local-server-rewrite.csproj b/GC-local-server-rewrite/GC-local-server-rewrite.csproj index abbc67a..5f2f0cc 100644 --- a/GC-local-server-rewrite/GC-local-server-rewrite.csproj +++ b/GC-local-server-rewrite/GC-local-server-rewrite.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/GC-local-server-rewrite/backports/CustomResponseSerializer.cs b/GC-local-server-rewrite/backports/CustomResponseSerializer.cs deleted file mode 100644 index d6de2ab..0000000 --- a/GC-local-server-rewrite/backports/CustomResponseSerializer.cs +++ /dev/null @@ -1,74 +0,0 @@ -using EmbedIO; - -namespace GCLocalServerRewrite.backports; - -/// -/// Provides custom response serializer callbacks. -/// -public static class CustomResponseSerializer -{ - private static readonly ResponseSerializerCallback CHUNKED_ENCODING_BASE_SERIALIZER = GetBaseSerializer(false); - private static readonly ResponseSerializerCallback BUFFERING_BASE_SERIALIZER = GetBaseSerializer(true); - - /// - /// Sends data in a HTTP response without serialization. - /// - /// - /// to write the response body to a memory buffer first, - /// then send it all together with a Content-Length header; to use chunked - /// transfer encoding. - /// - /// A that can be used to serialize data to a HTTP response. - /// - /// - /// s and one-dimensional arrays of s - /// are sent to the client unchanged; every other type is converted to a string. - /// - /// - /// The ContentType set on the response is used to negotiate - /// a compression method, according to request headers. - /// - /// - /// Strings (and other types converted to strings) are sent with the encoding specified by - /// . - /// - /// - public static ResponseSerializerCallback None(bool bufferResponse) - { - return bufferResponse ? BUFFERING_BASE_SERIALIZER : CHUNKED_ENCODING_BASE_SERIALIZER; - } - - private static ResponseSerializerCallback GetBaseSerializer(bool bufferResponse) - { - return async (context, data) => - { - if (data is null) - { - return; - } - - var isBinaryResponse = data is byte[]; - - if (!context.TryDetermineCompression(context.Response.ContentType, out var preferCompression)) - { - preferCompression = true; - } - - preferCompression = false; - - if (isBinaryResponse) - { - var responseBytes = (byte[])data; - using var stream = context.OpenResponseStream(bufferResponse, preferCompression); - await stream.WriteAsync(responseBytes).ConfigureAwait(false); - } - else - { - var responseString = data is string stringData ? stringData : data.ToString() ?? string.Empty; - await using var text = context.OpenResponseText(context.Response.ContentEncoding, bufferResponse, - preferCompression); - await text.WriteAsync(responseString).ConfigureAwait(false); - } - }; - } -} \ No newline at end of file diff --git a/GC-local-server-rewrite/backports/JsonDataAttribute.cs b/GC-local-server-rewrite/backports/JsonDataAttribute.cs deleted file mode 100644 index f14696f..0000000 --- a/GC-local-server-rewrite/backports/JsonDataAttribute.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace EmbedIO.WebApi -{ - /// - /// Specifies that a parameter of a controller method will receive - /// an object obtained by deserializing the request body as JSON. - /// The received object will be - /// only if the deserialized object is null. - /// If the request body is not valid JSON, - /// or if it cannot be deserialized to the type of the parameter, - /// a 400 Bad Request response will be sent to the client. - /// This class cannot be inherited. - /// - /// - /// - [AttributeUsage(AttributeTargets.Parameter)] - public class JsonDataAttribute : Attribute, IRequestDataAttribute - { - /// - public async Task GetRequestDataAsync(WebApiController controller, Type type, string parameterName) - { - string body; - - using (var reader = controller.HttpContext.OpenRequestText()) - { - body = await reader.ReadToEndAsync().ConfigureAwait(false); - } - - try - { - return Swan.Formatters.Json.Deserialize(body, type); - } - catch (FormatException) - { - throw HttpException.BadRequest($"Expected request body to be deserializable to {type.FullName}."); - } - } - } -} \ No newline at end of file diff --git a/GC-local-server-rewrite/server/Server.cs b/GC-local-server-rewrite/server/Server.cs index b3808ef..1336012 100644 --- a/GC-local-server-rewrite/server/Server.cs +++ b/GC-local-server-rewrite/server/Server.cs @@ -2,7 +2,6 @@ using EmbedIO.Actions; using EmbedIO.Files; using EmbedIO.WebApi; -using GCLocalServerRewrite.backports; using GCLocalServerRewrite.common; using GCLocalServerRewrite.controllers; using GCLocalServerRewrite.models; @@ -25,23 +24,23 @@ public class Server .WithLocalSessionManager() .WithCors() .WithWebApi(Configs.API_BASE_ROUTE, module => module.WithController()) - .WithWebApi(Configs.CARD_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.CARD_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.OPTION_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.OPTION_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.UPLOAD_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.UPLOAD_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.RESPONE_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.RESPONE_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.INCOM_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.INCOM_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.ALIVE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.ALIVE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.SERVER_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.SERVER_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.RANK_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.RANK_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) - .WithWebApi(Configs.UPDATE_SERVICE_BASE_ROUTE, CustomResponseSerializer.None(true), + .WithWebApi(Configs.UPDATE_SERVICE_BASE_ROUTE, ResponseSerializer.None(true), module => module.WithController()) .WithStaticFolder(Configs.STATIC_BASE_ROUTE, PathHelper.HtmlRootPath, true, m => m .WithContentCaching(Configs.USE_FILE_CACHE)) @@ -65,23 +64,6 @@ public class Server server.AddCustomMimeType(".wasm", "application/wasm"); server.AddCustomMimeType(".woff", "application/font-woff"); server.AddCustomMimeType(".woff2", "application/font-woff2"); - server.HandleHttpException(async (context, exception) => - { - context.Response.StatusCode = exception.StatusCode; - - switch (exception.StatusCode) - { - case 404: - var htmlContents = await File.ReadAllTextAsync(Path.Combine(PathHelper.HtmlRootPath, "index.html")); - await context.SendStringAsync(htmlContents, "text/html", Encoding.UTF8); - - break; - default: - await HttpExceptionHandler.Default(context, exception); - - break; - } - }); // Listen for state changes. server.StateChanged += (_, e) => $"WebServer New State - {e.NewState}".Info(); diff --git a/MudAdmin/ILLink.Descriptors.xml b/MudAdmin/ILLink.Descriptors.xml new file mode 100644 index 0000000..6e50d85 --- /dev/null +++ b/MudAdmin/ILLink.Descriptors.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/MudAdmin/MudAdmin.csproj b/MudAdmin/MudAdmin.csproj index ab96994..c7a056c 100644 --- a/MudAdmin/MudAdmin.csproj +++ b/MudAdmin/MudAdmin.csproj @@ -5,6 +5,7 @@ enable enable false + true @@ -20,11 +21,21 @@ false + + + + + + + ILLink.Descriptors.xml + + + - - - + + + diff --git a/MudAdmin/Pages/User.razor b/MudAdmin/Pages/User.razor index 110151f..b87ba8e 100644 --- a/MudAdmin/Pages/User.razor +++ b/MudAdmin/Pages/User.razor @@ -100,7 +100,7 @@ else - diff --git a/SharedProject/models/Navigator.cs b/SharedProject/models/Navigator.cs index ede9246..14128dc 100644 --- a/SharedProject/models/Navigator.cs +++ b/SharedProject/models/Navigator.cs @@ -32,6 +32,10 @@ public class Navigator [ProtoMember(9)] public string? ToolTipEn { get; set; } + + [ProtoIgnore] + public string? NameEntryString => NameEntry0?.ToString(); + public override string ToString() { return $"{Id}: {NameEntry1?.NameWithVariant}, {NameEntry1?.IllustrationCredit}"; }