private object invokeProxy(DirectRequest dr, System.Web.HttpContext ctx = null) { NHExt.Runtime.Proxy.AgentInvoker invoker = null; Logger.LoggerInstance.RuntimeLogger.Info("创建服务实例对象"); try { invoker = new Proxy.AgentInvoker(); invoker.IsTask = dr.IsTask; invoker.DllName = dr.Assembly; invoker.AssemblyName = dr.Action; invoker.SourcePage = dr.SourcePage; Logger.LoggerInstance.RuntimeLogger.Info("初始化服务参数"); foreach (JToken token in dr.Args) { JProperty jp = token as JProperty; if (token.Type != JTokenType.Null) { invoker.AppendField(new Proxy.PropertyField() { FieldName = jp.Name, FieldValue = jp }); } } } catch { NHExt.Runtime.Exceptions.RuntimeException ex = new NHExt.Runtime.Exceptions.RuntimeException("初始化服务参数失败,服务名称:" + invoker.AssemblyName); throw ex; } object obj = null; if (invoker != null) { Logger.LoggerHelper.Info("开始调用服务代理Do方法"); this.BeforeInvokeProxy(invoker, dr, ctx); obj = invoker.Do(); this.AfterInvokeProxy(invoker, obj, ctx); Logger.LoggerHelper.Info("调用服务代理Do方法成功,开始返回返回值"); } return obj; }
protected virtual void BeforeInvokeProxy(NHExt.Runtime.Proxy.AgentInvoker invoker, DirectRequest dr, HttpContext ctx) { }
protected virtual void CreateAgentParameterExtend(Model.IBizAgent agent, DirectRequest dr) { }
protected virtual void ValidateDirectParameter(DirectRequest req) { if (string.IsNullOrEmpty(req.Action)) { throw new NHExt.Runtime.Exceptions.RuntimeException("调用服务名称不能为空"); } if (string.IsNullOrEmpty(req.Assembly)) { throw new NHExt.Runtime.Exceptions.RuntimeException("调用程序集不能为空"); } }
protected virtual void CreateDirectParameterExtend(DirectRequest req, NameValueCollection nvc) { }
protected virtual DirectRequest CreateDirectParameter(DirectRequest req, NameValueCollection nvc) { string asyncTask = nvc["async"]; if (!string.IsNullOrEmpty(asyncTask)) { req.IsTask = true; } string uiActionName = nvc["action"].Trim(); string uiAssembly = uiActionName.Substring(0, uiActionName.LastIndexOf(".")); string strArgs = nvc["args"]; if (string.IsNullOrEmpty(strArgs)) { strArgs = "{}"; } JToken jToken = JToken.Parse(strArgs); //这个里面添加的肯定都是属性 foreach (JToken t in jToken.Children()) { req.Args.Add(t); } req.Action = uiActionName; req.Assembly = uiAssembly + ".dll"; this.CreateDirectParameterExtend(req, nvc); this.ValidateDirectParameter(req); Logger.LoggerInstance.RuntimeLogger.Info("请求解析完成action:" + req.Action + "程序集为:" + req.Assembly); return req; }