Ejemplo n.º 1
0
        public IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null,
                                          int?maxTracesToShow     = null, bool xhtml       = false, bool?showControls = null)
        {
            var result = Current?.RenderIncludes(position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml, showControls);

            return(result ?? HtmlString.Empty);
        }
Ejemplo n.º 2
0
 public static IHtmlString RenderIncludes(RenderPosition?position   = null, bool?showTrivial = null,
                                          bool?showTimeWithChildren = null,
                                          int?maxTracesToShow       = null, bool xhtml = false, bool?showControls = null)
 {
     return(Current.RenderIncludes(position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml,
                                   showControls));
 }
Ejemplo n.º 3
0
        public static System.Web.IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool xhtml = false, bool?showControls = null)
        {
            var path = VirtualPathUtility.ToAbsolute("~");

            return(MiniProfilerHandler.RenderIncludes(Profiler.Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml, showControls, path)
                   .ToMvcHtmlString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders script tag for including MiniProfiler.
        /// </summary>
        /// <param name="profiler">The profiler to render a tag for.</param>
        /// <param name="context">The <see cref="HttpContext"/> this tag is being rendered in.</param>
        /// <param name="position">The UI position to render the profiler in (defaults to <see cref="MiniProfilerBaseOptions.PopupRenderPosition"/>).</param>
        /// <param name="showTrivial">Whether to show trivial timings column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTrivial"/>).</param>
        /// <param name="showTimeWithChildren">Whether to show time with children column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTimeWithChildren"/>).</param>
        /// <param name="maxTracesToShow">The maximum number of profilers to show (before the oldest is removed - defaults to <see cref="MiniProfilerBaseOptions.PopupMaxTracesToShow"/>).</param>
        /// <param name="showControls">Whether to show the controls (defaults to <see cref="MiniProfilerBaseOptions.ShowControls"/>).</param>
        /// <param name="startHidden">Whether to start hidden (defaults to <see cref="MiniProfilerBaseOptions.PopupStartHidden"/>).</param>
        public static HtmlString RenderIncludes(
            this MiniProfiler profiler,
            HttpContext context,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            if (profiler == null)
            {
                return(HtmlString.Empty);
            }

            // This is populated in Middleware by SetHeadersAndState
            var state = RequestState.Get(context);
            var path  = (profiler.Options as MiniProfilerOptions)?.RouteBasePath.Value.EnsureTrailingSlash();

            var result = profiler.RenderIncludes(
                path: context.Request.PathBase + path,
                isAuthorized: state?.IsAuthorized ?? false,
                requestIDs: state?.RequestIDs,
                position: position,
                showTrivial: showTrivial,
                showTimeWithChildren: showTimeWithChildren,
                maxTracesToShow: maxTracesToShow,
                showControls: showControls,
                startHidden: startHidden);

            return(new HtmlString(result));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns the <c>css</c> and <c>javascript</c> includes needed to display the MiniProfiler results UI.
 /// </summary>
 /// <param name="position">Which side of the page the profiler popup button should be displayed on (defaults to left)</param>
 /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param>
 /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param>
 /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param>
 /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param>
 /// <param name="useExistingjQuery">Whether MiniProfiler should attempt to load its own version of jQuery, or rely on a version previously loaded on the page</param>
 /// <param name="samplingOnly">The sampling Only.</param>
 /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns>
 public static IHtmlString RenderIncludes(
     RenderPosition?position   = null,
     bool?showTrivial          = null,
     bool?showTimeWithChildren = null,
     int?maxTracesToShow       = null,
     bool?showControls         = null,
     bool?useExistingjQuery    = null,  // TODO: we need to deprecate this
     bool samplingOnly         = false, // TODO: can we remove this?
     bool?startHidden          = null)
 {
     return(UI.MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, startHidden));
 }
Ejemplo n.º 6
0
        public static HtmlString RenderIncludes(Profiler profiler, RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool xhtml = false, bool?showControls = null, string path = null)
        {
            const string format =
                @"<link rel=""stylesheet"" type=""text/css"" href=""{path}ssr-includes.css?v={version}""{closeXHTML}>
<script type=""text/javascript"">
    if (!window.jquip) document.write(unescape(""%3Cscript src='{path}ssr-jquip.all.js?v={version}' type='text/javascript'%3E%3C/script%3E""));
</script>
<script type=""text/javascript"" src=""{path}ssr-includes.js?v={version}""></script>
<script type=""text/javascript"">
    jQuery(function() {{
        MiniProfiler.init({{
            ids: {ids},
            path: '{path}',
            version: '{version}',
            renderPosition: '{position}',
            showTrivial: {showTrivial},
            showChildrenTime: {showChildren},
            maxTracesToShow: {maxTracesToShow},
            showControls: {showControls}
        }});
    }});
</script>";

            var result = "";

            if (profiler != null)
            {
                // HACK: unviewed ids are added to this list during Storage.Save, but we know we haven't see the current one yet,
                // so go ahead and add it to the end - it's usually the only id, but if there was a redirect somewhere, it'll be there, too
                Profiler.Settings.EnsureStorageStrategy();
                var ids = Profiler.Settings.Storage.GetUnviewedIds(profiler.User);
                ids.Add(profiler.Id);

                path = (path ?? VirtualPathUtility.ToAbsolute(Profiler.Settings.RouteBasePath).EnsureTrailingSlash()) + EndpointHost.Config.SStackHandlerFactoryPath;

                result = format.Format(new {
                    //path = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
                    path            = !string.IsNullOrEmpty(path) ? path.EnsureTrailingSlash() : "",
                    version         = Profiler.Settings.Version,
                    ids             = ids.ToJson(),
                    position        = (position ?? Profiler.Settings.PopupRenderPosition).ToString().ToLower(),
                    showTrivial     = showTrivial ?? Profiler.Settings.PopupShowTrivial ? "true" : "false",
                    showChildren    = showTimeWithChildren ?? Profiler.Settings.PopupShowTimeWithChildren ? "true" : "false",
                    maxTracesToShow = maxTracesToShow ?? Profiler.Settings.PopupMaxTracesToShow,
                    closeXHTML      = xhtml ? "/" : "",
                    showControls    = showControls ?? Profiler.Settings.ShowControls ? "true" : "false"
                });
            }

            return(new HtmlString(result));
        }
Ejemplo n.º 7
0
        public static IHtmlString RenderIncludes(
            this MiniProfiler profiler,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            if (profiler == null)
            {
                return(_empty);
            }
            var settings = profiler.Options as MiniProfilerOptions;

            if (settings == null)
            {
                return(_empty);
            }

            var authorized = settings.ResultsAuthorize?.Invoke(HttpContext.Current.Request) ?? true;

            // If we're not authroized, we're just rendering a <script> tag for no reason.
            if (!authorized)
            {
                return(_empty);
            }

            // unviewed ids are added to this list during Storage.Save, but we know we haven't
            // seen the current one yet, so go ahead and add it to the end
            var ids = authorized ? settings.Storage.GetUnviewedIds(profiler.User) : new List <Guid>();

            ids.Add(profiler.Id);

            var path = VirtualPathUtility.ToAbsolute(settings.RouteBasePath).EnsureTrailingSlash();

            var result = Internal.Render.Includes(
                profiler,
                path: path,
                isAuthorized: authorized,
                requestIDs: ids,
                position: position,
                showTrivial: showTrivial,
                showTimeWithChildren: showTimeWithChildren,
                maxTracesToShow: maxTracesToShow,
                showControls: showControls,
                startHidden: startHidden);

            return(new HtmlString(result));
        }
Ejemplo n.º 8
0
        public void Positions(RenderPosition?position, string expected)
        {
            var profiler      = GetBasicProfiler();
            var renderOptions = new RenderOptions()
            {
                Position = position
            };

            var result = Render.Includes(profiler, " / ", true, renderOptions);

            Output.WriteLine("Result: " + result);

            Assert.NotNull(result);
            Assert.Contains(expected, result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Renders script tag found in "include.partial.html".
        /// </summary>
        internal static HtmlString RenderIncludes(
            MiniProfiler profiler,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            if (profiler == null)
            {
                return(new HtmlString(""));
            }

            MiniProfiler.Settings.EnsureStorageStrategy();
            var authorized = MiniProfiler.Settings.Results_Authorize == null ||
                             MiniProfiler.Settings.Results_Authorize(HttpContext.Current.Request);

            // unviewed ids are added to this list during Storage.Save, but we know we haven't
            // seen the current one yet, so go ahead and add it to the end
            var ids = authorized ? MiniProfiler.Settings.Storage.GetUnviewedIds(profiler.User) : new List <Guid>();

            ids.Add(profiler.Id);

            string format;

            if (!TryGetResource("include.partial.html", out format))
            {
                return(new HtmlString("<!-- Could not find 'include.partial.html' -->"));
            }

            return(new HtmlString(format.Format(new
            {
                path = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
                version = MiniProfiler.Settings.Version,
                currentId = profiler.Id,
                ids = string.Join(",", ids.Select(guid => guid.ToString())),
                position = (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower(),
                showTrivial = (showTrivial ?? MiniProfiler.Settings.PopupShowTrivial).ToJs(),
                showChildren = (showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren).ToJs(),
                maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
                showControls = (showControls ?? MiniProfiler.Settings.ShowControls).ToJs(),
                authorized = authorized.ToJs(),
                toggleShortcut = MiniProfiler.Settings.PopupToggleKeyboardShortcut,
                startHidden = (startHidden ?? MiniProfiler.Settings.PopupStartHidden).ToJs(),
                trivialMilliseconds = MiniProfiler.Settings.TrivialDurationThresholdMilliseconds
            })));
        }
Ejemplo n.º 10
0
        internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?useExistingjQuery = null)
        {
            string format = GetResource("include.partial.html");

            var result = "";

            if (profiler != null)
            {
                // HACK: unviewed ids are added to this list during Storage.Save, but we know we haven't see the current one yet,
                // so go ahead and add it to the end - it's usually the only id, but if there was a redirect somewhere, it'll be there, too
                MiniProfiler.Settings.EnsureStorageStrategy();

                var authorized =
                    MiniProfiler.Settings.Results_Authorize == null ||
                    MiniProfiler.Settings.Results_Authorize(HttpContext.Current.Request);

                List <Guid> ids;
                if (authorized)
                {
                    ids = MiniProfiler.Settings.Storage.GetUnviewedIds(profiler.User);
                    ids.Add(profiler.Id);
                }
                else
                {
                    ids = new List <Guid> {
                        profiler.Id
                    };
                }

                result = format.Format(new
                {
                    path              = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
                    version           = MiniProfiler.Settings.Version,
                    ids               = ids.ToJson(),
                    position          = (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower(),
                    showTrivial       = showTrivial ?? MiniProfiler.Settings.PopupShowTrivial ? "true" : "false",
                    showChildren      = showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren ? "true" : "false",
                    maxTracesToShow   = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
                    showControls      = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false",
                    currentId         = profiler.Id,
                    authorized        = authorized ? "true" : "false",
                    useExistingjQuery = useExistingjQuery ?? MiniProfiler.Settings.UseExistingjQuery ? "true" : "false"
                });
            }

            return(new HtmlString(result));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Renders script tag found in "include.partial.html".
        /// </summary>
        /// <param name="profiler">The profiler to render a tag for.</param>
        /// <param name="context">The <see cref="HttpContext"/> this tag is being rendered in.</param>
        /// <param name="position">The UI position to render the profiler in (defaults to <see cref="MiniProfiler.Settings.PopupRenderPosition"/>).</param>
        /// <param name="showTrivial">Whether to show trivial timings column initially or not (defaults to <see cref="MiniProfiler.Settings.PopupShowTrivial"/>).</param>
        /// <param name="showTimeWithChildren">Whether to show time with children column initially or not (defaults to <see cref="MiniProfiler.Settings.PopupShowTimeWithChildren"/>).</param>
        /// <param name="maxTracesToShow">The maximum number of profilers to show (before the oldest is removed - defaults to <see cref="MiniProfiler.Settings.PopupMaxTracesToShow"/>).</param>
        /// <param name="showControls">Whether to show the controls (defaults to <see cref="MiniProfiler.Settings.ShowControls"/>).</param>
        /// <param name="startHidden">Whether to start hidden (defaults to <see cref="MiniProfiler.Settings.PopupStartHidden"/>).</param>
        public static HtmlString RenderIncludes(
            this MiniProfiler profiler,
            HttpContext context,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            if (profiler == null)
            {
                return(HtmlString.Empty);
            }

            // This is populated in Middleware by SetHeadersAndState
            var state = RequestState.Get(context);

            // Is the user authroized to see the results of the current MiniProfiler?
            var authorized = state?.IsAuthorized ?? false;
            var ids        = state?.RequestIDs ?? Enumerable.Empty <Guid>();

            if (!MiniProfilerMiddleware.Current.Embedded.TryGetResource("include.partial.html", out string format))
            {
                return(includeNotFound);
            }

            Func <bool, string> toJs = b => b ? "true" : "false";

            var sb = new StringBuilder(format);

            sb.Replace("{path}", MiniProfilerMiddleware.Current.BasePath.Value.EnsureTrailingSlash())
            .Replace("{version}", MiniProfiler.Settings.VersionHash)
            .Replace("{currentId}", profiler.Id.ToString())
            .Replace("{ids}", string.Join(",", ids.Select(guid => guid.ToString())))
            .Replace("{position}", (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower())
            .Replace("{showTrivial}", toJs(showTrivial ?? MiniProfiler.Settings.PopupShowTrivial))
            .Replace("{showChildren}", toJs(showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren))
            .Replace("{maxTracesToShow}", (maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow).ToString())
            .Replace("{showControls}", toJs(showControls ?? MiniProfiler.Settings.ShowControls))
            .Replace("{authorized}", toJs(authorized))
            .Replace("{toggleShortcut}", MiniProfiler.Settings.PopupToggleKeyboardShortcut)
            .Replace("{startHidden}", toJs(startHidden ?? MiniProfiler.Settings.PopupStartHidden))
            .Replace("{trivialMilliseconds}", MiniProfiler.Settings.TrivialDurationThresholdMilliseconds.ToString());
            return(new HtmlString(sb.ToString()));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Renders script tag found in "include.partial.html".
        /// </summary>
        /// <param name="profiler">The profiler to render a tag for.</param>
        /// <param name="position">The UI position to render the profiler in (defaults to <see cref="MiniProfiler.Settings.PopupRenderPosition"/>).</param>
        /// <param name="showTrivial">Whether to show trivial timings column initially or not (defaults to <see cref="MiniProfiler.Settings.PopupShowTrivial"/>).</param>
        /// <param name="showTimeWithChildren">Whether to show time with children column initially or not (defaults to <see cref="MiniProfiler.Settings.PopupShowTimeWithChildren"/>).</param>
        /// <param name="maxTracesToShow">The maximum number of profilers to show (before the oldest is removed - defaults to <see cref="MiniProfiler.Settings.PopupMaxTracesToShow"/>).</param>
        /// <param name="showControls">Whether to show the controls (defaults to <see cref="MiniProfiler.Settings.ShowControls"/>).</param>
        /// <param name="startHidden">Whether to start hidden (defaults to <see cref="MiniProfiler.Settings.PopupStartHidden"/>).</param>
        internal static HtmlString RenderIncludes(
            MiniProfiler profiler,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            if (profiler == null)
            {
                return(new HtmlString(string.Empty));
            }

            var authorized = MiniProfilerWebSettings.ResultsAuthorize?.Invoke(HttpContext.Current.Request) ?? true;

            // unviewed ids are added to this list during Storage.Save, but we know we haven't
            // seen the current one yet, so go ahead and add it to the end
            var ids = authorized ? MiniProfiler.Settings.Storage.GetUnviewedIds(profiler.User) : new List <Guid>();

            ids.Add(profiler.Id);
            if (!TryGetResource("include.partial.html", out string format))
            {
                return(new HtmlString("<!-- Could not find 'include.partial.html' -->"));
            }

            Func <bool, string> toJs = b => b ? "true" : "false";

            var sb = new StringBuilder(format);

            sb.Replace("{path}", VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash())
            .Replace("{version}", MiniProfiler.Settings.VersionHash)
            .Replace("{currentId}", profiler.Id.ToString())
            .Replace("{ids}", string.Join(",", ids.Select(guid => guid.ToString())))
            .Replace("{position}", (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower())
            .Replace("{showTrivial}", toJs(showTrivial ?? MiniProfiler.Settings.PopupShowTrivial))
            .Replace("{showChildren}", toJs(showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren))
            .Replace("{maxTracesToShow}", (maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow).ToString())
            .Replace("{showControls}", toJs(showControls ?? MiniProfiler.Settings.ShowControls))
            .Replace("{authorized}", toJs(authorized))
            .Replace("{toggleShortcut}", MiniProfiler.Settings.PopupToggleKeyboardShortcut)
            .Replace("{startHidden}", toJs(startHidden ?? MiniProfiler.Settings.PopupStartHidden))
            .Replace("{trivialMilliseconds}", MiniProfiler.Settings.TrivialDurationThresholdMilliseconds.ToString());
            return(new HtmlString(sb.ToString()));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns the <c>css</c> and <c>javascript</c> includes needed to display the MiniProfiler results UI.
 /// </summary>
 /// <param name="profiler">The profiler this extension method is called on</param>
 /// <param name="position">Which side of the page the profiler popup button should be displayed on (defaults to left)</param>
 /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param>
 /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param>
 /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param>
 /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param>
 /// <param name="startHidden">Should the profiler start as hidden. Default to null.</param>
 /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns>
 public static IHtmlString RenderIncludes(
     this MiniProfiler profiler,
     RenderPosition?position   = null,
     bool?showTrivial          = null,
     bool?showTimeWithChildren = null,
     int?maxTracesToShow       = null,
     bool?showControls         = null,
     bool?startHidden          = null)
 {
     return(MiniProfilerHandler.RenderIncludes(
                profiler,
                position,
                showTrivial,
                showTimeWithChildren,
                maxTracesToShow,
                showControls,
                startHidden));
 }
Ejemplo n.º 14
0
        public static string RenderIncludesAsString(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?startHidden = null)
        {
            var mvcString = UI.MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, startHidden);

            return(mvcString.ToString());
        }
Ejemplo n.º 15
0
 public static IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool xhtml = false, bool?showControls = null)
 {
     return(new HtmlString(string.Empty));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Renders script tag for including MiniProfiler.
        /// </summary>
        /// <param name="profiler">The profiler to render a tag for.</param>
        /// <param name="path">The root path that MiniProfiler is being served from.</param>
        /// <param name="isAuthorized">Whether the current user is authorized for MiniProfiler.</param>
        /// <param name="requestIDs">The request IDs to fetch for this render.</param>
        /// <param name="position">The UI position to render the profiler in (defaults to <see cref="MiniProfilerBaseOptions.PopupRenderPosition"/>).</param>
        /// <param name="showTrivial">Whether to show trivial timings column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTrivial"/>).</param>
        /// <param name="showTimeWithChildren">Whether to show time with children column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTimeWithChildren"/>).</param>
        /// <param name="maxTracesToShow">The maximum number of profilers to show (before the oldest is removed - defaults to <see cref="MiniProfilerBaseOptions.PopupMaxTracesToShow"/>).</param>
        /// <param name="showControls">Whether to show the controls (defaults to <see cref="MiniProfilerBaseOptions.ShowControls"/>).</param>
        /// <param name="startHidden">Whether to start hidden (defaults to <see cref="MiniProfilerBaseOptions.PopupStartHidden"/>).</param>
        public static string Includes(
            MiniProfiler profiler,
            string path,
            bool isAuthorized,
            List <Guid> requestIDs    = null,
            RenderPosition?position   = null,
            bool?showTrivial          = null,
            bool?showTimeWithChildren = null,
            int?maxTracesToShow       = null,
            bool?showControls         = null,
            bool?startHidden          = null)
        {
            var sb      = StringBuilderCache.Get();
            var options = profiler.Options;

            sb.Append("<script async=\"async\" id=\"mini-profiler\" src=\"");
            sb.Append(path);
            sb.Append("includes.min.js?v=");
            sb.Append(options.VersionHash);
            sb.Append("\" data-version=\"");
            sb.Append(options.VersionHash);
            sb.Append("\" data-path=\"");
            sb.Append(path);
            sb.Append("\" data-current-id=\"");
            sb.Append(profiler.Id.ToString());

            sb.Append("\" data-ids=\"");
            if (requestIDs != null)
            {
                var length = requestIDs.Count;
                for (var i = 0; i < length; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(',');
                    }
                    var id = requestIDs[i];
                    sb.Append(id.ToString());
                }
            }

            sb.Append("\" data-position=\"");
            sb.Append((position ?? options.PopupRenderPosition).ToString());

            sb.Append("\" data-scheme=\"");
            sb.Append(options.ColorScheme.ToString());
            sb.Append('"');

            if (isAuthorized)
            {
                sb.Append(" data-authorized=\"true\"");
            }
            if (showTrivial ?? options.PopupShowTrivial)
            {
                sb.Append(" data-trivial=\"true\"");
            }
            if (showTimeWithChildren ?? options.PopupShowTimeWithChildren)
            {
                sb.Append(" data-children=\"true\"");
            }
            if (showControls ?? options.ShowControls)
            {
                sb.Append(" data-controls=\"true\"");
            }
            if (startHidden ?? options.PopupStartHidden)
            {
                sb.Append(" data-start-hidden=\"true\"");
            }

            sb.Append(" data-max-traces=\"");
            sb.Append((maxTracesToShow ?? options.PopupMaxTracesToShow).ToString(CultureInfo.InvariantCulture));

            sb.Append("\" data-toggle-shortcut=\"");
            sb.Append(options.PopupToggleKeyboardShortcut);

            sb.Append("\" data-trivial-milliseconds=\"");
            sb.Append(options.TrivialDurationThresholdMilliseconds.ToString(CultureInfo.InvariantCulture));

            if (options.IgnoredDuplicateExecuteTypes.Count > 0)
            {
                sb.Append("\" data-ignored-duplicate-execute-types=\"");
                var i = 0;
                foreach (var executeType in options.IgnoredDuplicateExecuteTypes)
                {
                    if (i > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append(executeType);
                    i++;
                }
            }

            sb.Append("\"></script>");

            return(sb.ToStringRecycle());
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Returns the css and javascript includes needed to display the MiniProfiler results UI.
 /// </summary>
 /// <param name="position">Which side of the page the profiler popup button should be displayed on (defaults to left)</param>
 /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param>
 /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param>
 /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param>
 /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param>
 /// <param name="useExistingjQuery">Whether MiniProfiler should attempt to load its own version of jQuery, or rely on a version previously loaded on the page</param>
 /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns>
 public static IHtmlString RenderIncludes(RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?useExistingjQuery = null, bool samplingOnly = false)
 {
     return(UI.MiniProfilerHandler.RenderIncludes(Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, useExistingjQuery));
 }