<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using Signum.Entities.Authorization;
using Signum.Engine.Authorization;
using System.Reflection;
using Signum.Web.Operations;
using Signum.Entities;
using System.Web.Mvc;
using System.Diagnostics;
using Signum.Engine;
using Signum.Entities.Basics;
using Signum.Entities.Reflection;
using System.Linq.Expressions;
using Signum.Engine.Maps;
using System.Web.Routing;
using System.Web.Mvc.Html;
using System.Collections;
using System.Web.Script.Serialization;
using System.Drawing;
using Signum.Web.Omnibox;
using Signum.Entities.Profiler;
using Signum.Web.Extensions.Properties;

namespace Signum.Web.Profiler
{
    public static class ProfilerClient
    {
        public static string ViewPrefix = "~/Profiler/Views/{0}.cshtml";

        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(ProfilerClient));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerHeavy",
                    () => ProfilerPermission.ViewHeavyProfiler.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.Heavy(false))));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerTimeTable",
                    () => ProfilerPermission.ViewTimeTracker.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.TimeTable())));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerTimes",
                    () => ProfilerPermission.ViewTimeTracker.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.Times())));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("OverrideSessionTimeout",
                    () => ProfilerPermission.OverrideSessionTimeout.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.OverrideSessionTimeout(60))));
            }
        }

        public static Dictionary<string, Color> RoleColors = new Dictionary<string, Color>
        {
            { "SQL", Color.Gold },
            { "DB", Color.MediumSlateBlue },
            { "LINQ", Color.Violet },
            { "MvcRequest", Color.LimeGreen },
            { "MvcResult", Color.SeaGreen }
        };

        public static string HeavyDetailsToJson(this IEnumerable<HeavyProfilerEntry> entries)
        {
            return new JavaScriptSerializer().Serialize(entries.Select(e => new 
            {
                e.BeforeStart,
                e.Start,
                e.End,
                Elapsed = e.Elapsed.NiceToString(),
                e.Role,
                Color = GetColor(e.Role),
                e.Depth,
                AditionalData = e.AditionalDataPreview(),
                FullIndex = e.FullIndex()
            }));
        }

        private static string GetColor(string role)
        {
            if (role == null)
                return Color.Gray.ToHtml();
<commit_msg>Profiler JavaScriptSerializer MaxJsonLength<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using Signum.Entities.Authorization;
using Signum.Engine.Authorization;
using System.Reflection;
using Signum.Web.Operations;
using Signum.Entities;
using System.Web.Mvc;
using System.Diagnostics;
using Signum.Engine;
using Signum.Entities.Basics;
using Signum.Entities.Reflection;
using System.Linq.Expressions;
using Signum.Engine.Maps;
using System.Web.Routing;
using System.Web.Mvc.Html;
using System.Collections;
using System.Web.Script.Serialization;
using System.Drawing;
using Signum.Web.Omnibox;
using Signum.Entities.Profiler;
using Signum.Web.Extensions.Properties;

namespace Signum.Web.Profiler
{
    public static class ProfilerClient
    {
        public static string ViewPrefix = "~/Profiler/Views/{0}.cshtml";

        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(ProfilerClient));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerHeavy",
                    () => ProfilerPermission.ViewHeavyProfiler.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.Heavy(false))));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerTimeTable",
                    () => ProfilerPermission.ViewTimeTracker.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.TimeTable())));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("ProfilerTimes",
                    () => ProfilerPermission.ViewTimeTracker.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.Times())));

                SpecialOmniboxProvider.Register(new SpecialOmniboxAction("OverrideSessionTimeout",
                    () => ProfilerPermission.OverrideSessionTimeout.IsAuthorized(),
                    uh => uh.Action((ProfilerController pc) => pc.OverrideSessionTimeout(60))));
            }
        }

        public static Dictionary<string, Color> RoleColors = new Dictionary<string, Color>
        {
            { "SQL", Color.Gold },
            { "DB", Color.MediumSlateBlue },
            { "LINQ", Color.Violet },
            { "MvcRequest", Color.LimeGreen },
            { "MvcResult", Color.SeaGreen }
        };

        public static string HeavyDetailsToJson(this IEnumerable<HeavyProfilerEntry> entries)
        {
            var serializer = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };
            return serializer.Serialize(entries.Select(e => new 
            {
                e.BeforeStart,
                e.Start,
                e.End,
                Elapsed = e.Elapsed.NiceToString(),
                e.Role,
                Color = GetColor(e.Role),
                e.Depth,
                AditionalData = e.AditionalDataPreview(),
                FullIndex = e.FullIndex()
            }));
        }

        private static string GetColor(string role)
        {
            if (role == null)
                return Color.Gray.ToHtml();

{'fraction_non_alphanumeric': 0.10518053375196232, 'fraction_numerical': 0.0009419152276295133, 'mean_word_length': 2.333856619570905, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4884829', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1704, 'n_words': 301}