Exemple #1
0
        public void ContinueConvert(SiteDb siteDb, Guid OriginalPageId, string ConvertedTag, string ObjectNameOrId, string KoobooId, Page CurrentPage, List <string> ElementPath)
        {
            if (OriginalPageId == CurrentPage.Id)
            {
                return;
            }
            Menu menu = siteDb.Menus.GetByNameOrId(ObjectNameOrId);

            if (menu == null)
            {
                return;
            }
            var menuelement = DomService.GetElementByPath(CurrentPage.Dom, ElementPath);

            if (menuelement != null)
            {
                var rawmenu = MenuService.FindRawMenu(menuelement);
                if (rawmenu != null)
                {
                    AssignRawMenu(menu, rawmenu);
                }
                CurrentPage.Body = CurrentPage.Body.Substring(0, menuelement.location.openTokenStartIndex) + ConvertedTag + CurrentPage.Body.Substring(menuelement.location.endTokenEndIndex + 1);

                siteDb.Pages.AddOrUpdate(CurrentPage);
            }
        }
Exemple #2
0
        public static List <IRenderTask> GetLayoutPlan(string NameOrId, RenderContext context)
        {
            var layout = context.WebSite.SiteDb().Layouts.GetByNameOrId(NameOrId);

            if (layout == null)
            {
                return(null);
            }
            List <IRenderTask> renderplans = null;
            EvaluatorOption    options     = new  EvaluatorOption();

            options.RenderHeader  = true;
            options.OwnerObjectId = layout.Id;

            if (context.Request.Channel == RequestChannel.InlineDesign)
            {
                string body = DomService.ApplyKoobooId(layout.Body);
                options.RequireBindingInfo = true;
                renderplans = RenderEvaluator.Evaluate(body, options);
            }
            else
            {
                renderplans = Cache.RenderPlan.GetOrAddRenderPlan(context.WebSite.SiteDb(), layout.Id, () => RenderEvaluator.Evaluate(layout.Body, options));
            }

            return(renderplans);
        }
Exemple #3
0
        public void EnterText(Element element, string value, bool clearFirst = true)
        {
            string selectorValue = element.htmlSelector.selectorValue;
            string selectorType  = Convert.ToString(element.htmlSelector.selectBy);

            DomService.EnterText(selectorValue, selectorType, value, clearFirst);
        }
Exemple #4
0
        internal IEnumerable <dynamic> GetCQHTMLElementCollection(HtmlSelector selector)
        {
            string parentSelectorValue = selector.selectorValue;
            string parentSelectorType  = Convert.ToString(selector.selectBy);

            return(DomService.GetCQHTMLElementCollection(parentSelectorValue, parentSelectorType));
        }
Exemple #5
0
        public bool HasElement(Element element)
        {
            string selectorValue = element.htmlSelector.selectorValue;
            string selectorType  = Convert.ToString(element.htmlSelector.selectBy);

            return(DomService.HasElement(selectorValue, selectorType));
        }
        protected virtual async void EditOnTryMudBlazor()
        {
            // We use a seperator that wont be in code so we can send 2 files later
            var codeFiles = "__Main.razor" + (char)31 + Snippets.GetCode(Code);

            // Add dialogs for dialog examples
            if (Code.StartsWith("Dialog"))
            {
                var regex          = new Regex(@"\Show<(Dialog.*?_Dialog)\>");
                var dialogCodeName = regex.Match(codeFiles).Groups[1].Value;
                if (dialogCodeName != string.Empty)
                {
                    var dialogCodeFile = dialogCodeName + ".razor" + (char)31 + Snippets.GetCode(dialogCodeName);
                    codeFiles = codeFiles + (char)31 + dialogCodeFile;
                }
            }

            // Add Element.cs model for webapi periodic table
            if (codeFiles.Contains("webapi/periodictable", StringComparison.InvariantCultureIgnoreCase))
            {
                var elementCodeFile = "Element.cs" + (char)31 + Snippets.GetCode("Element");
                codeFiles = codeFiles + (char)31 + elementCodeFile;
            }

            var codeFileEncoded = codeFiles.ToCompressedEncodedUrl();
            // var tryMudBlazorLocation = "https://localhost:5001/";
            var tryMudBlazorLocation = "https://try.mudblazor.com/";
            var url = $"{tryMudBlazorLocation}snippet/{codeFileEncoded}";
            await DomService.OpenInNewTab(url);
        }
Exemple #7
0
        internal string GetHTMLElementText(Element element)
        {
            string selectorValue = element.htmlSelector.selectorValue;
            string selectorType  = Convert.ToString(element.htmlSelector.selectBy);

            return(DomService.GetHTMLElementText(selectorValue, selectorType));
        }
Exemple #8
0
        private static List <Form> GetEmbeddedForms(Document dom, Guid objectId, byte constType)
        {
            List <Form> formlist         = new List <Form>();
            int         itemindexcounter = 0;

            foreach (var item in dom.forms.item)
            {
                if (!Kooboo.Sites.Render.Components.Manager.IsComponentElement(item))
                {
                    if (!Service.DomService.IsAspNetWebForm(item))
                    {
                        Form form = new Form
                        {
                            OwnerObjectId  = objectId,
                            OwnerConstType = constType,
                            Body           = item.InnerHtml,
                            KoobooId       = DomService.GetKoobooId(item),
                            Method         = item.getAttribute("method") ?? "get",
                            IsEmbedded     = true
                        };

                        form.Engine = item.getAttribute("engine");

                        form.ItemIndex = itemindexcounter;

                        foreach (var att in item.attributes)
                        {
                            form.Attributes.Add(att.name, att.value);
                        }
                        formlist.Add(form);
                    }
                }
            }
            return(formlist);
        }
 protected virtual async void EditOnTryMudBlazor()
 {
     // We use a seperator that wont be in code so we can send 2 files later
     var codeFile        = "__Main.razor" + (char)31 + Snippets.GetCode(Code);
     var codeFileEncoded = codeFile.ToCompressedEncodedUrl();
     // var tryMudBlazorLocation = "https://localhost:5001/";
     var tryMudBlazorLocation = "https://try.mudblazor.com/";
     var url = $"{tryMudBlazorLocation}snippet/{codeFileEncoded}";
     await DomService.OpenInNewTab(url);
 }
Exemple #10
0
 public bool isNumberOfWindowsEqual(int no)
 {
     try
     {
         return(DomService.isNumberOfWindowsEqual(no));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #11
0
        public void Open()
        {
            if (enableProxy)
            {
                ProxyService.StartProxyServer();
            }

            dynamic browser = BrowserFactory.Create((int)type, enableProxy);

            DomService.InitializeService(browser);
        }
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                _touchStartId = await DomService.AddEventListener(_swipeArea, _dotnet, "touchstart", nameof(OnTouchStart), true);

                _touchEndId = await DomService.AddEventListener(_swipeArea, _dotnet, "touchend", nameof(OnTouchEnd), true);

                _touchCancelId = await DomService.AddEventListener(_swipeArea, _dotnet, "touchcancel", nameof(OnTouchCancel), true);
            }
            await base.OnAfterRenderAsync(firstRender);
        }
Exemple #13
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);
        }
Exemple #14
0
        public void PerformAction(Element element, DomAction action, int timeout)
        {
            try
            {
                string selectorValue = element.htmlSelector.selectorValue;
                string selectorType  = Convert.ToString(element.htmlSelector.selectBy);
                string actionType    = Convert.ToString(action.actionType);
                string actionSelect  = Convert.ToString(action.actionSelectyBy);
                string actionValue   = Convert.ToString(action.value);

                DomService.PerformAction(selectorValue, selectorType, actionValue, actionType, actionSelect);
            }
            catch (Exception)
            {
            }
        }
Exemple #15
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);
        }
Exemple #16
0
        internal string GetHTMLElementTextFromParent(dynamic parentElement, Field field)
        {
            string fieldSelectorValue = field.htmlElement.htmlSelector.selectorValue;
            string fieldSelectorType  = Convert.ToString(field.htmlElement.htmlSelector.selectBy);
            string fieldAttributeType;

            if (field.htmlElement.attributeValue == null)
            {
                fieldAttributeType = Convert.ToString(field.htmlElement.attributeType);
            }
            else
            {
                fieldAttributeType = field.htmlElement.attributeValue;
            }


            return(DomService.GetHTMLElementTextFromParent(parentElement, fieldSelectorValue, fieldSelectorType, fieldAttributeType));
        }
Exemple #17
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 #18
0
        public string DetectKoobooId(Document dom, Menu menu)
        {
            if (menu.children.Count() == 0)
            {
                return(null);
            }

            if (menu.children.Count() > 1)
            {
                var links = menu.children.Select(o => o.Url).ToList();
                return(DomService.DetectKoobooId(dom, links));
            }
            else
            {
                var onlychild = menu.children[0];
                var koobooid  = DetectKoobooId(dom, onlychild);
                // upgrade to one that contains that koobooid.
                // TODO: to be implemented.
            }
            return(null);
        }
Exemple #19
0
        public static List <IRenderTask> GetLayoutPlan(string NameOrId, RenderContext context)
        {
            var layout = context.WebSite.SiteDb().Layouts.GetByNameOrId(NameOrId);

            if (layout == null)
            {
                return(null);
            }
            List <IRenderTask> renderplans = null;

            EvaluatorOption options = RenderOptionHelper.GetLayoutOption(context, layout.Id);

            if (options.RequireBindingInfo)
            {
                string body = DomService.ApplyKoobooId(layout.Body);
                renderplans = RenderEvaluator.Evaluate(body, options);
            }
            else
            {
                renderplans = Cache.RenderPlan.GetOrAddRenderPlan(context.WebSite.SiteDb(), layout.Id, () => RenderEvaluator.Evaluate(layout.Body, options));
            }

            return(renderplans);
        }
Exemple #20
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 #21
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);
        }
 public void Dispose()
 {
     DomService.RemoveEventListener(_swipeArea, "touchstart", _touchStartId);
     DomService.RemoveEventListener(_swipeArea, "touchend", _touchEndId);
     DomService.RemoveEventListener(_swipeArea, "touchcancel", _touchCancelId);
 }
Exemple #23
0
 public string GetUrl()
 {
     return(DomService.GetPageUrl());
 }
Exemple #24
0
 public void ExecuteJavaScript(string script)
 {
     DomService.ExecuteJavaScript(script);
 }
Exemple #25
0
 public void Refresh()
 {
     DomService.Refresh();
 }
Exemple #26
0
 public bool isDocumentReady()
 {
     return(DomService.isDocumentReady());
 }
Exemple #27
0
        public ConvertResponse Convert(RenderContext context, JObject result)
        {
            var page   = context.GetItem <Page>();
            var sitedb = context.WebSite.SiteDb();

            string menuname = Lib.Helper.JsonHelper.GetString(result, "name");

            menuname = GetMenuName(sitedb, menuname);
            var data = Lib.Helper.JsonHelper.GetObject(result, "Data");

            //var newmenu = Newtonsoft.Json.JsonConvert.DeserializeObject<Menu>(data.ToString());
            var newmenu = Lib.Helper.JsonHelper.Deserialize <Menu>(data.ToString());

            newmenu.Name = menuname;
            newmenu.Id   = default(Guid);

            EnSureParentId(newmenu);

            string koobooid = Lib.Helper.JsonHelper.GetString(result, "KoobooId");

            if (string.IsNullOrEmpty(koobooid))
            {
                koobooid = DetectKoobooId(page.Dom, newmenu);
            }
            if (string.IsNullOrEmpty(koobooid))
            {
                return(null);
            }

            var response = new ConvertResponse
            {
                IsSuccess         = true,
                ComponentNameOrId = menuname,
                Tag      = "<menu id='" + menuname + "'></menu>",
                KoobooId = koobooid
            };

            if (page == null)
            {
                sitedb.Menus.AddOrUpdate(newmenu);
                return(response);
            }

            if (sitedb.WebSite.ContinueConvert)
            {
                var DomNode    = DomService.GetElementByKoobooId(page.Dom, koobooid);
                var DomElement = DomNode as Kooboo.Dom.Element;
                if (DomElement != null)
                {
                    var elementpaths = Kooboo.Sites.Service.DomService.GetElementPath(DomElement as Kooboo.Dom.Element);

                    sitedb.ContinueConverter.AddConverter(this.Type, page.Id, response.Tag, response.ComponentNameOrId, koobooid, elementpaths, DomElement.tagName);
                    // var OtherPages = sitedb.Pages.All().Where(o => o.Id != page.Id && !o.HasLayout).ToList();
                    //foreach (var item in OtherPages)
                    //{
                    //    ContinueConvert(sitedb, page.Id, response.Tag, koobooid, item, null, DomElement.ParentPathHash, newmenu);
                    //}
                }
            }

            sitedb.Menus.AddOrUpdate(newmenu);

            // if (!sitedb.WebSite.ContinueConvert)
            // {
            //    sitedb.WebSite.ContinueConvert = true;
            //     Kooboo.Data.GlobalDb.WebSites.AddOrUpdate(sitedb.WebSite);
            // }

            return(response);
        }
Exemple #28
0
 public bool isPageTitleEqual(string pageTitle)
 {
     return(DomService.isTitleEqual(pageTitle));
 }
Exemple #29
0
        public string Execute(RenderContext context, Dictionary <string, string> Paras, EvaluatorOption options)
        {
            if (Paras != null && Paras.Count() > 0)
            {
                Dictionary <string, string> datavalue = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (var item in Paras)
                {
                    if (item.Key.ToLower() != "name" && item.Key.ToLower() != "id")
                    {
                        datavalue.Add(item.Key, item.Value);
                    }
                }
                if (datavalue.Count() > 0)
                {
                    context.DataContext.Push(datavalue);
                }
            }

            string layoutNameOrId = GetLayoutNameOrId(Paras);
            string layoutbody     = null;

            if (!string.IsNullOrEmpty(layoutNameOrId))
            {
                layoutbody = GetSourceFromDb(context, layoutNameOrId);

                if (!string.IsNullOrEmpty(layoutbody))
                {
                    List <IRenderTask> renderplan;

                    if (options == null)
                    {
                        options                         = new EvaluatorOption();
                        options.RenderUrl               = false;
                        options.RenderHeader            = false;
                        options.EnableImageBrowserCache = true;
                        options.EnableJsCssBrowserCache = true;
                    }


                    Guid sourceid = Lib.Security.Hash.ComputeHashGuid(layoutbody);  // GetLayoutGuid(layoutNameOrId);

                    if (context.Request.Channel == RequestChannel.InlineDesign)
                    {
                        layoutbody = DomService.ApplyKoobooId(layoutbody);
                        options.RequireBindingInfo = true;
                        renderplan = RenderEvaluator.Evaluate(layoutbody, options);
                    }
                    else
                    {
                        SiteDb sitedb;
                        if (context.WebSite == null)
                        {
                            var site = new WebSite()
                            {
                                Name = "__Koobootemp"
                            };
                            sitedb = site.SiteDb();
                        }
                        else
                        {
                            sitedb = context.WebSite.SiteDb();
                        }

                        renderplan = Cache.RenderPlan.GetOrAddRenderPlan(sitedb, sourceid, () => RenderEvaluator.Evaluate(layoutbody, options));
                    }
                    return(RenderHelper.Render(renderplan, context));
                }
            }

            return(null);
        }
Exemple #30
0
        public string Execute(RenderContext context, Dictionary <string, string> Paras, EvaluatorOption options)
        {
            if (Paras != null && Paras.Count() > 0)
            {
                Dictionary <string, string> datavalue = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (var item in Paras)
                {
                    if (item.Key.ToLower() != "file" && item.Key.ToLower() != "virtual")
                    {
                        datavalue.Add(item.Key, item.Value);
                    }
                }
                if (datavalue.Count() > 0)
                {
                    context.DataContext.Push(datavalue);
                }
            }

            var file = GetFilePath(context, Paras);

            var source = GetSourceFromDb(context, file);

            if (!string.IsNullOrEmpty(source))
            {
                List <IRenderTask> renderplan;

                if (options == null)
                {
                    options              = new EvaluatorOption();
                    options.RenderUrl    = true;
                    options.RenderHeader = false;
                }


                Guid sourceid = Lib.Security.Hash.ComputeGuidIgnoreCase(source);

                if (context.Request.Channel == RequestChannel.InlineDesign)
                {
                    source = DomService.ApplyKoobooId(source);
                    options.RequireBindingInfo = true;
                    renderplan = RenderEvaluator.Evaluate(source, options);
                }
                else
                {
                    SiteDb sitedb;
                    if (context.WebSite == null)
                    {
                        var site = new WebSite()
                        {
                            Name = "__Koobootemp"
                        };
                        sitedb = site.SiteDb();
                    }
                    else
                    {
                        sitedb = context.WebSite.SiteDb();
                    }

                    renderplan = Cache.RenderPlan.GetOrAddRenderPlan(sitedb, sourceid, () => RenderEvaluator.Evaluate(source, options));
                }

                return(RenderHelper.Render(renderplan, context));
            }

            return(null);
        }