-
Notifications
You must be signed in to change notification settings - Fork 65
/
ErrorDetailPage.cs
127 lines (116 loc) · 4.94 KB
/
ErrorDetailPage.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#region License, Terms and Author(s)
//
// ELMAH - Error Logging Modules and Handlers for ASP.NET
// Copyright (c) 2004-9 Atif Aziz. All rights reserved.
//
// Author(s):
//
// Atif Aziz, http://www.raboof.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
[assembly: Elmah.Scc("$Id: ErrorDetailPage.cs 776 2011-01-12 21:09:24Z azizatif $")]
namespace Elmah
{
#region Imports
using System;
using System.Linq;
using MoreLinq;
#endregion
/// <summary>
/// Renders an HTML page displaying details about an error from the
/// error log.
/// </summary>
sealed partial class ErrorDetailPage
{
public ErrorLog ErrorLog { get; set; }
static HelperResult MarkupStackTrace(string text)
{
Debug.Assert(text != null);
return new HelperResult(writer =>
{
if (writer == null) throw new ArgumentNullException("writer");
var frames = StackTraceParser.Parse
(
text,
(idx, len, txt) => new
{
Index = idx,
End = idx + len,
Html = txt.Length > 0
? Elmah.Html.Encode(txt).ToHtmlString()
: string.Empty,
},
(t, m) => new
{
Type = new { t.Index, t.End, Html = "<span class='st-type'>" + t.Html + "</span>" },
Method = new { m.Index, m.End, Html = "<span class='st-method'>" + m.Html + "</span>" }
},
(t, n) => new
{
Type = new { t.Index, t.End, Html = "<span class='st-param-type'>" + t.Html + "</span>" },
Name = new { n.Index, n.End, Html = "<span class='st-param-name'>" + n.Html + "</span>" }
},
(p, ps) => new { List = p, Parameters = ps.ToArray() },
(f, l) => new
{
File = f.Html.Length > 0
? new { f.Index, f.End, Html = "<span class='st-file'>" + f.Html + "</span>" }
: null,
Line = l.Html.Length > 0
? new { l.Index, l.End, Html = "<span class='st-line'>" + l.Html + "</span>" }
: null,
},
(f, tm, p, fl) =>
from tokens in new[]
{
new[]
{
new { f.Index, End = f.Index, Html = "<span class='st-frame'>" },
tm.Type,
tm.Method,
new { p.List.Index, End = p.List.Index, Html = "<span class='params'>" },
},
from pe in p.Parameters
from e in new[] { pe.Type, pe.Name }
select e,
new[]
{
new { Index = p.List.End, p.List.End, Html = "</span>" },
fl.File,
fl.Line,
new { Index = f.End, f.End, Html = "</span>" },
},
}
from token in tokens
where token != null
select token
);
var markups =
from token in Enumerable.Repeat(new { Index = 0, End = 0, Html = string.Empty }, 1)
.Concat(from tokens in frames from token in tokens select token)
.Pairwise((prev, curr) => new { Previous = prev, Current = curr })
from m in new object[]
{
text.Substring(token.Previous.End, token.Current.Index - token.Previous.End),
Elmah.Html.Raw(token.Current.Html)
}
select Elmah.Html.Encode(m).ToHtmlString() into m
where m.Length > 0
select m;
writer.Write(markups.ToDelimitedString(string.Empty));
});
}
}
}