Example #1
0
 /// <summary>
 /// Giving freshly selected collections, this method puts them in the correct
 /// hierarchy under the 'result' MiniProfiler.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="timingsWrapper">The timings to map</param>
 protected void MapTimings(MiniProfiler result, DbTimingsWrapper timingsWrapper)
 {
     result.ClientTimings = timingsWrapper.ClientTimings;
     result.CustomLinks = timingsWrapper.CustomLinks;
     result.Root = timingsWrapper.Root;
 }
Example #2
0
        /// <summary>
        /// Stores to <c>dbo.MiniProfilers</c> under its <see cref="MiniProfiler.Id"/>;
        /// </summary>
        /// <param name="profiler">The Mini Profiler</param>
        public override void Save(MiniProfiler profiler)
        {
            const string Sql =
            @"insert into MiniProfilers
            (Id,
             Started,
             DurationMilliseconds,
             [User],
             HasUserViewed,
             Json)
            select       @Id,
             @Started,
             @DurationMilliseconds,
             @User,
             @HasUserViewed,
             @Json
            where not exists (select 1 from MiniProfilers where Id = @Id)"; // this syntax works on both mssql and sqlite

            var wrapper = new DbTimingsWrapper {ClientTimings = profiler.ClientTimings, CustomLinks = profiler.CustomLinks, Root = profiler.Root};

            using (var conn = GetOpenConnection())
            {
                conn.Execute(
                    Sql,
                    new
                        {
                            profiler.Id,
                            profiler.Started,
                            User = profiler.User.Truncate(100),
                            RootTimingId = profiler.Root.Id,
                            profiler.DurationMilliseconds,
                            profiler.HasUserViewed,
                            Json = wrapper.ToJson()
                        });
            }
        }