/// <summary> /// 处理客户端请求 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { string contextMethod = ""; #region 解码阶段 WebRequestDecoder decoder = null; try { decoder = WebRequestDecoder.CreateInstance(context); } catch (NotImplementedException) { decoder = this.OnDecodeResolve(context); if (decoder == null) { throw new NotSupportedException("无法为当前的请求提供适当的解码器"); } } contextMethod = decoder.LogicalMethod; #endregion #region 调用阶段 object result = this.Invoke(contextMethod, decoder.Deserialize()); ResponseAnnotationAttribute resAnn = this.GetAnnation(contextMethod); #endregion #region 编码阶段 WebResponseEncoder encoder = null; try { encoder = WebResponseEncoder.CreateInstance(context, resAnn.ResponseFormat); } catch (NotImplementedException) { encoder = this.OnEncoderResolve(context, contextMethod, resAnn); if (encoder == null) { throw new NotSupportedException("无法为当前的请求提供适当的编码器"); } } #region 处理化自定义的序列化机制 OnSerializeHandler handler = this.OnGetCustomerSerializer(contextMethod); if (handler != null) { encoder.OnSerialize += handler; } #endregion #endregion #region 回复阶段 encoder.Write(result); InitializeCachePolicy(context, resAnn); #endregion }
/// <summary> /// /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { #region 获取所有的方法 //IPermissionDataAccess permissionDataAccess = new PermissionDataAccess(); //var methods = this.GetType().GetMethods(); //foreach (MethodInfo method in methods) //{ // ResponseAnnotationAttribute[] resAnns = (ResponseAnnotationAttribute[])method.GetCustomAttributes(typeof(ResponseAnnotationAttribute), false); // ResponseAnnotationAttribute ann = null; // ann = resAnns.Length == 0 ? ResponseAnnotationAttribute.Default : resAnns[0]; // ann = (ann as ICloneable).Clone() as ResponseAnnotationAttribute; // Permission a = new Permission(); // a.PermissionId = KeyGenerator.Instance.GetNextValue("Permission"); // a.Code = method.Name; // a.Fullname = ann.MethodDescription; // permissionDataAccess.Insert(a); //} #endregion string contextMethod = string.Empty; //解码:get或者post的参数解析 WebRequestDecoder decoder; try { decoder = WebRequestDecoder.CreateInstance(context); } catch (NotImplementedException) { decoder = OnDecodeResolve(context); if (decoder == null) { throw new NotSupportedException("无法为当前的请求提供适当的解码器"); } } contextMethod = decoder.LogicalMethodName; //登录操作超时判断 if (contextMethod != "Login" && contextMethod != "GetSvr" && !IsLogined) { context.Response.Write("-100"); return; } //权限判断 //if (!PermissionSingleton.Instance.CheckPermission(User.RoleId, contextMethod)) if (false) { context.Response.Write("-101"); return; } //反射调用,返回结果 object result = Invoke(contextMethod, decoder.Deserialize()); ResponseAnnotationAttribute resAnn = GetAnnation(contextMethod); //编码阶段 WebResponseEncoder encoder; try { encoder = WebResponseEncoder.CreateInstance(context, resAnn.ResponseFormat); } catch (NotImplementedException) { encoder = OnEncoderResolve(context, contextMethod, resAnn); if (encoder == null) { throw new NotSupportedException("无法为当前的请求提供适当的编码器"); } } OnSerializeHandler handler = OnGetCustomerSerializer(contextMethod); if (handler != null) { encoder.OnSerialize += handler; } //回复 encoder.Write(result); InitializeCachePolicy(context, resAnn); }