コード例 #1
0
ファイル: Page_Context.cs プロジェクト: eyouyou/Bsc
        public virtual ActionResult ExecutePlugins()
        {
            // Execute plugins on page
            var page = PageRequestContext.Page.AsActual();
            var httpMethod = this.ControllerContext.HttpContext.Request.HttpMethod.ToUpper();
            if (page.Plugins != null)
            {
                foreach (var plugin in page.Plugins)
                {
                    var result = ExecutePlugin(plugin, null, httpMethod);
                    if (result != null)
                    {
                        return result;
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.PageLayout))
            {
                // Execute plugins on Layout
                var layout = new Layout(this.PageRequestContext.Site, this.PageLayout).LastVersion().AsActual();
                if (layout != null && layout.Plugins != null)
                {
                    foreach (var plugin in layout.Plugins)
                    {
                        var result = ExecutePlugin(plugin, null, httpMethod);
                        if (result != null)
                        {
                            return result;
                        }
                    }
                }
            }

            // Execute plugins on views
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(PageRequestContext.Site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    if (view.Plugins != null)
                    {
                        var positionContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), GetPositionViewData(viewPosition.PagePositionId));

                        foreach (var plugin in view.Plugins)
                        {
                            var result = ExecutePlugin(plugin, positionContext, httpMethod);
                            if (result != null)
                            {
                                return result;
                            }
                        }
                    }
                }
            }
            return null;
        }
コード例 #2
0
ファイル: Page_Context.cs プロジェクト: eyouyou/Bsc
 private ActionResult ExecutePlugin(string pluginType, PagePositionContext positionContext, string httpMethod)
 {
     var type = Type.GetType(pluginType);
     if (type == null)
     {
         return null;
     }
     ActionResult result = null;
     var plugin = (ICommonPagePlugin)TypeActivator.CreateInstance(type);
     var httpMethodPlugin = plugin as IHttpMethodPagePlugin;
     var pagePlugin = plugin as IPagePlugin;
     switch (httpMethod)
     {
         case "POST":
             if (httpMethodPlugin != null)
             {
                 result = httpMethodPlugin.HttpPost(this, positionContext);
             }
             if (result == null && pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
         case "GET":
             if (httpMethodPlugin != null)
             {
                 result = httpMethodPlugin.HttpGet(this, positionContext);
             }
             if (result == null && pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
         default:
             if (pagePlugin != null)
             {
                 result = pagePlugin.Execute(this, positionContext);
             }
             break;
     }
     return result;
 }
コード例 #3
0
ファイル: Page_Context.cs プロジェクト: eyouyou/Bsc
        public virtual void ExecuteDataRules()
        {
            var pageViewData = ControllerContext.Controller.ViewData;

            var site = PageRequestContext.Site.AsActual();
            var page = PageRequestContext.Page.AsActual();

            var dataRuleContext = new DataRuleContext(PageRequestContext.Site, PageRequestContext.Page) { ValueProvider = PageRequestContext.GetValueProvider() };
            if (page.DataRules != null)
            {
                DataRuleExecutor.Execute(pageViewData, dataRuleContext, page.DataRules);
            }
            var viewPositions = page.PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
            foreach (ViewPosition viewPosition in viewPositions)
            {
                var view = new Models.View(site, viewPosition.ViewName).LastVersion().AsActual();
                if (view != null)
                {
                    var positionViewData = (ViewDataDictionary)GetPositionViewData(viewPosition.PagePositionId).Merge(pageViewData);
                    var viewDataContext = new PagePositionContext(view, viewPosition.ToParameterDictionary(), positionViewData);
                    var dataRules = view.DataRules;
                    if (dataRules != null)
                    {
                        var valueProvider = PageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(viewDataContext.Parameters));
                        dataRuleContext.ValueProvider = valueProvider;
                        DataRuleExecutor.Execute(positionViewData, dataRuleContext, dataRules);
                    }
                    if (positionViewData.Model == null)
                    {
                        positionViewData.Model = positionViewData.Values.FirstOrDefault();
                    }
                    SetPositionViewData(viewPosition.PagePositionId, positionViewData);
                }
            }
        }