public override void OnSendMvcParameters() { try { while (SendParameters.Count > 0) { TmParameter mvc = SendParameters.Dequeue(); ///用Json将参数(MvcParameter),序列化转换成字符串(string) string mvcJsons = TmJson.ToString <TmParameter>(mvc); if (TClient != null) { TClient.SendString(mvcJsons); } //else //{ // if (IsRunning) // { // IsRunning = false; // StartConnect(); // Console.WriteLine(TmTimerTool.CurrentTime() + " TClient is Null. new TClient() 重新连接。"); // } //} } } catch (Exception ex) { Console.WriteLine(TmTimerTool.CurrentTime() + " SendMvcParameters: " + ex.Message); } }
public override void OnSendMvcParameters() { try { while (SendParameters.Count > 0) { TmParameter mvc = SendParameters.Dequeue(); while (mvc.Keys.Count > 0) { TmTcpSession tpeer; TPeers.TryGetValue(mvc.Keys[0], out tpeer); ///用Json将参数(MvcParameter),序列化转换成字符串(string) string mvcJsons = TmJson.ToString <TmParameter>(mvc); if (tpeer != null) { tpeer.SendString(mvcJsons); } else { Console.WriteLine(TmTimerTool.CurrentTime() + " 没找TPeer,用Key: " + mvc.Keys[0]); break; } mvc.Keys.Remove(mvc.Keys[0]); } } } catch (Exception ex) { Console.WriteLine(TmTimerTool.CurrentTime() + " OnSendMvcParameters: " + ex.Message); } }
public static TmParameter ToJsonParameter <T>(TenCode ten, ElevenCode eleven, string key, T value) { TmParameter parameter = new TmParameter(); string json = TmJson.ToString <T>(value); parameter.TenCode = ten; parameter.ElevenCode = eleven; parameter.Parameters.Add(key, json); return(parameter); }
public static void AddJsonParameter <T>(TmParameter parameter, string key, T value) { object obj; bool yes = parameter.Parameters.TryGetValue(key, out obj); if (yes) { parameter.Parameters.Remove(key); } string json = TmJson.ToString <T>(value); parameter.Parameters.Add(key, json); }