Exemplo n.º 1
0
        private IHttpHandler GetHandler(HttpContext context, string filename)
        {
            Type t = null;
            Exception typeException = null;
            string className = filename;

            if (Utility.Settings != null && Utility.Settings.UrlClassMappings.ContainsKey(filename))
            {
                className = Utility.Settings.UrlClassMappings[filename] as string;
                if (context.Trace.IsEnabled) context.Trace.Write(Constant.AjaxID, "Url match to Type: " + className);
            }

            try
            {
                t = Type.GetType(className, true);
            }
            catch (Exception ex)
            {
                if (context.Trace.IsEnabled) context.Trace.Write(Constant.AjaxID, "Type not found: " + className);
                typeException = ex;
            }

            AjaxProcessor[] p = new AjaxProcessor[3];
            p[0] = new XmlHttpRequestProcessor(context, t);
            p[1] = new IFrameProcessor(context, t);
            p[2] = new ExtJSProcessor(context, t);

            for (int i = 0; i < p.Length; i++)
            {
                if (!p[i].CanHandleRequest) continue;

                if (typeException != null)
                {
#if(WEBEVENT)
					string errorText = string.Format(Constant.AjaxID + " Error", context.User.Identity.Name);

					Management.WebAjaxErrorEvent ev = new Management.WebAjaxErrorEvent(errorText, WebEventCodes.WebExtendedBase + 200, typeException);
					ev.Raise();
#endif
                    p[i].SerializeObject(new NotSupportedException("This method is either not marked with an AjaxMethod or is not available."));
                    return null;
                }

                AjaxMethodAttribute[] ma = (AjaxMethodAttribute[])p[i].AjaxMethod.GetCustomAttributes(typeof(AjaxMethodAttribute), true);

                bool useAsync = false;
                HttpSessionStateRequirement sessionReq = HttpSessionStateRequirement.ReadWrite;

                if (ma.Length > 0)
                {
                    useAsync = ma[0].UseAsyncProcessing;

                    if (ma[0].RequireSessionState != HttpSessionStateRequirement.UseDefault)
                        sessionReq = ma[0].RequireSessionState;
                }

                switch (sessionReq)
                {
                    case HttpSessionStateRequirement.Read:
                        if (!useAsync)
                            return new AjaxSyncHttpHandlerSessionReadOnly(p[i]);
                        else
                            return new AjaxAsyncHttpHandlerSessionReadOnly(p[i]);

                    case HttpSessionStateRequirement.ReadWrite:
                        if (!useAsync)
                            return new AjaxSyncHttpHandlerSession(p[i]);
                        else
                            return new AjaxAsyncHttpHandlerSession(p[i]);

                    case HttpSessionStateRequirement.None:
                        if (!useAsync)
                            return new AjaxSyncHttpHandler(p[i]);
                        else
                            return new AjaxAsyncHttpHandler(p[i]);

                    default:
                        if (!useAsync)
                            return new AjaxSyncHttpHandlerSession(p[i]);
                        else
                            return new AjaxAsyncHttpHandlerSession(p[i]);
                }
            }

            return null;
        }
Exemplo n.º 2
0
        private IHttpHandler GetHandler(HttpContext context, string filename)
        {
            Type      t             = null;
            Exception typeException = null;
            string    className     = filename;

            if (Utility.Settings != null && Utility.Settings.UrlClassMappings.ContainsKey(filename))
            {
                className = Utility.Settings.UrlClassMappings[filename] as string;
                if (context.Trace.IsEnabled)
                {
                    context.Trace.Write(Constant.AjaxID, "Url match to Type: " + className);
                }
            }

            try
            {
                t = Type.GetType(className, true);
            }
            catch (Exception ex)
            {
                if (context.Trace.IsEnabled)
                {
                    context.Trace.Write(Constant.AjaxID, "Type not found: " + className);
                }
                typeException = ex;
            }

            AjaxProcessor[] p = new AjaxProcessor[3];
            p[0] = new XmlHttpRequestProcessor(context, t);
            p[1] = new IFrameProcessor(context, t);
            p[2] = new ExtJSProcessor(context, t);

            for (int i = 0; i < p.Length; i++)
            {
                if (!p[i].CanHandleRequest)
                {
                    continue;
                }

                if (typeException != null)
                {
#if (WEBEVENT)
                    string errorText = string.Format(Constant.AjaxID + " Error", context.User.Identity.Name);

                    Management.WebAjaxErrorEvent ev = new Management.WebAjaxErrorEvent(errorText, WebEventCodes.WebExtendedBase + 200, typeException);
                    ev.Raise();
#endif
                    p[i].SerializeObject(new NotSupportedException("This method is either not marked with an AjaxMethod or is not available."));
                    return(null);
                }

                AjaxMethodAttribute[] ma = (AjaxMethodAttribute[])p[i].AjaxMethod.GetCustomAttributes(typeof(AjaxMethodAttribute), true);

                bool useAsync = false;
                HttpSessionStateRequirement sessionReq = HttpSessionStateRequirement.ReadWrite;

                if (ma.Length > 0)
                {
                    useAsync = ma[0].UseAsyncProcessing;

                    if (ma[0].RequireSessionState != HttpSessionStateRequirement.UseDefault)
                    {
                        sessionReq = ma[0].RequireSessionState;
                    }
                }

                switch (sessionReq)
                {
                case HttpSessionStateRequirement.Read:
                    if (!useAsync)
                    {
                        return(new AjaxSyncHttpHandlerSessionReadOnly(p[i]));
                    }
                    else
                    {
                        return(new AjaxAsyncHttpHandlerSessionReadOnly(p[i]));
                    }

                case HttpSessionStateRequirement.ReadWrite:
                    if (!useAsync)
                    {
                        return(new AjaxSyncHttpHandlerSession(p[i]));
                    }
                    else
                    {
                        return(new AjaxAsyncHttpHandlerSession(p[i]));
                    }

                case HttpSessionStateRequirement.None:
                    if (!useAsync)
                    {
                        return(new AjaxSyncHttpHandler(p[i]));
                    }
                    else
                    {
                        return(new AjaxAsyncHttpHandler(p[i]));
                    }

                default:
                    if (!useAsync)
                    {
                        return(new AjaxSyncHttpHandlerSession(p[i]));
                    }
                    else
                    {
                        return(new AjaxAsyncHttpHandlerSession(p[i]));
                    }
                }
            }

            return(null);
        }