0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Reflection;
|
|
4 using System.Text;
|
|
5 using System.Web.UI;
|
|
6
|
|
7 using BLToolkit.Aspects;
|
|
8
|
|
9 public partial class Admin_Counters : Page
|
|
10 {
|
|
11 protected void Page_Load(object sender, EventArgs e)
|
|
12 {
|
|
13 if (Request["cleanup"] == "1")
|
|
14 {
|
|
15 CacheAspect.ClearCache();
|
|
16 Response.Redirect("Counters.aspx");
|
|
17 }
|
|
18
|
|
19 List<MethodCallCounter> counters = new List<MethodCallCounter>();
|
|
20
|
|
21 lock (CounterAspect.Counters.SyncRoot)
|
|
22 foreach (MethodCallCounter c in CounterAspect.Counters)
|
|
23 lock (c.CurrentCalls.SyncRoot)
|
|
24 if (c.TotalCount > 0 || c.CachedCount > 0 | c.CurrentCalls.Count > 0)
|
|
25 counters.Add(c);
|
|
26
|
|
27 counters.Sort(delegate(MethodCallCounter x, MethodCallCounter y)
|
|
28 {
|
|
29 int c = string.Compare(
|
|
30 x.MethodInfo.DeclaringType.Name,
|
|
31 y.MethodInfo.DeclaringType.Name);
|
|
32
|
|
33 if (c != 0)
|
|
34 return c;
|
|
35
|
|
36 return string.Compare(x.MethodInfo.Name, y.MethodInfo.Name);
|
|
37 });
|
|
38
|
|
39 counterRepeater.DataSource = counters;
|
|
40
|
|
41 DataBind();
|
|
42 }
|
|
43
|
|
44 protected string GetName(Type type)
|
|
45 {
|
|
46 string name = type.Name;
|
|
47
|
|
48 if (type.IsGenericType || type.Name.IndexOf('_') > 0 && type.BaseType.IsGenericType)
|
|
49 {
|
|
50 if (!type.IsGenericType)
|
|
51 type = type.BaseType;
|
|
52
|
|
53 name = type.Name.Split('`')[0] + "<";
|
|
54
|
|
55 foreach (Type t in type.GetGenericArguments())
|
|
56 name += GetName(t) + ",";
|
|
57
|
|
58 name = name.TrimEnd(',') + ">";
|
|
59 }
|
|
60
|
|
61 return name;
|
|
62 }
|
|
63
|
|
64 protected string GetTime(TimeSpan time)
|
|
65 {
|
|
66 if (time == TimeSpan.MinValue || time == TimeSpan.MaxValue)
|
|
67 return "";
|
|
68
|
|
69 string s = time.ToString();
|
|
70
|
|
71 if (s.Length > 12)
|
|
72 s = s.Substring(0, 12);
|
|
73
|
|
74 if (time.TotalSeconds <= 1)
|
|
75 s = string.Format("<font color=gray>{0}</font>", s);
|
|
76
|
|
77 return s;
|
|
78 }
|
|
79
|
|
80 protected string GetCurrent(MethodCallCounter counter)
|
|
81 {
|
|
82 List<InterceptCallInfo> info = new List<InterceptCallInfo>();
|
|
83
|
|
84 lock (counter.CurrentCalls.SyncRoot)
|
|
85 {
|
|
86 if (counter.CurrentCalls.Count == 0)
|
|
87 return "";
|
|
88
|
|
89 foreach (InterceptCallInfo c in counter.CurrentCalls)
|
|
90 info.Add(c);
|
|
91 }
|
|
92
|
|
93 StringBuilder sb = new StringBuilder();
|
|
94
|
|
95 sb.Append("<tr><td colspan=8 align=left><table class='grid' cellspacing=0 cellpadding=0 rules=all border=1 style='border-collapse:collapse'>");
|
|
96
|
|
97 sb.Append("<tr class='gridheader'>");
|
|
98 sb.Append("<td>Time</td>");
|
|
99 sb.Append("<td>Login</td>");
|
|
100
|
|
101 foreach (ParameterInfo pi in counter.MethodInfo.GetParameters())
|
|
102 sb.AppendFormat("<td>{0}</td>", pi.Name);
|
|
103
|
|
104 sb.Append("</tr>");
|
|
105
|
|
106 foreach (InterceptCallInfo c in counter.CurrentCalls)
|
|
107 {
|
|
108 sb.AppendFormat("<tr>");
|
|
109
|
|
110 sb.AppendFormat("<td>{0}</td>", DateTime.Now - c.BeginCallTime);
|
|
111 sb.AppendFormat("<td>{0}</td>", c.CurrentPrincipal.Identity.Name);
|
|
112
|
|
113 foreach (object value in c.ParameterValues)
|
|
114 {
|
|
115 sb.AppendFormat("<td>");
|
|
116
|
|
117 sb.Append(
|
|
118 value == null ? "<null>" :
|
|
119 value is string ? "\"" + value.ToString().Replace("\n", "<br>\n") + "\"" :
|
|
120 value is char ? "'" + value + "'" :
|
|
121 value.ToString());
|
|
122
|
|
123 sb.AppendFormat("</td>");
|
|
124 }
|
|
125
|
|
126 sb.AppendFormat("</tr>");
|
|
127 }
|
|
128
|
|
129 sb.Append("</td></tr></table>");
|
|
130
|
|
131 return sb.ToString();
|
|
132 }
|
|
133 }
|