/// <summary> /// Stores <param name="profiler"/> to MongoDB under its <see cref="MiniProfiler.Id"/>; /// stores all child Timings and SqlTimings to their respective tables. /// </summary> public override void Save(MiniProfiler profiler) { var miniProfilerPoco = new MiniProfilerPoco { Id = profiler.Id, RootTimingId = profiler.Root != null ? profiler.Root.Id : (Guid?)null, Name = profiler.Name, Started = profiler.Started, DurationMilliseconds = (double)profiler.DurationMilliseconds, User = profiler.UserName, HasUserViewed = profiler.HasUserViewed, MachineName = profiler.MachineName, CustomLinksJson = profiler.CustomLinksJson, ClientTimingsRedirectCounts = profiler.ClientTimings != null ? profiler.ClientTimings.RedirectCount : (int?)null }; var result = Profilers.Save(miniProfilerPoco, WriteConcern.Acknowledged); if (!result.UpdatedExisting) { SaveTiming(profiler.Root); } SaveClientTimings(profiler); }
/// <summary> /// Stores <param name="profiler"/> to MongoDB under its <see cref="MiniProfiler.Id"/>; /// stores all child Timings and SqlTimings to their respective tables. /// </summary> public override void Save(MiniProfiler profiler) { var profilerPoco = new MiniProfilerPoco { Id = profiler.Id.ToString(), Name = Truncate(profiler.Name, 200), Started = profiler.Started, MachineName = Truncate(profiler.MachineName, 100), User = Truncate(profiler.User, 100), Level = profiler.Level, RootTimingId = profiler.Root.Id, DurationMilliseconds = (double)profiler.DurationMilliseconds, DurationMillisecondsInSql = (double)profiler.DurationMillisecondsInSql, HasSqlTimings = profiler.HasSqlTimings, HasDuplicateSqlTimings = profiler.HasDuplicateSqlTimings, HasTrivialTimings = profiler.HasTrivialTimings, HasAllTrivialTimings = profiler.HasAllTrivialTimings, TrivialDurationThresholdMilliseconds = (double)profiler.TrivialDurationThresholdMilliseconds, HasUserViewed = profiler.HasUserViewed }; var result = Profilers.Save(profilerPoco, SafeMode.True); if (result.UpdatedExisting == false) { //Save Root Timing SaveTiming(profiler, profiler.Root); } // we may have a missing client timing - re save if (profiler.ClientTimings != null) { SaveClientTiming(profiler); } }
/// <summary> /// Sets the profiler as view /// </summary> public override void SetViewed(string user, Guid id) { var profiler = Profilers.FindOne(Query.EQ("_id", id.ToString())); if (profiler != null) { profiler.HasUserViewed = true; Profilers.Save(profiler); } }