Esempio n. 1
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginCheckPermission( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            IList paths = ctx.utils.getLayoutPath();
            for (int i = paths.Count - 1; i >= 0; i--) {

                ControllerBase controller = ControllerFactory.FindSecurityController( paths[i].ToString(), ctx );
                if (controller == null) continue;

                if (ctx.controller.utils.isCheckPermission( controller.GetType() )) {
                    controller.CheckPermission();
                }

                if (ctx.utils.isEnd()) {
                    String msg = controller.utils.getActionResult();
                    context.endMsgByText( checkFrame( ctx, msg ) );
                    return;
                }
            }

            context.getController().CheckPermission();
            if (ctx.utils.isEnd()) {
                context.endMsgByText( checkFrame( ctx, context.getController().utils.getActionResult() ) );
                return;
            }
        }
        public override void Process( ProcessContext context )
        {
            MvcContext ctx = context.ctx;
            MvcEventPublisher.Instance.BeginUrlRewrite( ctx );
            if (ctx.utils.isSkipCurrentProcessor()) return;

            foreach (KeyValuePair<String, String> kv in LinkMap.GetShortUrlMap()) {

                if (strUtil.IsNullOrEmpty( kv.Value )) continue;

                String sPath = strUtil.Join( "", kv.Key );
                sPath = strUtil.Append( sPath, MvcConfig.Instance.UrlExt );

                if (ctx.url.PathAndQueryWithouApp.Equals( sPath )) {

                    if (kv.Value.StartsWith( "http:" )) {
                        ctx.web.Redirect( kv.Value );
                        ctx.utils.end();
                    }
                    else {
                        String newUrl = strUtil.Join( ctx.url.SiteAndAppPath, kv.Value );
                        ctx.setUrl( newUrl );
                    }

                }

            }
        }
Esempio n. 3
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginAddNsLayout( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            String content = context.getContent();

            int intNoLayout = ctx.utils.getNoLayout();
            if (intNoLayout < 0) intNoLayout = 0;

            IList paths = ctx.utils.getLayoutPath();
            int pathCount = paths.Count - intNoLayout;
            for (int i = 0; i < pathCount; i++) {

                Boolean isLastLayout = i == pathCount - 1;

                content = addLayoutPrivate( paths[i].ToString(), content, ctx, isLastLayout );

                if (ctx.utils.isEnd()) return;
            }

            if (intNoLayout > 0) {
                if (ctx.utils.isFrame()) {
                    content = MvcUtil.getFrameContent( content );
                }
                else {
                    content = MvcUtil.getNoLayoutContent( content );
                }
            }

            context.setContent( content );
        }
Esempio n. 4
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginAddLayout( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;
            ControllerBase controller = context.getController();

            if (controller.utils.isHided( controller.GetType() )) {
                return;
            }

            int intNoLayout = ctx.utils.getNoLayout();
            IList paths = ctx.utils.getLayoutPath();
            if (intNoLayout >= paths.Count + 1) return;

            String actionContent = context.getContent();

            //检查缓存
            String cacheKey = null;
            if (MvcConfig.Instance.IsActionCache) {
                IActionCache actionCache = ControllerMeta.GetActionCache( controller.GetType(), "Layout" );

                cacheKey = getCacheKey( actionCache, ctx );
                if (strUtil.HasText( cacheKey )) {
                    Object cacheContent = checkCache( cacheKey );
                    if (cacheContent != null) {
                        logger.Info( "load from layoutCache=" + cacheKey );
                        context.setContent( HtmlCombiner.combinePage( cacheContent.ToString(), actionContent ) );
                        return;
                    }
                }
            }

            String layoutContent;
            if (controller.LayoutControllerType == null) {
                layoutContent = runCurrentLayout( controller, ctx, context, actionContent );
            }
            else {
                layoutContent = runOtherLayout( controller, ctx, context, actionContent );
            }

            // 加入缓存
            if (MvcConfig.Instance.IsActionCache) {
                if (strUtil.HasText( cacheKey )) {
                    addContentToCache( cacheKey, layoutContent );
                }
            }

            if (ctx.utils.isEnd()) {
                context.endMsgByText( layoutContent );
            }
            else {
                context.setContent( HtmlCombiner.combinePage( layoutContent, actionContent ) );
            }
        }
        private void GetToken(ProcessContext ctx)
        {
            ctx.Type = RegexType.None;
            ctx.Token = string.Empty;

            if (ctx.ExpressionIndex == ctx.Expression.Length)
            {
                ctx.Type = RegexType.End;
            }
        }
 protected override string GetInstanceName(ProcessContext context)
 {
     AzureConnectionSettings azureConnectionSettings = context.Settings.ConnectionSettings as AzureConnectionSettings;
     if (azureConnectionSettings != null)
     {
         string storageName = azureConnectionSettings.StorageName;
         return base.GetSHA1(storageName).Substring(0, 32);
     }
     return base.GetInstanceName(context);
 }
Esempio n. 7
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginCheckHttpMethod( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MethodInfo actionMethod = context.ctx.ActionMethodInfo; // context.getActionMethod();
            String httpMethod = context.ctx.HttpMethod;
            Boolean isMethodError = isHttpMethodError( context.getController().utils.getHttpMethodAttributes( actionMethod ), httpMethod );
            if (isMethodError) {
                context.endMsg( lang.get( "exHttpMethodError" ), HttpStatus.MethodNotAllowed_405 );
            }
        }
Esempio n. 8
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginCheckLoginAction( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MethodInfo actionMethod = context.ctx.ActionMethodInfo; //  context.getActionMethod();
            Attribute loginAttr = context.getController().utils.getAttribute( actionMethod, typeof( LoginAttribute ) );

            if (loginAttr != null && context.IsUserLogin() == false) {
                context.ctx.controller.redirectLogin();
            }
        }
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginCheckForbiddenAction( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MethodInfo actionMethod = context.ctx.ActionMethodInfo; // context.getActionMethod();

            Attribute forbiddenAttr = context.getController().utils.getAttribute( actionMethod, typeof( NonVisitAttribute ) );
            if (forbiddenAttr != null) {
                context.endMsg( lang.get( "exVisitForbidden" ), HttpStatus.Forbidden_403 );
            }
        }
        public MessageResult Process(ProcessContext context)
        {
            // get message data
            var sleepMessage = context.Data<SleepMessage>();

            Console.WriteLine("Sleep Messeage Received: '{0}', Time: {1}, Id: {2}", 
                sleepMessage.Text, sleepMessage.Time, context.Message.Id);

            Thread.Sleep(sleepMessage.Time);

            if (sleepMessage.Throw)
                throw new InvalidOperationException("This is a test sleep exception");

            return MessageResult.Successful;
        }
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginCheckActionMethod( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;
            MethodInfo actionMethod = ctx.controller.utils.getMethod( ctx.route.action );

            if (actionMethod == null) {
                context.endMsg( lang.get( "exActionNotFound" ), HttpStatus.NotFound_404 );
            }
            else {
                context.ctx.setActionMethodInfo( actionMethod );
            }
        }
Esempio n. 12
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginInitContext( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            ContextInitBase initor = getContextInit();

            initor.InitViewer( ctx );       // ��ʼ����ǰ��¼�û�(������)
            initor.InitOwner( ctx );       // ��ʼ����ǰ�����ʶ���(site��group��user)
            initor.InitController( ctx );  // ��ʼ��������
            initor.InitPermission( ctx ); // ��ʼ��Ȩ�޼��
            initor.InitApp( ctx );                 // ��ʼ����ǰapp
        }
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginInitContext( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            ContextInitBase initor = getContextInit();

            initor.InitViewer( ctx );       // 初始化当前登录用户(访问者)
            initor.InitOwner( ctx );       // 初始化当前被访问对象(site或group或user)
            initor.InitController( ctx );  // 初始化控制器
            initor.InitPermission( ctx ); // 初始化权限检查
            initor.InitApp( ctx );                 // 初始化当前app
        }
Esempio n. 14
0
 public TextRange Process(string regexExpression)
 {
     ProcessContext ctx = new ProcessContext(regexExpression);
     GetToken(ctx);
     if (RegexType.End.Equals(ctx.Type))
     {
         return null;
     }
     ProcessGroup();
     if (!RegexType.End.Equals(ctx.Type))
     {
         throw new ApplicationException();
     }
     return new TextRange(new TextPointer(), new TextPointer());
 }
Esempio n. 15
0
        private static void addPageCache( ProcessContext context, MvcContext ctx )
        {
            if (ctx.controller == null) return;
            if (ctx.IsMock) return;

            IPageCache pageCache = ControllerMeta.GetPageCache( ctx.controller.GetType(), ctx.route.action );
            if (pageCache == null) return;
            if (pageCache.IsCache( ctx ) == false) return;

            String key = ctx.url.PathAndQuery;
            if (MvcConfig.Instance.CheckDomainMap()) key = ctx.url.ToString();

            CacheManager.GetApplicationCache().Put( key, context.getContent() );

            logger.Info( "add page cache, key=" + key );
            pageCache.AfterCachePage( ctx );
        }
Esempio n. 16
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginParseRoute( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            try {
                Route r = RouteTool.Recognize( context.ctx );

                //logger.Info( string.Format( "owner={0}, ownertype={1}, controller={2}, action={3}", r.owner, r.ownerType, r.controller, r.action ) );

                context.ctx.utils.setRoute( r );
                IsSiteClosed( context.ctx );
            }
            catch (MvcException ex) {
                context.endMsg( ex.Message, HttpStatus.NotFound_404 );
            }
        }
        /// <summary>
        /// Get the next <see cref="DateTime" /> to attempt retry.
        /// </summary>
        /// <param name="processContext">The process context.</param>
        /// <returns>
        ///   <see cref="DateTime" /> the message should be retried.
        /// </returns>
        public virtual DateTime NextAttempt(ProcessContext processContext)
        {
            var message = processContext.Message;

            // retry weight, 1 = 1 min, 2 = 30 min, 3 = 2 hrs, 4+ = 8 hrs
            if (message.ErrorCount > 3)
                return DateTime.Now.AddHours(8);

            if (message.ErrorCount == 3)
                return DateTime.Now.AddHours(2);

            if (message.ErrorCount == 2)
                return DateTime.Now.AddMinutes(30);

            // default
            return DateTime.Now.AddMinutes(1);
        }
Esempio n. 18
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginAddLayout( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;
            ControllerBase controller = context.getController();

            if (controller.utils.isHided( controller.GetType() )) {
                return;
            }

            int intNoLayout = ctx.utils.getNoLayout();
            IList paths = ctx.utils.getLayoutPath();
            if (intNoLayout >= paths.Count + 1) return;

            String actionContent = context.getContent();

            //检查缓存
            CacheInfo ci = CacheInfo.InitLayout( ctx );
            Object cacheContent = ci.CheckCache();
            if (cacheContent != null) {
                logger.Info( "load from layoutCache=" + ci.CacheKey );
                context.setContent( HtmlCombiner.combinePage( cacheContent.ToString(), actionContent ) );
                return;
            }

            String layoutContent = ControllerRunner.RunLayout( ctx );

            // 加入缓存
            if (ci.IsActionCache) {
                ci.AddContentToCache( layoutContent );
            }

            if (ctx.utils.isEnd()) {
                context.endMsgByText( layoutContent );
            }
            else {
                context.setContent( HtmlCombiner.combinePage( layoutContent, actionContent ) );
            }
        }
Esempio n. 19
0
        public override void Process( ProcessContext context )
        {
            MvcContext ctx = context.ctx;

            MvcEventPublisher.Instance.BeginParseRoute( ctx );
            if (ctx.utils.isSkipCurrentProcessor()) return;

            try {
                Route r = RouteTool.Recognize( ctx );

                if (r == null) {
                    throw new MvcException( HttpStatus.NotFound_404, "can't find matching route : Url=" + ctx.url.ToString() );
                }

                ctx.utils.setRoute( r );
                IsSiteClosed( ctx );
            }
            catch (MvcException ex) {
                ctx.utils.endMsg( ex.Message, HttpStatus.NotFound_404 );
            }
        }
Esempio n. 20
0
        public override void Process( ProcessContext context )
        {
            MvcContext ctx = context.ctx;

            // page meta
            String pageContent = context.getContent();
            pageContent = processPageMeta( pageContent, ctx );
            context.setContent( pageContent );

            // page cache
            if (MvcConfig.Instance.IsPageCache) {
                addPageCache( context, ctx );
            }

            MvcEventPublisher.Instance.BeginRender( ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            ctx.utils.clearResource();
            ctx.web.ResponseWrite( context.getContent() );

            MvcEventPublisher.Instance.EndRender( ctx );
        }
 public MessageResult Process(ProcessContext context)
 {
     return MessageResult.None;
 }
        /// <summary>
        /// Determine if the the message should be retried.
        /// </summary>
        /// <param name="processContext">The process context.</param>
        /// <param name="exception">The exception thrown while processing message.</param>
        /// <returns>
        ///   <c>true</c> if the message should be retried; otherwise <c>false</c>.
        /// </returns>
        public virtual bool ShouldRetry(ProcessContext processContext, Exception exception)
        {
            var message = processContext.Message;

            return message.ErrorCount < message.RetryCount;
        }
Esempio n. 23
0
        public override void Process( ProcessContext context )
        {
            MvcEventPublisher.Instance.BeginProcessAction( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            ControllerBase controller = context.getController();

            // 检查缓存
            CacheInfo ci = CacheInfo.Init( ctx );
            Object cacheContent = ci.CheckCache();
            if (cacheContent != null) {
                logger.Info( "load from actionCache=" + ci.CacheKey );
                context.setContent( cacheContent.ToString() );
                getPageMetaFromCache( ctx, ci.CacheKey );
                return;
            }

            MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod();

            // 设值模板并载入全局变量
            setControllerView( controller, actionMethod );

            // 运行并处理post值
            ActionRunner.runAction( ctx, controller, actionMethod, controller.utils.runAction );
            String actionContent = controller.utils.getActionResult();

            // 加入缓存
            if (ci.IsActionCache) {
                ci.AddContentToCache( actionContent );
                // 加入PageMeta
                addPageMetaToCache( ctx, ci.CacheKey );
            }

            actionContent = PostValueProcessor.ProcessPostValue( actionContent, ctx );

            if (ctx.utils.isAjax) {
                context.showEnd( actionContent );
            }
            else if (ctx.utils.isFrame()) {

                int intNoLayout = ctx.utils.getNoLayout();

                if (intNoLayout == 0) {

                    String content = MvcUtil.getFrameContent( actionContent );
                    context.showEnd( content );
                }
                else {
                    context.setContent( actionContent );
                }

            }
            else if (ctx.utils.isEnd()) {
                context.showEnd( actionContent );
            }
            else {
                context.setContent( actionContent );
            }

            updateActionCache( ctx );

            MvcEventPublisher.Instance.EndProcessAction( context.ctx );
        }
Esempio n. 24
0
        public override void Process( ProcessContext context ) {

            MvcEventPublisher.Instance.BeginProcessAction( context.ctx );
            if (context.ctx.utils.isSkipCurrentProcessor()) return;

            MvcContext ctx = context.ctx;

            ControllerBase controller = ctx.controller;


            // 1) 检查 action 缓存
            ActionCacheChecker xChecker = ActionCacheChecker.InitAction( ctx );
            Object cacheContent = xChecker.GetCache();
            if (cacheContent != null) {
                logger.Info( "load from actionCache=" + xChecker.CacheKey );
                context.setContent( cacheContent.ToString() );
                setPageMeta_FromCache( ctx, xChecker.CacheKey );
                return;
            }

            // 2) 运行 before action (获取所有的 ActionObserver)
            List<ActionObserver> actionObservers = ControllerMeta.GetActionObservers( controller.GetType(), ctx.route.action );
            if (actionObservers != null) {
                foreach (ActionObserver x in actionObservers) {
                    ActionObserver ob = (ActionObserver)ObjectContext.Create( x.GetType() );
                    obList.Add( ob );
                    Boolean isContinue = ob.BeforeAction( ctx );
                    if (!isContinue) return;
                }
            }

            // 3) 运行 action
            MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod();

            // 设值模板并载入全局变量
            setControllerView( controller, actionMethod );

            // 运行并处理post值
            ActionRunner.runAction( ctx, controller, actionMethod, controller.utils.runAction );
            if (ctx.utils.isEnd()) {
                afterAction( ctx );
                return;
            }

            String actionContent = controller.utils.getActionResult();

            // 4) 后续缓存处理
            if (xChecker.IsActionCache) {
                xChecker.AddCache( actionContent );
                addPageMeta_ToCache( ctx, xChecker.CacheKey );
            }

            actionContent = PostValueProcessor.ProcessPostValue( actionContent, ctx );

            if (ctx.utils.isAjax) {
                context.showEnd( actionContent );
            }
            else if (ctx.utils.isFrame()) {

                int intNoLayout = ctx.utils.getNoLayout();

                if (intNoLayout == 0) {

                    String content = MvcUtil.getFrameContent( actionContent );
                    context.showEnd( content );
                }
                else {
                    context.setContent( actionContent );
                }
            }
            else {
                context.setContent( actionContent );
            }

            afterAction( ctx );
        }
Esempio n. 25
0
        private String runOtherLayout( ControllerBase controller, MvcContext ctx, ProcessContext context, String actionContent )
        {
            ControllerBase layoutController = ControllerFactory.FindController( controller.LayoutControllerType, ctx );
            layoutController.utils.switchViewToLayout();

            ActionRunner.runLayoutAction( ctx, layoutController, layoutController.Layout );

            return layoutController.utils.getActionResult();
        }
Esempio n. 26
0
        private String runCurrentLayout( ControllerBase controller, MvcContext ctx, ProcessContext context, String actionContent )
        {
            MethodInfo layoutMethod = controller.utils.getMethod( "Layout" );
            if (layoutMethod.DeclaringType != controller.GetType()) {
                String filePath = MvcUtil.getParentViewPath( layoutMethod, ctx.route.getRootNamespace( layoutMethod.DeclaringType.FullName ) );
                controller.utils.setCurrentView( controller.utils.getTemplateByFileName( filePath ) );
            }
            else {
                controller.utils.switchViewToLayout();
            }

            controller.actionContent( "" ); // 清理当前内容,否则下面的utils.getActionResult()得不到正确结果
            controller.Layout();

            return controller.utils.getActionResult();
        }
Esempio n. 27
0
 public abstract void Process( ProcessContext context );
        private void RetryMessage(Message message, Exception exception)
        {
            if (message == null)
                return;

            if (Configuration.RetryFactory == null)
                return;

            // create message retry 
            var retry = Configuration.RetryFactory();
            if (retry == null)
                return;

            var context = new ProcessContext(message, Container);
            bool shouldRetry = retry.ShouldRetry(context, exception);
            if (!shouldRetry)
                return;

            var nextAttempt = retry.NextAttempt(context);

            Logger.Debug()
                .Message("Message {0} scheduled for retry on {1}.", message.Id, nextAttempt)
                .Write();

            // schedule retry 
            Repository.Schedule(message.Id, nextAttempt);
        }
        private MessageResult ProcessSubscriber(Message message)
        {
            var context = new ProcessContext(message, Container);

            using (var subscriber = CreateSubscriber())
                return subscriber.Process(context);
        }