Example #1
0
        public override IContentQuery <Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext)
        {
            var contentQuery = base.GetContentQuery(dataRuleContext);

            if (contentQuery is MediaContentQuery)
            {
                throw new KoobooException(string.Format("The binary folder '{0}' does not support '{1}'.", FolderName, "CategoryDataRule"));
            }
            var site           = dataRuleContext.Site;
            var repository     = Sites.Models.ModelExtensions.GetRepository(site);
            var categoryFolder = (TextFolder)(new TextFolder(repository, CategoryFolderName).AsActual());

            if (categoryFolder == null)
            {
                throw new KoobooException(string.Format("The folder does not exists.\"{0}\"".Localize(), CategoryFolderName));
            }
            contentQuery = ((TextContentQuery)contentQuery).Categories(categoryFolder);
            if (CategoryClauses != null)
            {
                contentQuery = contentQuery.Where(CategoryClauses.Parse(categoryFolder.GetSchema(), dataRuleContext.ValueProvider));
            }

            if (Page_Context.Current.EnabledInlineEditing(EditingType.Content))
            {
                contentQuery = contentQuery.Where(
                    new Content.Query.Expressions.OrElseExpression(
                        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", true),
                        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", null)));
            }
            else
            {
                contentQuery = contentQuery.WhereEquals("Published", true); //default query published=true.
            }
            return(contentQuery);
        }
Example #2
0
        public override Content.Query.IContentQuery<Content.Models.TextContent> Execute(DataRuleContext dataRuleContext)
        {
            var contentQuery = base.Execute(dataRuleContext);
            if (contentQuery is MediaContentQuery)
            {
                throw new KoobooException(string.Format("The binary folder '{0}' does not support '{1}'.", FolderName, "CategoryDataRule"));
            }
            var site = dataRuleContext.Site;
            var repository = Sites.Models.ModelExtensions.GetRepository(site);
            var categoryFolder = (TextFolder)(new TextFolder(repository, CategoryFolderName).AsActual());
            if (categoryFolder == null)
            {
                throw new KoobooException(string.Format("The folder does not exists.\"{0}\"".Localize(), CategoryFolderName));
            }
            contentQuery = ((TextContentQuery)contentQuery).Categories(categoryFolder);
            if (CategoryClauses != null)
            {
                contentQuery = contentQuery.Where(CategoryClauses.Parse(categoryFolder.GetSchema(), dataRuleContext.ValueProvider));
            }

            if (Page_Context.Current.EnabledInlineEditing(EditingType.Content))
            {
                contentQuery = contentQuery.Where(
                    new Content.Query.Expressions.OrElseExpression(
                        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", true),
                        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", null)));
            }
            else
                contentQuery = contentQuery.WhereEquals("Published", true); //default query published=true.

            return contentQuery;
        }
Example #3
0
        //[DataMember(Order = 13)]
        //public new string FolderName { get; set; }
        public override IContentQuery <Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext)
        {
            var site       = dataRuleContext.Site;
            var repository = Sites.Models.ModelExtensions.GetRepository(site);

            if (repository == null)
            {
                throw new SiteRepositoryNotExists();
            }
            var folder = FolderHelper.Parse <TextFolder>(repository, FolderName).AsActual();

            if (folder == null)
            {
                throw new KoobooException(string.Format("The folder does not exists.\"{0}\"".Localize(), FolderName));
            }
            Content.Query.IContentQuery <Content.Models.TextContent> contentQuery = null;
            if (folder is TextFolder)
            {
                var textFolder = (TextFolder)folder;
                contentQuery = textFolder.CreateQuery();
            }
            //else
            //{
            //    var binaryFolder = (MediaFolder)folder;
            //    contentQuery = binaryFolder.CreateQuery();
            //}
            if (WhereClauses != null)
            {
                contentQuery = contentQuery.Where(WhereClauses.Parse(folder.GetSchema(), dataRuleContext.ValueProvider));
            }
            if (!string.IsNullOrEmpty(CategoryFolderName) && this.CategoryClauses != null && this.CategoryClauses.Length > 0)
            {
                var categoryFolder = FolderHelper.Parse <TextFolder>(repository, CategoryFolderName);
                var categoryQuery  = categoryFolder.CreateQuery();
                var expression     = CategoryClauses.Parse(categoryFolder.GetSchema(), dataRuleContext.ValueProvider);
                if (expression != null)
                {
                    categoryQuery = categoryQuery.Where(expression);
                    contentQuery  = contentQuery.WhereCategory(categoryQuery);
                }
            }


            //query the Published=null content for inline editor..
            if (Page_Context.Current.EnabledInlineEditing(EditingType.Content))
            {
                //contentQuery = contentQuery.Where(
                //    new Content.Query.Expressions.OrElseExpression(
                //        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", true),
                //        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", null)));
            }
            else
            {
                contentQuery = contentQuery.WhereEquals("Published", true); //default query published=true.
            }
            return(contentQuery);
        }
Example #4
0
        public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration)
        {
            var url = EvaluateStringFormulas(this.URL, dataRuleContext);
            NameValueCollection form    = KeyValuesToNameValueCollection(dataRuleContext, this.FormData);
            NameValueCollection headers = KeyValuesToNameValueCollection(dataRuleContext, this.Headers);

            var httpDataRequest = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IHttpDataRequest>();

            return(httpDataRequest.GetData(url, this.HttpMethod, ContentType, form, headers));
        }
Example #5
0
 public static void Execute(ViewDataDictionary viewData, DataRuleContext dataRuleContext, IEnumerable<DataRuleSetting> dataRules)
 {
     foreach (var item in dataRules)
     {
         var data = item.DataRule.Execute(dataRuleContext, item.TakeOperation, item.CachingDuration);
         if (item.DataName.EqualsOrNullEmpty(ModelName, StringComparison.CurrentCultureIgnoreCase))
         {
             viewData.Model = data;
         }
         viewData[item.DataName] = data;
     }
 }
Example #6
0
 public static void Execute(ViewDataDictionary viewData, DataRuleContext dataRuleContext, IEnumerable <DataRuleSetting> dataRules)
 {
     foreach (var item in dataRules)
     {
         var data = item.DataRule.Execute(dataRuleContext, item.TakeOperation, item.CachingDuration);
         if (item.DataName.EqualsOrNullEmpty(ModelName, StringComparison.CurrentCultureIgnoreCase))
         {
             viewData.Model = data;
         }
         viewData[item.DataName] = data;
     }
 }
Example #7
0
        //[DataMember(Order = 13)]
        //public new string FolderName { get; set; }
        public override Content.Query.IContentQuery<Content.Models.TextContent> Execute(DataRuleContext dataRuleContext)
        {
            var site = dataRuleContext.Site;
            var repository = Sites.Models.ModelExtensions.GetRepository(site);
            if (repository == null)
            {
                throw new SiteRepositoryNotExists();
            }
            var folder = FolderHelper.Parse<TextFolder>(repository, FolderName).AsActual();
            if (folder == null)
            {
                throw new KoobooException(string.Format("The folder does not exists.\"{0}\"".Localize(), FolderName));
            }
            Content.Query.IContentQuery<Content.Models.TextContent> contentQuery = null;
            if (folder is TextFolder)
            {
                var textFolder = (TextFolder)folder;
                contentQuery = textFolder.CreateQuery();
            }
            //else
            //{
            //    var binaryFolder = (MediaFolder)folder;
            //    contentQuery = binaryFolder.CreateQuery();
            //}
            if (WhereClauses != null)
            {
                contentQuery = contentQuery.Where(WhereClauses.Parse(folder.GetSchema(), dataRuleContext.ValueProvider));
            }
            if (!string.IsNullOrEmpty(CategoryFolderName) && this.CategoryClauses != null && this.CategoryClauses.Length > 0)
            {
                var categoryFolder = FolderHelper.Parse<TextFolder>(repository, CategoryFolderName);
                var categoryQuery = categoryFolder.CreateQuery();
                var expression = CategoryClauses.Parse(categoryFolder.GetSchema(), dataRuleContext.ValueProvider);
                if (expression != null)
                {
                    categoryQuery = categoryQuery.Where(expression);
                    contentQuery = contentQuery.WhereCategory(categoryQuery);
                }
            }

            //query the Published=null content for inline editor..
            if (Page_Context.Current.EnabledInlineEditing(EditingType.Content))
            {
                //contentQuery = contentQuery.Where(
                //    new Content.Query.Expressions.OrElseExpression(
                //        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", true),
                //        new Content.Query.Expressions.WhereEqualsExpression(null, "Published", null)));
            }
            else
                contentQuery = contentQuery.WhereEquals("Published", true); //default query published=true.
            return contentQuery;
        }
Example #8
0
 public void Test2()
 {
     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, context);
     var query = new TranslatedQueryMock();
     StringVisitor visitor = new StringVisitor(query);
     visitor.Visite(expression);
     Assert.AreEqual("((((((((title Conatins title1) OR (title Conatins title1))) AND (body Conatins body1))) OR (body Conatins body2))) OR (userkey Conatins userkey1))", query.ClauseText);
 }
Example #9
0
        public override Content.Query.IContentQuery<Content.Models.TextContent> Execute(DataRuleContext dataRuleContext)
        {
            var site = dataRuleContext.Site;
            var repositoryName = site.Repository;
            if (string.IsNullOrEmpty(repositoryName))
            {
                throw new KoobooException("The repository for site is null.");
            }
            var repository = new Repository(repositoryName);
            var schema = new Schema(repository, SchemaName);
            var contentQuery = (IContentQuery<Content.Models.TextContent>)schema.CreateQuery();

            contentQuery.Where(WhereClauses.Parse(schema,dataRuleContext.ValueProvider));

            return contentQuery;
        }
Example #10
0
        public override IContentQuery <Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext)
        {
            var site           = dataRuleContext.Site;
            var repositoryName = site.Repository;

            if (string.IsNullOrEmpty(repositoryName))
            {
                throw new KoobooException("The repository for site is null.");
            }
            var repository   = new Repository(repositoryName);
            var schema       = new Schema(repository, SchemaName);
            var contentQuery = (IContentQuery <Content.Models.TextContent>)schema.CreateQuery();

            contentQuery.Where(WhereClauses.Parse(schema, dataRuleContext.ValueProvider));

            return(contentQuery);
        }
Example #11
0
        private static NameValueCollection KeyValuesToNameValueCollection(DataRuleContext dataRuleContext, IEnumerable <CKeyValuePair <string, string> > keyValuePairs)
        {
            NameValueCollection values = new NameValueCollection();

            if (keyValuePairs != null && keyValuePairs.Count() > 0)
            {
                foreach (var item in keyValuePairs)
                {
                    if (!string.IsNullOrEmpty(item.Key))
                    {
                        var value = EvaluateStringFormulas(item.Value, dataRuleContext);
                        values[item.Key] = value;
                    }
                }
            }

            return(values);
        }
Example #12
0
        public virtual IHtmlString RenderView(HtmlHelper htmlHelper, Page_Context pageContext, string viewName, ViewDataDictionary viewData, object parameters, bool executeDataRule)
        {
            Kooboo.CMS.Sites.Models.View view = (new Kooboo.CMS.Sites.Models.View(pageContext.PageRequestContext.Site, viewName).LastVersion()).AsActual();

            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 = 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(htmlHelper, 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("");
            }
        }
Example #13
0
 public override Content.Query.IContentQuery<Content.Models.ContentBase> Execute(DataRuleContext dataRuleContext)
 {
     var contentQuery = base.Execute(dataRuleContext);
     if (contentQuery is MediaContentQuery)
     {
         throw new KoobooException(string.Format("The binary folder '{0}' does not support '{1}'.", FolderName, "CategorizableDataRule"));
     }
     var site = dataRuleContext.PageRequestContext.Site;
     var repositoryName = site.Repository;
     var repository = new Repository(repositoryName);
     var categorizableFolder = (TextFolder)(new TextFolder(repository, CategoryFolderName).AsActual());
     contentQuery = ((TextContentQuery)contentQuery);//.Categorizables(categorizableFolder);
     if (CategoryClauses != null)
     {
         foreach (var clause in CategoryClauses)
         {
             contentQuery = clause.Parse(contentQuery, dataRuleContext);
         }
     }
     return contentQuery;
 }
Example #14
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:
                    int top = 10;
                    if (int.TryParse(((FolderDataRule)dataRule).Top, out top))
                    {
                        model = contentQuery.Take(top);
                    }

                    viewPath = schema.GetFormTemplate(FormType.List);
                    break;
            }
            return ViewRender.RenderViewInternal(this.Html, viewPath, null, model);
        }
Example #15
0
        public static void Execute(ViewDataDictionary viewData, DataRuleContext dataRuleContext, IEnumerable<DataRuleSetting> dataRules)
        {
            foreach (var item in dataRules)
            {
                var contentQuery = item.DataRule.Execute(dataRuleContext);
                object data = contentQuery;
                if (item.DataRule is DataRuleBase)
                {
                    var dataRuleBase = (DataRuleBase)item.DataRule;
                    if (!string.IsNullOrEmpty(dataRuleBase.SortField))
                    {
                        if (dataRuleBase.SortDirection == DataRule.SortDirection.Ascending)
                        {
                            contentQuery = contentQuery.OrderBy(dataRuleBase.SortField);
                        }
                        else
                        {
                            contentQuery = contentQuery.OrderByDescending(dataRuleBase.SortField);
                        }
                    }
                    if (item.DataRule.EnablePaging.Value)
                    {
                        string pageIndexParameterName;
                        var pageIndexValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName);
                        var intPageIndexValue = 1;
                        int.TryParse(pageIndexValue, out intPageIndexValue);
                        if (intPageIndexValue < 1)
                        {
                            intPageIndexValue = 1;
                        }

                        string pageSizeParameterName;
                        var pageSizeValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName);
                        var intPageSize = 10;
                        int.TryParse(pageSizeValue, out intPageSize);
                        if (intPageSize < 1)
                        {
                            intPageSize = 10;
                        }

                        var totalCount = contentQuery.Count();

                        data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize)
                            , intPageIndexValue
                            , intPageSize
                            , totalCount)
                            {
                                PageIndexParameterName = pageIndexParameterName
                            };
                    }
                    else if (!string.IsNullOrEmpty(dataRuleBase.Top))
                    {
                        string fieldName;
                        var topValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.Top, dataRuleContext.ValueProvider, out fieldName);
                        var intTopValue = 1;
                        int.TryParse(topValue, out intTopValue);

                        data = contentQuery.Take(intTopValue);
                    }
                    else
                    {
                        data = contentQuery;
                    }
                }

                if (data is IContentQuery<ContentBase>)
                {
                    data = GetData(item, (IContentQuery<TextContent>)data);
                }

                if (item.DataName.EqualsOrNullEmpty(ModelName, StringComparison.CurrentCultureIgnoreCase))
                {
                    viewData.Model = data;
                }
                viewData[item.DataName] = data;
            }
        }
Example #16
0
 public abstract Content.Query.IContentQuery<Content.Models.TextContent> Execute(DataRuleContext dataRuleContext);
Example #17
0
 public abstract IContentQuery<Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext);
Example #18
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);
                }
            }
        }
Example #19
0
        private static string EvaluateStringFormulas(string formula, DataRuleContext dataRuleContext)
        {
            var formulaParser = new FormulaParser();

            return(formulaParser.Populate(formula, new ValueProviderBridge(dataRuleContext.ValueProvider)));
        }
Example #20
0
        public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration)
        {
            var contentQuery = this.GetContentQuery(dataRuleContext);
            object data = contentQuery;

            if (!string.IsNullOrEmpty(this.SortField))
            {
                if (this.SortDirection == DataRule.SortDirection.Ascending)
                {
                    contentQuery = contentQuery.OrderBy(this.SortField);
                }
                else
                {
                    contentQuery = contentQuery.OrderByDescending(this.SortField);
                }
            }
            if (this.EnablePaging.Value)
            {
                string pageIndexParameterName;
                var pageIndexValue = ParameterizedFieldValue.GetFieldValue(this.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName);
                var intPageIndexValue = 1;
                int.TryParse(pageIndexValue, out intPageIndexValue);
                if (intPageIndexValue < 1)
                {
                    intPageIndexValue = 1;
                }

                var intPageSize = 10;
                if (string.IsNullOrEmpty(this.Top))
                {
                    string pageSizeParameterName;
                    var pageSizeValue = ParameterizedFieldValue.GetFieldValue(this.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName);

                    int.TryParse(pageSizeValue, out intPageSize);
                    if (intPageSize < 1)
                    {
                        intPageSize = 10;
                    }
                }
                else
                {
                    string fieldName;
                    var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider,
                        out fieldName);
                    int.TryParse(topValue, out intPageSize);
                }

                var totalCount = contentQuery.Count();

                data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize)
                    , intPageIndexValue
                    , intPageSize
                    , totalCount)
                {
                    PageIndexParameterName = pageIndexParameterName
                };
            }
            else if (!string.IsNullOrEmpty(this.Top))
            {
                string fieldName;
                var topValue = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName);
                var intTopValue = 1;
                int.TryParse(topValue, out intTopValue);

                data = contentQuery.Take(intTopValue);
            }
            else
            {
                data = contentQuery;
            }

            if (data is IContentQuery<ContentBase>)
            {
                data = GetData((IContentQuery<TextContent>)data, operation, cacheDuration);
            }

            return data;
        }
Example #21
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);
        }
Example #22
0
        public static void Execute(ViewDataDictionary viewData, DataRuleContext dataRuleContext, IEnumerable <DataRuleSetting> dataRules)
        {
            foreach (var item in dataRules)
            {
                var    contentQuery = item.DataRule.Execute(dataRuleContext);
                object data         = contentQuery;
                if (item.DataRule is DataRuleBase)
                {
                    var dataRuleBase = (DataRuleBase)item.DataRule;
                    if (!string.IsNullOrEmpty(dataRuleBase.SortField))
                    {
                        if (dataRuleBase.SortDirection == DataRule.SortDirection.Ascending)
                        {
                            contentQuery = contentQuery.OrderBy(dataRuleBase.SortField);
                        }
                        else
                        {
                            contentQuery = contentQuery.OrderByDescending(dataRuleBase.SortField);
                        }
                    }
                    if (item.DataRule.EnablePaging())
                    {
                        string pageIndexParameterName;
                        var    pageIndexValue    = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName);
                        var    intPageIndexValue = 1;
                        int.TryParse(pageIndexValue, out intPageIndexValue);
                        if (intPageIndexValue < 1)
                        {
                            intPageIndexValue = 1;
                        }

                        string pageSizeParameterName;
                        var    pageSizeValue = ParameterizedFieldValue.GetFieldValue(dataRuleBase.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName);
                        var    intPageSize   = 10;
                        int.TryParse(pageSizeValue, out intPageSize);
                        if (intPageSize < 1)
                        {
                            intPageSize = 10;
                        }

                        var totalCount = contentQuery.Count();

                        data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize)
                                                     , intPageIndexValue
                                                     , intPageSize
                                                     , totalCount)
                        {
                            PageIndexParameterName = pageIndexParameterName
                        };
                    }
                    else if (!string.IsNullOrEmpty(dataRuleBase.Top))
                    {
                        string fieldName;
                        var    topValue    = ParameterizedFieldValue.GetFieldValue(dataRuleBase.Top, dataRuleContext.ValueProvider, out fieldName);
                        var    intTopValue = 1;
                        int.TryParse(topValue, out intTopValue);

                        data = contentQuery.Take(intTopValue);
                    }
                }

                if (data is IContentQuery <ContentBase> )
                {
                    data = GetData(item, (IContentQuery <TextContent>)data);
                }


                if (item.DataName.EqualsOrNullEmpty(ModelName, StringComparison.CurrentCultureIgnoreCase))
                {
                    viewData.Model = data;
                }
                viewData[item.DataName] = data;
            }
        }
Example #23
0
        public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration)
        {
            var url = EvaluateStringFormulas(this.URL, dataRuleContext);
            NameValueCollection form = KeyValuesToNameValueCollection(dataRuleContext, this.FormData);
            NameValueCollection headers = KeyValuesToNameValueCollection(dataRuleContext, this.Headers);

            var httpDataRequest = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve<IHttpDataRequest>();
            return httpDataRequest.GetData(url, this.HttpMethod, ContentType, form, headers);
        }
Example #24
0
 public abstract Content.Query.IContentQuery <Content.Models.TextContent> Execute(DataRuleContext dataRuleContext);
Example #25
0
 private static string EvaluateStringFormulas(string formula, DataRuleContext dataRuleContext)
 {
     var formulaParser = new FormulaParser();
     return formulaParser.Populate(formula, new ValueProviderBridge(dataRuleContext.ValueProvider));
 }
 public override Content.Query.IContentQuery<Content.Models.ContentBase> Execute(DataRuleContext dataRuleContext)
 {            
     var contentQuery = base.Execute(dataRuleContext);
     if (contentQuery is MediaContentQuery)
     {
         throw new KoobooException(string.Format("The binary folder '{0}' does not support '{1}'.", FolderName, "CategorizableDataRule"));
     }
     var site = dataRuleContext.PageRequestContext.Site;
     var repositoryName = site.Repository;
     var repository = new Repository(repositoryName);
     var categorizableFolder = (TextFolder)(new TextFolder(repository, CategoryFolderName).AsActual());
     contentQuery = ((TextContentQuery)contentQuery);//.Categorizables(categorizableFolder);
     if (CategoryClauses != null)
     {
         foreach (var clause in CategoryClauses)
         {
             contentQuery = clause.Parse(contentQuery, dataRuleContext);
         }
     }
     return contentQuery;
 }
Example #27
0
 public abstract IContentQuery <Content.Models.TextContent> GetContentQuery(DataRuleContext dataRuleContext);
Example #28
0
        private static NameValueCollection KeyValuesToNameValueCollection(DataRuleContext dataRuleContext, IEnumerable<CKeyValuePair<string, string>> keyValuePairs)
        {
            NameValueCollection values = new NameValueCollection();
            if (keyValuePairs != null && keyValuePairs.Count() > 0)
            {
                foreach (var item in keyValuePairs)
                {
                    if (!string.IsNullOrEmpty(item.Key))
                    {
                        var value = EvaluateStringFormulas(item.Value, dataRuleContext);
                        values[item.Key] = value;
                    }
                }
            }

            return values;
        }
Example #29
0
        public object Execute(DataRuleContext dataRuleContext, TakeOperation operation, int cacheDuration)
        {
            var    contentQuery = this.GetContentQuery(dataRuleContext);
            object data         = contentQuery;

            if (!string.IsNullOrEmpty(this.SortField))
            {
                if (this.SortDirection == DataRule.SortDirection.Ascending)
                {
                    contentQuery = contentQuery.OrderBy(this.SortField);
                }
                else
                {
                    contentQuery = contentQuery.OrderByDescending(this.SortField);
                }
            }
            if (this.EnablePaging.Value)
            {
                string pageIndexParameterName;
                var    pageIndexValue    = ParameterizedFieldValue.GetFieldValue(this.PageIndex, dataRuleContext.ValueProvider, out pageIndexParameterName);
                var    intPageIndexValue = 1;
                int.TryParse(pageIndexValue, out intPageIndexValue);
                if (intPageIndexValue < 1)
                {
                    intPageIndexValue = 1;
                }

                string pageSizeParameterName;
                var    pageSizeValue = ParameterizedFieldValue.GetFieldValue(this.PageSize, dataRuleContext.ValueProvider, out pageSizeParameterName);
                var    intPageSize   = 10;
                int.TryParse(pageSizeValue, out intPageSize);
                if (intPageSize < 1)
                {
                    intPageSize = 10;
                }

                var totalCount = contentQuery.Count();

                data = new DataRulePagedList(contentQuery.Skip((intPageIndexValue - 1) * intPageSize).Take(intPageSize)
                                             , intPageIndexValue
                                             , intPageSize
                                             , totalCount)
                {
                    PageIndexParameterName = pageIndexParameterName
                };
            }
            else if (!string.IsNullOrEmpty(this.Top))
            {
                string fieldName;
                var    topValue    = ParameterizedFieldValue.GetFieldValue(this.Top, dataRuleContext.ValueProvider, out fieldName);
                var    intTopValue = 1;
                int.TryParse(topValue, out intTopValue);

                data = contentQuery.Take(intTopValue);
            }
            else
            {
                data = contentQuery;
            }


            if (data is IContentQuery <ContentBase> )
            {
                data = GetData((IContentQuery <TextContent>)data, operation, cacheDuration);
            }

            return(data);
        }