コード例 #1
0
ファイル: Handler1.ashx.cs プロジェクト: Houfeng/AjaxEngine
 protected override void OnInvoke(HandleEventArgs e)
 {
 }
コード例 #2
0
 protected virtual void OnPrecess(HandleEventArgs requestEventArgs)
 {
 }
コード例 #3
0
        public virtual void ProcessRequest(HttpContext context)
        {
            this.Context           = context;
            this.ServiceEntity     = this;
            this.InvokeMethodName  = Context.Request[Const.METHOD] ?? Context.Request.Headers[Const.METHOD];
            this.JsonpCallbackName = Context.Request[Const.CALLBACK] ?? Context.Request.Headers[Const.CALLBACK];
            //调用前
            HandleEventArgs processEventArgs = new HandleEventArgs();

            this.OnPrecess(processEventArgs);
            if (processEventArgs.Cancel)
            {
                context.Response.Clear();
                if (string.IsNullOrEmpty(this.JsonpCallbackName))
                {
                    context.Response.ContentType = Const.APPLICATION_JSON;
                    context.Response.Write(this.Serializer.Serialize(processEventArgs.Result));
                }
                else
                {
                    context.Response.ContentType = Const.APPLICATION_JAVASCRIPT;
                    context.Response.Write(string.Format("{0}({1});", this.JsonpCallbackName, this.Serializer.Serialize(processEventArgs.Result)));
                }
                context.Response.End();
            }
            //生成文档
            if (string.IsNullOrEmpty(context.Request[Const.METHOD]) &&
                string.IsNullOrEmpty(context.Request[Const.CLIENT_SCRIPT]))
            {
                ServiceDocBuilder docBuilder = new ServiceDocBuilder(this.ServiceEntity);
                context.Response.Clear();
                context.Response.ContentType = Const.TEXT_HTML;
                context.Response.Write(docBuilder.ToString());
                context.Response.End();
                return;
            }
            //生成代理脚本
            if (!string.IsNullOrEmpty(context.Request[Const.CLIENT_SCRIPT]))
            {
                var clientScript = context.Request[Const.CLIENT_SCRIPT].ToLower().Split(',');
                context.Response.Clear();
                context.Response.ContentType = Const.APPLICATION_JAVASCRIPT;
                if (clientScript.Contains(Const.JQUERY))
                {
                    context.Response.Write(Resources.Jquery);
                }
                if (clientScript.Contains(Const.CORE))
                {
                    context.Response.Write(Resources.ServiceCore);
                }
                if (clientScript.Contains(Const.AGENT))
                {
                    string ns = this.AgentScriptNamespace;
                    if (string.IsNullOrEmpty(ns))
                    {
                        ns = this.GetType().Name;
                    }
                    ServiceAgentBuilder agentBuilder = new ServiceAgentBuilder(context.Request.Url.ToString().Split('?')[0], ns, this.ServiceEntity);
                    context.Response.Write(agentBuilder.ToString());
                }
                context.Response.End();
                return;
            }
            //调用前
            HandleEventArgs invokeEventArgs = new HandleEventArgs();

            this.OnInvoke(invokeEventArgs);
            if (invokeEventArgs.Cancel)
            {
                context.Response.Clear();
                context.Response.Write(this.Serializer.Serialize(invokeEventArgs.Result));
                context.Response.End();
            }
            //调用
            if (!string.IsNullOrEmpty(this.InvokeMethodName))
            {
                object result = this.InvokeEntityMethod(this.InvokeMethodName, context.Request.HttpMethod);
                context.Response.Clear();
                if (string.IsNullOrEmpty(this.JsonpCallbackName))
                {
                    context.Response.ContentType = Const.APPLICATION_JSON;
                    context.Response.Write(this.Serializer.Serialize(result));
                }
                else
                {
                    context.Response.ContentType = Const.APPLICATION_JAVASCRIPT;
                    context.Response.Write(string.Format("{0}({1});", this.JsonpCallbackName, this.Serializer.Serialize(result)));
                }
                context.Response.End();
            }
            else
            {
                HandleError("没有找到指定调用方法");
            }
        }
コード例 #4
0
 protected virtual void OnInvoke(HandleEventArgs invokeEventArgs)
 {
 }