示例#1
0
        public void RenderView(string ViewBody)
        {
            var options = RenderOptionHelper.GetViewOption(context, default(Guid));

            var renderplan = RenderEvaluator.Evaluate(ViewBody, options);


            var result = RenderHelper.Render(renderplan, this.context);

            if (!string.IsNullOrWhiteSpace(result))
            {
                write(result);
            }
        }
示例#2
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));
        }
示例#3
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));
        }