forked from NewLifeX/X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbRunTimeModule.cs
More file actions
37 lines (32 loc) · 1.29 KB
/
DbRunTimeModule.cs
File metadata and controls
37 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#if !__CORE__
using System;
using System.Web;
using NewLife.Web;
using XCode.DataAccessLayer;
namespace XCode.Web
{
/// <summary>页面查询执行时间模块</summary>
public class DbRunTimeModule : RunTimeModule
{
/// <summary>执行时间字符串</summary>
public static String DbRunTimeFormat { get; set; } = "查询{0}次,执行{1}次,耗时{2:n0}毫秒!";
/// <summary>初始化模块,准备拦截请求。</summary>
/// <param name="context"></param>
protected override void OnInit(HttpContext context)
{
context.Items["DAL.QueryTimes"] = DAL.QueryTimes;
context.Items["DAL.ExecuteTimes"] = DAL.ExecuteTimes;
}
/// <summary>输出</summary>
/// <param name="context"></param>
/// <returns></returns>
protected override String Render(HttpContext context)
{
var ts = DateTime.Now - context.Timestamp;
var StartQueryTimes = (Int32)context.Items["DAL.QueryTimes"];
var StartExecuteTimes = (Int32)context.Items["DAL.ExecuteTimes"];
return String.Format(DbRunTimeFormat, DAL.QueryTimes - StartQueryTimes, DAL.ExecuteTimes - StartExecuteTimes, ts.TotalMilliseconds);
}
}
}
#endif