Example #1
0
        public async Task Invoke(HttpContext context, IToolkitService service)
        {
            System.Diagnostics.Trace.WriteLine($"Thread Id  {System.Threading.Thread.CurrentThread.ManagedThreadId}");

            ProcessJWT(context);
            if (WebStartPage.IsDefault(context))
            {
                await WebStartPage.Start(context);

                return;
            }
            PathStringParser parser = new PathStringParser(context.Request.Path);

            if (!string.IsNullOrEmpty(parser.Parser))
            {
                var factory = service.GlobalVariable.FactoryManager.GetCodeFactory(
                    HttpHandlerPlugInFactory.REG_NAME);
                if (factory.Contains(parser.Parser))
                {
                    //LoggerHelper.Logger.LogInformation("Use Parser {0}", parser.Parser);
                    IHttpHandler handler = factory.CreateInstance <IHttpHandler>(parser.Parser);
                    Task         task    = handler.ProcessRequest(context, fNext, parser);
                    if (task == null)
                    {
                        await fNext(context);
                    }
                    else
                    {
                        await task;
                    }
                }
                else
                {
                    await fNext(context);
                }
            }
            else
            {
                await fNext(context);
            }
        }
Example #2
0
        public Task ProcessRequest(HttpContext context, RequestDelegate next, PathStringParser parser)
        {
            PageSourceInfo info = null;

            parser.Parse((input) =>
            {
                info = ParseUrl(input, info);
            });
            if (info == null)
            {
                return(null);
            }

            context.Items[WebUtil.SOURCE_INFO] = info;

            WebDefaultXmlConfig defaultConfig = WebGlobalVariable.WebCurrent.WebDefaultValue;
            WebBasePage         page          = null;

            try
            {
                if (info.IsContent)
                {
                    page = new WebModuleContentPage(context, next, info);
                }
                else
                {
                    page = new WebModuleRedirectPage(context, next, info);
                }
                return(page.LoadPage());
            }
            catch (RedirectException ex)
            {
                context.Response.Redirect(ex.Url.ToString(), false);
                return(Task.FromResult(0));
            }
            catch (ReLogOnException ex)
            {
                return(HandleException(defaultConfig.ReLogOnHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ErrorPageException ex)
            {
                return(HandleException(defaultConfig.ErrorPageHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ErrorOperationException ex)
            {
                return(HandleException(defaultConfig.ErrorOperationHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ToolkitException ex)
            {
                return(HandleException(defaultConfig.ToolkitHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (Exception ex)
            {
                Exception innerEx = ex.InnerException;
                if (innerEx != null)
                {
                    return(ProcessException(context, defaultConfig, page, info, innerEx));
                }
                else
                {
                    return(ProcessException(context, defaultConfig, page, info, ex));
                }
            }
        }