|
|
@ -19,7 +19,7 @@ namespace JXSoft { |
|
|
|
public Color printColor = Color.white; |
|
|
|
public Color printColor = Color.white; |
|
|
|
|
|
|
|
|
|
|
|
#region ReceiveFunctions |
|
|
|
#region ReceiveFunctions |
|
|
|
public void receiveResponse<T>(string json) where T : IResponse, new() |
|
|
|
public void receiveResponse<T>(string protocolData) where T : IResponse, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
//如果找不到对应命令,则添加命令 |
|
|
|
//如果找不到对应命令,则添加命令 |
|
|
|
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null) |
|
|
|
if (mCommandContainer.Get<ExcuteResponseCommand<T>>() == null) |
|
|
@ -27,7 +27,7 @@ namespace JXSoft { |
|
|
|
mCommandContainer.Register(new ExcuteResponseCommand<T>(new T())); |
|
|
|
mCommandContainer.Register(new ExcuteResponseCommand<T>(new T())); |
|
|
|
} |
|
|
|
} |
|
|
|
//找到命令后添加命令 |
|
|
|
//找到命令后添加命令 |
|
|
|
mCommandContainer.Get<ExcuteResponseCommand<T>>().setJson(json); |
|
|
|
mCommandContainer.Get<ExcuteResponseCommand<T>>().setProtocolData(protocolData); |
|
|
|
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>()); |
|
|
|
this.SendCommand(mCommandContainer.Get<ExcuteResponseCommand<T>>()); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -97,7 +97,7 @@ namespace JXSoft { |
|
|
|
/// <typeparam name="TResponse">响应数据格式</typeparam> |
|
|
|
/// <typeparam name="TResponse">响应数据格式</typeparam> |
|
|
|
public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse : IResponse |
|
|
|
public class ExcuteResponseCommand<TResponse> : AbstractCommand where TResponse : IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string json; |
|
|
|
public string protocolData; |
|
|
|
private TResponse response; |
|
|
|
private TResponse response; |
|
|
|
private Color printColor = Color.white; |
|
|
|
private Color printColor = Color.white; |
|
|
|
public ExcuteResponseCommand(TResponse response) |
|
|
|
public ExcuteResponseCommand(TResponse response) |
|
|
@ -109,7 +109,7 @@ namespace JXSoft { |
|
|
|
} |
|
|
|
} |
|
|
|
protected override void OnExecute() |
|
|
|
protected override void OnExecute() |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool isSet = response.trySetData(json); |
|
|
|
bool isSet = response.trySetData(protocolData); |
|
|
|
if (isSet) |
|
|
|
if (isSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (response.toProtocolData() != "") { |
|
|
|
if (response.toProtocolData() != "") { |
|
|
@ -118,9 +118,9 @@ namespace JXSoft { |
|
|
|
this.SendEvent(new ResponseMsgEvent(response)); |
|
|
|
this.SendEvent(new ResponseMsgEvent(response)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public void setJson(string json) |
|
|
|
public void setProtocolData(string protocolData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.json = json; |
|
|
|
this.protocolData = protocolData; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -150,7 +150,7 @@ namespace JXSoft { |
|
|
|
public interface IResponse |
|
|
|
public interface IResponse |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// 此处用于截获接收到的数据,建议作为调试依据 |
|
|
|
/// 可以用于打印调试信息 |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
string toProtocolData(); |
|
|
|
string toProtocolData(); |
|
|
@ -244,6 +244,38 @@ namespace JXSoft { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 用于扩展类型结构 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
public static class IResponseExtention { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static bool isTypeOfJson(this IResponse self, string json) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
JsonData protocolData = new JsonData(); |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
protocolData = JsonMapper.ToObject(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JsonData classData = JsonMapper.ToObject(JsonMapper.ToJson(self)); |
|
|
|
|
|
|
|
if (protocolData.Keys.Count != classData.Keys.Count) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach (string key in classData.Keys) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!protocolData.ContainsKey(key)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region event |
|
|
|
#region event |
|
|
|