feat: Completed early communication testing.

data-table has serious performance problem.
This commit is contained in:
real-zony
2022-10-06 21:35:55 +08:00
parent 6554be6b6d
commit a11ef70021
9 changed files with 102 additions and 46 deletions

View File

@@ -30,7 +30,7 @@ WebApplication? RegisterAndConfigureServices()
insideApp.UseAuthorization();
insideApp.MapControllers();
insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
// insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
return insideApp;
}

View File

@@ -1,4 +1,5 @@
using SuperSocket.WebSocket.Server;
using Newtonsoft.Json;
using SuperSocket.WebSocket.Server;
namespace ZonyLrcTools.LocalServer;
@@ -7,9 +8,65 @@ public class SuperSocketListener
public async Task ListenAsync()
{
var host = WebSocketHostBuilder.Create()
.UseWebSocketMessageHandler(async (session, message) => { await session.SendAsync(message.Message); })
.UseWebSocketMessageHandler(async (session, message) =>
{
await session.SendAsync(JsonConvert.SerializeObject(new CommunicateEvent<OutputEvent>
{
Action = "output",
Type = ActionType.ResponseAction,
Data = new OutputEvent()
}));
for (int index = 0; index < 50; index++)
{
var data = new List<GetFileInfoEvent>();
for (int j = 0; j < 500; j++)
{
data.Add(new GetFileInfoEvent
{
Name = j.ToString(),
Size = j.ToString()
});
}
await session.SendAsync(JsonConvert.SerializeObject(new CommunicateEvent<List<GetFileInfoEvent>>
{
Action = "getFileInfo",
Type = ActionType.ResponseAction,
Data = data
}));
}
await Task.Delay(100);
})
.Build();
await host.StartAsync();
}
}
public class CommunicateEvent<T> where T : class
{
[JsonProperty("action")] public string? Action { get; set; }
[JsonProperty("type")] public ActionType Type { get; set; }
[JsonProperty("data")] public T? Data { get; set; }
}
public class OutputEvent
{
[JsonProperty("text")] public string Text => DateTime.Now.ToString("HH:mm:ss");
}
public class GetFileInfoEvent
{
[JsonProperty("name")] public string Name { get; set; }
[JsonProperty("size")] public string Size { get; set; }
}
public enum ActionType
{
RequestAction,
ResponseAction
}

View File

@@ -25,6 +25,10 @@
<EmbeddedResource Include="UiStaticResources\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj" />
</ItemGroup>
<!-- <ItemGroup>-->
<!-- <ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />-->
<!-- </ItemGroup>-->