- SqlServerStorage UserHasViewed - true. , X-MiniProfiler-Id .
public class MvcMiniProfilerStorage : SqlServerStorage
{
public MvcMiniProfilerStorage(string connectionString) : base(connectionString)
{
}
public override void Save(MiniProfiler profiler)
{
const string sql =
@"insert into MiniProfilers
(Id,
Name,
Started,
MachineName,
[User],
Level,
RootTimingId,
DurationMilliseconds,
DurationMillisecondsInSql,
HasSqlTimings,
HasDuplicateSqlTimings,
HasTrivialTimings,
HasAllTrivialTimings,
TrivialDurationThresholdMilliseconds,
HasUserViewed)
select @Id,
@Name,
@Started,
@MachineName,
@User,
@Level,
@RootTimingId,
@DurationMilliseconds,
@DurationMillisecondsInSql,
@HasSqlTimings,
@HasDuplicateSqlTimings,
@HasTrivialTimings,
@HasAllTrivialTimings,
@TrivialDurationThresholdMilliseconds,
@HasUserViewed
where not exists (select 1 from MiniProfilers where Id = @Id)";
using (DbConnection conn = GetOpenConnection())
{
int insertCount = conn.Execute(sql,
new
{
profiler.Id,
Name = Truncate(profiler.Name, 200),
profiler.Started,
MachineName = Truncate(profiler.MachineName, 100),
User = Truncate(profiler.User, 100),
profiler.Level,
RootTimingId = profiler.Root.Id,
profiler.DurationMilliseconds,
profiler.DurationMillisecondsInSql,
profiler.HasSqlTimings,
profiler.HasDuplicateSqlTimings,
profiler.HasTrivialTimings,
profiler.HasAllTrivialTimings,
profiler.TrivialDurationThresholdMilliseconds,
HasUserViewed = true
});
if (insertCount > 0)
{
SaveTiming(conn, profiler, profiler.Root);
}
}
}
private static string Truncate(string s, int maxLength)
{
return s != null && s.Length >
maxLength ? s.Substring(0, maxLength) : s;
}
}