-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWcfEntry.cs
84 lines (71 loc) · 2.08 KB
/
WcfEntry.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
using System;
using System.Diagnostics;
using Glimpse.Core.Extensibility;
using Glimpse.Core.Message;
namespace Glimpse.Wcf
{
public class WcfEntry : ITimelineMessage
{
private IExecutionTimer _timer;
private Stopwatch _stopWatch;
public WcfEntry()
{
Id = Guid.NewGuid();
_stopWatch = Stopwatch.StartNew();
StartTime = DateTime.Now;
}
#region ITimelineMessage
public Guid Id { get; private set; }
public TimeSpan Offset { get; set; }
public TimeSpan Duration { get; set; }
public DateTime StartTime { get; set; }
public string EventName { get; set; }
public TimelineCategoryItem EventCategory
{
get { return new TimelineCategoryItem("WCF", "#F00000", "#FF0000"); }
set { }
}
public string EventSubText { get; set; }
#endregion
// WCF Message data
public string MessageId;
public string RequestBody;
public string ResponseBody;
public IExecutionTimer Timer
{
set
{
_timer = value;
var point = _timer.Point();
Duration = point.Duration;
Offset = point.Offset;
StartTime = point.StartTime;
}
}
public void CalcDuration()
{
if (_timer == null)
return;
if (_stopWatch == null)
{
_stopWatch = Stopwatch.StartNew();
Duration = TimeSpan.FromMilliseconds(0);
}
else if (DateTime.Now - _stopWatch.Elapsed < _timer.RequestStart)
{
_stopWatch = Stopwatch.StartNew();
Duration = TimeSpan.FromMilliseconds(0);
}
else
{
Duration = _stopWatch.Elapsed;
_stopWatch = Stopwatch.StartNew();
}
}
public void Cleanup()
{
_timer = null;
_stopWatch = null;
}
}
}