public void Test_Or_And_Or_Or_Or()
        {
            DataRuleContext context = new DataRuleContext(null, null)
            {
                ValueProvider = new NameValueCollectionValueProvider(new NameValueCollection())
            };

            WhereClause[] clauses = new WhereClause[] {
                new WhereClause()
                {
                    FieldName = "title", Operator = Operator.Contains, Value1 = "title1", Logical = Logical.Or
                },
                new WhereClause()
                {
                    FieldName = "title", Operator = Operator.Contains, Value1 = "title1", Logical = Logical.And
                },
                new WhereClause()
                {
                    FieldName = "body", Operator = Operator.Contains, Value1 = "body1", Logical = Logical.Or
                },
                new WhereClause()
                {
                    FieldName = "body", Operator = Operator.Contains, Value1 = "body2", Logical = Logical.Or
                },
                new WhereClause()
                {
                    FieldName = "userkey", Operator = Operator.Contains, Value1 = "userkey1", Logical = Logical.Or
                }
            };
            var           expression = WhereClauseToContentQueryHelper.Parse(clauses, schema, valueProvider);
            StringVisitor visitor    = new StringVisitor(translatedQuery);

            visitor.Visite(expression);
            Assert.AreEqual("((((((((title Contains title1) OR (title Contains title1))) AND (body Contains body1))) OR (body Contains body2))) OR (userkey Contains userkey1))", translatedQuery.ClauseText);
        }
Esempio n. 2
0
        protected virtual IHtmlString RenderContentPosition(ContentPosition contentPosition)
        {
            var site       = this.PageContext.PageRequestContext.Site;
            var repository = site.GetRepository();

            if (repository == null)
            {
                throw new KoobooException("The repository for site is null.");
            }
            var dataRule        = contentPosition.DataRule;
            var dataRuleContext = new DataRuleContext(this.PageContext.PageRequestContext.Site,
                                                      this.PageContext.PageRequestContext.Page)
            {
                ValueProvider = this.PageContext.PageRequestContext.GetValueProvider()
            };
            var    contentQuery = dataRule.Execute(dataRuleContext);
            string viewPath     = "";
            var    schema       = dataRule.GetSchema(repository);
            Object model        = contentQuery;

            switch (contentPosition.Type)
            {
            case ContentPositionType.Detail:
                viewPath = schema.GetFormTemplate(FormType.Detail);
                model    = contentQuery.FirstOrDefault();
                break;

            case ContentPositionType.List:
            default:
                viewPath = schema.GetFormTemplate(FormType.List);
                break;
            }
            return(RenderViewInternal(this.Html, viewPath, null, model));
        }
Esempio n. 3
0
        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewName">Name of the view.</param>
        /// <param name="viewData">The view data.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="executeDataRule">if set to <c>true</c> [execute data rule].</param>
        /// <returns></returns>
        public virtual IHtmlString RenderView(string viewName, ViewDataDictionary viewData, object parameters, bool executeDataRule)
        {
            Kooboo.CMS.Sites.Models.View view = Kooboo.CMS.Sites.Models.IPersistableExtensions.AsActual(new Kooboo.CMS.Sites.Models.View(this.PageContext.PageRequestContext.Site, viewName).LastVersion());

            if (view != null)
            {
                //backup the parent view context
                var parentPositionContext = PageContext.ViewDataContext;

                var parameters1 = parameters is IDictionary <string, object>?((IDictionary <string, object>)parameters) : new RouteValueDictionary(parameters);
                PageContext.ViewDataContext = new PagePositionContext(view, parameters1, viewData);

                if (executeDataRule)
                {
                    viewData = new ViewDataDictionary(viewData);
                    var pageRequestContext = this.PageContext.PageRequestContext;
                    if (view.DataRules != null)
                    {
                        var valueProvider = pageRequestContext.GetValueProvider();
                        valueProvider.Insert(0, new ViewParameterValueProvider(PageContext.ViewDataContext.Parameters));
                        var dataRuleContext = new DataRuleContext(pageRequestContext.Site, pageRequestContext.Page)
                        {
                            ValueProvider = valueProvider
                        };
                        DataRuleExecutor.Execute(viewData, dataRuleContext, view.DataRules);
                    }
                }

                var html = RenderViewInternal(this.Html, view.TemplateFileVirutalPath, viewData, null);


                if (PageContext.EnableTrace)
                {
                    html = new HtmlString(string.Format(GeneratedByViewComment, viewName, html.ToString()));
                }

                //restore the parent view context
                PageContext.ViewDataContext = parentPositionContext;

                return(html);
            }
            else
            {
                return(new HtmlString(""));
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        protected virtual IHtmlString RenderContentPosition(ContentPosition contentPosition)
        {
            var site       = this.PageContext.PageRequestContext.Site;
            var repository = site.GetRepository();

            if (repository == null)
            {
                throw new KoobooException("The repository for site is null.");
            }
            var dataRule        = (IContentDataRule)(contentPosition.DataRule);
            var dataRuleContext = new DataRuleContext(this.PageContext.PageRequestContext.Site,
                                                      this.PageContext.PageRequestContext.Page)
            {
                ValueProvider = this.PageContext.PageRequestContext.GetValueProvider()
            };

            string        viewPath = "";
            TakeOperation operation;
            var           schema = dataRule.GetSchema(repository);

            switch (contentPosition.Type)
            {
            case ContentPositionType.Detail:
                viewPath  = schema.GetFormTemplate(FormType.Detail);
                operation = TakeOperation.First;
                break;

            case ContentPositionType.List:
            default:
                viewPath  = schema.GetFormTemplate(FormType.List);
                operation = TakeOperation.List;
                break;
            }
            var model = dataRule.Execute(dataRuleContext, operation, 0);

            return(ViewRender.RenderViewInternal(this.Html, viewPath, null, model));
        }