Exemplo n.º 1
0
        public string Render(RenderContext context)
        {
            // step get the repeat object. and push to datacontext every time.
            object repeatcontainer = context.DataContext.GetValue(this.datakey);

            if (repeatcontainer == null)
            {
                return(null);
            }


            StringBuilder sb = new StringBuilder();

            string container = RenderHelper.Render(this.ContainerTask, context);

            if (!string.IsNullOrEmpty(container))
            {
                sb.Append(container);
            }

            if (repeatcontainer is DataMethodResult)
            {
                repeatcontainer = ((DataMethodResult)repeatcontainer).Value;
            }
            else if (repeatcontainer.GetType() == typeof(string))
            {
                // this is json.
                repeatcontainer = Lib.Helper.JsonHelper.Deserialize <List <object> >(repeatcontainer.ToString());
            }

            IList itemcollection = GetList(repeatcontainer);

            context.DataContext.RepeatCounter.Push(itemcollection.Count);
            int counter = 0;

            foreach (var item in itemcollection)
            {
                counter = counter + 1;
                context.DataContext.RepeatCounter.CurrentCounter.Current = counter;

                if (counter > Kooboo.Data.AppSettings.MaxForEachLoop)
                {
                    throw new System.Exception(Data.Language.Hardcoded.GetValue("You have reached the max loop limitation in your account", context));
                }

                context.DataContext.Push(this.alias, item);

                sb.Append(RenderHelper.Render(this.SubTasks, context));

                context.DataContext.Pop();
            }
            context.DataContext.RepeatCounter.Pop();

            if (!string.IsNullOrEmpty(this.ContainerEndTag))
            {
                sb.Append(this.ContainerEndTag);
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public string Render(RenderContext context)
        {
            RenderComponent(context);
            var plans  = RenderPlanManager.GetLayoutPlan(this.LayoutName, context);
            var result = RenderHelper.Render(plans, context);

            return(result);
        }
Exemplo n.º 3
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            if (option.RequireBindingInfo)
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, option);
                var traceability = new ComponentTrace(context.Page.Id.ToString(), "page");
                var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                    { "scope", "true" }
                });
                RenderPlan.Insert(0, bindingTask);
                RenderPlan.Add(bindingTask.BindingEndRenderTask);

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }
            else
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, option));

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
Exemplo n.º 4
0
        public static string Bind(object Model, string Html, string ModelName = "model")
        {
            if (Model == null)
            {
                return(Html);
            }
            RenderContext context = new RenderContext();

            context.DataContext.Push(ModelName, Model);

            var plans = RenderEvaluator.Evaluate(Html, new EvaluatorOption());

            return(RenderHelper.Render(plans, context));
        }
Exemplo n.º 5
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            if (context.RenderContext.Request.Channel != Data.Context.RequestChannel.InlineDesign)
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, GetPageOption(context)));

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
            }
            else
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, GetPageOption(context));
                RenderPlan.Insert(0, new BindingObjectRenderTask()
                {
                    ObjectType = "page", NameOrId = context.Page.Id.ToString()
                });

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
Exemplo n.º 6
0
        public static async Task <string> RenderMockPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            option.Evaluators = EvaluatorContainer.MockData;

            context.RenderContext.MockData = true;

            RenderPlan = RenderEvaluator.Evaluate(context.Page.Body, option);

            result = RenderHelper.Render(RenderPlan, context.RenderContext);

            return(result);
        }
Exemplo n.º 7
0
        public static string Bind(string Html, RenderContext context)
        {
            var plans = RenderEvaluator.Evaluate(Html, new EvaluatorOption());

            return(RenderHelper.Render(plans, context));
        }
Exemplo n.º 8
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            if (option.RequireBindingInfo)
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, option);
                var traceability = new ComponentTrace(context.Page.Id.ToString(), "page");
                var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                    { "scope", "true" }
                });
                RenderPlan.Insert(0, bindingTask);
                RenderPlan.Add(bindingTask.BindingEndRenderTask);

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }
            else
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, option));

                // check the cache.
                if (context.Page.EnableCache)
                {
                    Dictionary <string, string> querystring = null;

                    if (!string.IsNullOrWhiteSpace(context.Page.CacheQueryKeys))
                    {
                        //querystring = RequestManager.GetQueryString(context.RenderContext.Request);
                        querystring = GetParaValues(context.RenderContext, context.Page.CacheKeys);
                    }

                    if (context.Page.CacheByVersion)
                    {
                        result = PageCache.PageCache.GetByVersion(context.SiteDb.Id, context.Page.Id, context.Page.Version, querystring);
                    }
                    else
                    {
                        result = PageCache.PageCache.GetByMinutes(context.SiteDb.Id, context.Page.Id, context.Page.CacheMinutes, querystring, context.Page.Version);
                    }

                    if (string.IsNullOrEmpty(result))
                    {
                        result = RenderHelper.Render(RenderPlan, context.RenderContext);

                        Kooboo.Sites.Render.PageCache.PageCache.Set(context.SiteDb.Id, context.Page.Id, result, context.Page.Version, querystring);
                    }


                    // cache result may have replacement.
                }
                else
                {
                    result = RenderHelper.Render(RenderPlan, context.RenderContext);
                }
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
Exemplo n.º 9
0
        public string Render(RenderContext context)
        {
            long low = this.LowBound;

            if (low == long.MinValue && !string.IsNullOrEmpty(this.LowBoundKey))
            {
                var lowvalue = context.DataContext.GetValue(this.LowBoundKey);

                if (lowvalue == null || !long.TryParse(lowvalue.ToString(), out low))
                {
                    return(null);
                }
            }

            long high = this.HighBound;

            if (high == long.MinValue && !string.IsNullOrEmpty(this.HighBoundKey))
            {
                var highvalue = context.DataContext.GetValue(this.HighBoundKey);
                if (highvalue == null || !long.TryParse(highvalue.ToString(), out high))
                {
                    return(null);
                }
            }

            if (high == long.MinValue || low == long.MinValue)
            {
                return(null);
            }
            int count = (int)(high - low);

            if (count < 1)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            string container = RenderHelper.Render(this.ContainerTask, context);

            if (!string.IsNullOrEmpty(container))
            {
                sb.Append(container);
            }

            context.DataContext.RepeatCounter.Push(count);
            int counter = 0;

            for (long i = low; i < high; i++)
            {
                counter = counter + 1;

                if (counter > Kooboo.Data.AppSettings.MaxForEachLoop)
                {
                    throw new System.Exception(Data.Language.Hardcoded.GetValue("You have reached the max loop limitation in your account", context));
                }

                context.DataContext.RepeatCounter.CurrentCounter.Current = counter;

                if (!string.IsNullOrEmpty(this.datakey))
                {
                    context.DataContext.Push(this.datakey, i);
                }

                sb.Append(RenderHelper.Render(this.SubTasks, context));

                if (!string.IsNullOrEmpty(this.datakey))
                {
                    context.DataContext.Pop();
                }
            }

            context.DataContext.RepeatCounter.Pop();

            if (!string.IsNullOrEmpty(this.ContainerEndTag))
            {
                sb.Append(this.ContainerEndTag);
            }

            return(sb.ToString());
        }
Exemplo n.º 10
0
        public string Render(RenderContext context)
        {
            if (this.OwnerObjectId == default(Guid))
            {
                // this should not happen... just in case...
                InitOrgTask();
                string open = Kooboo.Sites.Service.DomService.GenerateOpenTag(this.FormAttributes, "form");
                return(open + RenderHelper.Render(this.BodyTask, context) + "</form>");
            }

            var sitedb = context.WebSite.SiteDb();

            var form = sitedb.Forms.Get(this.FormId);

            FormSetting formsetting = null;

            if (form != null)
            {
                formsetting = sitedb.FormSetting.GetByFormId(form.Id);
            }

            if (form == null || formsetting == null || formsetting.Enable == false || string.IsNullOrEmpty(formsetting.FormSubmitter))
            {
                InitOrgTask();
                string open = Kooboo.Sites.Service.DomService.GenerateOpenTag(this.FormAttributes, "form");
                return(open + RenderHelper.Render(this.BodyTask, context) + "</form>");
            }
            // or else result

            string submiturl = Kooboo.Sites.HtmlForm.FormManager.GetSubmitUrl(form, formsetting, context);



            Dictionary <string, string> attributes = new Dictionary <string, string>(FormAttributes);

            attributes["action"] = submiturl;
            attributes["method"] = string.IsNullOrEmpty(formsetting.Method) ? "post" : formsetting.Method;

            string key = "kform_" + Lib.Security.ShortGuid.GetNewShortId();

            /// append additional koobooform id.....
            //if (form.FormType == FormType.KoobooForm || formsetting.AllowAjax)
            //{
            attributes["id"] = key;
            //}

            string opentag = Kooboo.Sites.Service.DomService.GenerateOpenTag(attributes, "form");

            if (formsetting.IsSelfRefresh)
            {
                opentag = opentag + "<input type='hidden' name=\"" + Sites.HtmlForm.FormManager.FormUrlName + "\" value=\"" + context.Request.RawRelativeUrl + "\" />";
            }


            //if (formsetting.AllowAjax)
            //{
            string addtionalJS = "<script src=\"/_admin/scripts/lib/jquery.min.js\"></script><script src=\"/_admin/scripts/lib/jqBootstrapValidation.js\"></script>";

            opentag += addtionalJS;

            opentag += JsString(key, formsetting.SuccessCallBack, formsetting.FailedCallBack);
            // }


            if (!string.IsNullOrEmpty(form.Body))
            {
                InitFormBodyTask(form.Body);
                return(opentag + RenderHelper.Render(this.BodyTask, context) + "</form>");
            }
            else
            {
                InitOrgTask();
                return(opentag + RenderHelper.Render(this.BodyTask, context) + "</form>");
            }
        }