コード例 #1
0
        private void UpsertRouteHit(ActionDescriptor actionDesc, MiniProfiler profiler)
        {
            var routeName = actionDesc.ControllerDescriptor.ControllerName + "/" + actionDesc.ActionName;

            using (var conn = GetConnection(profiler))
            {
                var param = new { routeName = routeName };

                using (profiler.Step("Insert RouteHits"))
                {
                   conn.Execute("insert or ignore into RouteHits (RouteName, HitCount) values (@routeName, 0)", param);
                }
                using (profiler.Step("Update RouteHits"))
                {
                    // let's put some whitespace in this query to demonstrate formatting
                    conn.Execute(
            @"update RouteHits
            set    HitCount = HitCount + 1
            where  RouteName = @routeName", param);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns an open connection that will have its queries profiled.
        /// </summary>
        public static DbConnection GetConnection(MiniProfiler profiler = null)
        {
            using (profiler.Step("GetOpenConnection"))
            {
                DbConnection cnn = new System.Data.SQLite.SQLiteConnection(WcfCommon.ConnectionString);

                // to get profiling times, we have to wrap whatever connection we're using in a ProfiledDbConnection
                // when MiniProfiler.Current is null, this connection will not record any database timings
                if (MiniProfiler.Current != null)
                {
                    cnn = new MvcMiniProfiler.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);
                }

                cnn.Open();
                return cnn;
            }
        }
コード例 #3
0
        private void RecursiveMethod(ref int i, DbConnection conn, MiniProfiler profiler)
        {
            Thread.Sleep(5); // ensure we show up in the profiler

            if (i >= 10) return;

            using (profiler.Step("Nested call " + i))
            {
                // run some meaningless queries to illustrate formatting
                conn.Query(
            @"select *
            from   MiniProfilers
            where  Name like @name
            or Name = @name
            or DurationMilliseconds >= @duration
            or HasSqlTimings = @hasSqlTimings
            or Started > @yesterday ", new
                                 {
                                     name = "Home/Index",
                                     duration = 100.5,
                                     hasSqlTimings = true,
                                     yesterday = DateTime.UtcNow.AddDays(-1)
                                 });

                conn.Query(@"select RouteName, HitCount from RouteHits where HitCount < 100000000 or HitCount > 0 order by HitCount, RouteName -- this should hopefully wrap");

                // massive query to test if max-height is properly removed from <pre> stylings
                conn.Query(
            @"select *
            from   (select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 0 and 9
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 10 and 19
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 20 and 29
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 30 and 39
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 40 and 49
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 50 and 59
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 60 and 69
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 70 and 79
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 80 and 89
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount between 90 and 99
            union all
            select RouteName,
               HitCount
            from   RouteHits
            where  HitCount > 100)
            order  by RouteName");

                using (profiler.Step("Incrementing a reference parameter named i")) // need a long title to test max-width
                {
                    i++;
                }
                RecursiveMethod(ref i, conn, profiler);
            }
        }