Exemple #1
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            if (settings == null || string.IsNullOrEmpty(settings.NameOrId))
            {
                return(Task.FromResult(string.Empty));
            }
            var      frontcontext = context.GetItem <Render.FrontContext>();
            DateTime logstart     = DateTime.UtcNow;

            Menu menu = frontcontext.SiteDb.Menus.GetByNameOrId(settings.NameOrId);

            if (menu == null)
            {
                frontcontext.AddLogEntry("menu", "", logstart, 404);
                return(Task.FromResult(string.Empty));
            }

            string returnstring = MenuHelper.Render(menu, context, GetRenderLevel(settings));

            frontcontext.AddLogEntry("menu", menu.Name, logstart, 200);

            //if (context.Request.Channel == RequestChannel.InlineDesign)
            //{
            //    returnstring = DomService.ApplyKoobooId(returnstring);
            //}

            return(Task.FromResult(returnstring));
        }
Exemple #2
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            // other engine only support inner html or dynamic render....
            string result = Kooboo.Sites.Engine.Manager.Execute(settings.Engine, context, settings.InnerHtml, settings.TagName, settings.TagAttributes);

            return(Task.FromResult <string>(result));
        }
Exemple #3
0
        public static ComponentSetting LoadFromElement(Element ComponentElement)
        {
            ComponentSetting setting = new ComponentSetting();

            setting.NameOrId = ComponentElement.id;
            setting.TagName  = ComponentElement.tagName;

            setting.InnerHtml = ComponentElement.InnerHtml;

            foreach (var item in ComponentElement.attributes)
            {
                if (item != null && item.name.ToLower() == Kooboo.Sites.Render.Components.Constants.KoobooAttributeName)
                {
                    setting.Engine = item.value != null?item.value.ToLower() : null;
                }
                setting.TagAttributes.Add(item.name, item.value);
            }

            if (string.IsNullOrEmpty(setting.TagName))
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(setting.NameOrId) && string.IsNullOrWhiteSpace(setting.InnerHtml))
            {
                return(null);
            }

            foreach (var item in ComponentElement.childNodes.item)
            {
                if (item.nodeType == enumNodeType.ELEMENT)
                {
                    Element child = item as Element;
                    if (child == null)
                    {
                        continue;
                    }
                    string elementid = child.id;
                    if (string.IsNullOrEmpty(elementid))
                    {
                        elementid = child.tagName;
                    }

                    if (!string.IsNullOrEmpty(elementid) && !setting.Settings.ContainsKey(elementid))
                    {
                        setting.Settings.Add(elementid, child.textContent);
                    }
                }
            }
            return(setting);
        }
Exemple #4
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            if (settings != null && !string.IsNullOrEmpty(settings.NameOrId))
            {
                HtmlBlock htmlBlock = context.WebSite.SiteDb().HtmlBlocks.GetByNameOrId(settings.NameOrId);

                if (htmlBlock != null)
                {
                    return(Task.FromResult(htmlBlock.GetValue(context.Culture).ToString()));
                }
            }

            return(Task.FromResult(string.Empty));
        }
Exemple #5
0
        private int GetRenderLevel(ComponentSetting setting)
        {
            int result = 999;

            if (setting.Settings != null)
            {
                if (setting.Settings.ContainsKey(MenuLevelSettingName))
                {
                    var strlevel = setting.Settings[MenuLevelSettingName];
                    int.TryParse(strlevel, out result);
                }
            }

            return(result);
        }
Exemple #6
0
        public Task <string> RenderMockAsync(RenderContext context, ComponentSetting setting)
        {
            var      frontcontext = context.GetItem <FrontContext>();
            DateTime logstart     = DateTime.UtcNow;

            View view = context.WebSite.SiteDb().Views.GetByNameOrId(setting.NameOrId);

            view = CheckAlternativeView(view, frontcontext);

            frontcontext.ExecutingView = view;

            string viewBody = null;

            frontcontext.Views.Add(view);

            if (setting.Settings != null && setting.Settings.Count() > 0)
            {
                context.DataContext.Push(setting.Settings);
            }


            viewBody = view.Body;

            Guid viewid = view.Id;

            List <IRenderTask> renderplan;
            string             returnstring = string.Empty;

            var options = RenderOptionHelper.GetViewOption(context, viewid);

            options.MockData = true;

            renderplan = RenderEvaluator.Evaluate(viewBody, options);

            returnstring += RenderHelper.Render(renderplan, frontcontext.RenderContext);

            if (setting.Settings != null && setting.Settings.Count() > 0)
            {
                context.DataContext.Pop();
            }

            frontcontext.AddLogEntry("view", view.Name, logstart, 200);

            frontcontext.ExecutingView = null;
            return(Task.FromResult(returnstring));
        }
Exemple #7
0
        public async static void Render(FrontContext context)
        {
            Components.ComponentSetting setting = new Components.ComponentSetting();
            setting.TagName  = "view";
            setting.NameOrId = context.Route.objectId.ToString();

            var    ViewComponent = Components.Container.Get("view");
            string viewresult    = null;

            if (ViewComponent != null)
            {
                viewresult = await ViewComponent.RenderAsync(context.RenderContext, setting);
            }

            if (!string.IsNullOrEmpty(viewresult))
            {
                context.RenderContext.Response.Body = Encoding.UTF8.GetBytes(viewresult);
            }
        }
Exemple #8
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            if (context.MockData)
            {
                return(null);
            }

            string code   = settings.InnerHtml;
            string result = null;

            if (settings.Engine == "kscript")
            {
                if (!string.IsNullOrWhiteSpace(settings.NameOrId))
                {
                    var kscript = context.WebSite.SiteDb().Code.Get(settings.NameOrId);
                    if (kscript != null)
                    {
                        result = Scripting.Manager.ExecuteCode(context, kscript.Body, kscript.Id);  ///  code = kscript.Body;
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(code))
                    {
                        result = Scripting.Manager.ExecuteInnerScript(context, code);
                    }
                }
            }
            else
            {
                // other engine only support inner html or dynamic render....
                if (!string.IsNullOrWhiteSpace(settings.Engine) && !string.IsNullOrWhiteSpace(code))
                {
                    result = Kooboo.Sites.Engine.Manager.Execute(settings.Engine, context, code, settings.TagName, settings.TagAttributes);
                }
                else
                {
                    result = code;
                }
            }

            return(Task.FromResult <string>(result));
        }
Exemple #9
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            if (settings != null && !string.IsNullOrEmpty(settings.NameOrId))
            {
                HtmlBlock htmlBlock = context.WebSite.SiteDb().HtmlBlocks.GetByNameOrId(settings.NameOrId);

                if (htmlBlock != null)
                {
                    var result = htmlBlock.GetValue(context.Culture).ToString();
                    if (context.Request.Channel == RequestChannel.InlineDesign)
                    {
                        result = DomService.ApplyKoobooId(result);
                    }

                    return(Task.FromResult(result));
                }
            }

            return(Task.FromResult(string.Empty));
        }
Exemple #10
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting setting)
        {
            var      frontcontext = context.GetItem <FrontContext>();
            DateTime logstart     = DateTime.UtcNow;

            View view = null;

            if (context.WebSite.EnableFrontEvents && context.IsSiteBinding)
            {
                view = Kooboo.Sites.FrontEvent.Manager.RaiseViewEvent(FrontEvent.enumEventType.ViewFinding, context, setting);

                if (view == null)
                {
                    view = context.WebSite.SiteDb().Views.GetByNameOrId(setting.NameOrId);
                    if (view != null)
                    {
                        var result = FrontEvent.Manager.RaiseViewEvent(FrontEvent.enumEventType.ViewFound, context, setting, view);

                        if (result != null)
                        {
                            view = result;
                        }
                    }
                    else
                    {
                        view = FrontEvent.Manager.RaiseViewEvent(FrontEvent.enumEventType.ViewNotFound, context, setting);
                    }
                }
            }

            if (view == null)
            {
                view = context.WebSite.SiteDb().Views.GetByNameOrId(setting.NameOrId);
            }


            if (view == null)
            {
                frontcontext.AddLogEntry("view", "", logstart, 404);
                return(Task.FromResult(string.Empty));
            }

            view = CheckAlternativeView(view, frontcontext);

            frontcontext.ExecutingView = view;

            var    dataResults = new Dictionary <string, object>();
            string viewBody    = null;

            frontcontext.Views.Add(view);

            if (setting.Settings != null && setting.Settings.Count() > 0)
            {
                context.DataContext.Push(setting.Settings);
            }

            var allviewdatamethods = Cache.SiteObjectCache <ViewDataMethod> .List(frontcontext.SiteDb).Where(o => o.ViewId == view.Id).ToList();

            foreach (var datemethod in allviewdatamethods)
            {
                frontcontext.ViewDataMethods.Add(datemethod);

                var result = DataSources.DataMethodExecutor.ExecuteViewDataMethod(frontcontext, datemethod);

                if (result != null)
                {
                    if (result is PagedResult)
                    {
                        var pagedresult = result as  PagedResult;

                        dataResults[datemethod.AliasName] = pagedresult.DataList;
                        dataResults[datemethod.AliasName + ".TotalPages"] = pagedresult.TotalPages;
                        List <int> PageNrs = new List <int>();
                        for (int i = 1; i <= pagedresult.TotalPages; i++)
                        {
                            PageNrs.Add(i);
                        }
                        dataResults[datemethod.AliasName + ".CurrentPage"] = pagedresult.PageNumber;
                        dataResults[datemethod.AliasName + ".Pages"]       = PageNrs;
                    }
                    else
                    {
                        //if (result is DataMethodResult)
                        //{
                        //    var methodresult = result as DataMethodResult;
                        //    if (methodresult.Value is PagedResult)
                        //    {
                        //        var pagedresult = methodresult.Value as PagedResult;

                        //        dataResults[datemethod.AliasName + ".TotalPages"] = pagedresult.TotalPages;
                        //        List<int> PageNrs = new List<int>();
                        //        for (int i = 1; i <= pagedresult.TotalPages; i++)
                        //        {
                        //            PageNrs.Add(i);
                        //        }
                        //        dataResults[datemethod.AliasName + ".CurrentPage"] = pagedresult.PageNumber;
                        //        dataResults[datemethod.AliasName + ".Pages"] = PageNrs;
                        //    }
                        //}

                        dataResults[datemethod.AliasName] = result;
                    }
                }
            }

            if (dataResults.Count > 0)
            {
                context.DataContext.Push(dataResults);
            }

            viewBody = view.Body;

            Guid viewid = view.Id;

            List <IRenderTask> renderplan;
            string             returnstring = string.Empty;

            var options = RenderOptionHelper.GetViewOption(context, viewid);

            if (options.RequireBindingInfo)
            {
                viewBody   = DomService.ApplyKoobooId(viewBody);
                renderplan = RenderEvaluator.Evaluate(viewBody, options);
            }
            else
            {
                renderplan = Cache.RenderPlan.GetOrAddRenderPlan(frontcontext.SiteDb, viewid, () => RenderEvaluator.Evaluate(viewBody, options));
            }


            returnstring += RenderHelper.Render(renderplan, frontcontext.RenderContext);

            if (dataResults.Count > 0)
            {
                context.DataContext.Pop();
            }


            if (setting.Settings != null && setting.Settings.Count() > 0)
            {
                context.DataContext.Pop();
            }


            frontcontext.AddLogEntry("view", view.Name, logstart, 200);

            frontcontext.ExecutingView = null;
            return(Task.FromResult(returnstring));
        }
Exemple #11
0
        public Task <string> RenderAsync(RenderContext context, ComponentSetting settings)
        {
            if (settings == null || string.IsNullOrWhiteSpace(settings.NameOrId))
            {
                return(null);
            }
            var sitedb = context.WebSite.SiteDb();

            var formid = Data.IDGenerator.GetOrGenerate(settings.NameOrId, ConstObjectType.Form);

            var form = sitedb.Forms.Get(formid);

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

            var formsetting = sitedb.FormSetting.GetByFormId(form.Id);

            string body = form.Body;

            if (body.IndexOf("<form", StringComparison.OrdinalIgnoreCase) == -1)
            {
                body = "<form>" + body + "</form>";
            }

            if (formsetting == null || formsetting.Enable == false || string.IsNullOrWhiteSpace(formsetting.FormSubmitter))
            {
                return(Task.FromResult(body));
            }

            var computeHash = Lib.Security.Hash.ComputeHashGuid(body);

            if (computeHash != this.FormHash)
            {
                this.FormHash = computeHash;
                // reset form...
                var el = GetFormElement(body);
                this.FormAttributes = new Dictionary <string, string>();

                foreach (var item in el.attributes)
                {
                    this.FormAttributes.Add(item.name, item.value);
                }
                var option = RenderOptionHelper.GetFormOption(context, form.Id);
                this.bodyRenderTask = RenderEvaluator.Evaluate(el.InnerHtml, option);
            }

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


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

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

            if (formsetting.AllowAjax)
            {
                attributes["onsubmit"] = "return false;";
            }

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

            /// append additional koobooform id.....
            if (form.FormType == Models.FormType.KoobooForm)
            {
                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 ajax, append the additional text here...

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


            string result = opentag + RenderHelper.Render(GetBodyTask(form.Body), context) + "</form>";

            result += JsString(key, formsetting.SuccessCallBack, formsetting.FailedCallBack, formsetting.AllowAjax);

            return(Task.FromResult(result));
        }