Ejemplo n.º 1
0
        /// <summary>
        /// Output just the scripts for the Agility preview and development bar.
        /// </summary>
        /// <param name="helper"></param>
        public static HtmlString RenderAgilityPreviewBarScripts(this IHtmlHelper helper)
        {
            Agility.Web.Objects.AgilityPage p = AgilityContext.Page;
            if (p != null)
            {
                StringBuilder sb = new StringBuilder();

                //inject the status panel scripts
                if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode)
                {
                    string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();
                    sb.Append(script);
                }


                //handle dependencies on ouput cache...
                if (AgilityContext.OutputCacheKeys.Count > 0)
                {
                    AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys);
                }

                return(new HtmlString(sb.ToString()));
            }
            else if (AgilityContext.IsTemplatePreview)
            {
                //template preview...
                string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();

                return(new HtmlString(script));
            }
            else
            {
                return(new HtmlString(""));
            }
        }
Ejemplo n.º 2
0
        public async Task <HtmlString> InvokeAsync()
        {
            AgilityContext.HttpContext = HttpContext;

            StringBuilder sb = new StringBuilder();

            Agility.Web.Objects.AgilityPage p = AgilityContext.Page;
            if (p != null)
            {
                //inject the status panel scripts
                if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode)
                {
                    string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();
                    sb.AppendLine(script);
                }

                if (!string.IsNullOrEmpty(p.CustomAnalyticsScript))
                {
                    string script = p.CustomAnalyticsScript;

                    if (script.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) != -1)
                    {
                        string scriptBottomPage = script.Substring(script.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) + AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR.Length);
                        if (!string.IsNullOrEmpty(scriptBottomPage))
                        {
                            sb.AppendLine(scriptBottomPage);
                        }
                    }
                }


                //add the Javascript tracking stuff
                if (p.IncludeInStatsTracking)
                {
                    //global script
                    if (!string.IsNullOrEmpty(AgilityContext.Domain.StatsTrackingScript))
                    {
                        string scriptTopGlobal = AgilityContext.Domain.StatsTrackingScript;

                        if (scriptTopGlobal.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) != -1)
                        {
                            string scriptBottomGlobal = scriptTopGlobal.Substring(scriptTopGlobal.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) + AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR.Length);
                            if (!string.IsNullOrEmpty(scriptBottomGlobal))
                            {
                                sb.AppendLine(scriptBottomGlobal);
                            }
                        }
                    }
                }

                //handle dependencies on ouput cache...
                if (AgilityContext.OutputCacheKeys.Count > 0)
                {
                    AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys);
                }
            }
            else if (AgilityContext.IsTemplatePreview)
            {
                //template preview...
                string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();
                sb.AppendLine(script);
            }


            return(new HtmlString(sb.ToString()));
        }