diff --git a/ReservoirServer/BoxStateReporter.cs b/ReservoirServer/BoxStateReporter.cs index a45ca1c..3480eb2 100644 --- a/ReservoirServer/BoxStateReporter.cs +++ b/ReservoirServer/BoxStateReporter.cs @@ -61,9 +61,10 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e) private void Report(KeyValuePair val) { + Box box = val.Value; try { - Box box = val.Value; + DateTime now = DateTime.Now; box.locker.EnterWriteLock(); @@ -99,6 +100,11 @@ private void Report(KeyValuePair val) { Console.Error.WriteLine(ex.ToString()); } + finally + { + box.locker.ExitWriteLock(); + box.locker.ExitReadLock(); + } } diff --git a/ReservoirServer/Enterty/SimpleBoxData.cs b/ReservoirServer/Enterty/SimpleBoxData.cs index 42f1739..eeba7ec 100644 --- a/ReservoirServer/Enterty/SimpleBoxData.cs +++ b/ReservoirServer/Enterty/SimpleBoxData.cs @@ -9,11 +9,17 @@ class SimpleBoxData : IBoxData public string PlatformN { get; set; } public string DeviceN { get; set; } public string Type { get; set; } + public object Message { get; set; } } + class BoxDataWithDate : SimpleBoxData + { + public DateTime @DateTime; + } + class BoxDataHeartBeat : IBoxData { public string PlatformN { get; set; } diff --git a/ReservoirServer/GlobalConfig.cs b/ReservoirServer/GlobalConfig.cs index ada6047..d3dcb88 100644 --- a/ReservoirServer/GlobalConfig.cs +++ b/ReservoirServer/GlobalConfig.cs @@ -21,6 +21,7 @@ static class GlobalConfig public static string TopicName => ini.GetValue("activemq", "topicname"); public static byte ReporterMaxCoreUsage => (byte)ini.GetInteger("reporter", "maxcoreusage"); public static int ReportInterval => ini.GetInteger("reporter", "reportinterval"); + public static string BoxServerCharset=> ini.GetValue("boxserver", "charset"); public static void ParseConfigFile(string fname) { diff --git a/ReservoirServer/Program.cs b/ReservoirServer/Program.cs index 4371fa5..fdea062 100644 --- a/ReservoirServer/Program.cs +++ b/ReservoirServer/Program.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; @@ -15,7 +16,7 @@ namespace ReservoirServer class Program { //TODO: Log file, Safety(Encryption), JSON error catch, system service - public static readonly string version = "1.05"; + public static readonly string version = "1.06"; #if DEBUG public static string VERSION => version + "a"; @@ -32,6 +33,7 @@ class Program static void Main(string[] args) { CommandParser cmd = new CommandParser(args); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); string inipath = null; bool ver = false; cmd.Parse(out inipath, out logpath, out ver); diff --git a/ReservoirServer/SimpleBoxAdapter.cs b/ReservoirServer/SimpleBoxAdapter.cs index 17327bd..212e7c0 100644 --- a/ReservoirServer/SimpleBoxAdapter.cs +++ b/ReservoirServer/SimpleBoxAdapter.cs @@ -92,11 +92,12 @@ public void SimpleBoxDataReportHandler(string data) public void SimpleBoxDataSubscribeHandler(string json) { SimpleSubscribeData subdata = JsonConvert.DeserializeObject(json); - SimpleBoxData boxdata = new SimpleBoxData() + SimpleBoxData boxdata = new BoxDataWithDate() { Type = subdata.Type, Message = subdata.Message, PlatformN = subdata.PlatformN, + DateTime = subdata.DateTime, }; foreach (string bid in subdata.DeviceN) @@ -105,7 +106,7 @@ public void SimpleBoxDataSubscribeHandler(string json) if (box != null) { boxdata.DeviceN = bid; - string senddata = JsonConvert.SerializeObject(boxdata); + string senddata = JsonConvert.SerializeObject(boxdata, jsonSettings); box.locker.EnterReadLock(); var client = box.ComClient; box.locker.ExitReadLock(); diff --git a/ReservoirServer/SimpleBoxServer.cs b/ReservoirServer/SimpleBoxServer.cs index 6224b43..8cb49dd 100644 --- a/ReservoirServer/SimpleBoxServer.cs +++ b/ReservoirServer/SimpleBoxServer.cs @@ -14,6 +14,7 @@ namespace ReservoirServer public delegate void OnBoxDisconnectedDlg(IComClient client); public delegate void OnBoxDataRecDlg(IComClient client, string data); + class SimpleBoxServer { BoxTCPDriver tcpserver = new BoxTCPDriver(); @@ -23,6 +24,8 @@ class SimpleBoxServer public virtual event OnBoxDisconnectedDlg OnBoxDisconnected; public virtual event OnBoxDataRecDlg OnBoxDataRec; + private string _charset = GlobalConfig.BoxServerCharset; + public SimpleBoxServer(string serverID, IPAddress ip, ushort port) { this.PlatformID = serverID; @@ -37,7 +40,7 @@ public SimpleBoxServer(string serverID, IPAddress ip, ushort port) public virtual void SendPack(IComClient client,string data) { - tcpserver.SendDataAsync(client, Encoding.UTF8.GetBytes(data)); + tcpserver.SendDataAsync(client, Encoding.GetEncoding(_charset).GetBytes(data)); } protected virtual void Tcpserver_OnTransmitError(IComClient client, Exception ex) @@ -47,7 +50,7 @@ protected virtual void Tcpserver_OnTransmitError(IComClient client, Exception ex protected virtual void Tcpserver_OnComDataReceived(IComClient client, byte[] data) { - string s = Encoding.UTF8.GetString(data); + string s = Encoding.GetEncoding(_charset).GetString(data); OnBoxDataRec?.Invoke(client, s); }