public static void Receive(string message) { try { MessageStruct ms = JsonConvert.DeserializeObject <MessageStruct>(message); switch (ms.type) { case MessageType.setting: SettingsManager.Deal(ms.content); break; case MessageType.action: ActionManager.Deal(ms.content); break; case MessageType.nursery: NurseryManager.Deal(ms.content); break; case MessageType.logging: LoggingManager.Deal(ms.content); break; default: LoggingManager.Warn("Invalid message type"); break; } } catch (JsonException e) { LoggingManager.Warn($"Deserialize MessageSettingStruct failed:{e.Message}"); } }
public static void Deal(string message) { bool success = JsonUtil.ParseStruct(message, out MessageStruct ms); if (success) { switch (ms.type) { case MessageType.setting: SettingsManager.Deal(ms.content); break; case MessageType.action: ActionManager.Deal(ms.content); break; case MessageType.nursery: NurseryManager.Deal(ms.content); break; //case MessageType.log: break; default: LogClerk.Error("Invalid message type"); break; } } }