internal void CallMethod(string className, string methodName) { var requestMethod = request.HttpMethod; var obj = assembly.CreateInstance(String.Format("{0}.{1}", nameSpace, className)); if (obj != null) { MethodInfo method = obj.GetType().GetMethod(String.Format("{0}_{1}", methodName, requestMethod), BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (method != null) { if (method.ReturnType == typeof(String)) { response.Write(method.Invoke(obj, null) as String); } else { method.Invoke(obj, null); } if (requestMethod == "POST") { CmsCacheUtility.EvalCacheUpdate <MCacheUpdateAttribute>(method); //清理缓存 } return; } } OutputInternalError(className, methodName, requestMethod); }
internal static Task CallMethod(ICompatibleHttpContext context, Type typeName, string methodName) { var requestMethod = context.Request.Method(); var obj = assembly.CreateInstance($"{typeName.FullName}"); if (obj != null) { if (requestMethod != "GET") { methodName += "_" + requestMethod; } var method = obj.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (method != null) { Task task = null; if (method.ReturnType == typeof(Task)) { task = method.Invoke(obj, new object[] { context }) as Task; } else if (method.ReturnType == typeof(string)) { task = context.Response.WriteAsync(method.Invoke(obj, null) as string); } else if (method.ReturnType == typeof(void)) { method.Invoke(obj, null); task = SafetyTask.CompletedTask; } else { var result = method.Invoke(obj, null); task = context.Response.WriteAsync(JsonConvert.SerializeObject(result)); } if (requestMethod == "POST") { CmsCacheUtility.EvalCacheUpdate <MCacheUpdateAttribute>(method); //清理缓存 } return(task); } } return(OutputInternalError(context, typeName.FullName, methodName, requestMethod)); }
internal void CallMethod(string className, string methodName) { string requestMethod; //请求方式 object obj; //创建的模块类 requestMethod = request.HttpMethod; obj = assembly.CreateInstance(String.Format("{0}.{1}", nameSpace, className)); MethodInfo method = obj.GetType().GetMethod(String.Format("{0}_{1}", methodName, requestMethod), BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (method != null) { if (method.ReturnType == typeof(String)) { response.Write(method.Invoke(obj, null) as String); } else { method.Invoke(obj, null); } CmsCacheUtility.EvalCacheUpdate <MCacheUpdateAttribute>(method); } else { string tpl = @" <div style=""font-size:12px;text-align:center;padding:10px;""> <h3>访问的页面出错,代码:502</h3> <strong>这可能因为当前系统版本不支持此功能!</strong><br /> 相关信息:{0}</div> "; response.Write( String.Format(tpl, className + "/" + methodName + "/" + requestMethod)); // OnError("操作未定义!"+className+"/"+methodName); response.End(); response.StatusCode = 500; } }