private string CreateEditModel(JZ.Models.Test test) { PostSourceEntity model = new PostSourceEntity() { NameSpace = "JZ.Server", ClassName = "TestServer", FunctionName = "Update", Parameters = test.ToJson() }; return(model.ToJson()); }
private string CreateDeleteModel() { PostSourceEntity model = new PostSourceEntity() { NameSpace = "JZ.Server", ClassName = "TestServer", FunctionName = "DeleteByWhere", Parameters = "1=1" }; return(model.ToJson()); }
private string CreateAddModel() { JZ.Models.Test test = new Models.Test() { Value = Guid.NewGuid().ToString() }; PostSourceEntity model = new PostSourceEntity() { NameSpace = "JZ.Server", ClassName = "TestServer", FunctionName = "Insert", Parameters = test.ToJson() }; return(model.ToJson()); }
public string PostSource(string strJson) { try { if (string.IsNullOrEmpty(strJson)) { return("传入参数为空!"); } PostSourceEntity entity = strJson.ToJsonObject <PostSourceEntity>(); string str = string.Empty; str = JZ.Server.PublicServer.CallFunction(entity); return(str); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
private static void Rec(SocketHelper.Sockets sks) { if (sks.ex != null) { //string.Format("客户端出现异常:{0}.!", sks.ex.Message); } else { if (sks.NewClientFlag) { //string.Format("新客户端:{0}连接成功.!", sks.Ip) } else { byte[] buffer = new byte[sks.Offset]; Array.Copy(sks.RecBuffer, buffer, sks.Offset); string str = string.Empty; if (sks.Offset == 0) { str = "客户端下线"; } else { str = Encoding.UTF8.GetString(buffer); if (string.IsNullOrEmpty(str)) { server.SendToClient(sks.Ip, ExcuteMessage.Error("传入参数为空!")); return; } PostSourceEntity entity = str.ToJsonObject <PostSourceEntity>(); str = JZ.Server.PublicServer.CallFunction(entity); server.SendToClient(sks.Ip, str); } } } }
/// <summary> /// 功能描述:反射调用方法 /// </summary> /// <param name="source">source</param> /// <param name="action">推送广播</param> /// <returns>返回值</returns> public static string CallFunction(PostSourceEntity source) { try { Type type; if (string.IsNullOrEmpty(source.ClassTName)) { type = Assembly.Load("JZ.Server").GetType(string.Format("{0}.{1}", source.NameSpace, source.ClassName)); } else { type = Assembly.Load("JZ.Server").GetType(string.Format("{0}.{1}`1", source.NameSpace, source.ClassName)); Type typeArgument = Assembly.Load(source.TAssemblyName).GetType(source.ClassTName); // MakeGenericType is badly named type = type.MakeGenericType(typeArgument); } object obj = Activator.CreateInstance(type); if (obj == null) { return(ExcuteMessage.Error("没有找到指定的逻辑对象。")); } object[] parameters = null; MethodInfo method = null; if (source.Parameters != null) { method = type.GetMethod(source.FunctionName, new Type[] { typeof(string) }); parameters = new object[] { source.Parameters }; } else { method = type.GetMethod(source.FunctionName, new Type[] { }); } if (method == null) { return(ExcuteMessage.Error("没有找到指定的函数。")); } if (string.IsNullOrEmpty(source.MethodTName)) { object objReturn = method.Invoke(obj, parameters); if (objReturn != null) { return(objReturn.ToString()); } } else { object objReturn = method.MakeGenericMethod(new Type[] { Assembly.Load(source.TAssemblyName).GetType(source.ClassTName) }).Invoke(obj, parameters); if (objReturn != null) { return(objReturn.ToString()); } } return(""); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }