Refactor/Fix: Standardize Dialog Themes & Fix WebSocket Fragmentation. Detail: UserInfoDialog design refresh, standardized all dialogs, fixed backend WebSocketServer fragmentation bug.
This commit is contained in:
58
Project/Web/MachineBridge/MachineBridge.Settings.cs
Normal file
58
Project/Web/MachineBridge/MachineBridge.Settings.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Project;
|
||||
|
||||
namespace Project.Web
|
||||
{
|
||||
public partial class MachineBridge
|
||||
{
|
||||
public string GetSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonConvert.SerializeObject(Pub.setting);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return JsonConvert.SerializeObject(new { Error = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
public string SaveSettings(string jsonSettings)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonSettings))
|
||||
{
|
||||
return JsonConvert.SerializeObject(new { Success = false, Message = "Empty settings data" });
|
||||
}
|
||||
|
||||
var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonSettings);
|
||||
|
||||
// Update properties using reflection or manual mapping
|
||||
// Since Setting class inherits arUtil.Setting and might have complex types, manual mapping for known properties or generic reflection is better.
|
||||
// For now, let's target 'Theme' specifically as requested, and generic handling for others if possible?
|
||||
// Actually, Pub.setting is an instance. We can try to deserialize INTO it, or update properties.
|
||||
|
||||
if (dict.ContainsKey("Theme"))
|
||||
{
|
||||
Pub.setting.Theme = dict["Theme"]?.ToString();
|
||||
}
|
||||
|
||||
// Add other setting properties here as needed in the future
|
||||
// or implement a generic property updater
|
||||
|
||||
Pub.setting.Save(); // Save to XML
|
||||
|
||||
return JsonConvert.SerializeObject(new { Success = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return JsonConvert.SerializeObject(new { Success = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,14 +124,23 @@ namespace Project.Web
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
if (result.MessageType == WebSocketMessageType.Close)
|
||||
List<byte> messageBytes = new List<byte>();
|
||||
WebSocketReceiveResult result;
|
||||
do
|
||||
{
|
||||
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", CancellationToken.None);
|
||||
result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
if (result.MessageType == WebSocketMessageType.Close)
|
||||
{
|
||||
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", CancellationToken.None);
|
||||
return;
|
||||
}
|
||||
messageBytes.AddRange(new ArraySegment<byte>(buffer, 0, result.Count));
|
||||
}
|
||||
else if (result.MessageType == WebSocketMessageType.Text)
|
||||
while (!result.EndOfMessage);
|
||||
|
||||
if (result.MessageType == WebSocketMessageType.Text)
|
||||
{
|
||||
string msg = Encoding.UTF8.GetString(buffer, 0, result.Count);
|
||||
string msg = Encoding.UTF8.GetString(messageBytes.ToArray());
|
||||
await HandleMessage(msg, socket);
|
||||
}
|
||||
}
|
||||
@@ -551,7 +560,7 @@ namespace Project.Web
|
||||
|
||||
case "USERLIST_GET_LIST":
|
||||
{
|
||||
string process = json.process ?? "%";
|
||||
string process = json.process ?? string.Empty;
|
||||
string result = _bridge.UserList_GetList(process);
|
||||
var response = new { type = "USERLIST_LIST_DATA", data = JsonConvert.DeserializeObject(result) };
|
||||
await Send(socket, JsonConvert.SerializeObject(response));
|
||||
@@ -725,6 +734,25 @@ namespace Project.Web
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
// ===== Settings API =====
|
||||
case "GET_SETTINGS":
|
||||
{
|
||||
string result = _bridge.GetSettings();
|
||||
var response = new { type = "SETTINGS_DATA", data = JsonConvert.DeserializeObject(result) };
|
||||
await Send(socket, JsonConvert.SerializeObject(response));
|
||||
}
|
||||
break;
|
||||
|
||||
case "SAVE_SETTINGS":
|
||||
{
|
||||
string settingsData = JsonConvert.SerializeObject(json.settings);
|
||||
string result = _bridge.SaveSettings(settingsData);
|
||||
var response = new { type = "SETTINGS_SAVED", data = JsonConvert.DeserializeObject(result) };
|
||||
await Send(socket, JsonConvert.SerializeObject(response));
|
||||
}
|
||||
break;
|
||||
|
||||
// ===== Kuntae API =====
|
||||
case "GET_KUNTAE_LIST":
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user