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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Tracking
{
using System;
using System.Runtime;
using System.Runtime.Serialization;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Runtime.Diagnostics;
[Fx.Tag.XamlVisible(false)]
[DataContract]
public abstract class TrackingRecord
{
IDictionary<string, string> annotations;
DateTime eventTime;
TraceLevel level;
EventTraceActivity eventTraceActivity;
static ReadOnlyDictionaryInternal<string, string> readonlyEmptyAnnotations;
protected TrackingRecord(Guid instanceId)
{
this.InstanceId = instanceId;
this.EventTime = DateTime.UtcNow;
this.Level = TraceLevel.Info;
this.eventTraceActivity = new EventTraceActivity(instanceId);
}
protected TrackingRecord(Guid instanceId, long recordNumber)
: this(instanceId)
{
this.RecordNumber = recordNumber;
}
protected TrackingRecord(TrackingRecord record)
{
this.InstanceId = record.InstanceId;
this.RecordNumber = record.RecordNumber;
this.EventTime = record.EventTime;
this.Level = record.Level;
if (record.HasAnnotations)
{
Dictionary<string, string> copy = new Dictionary<string, string>(record.annotations);
this.annotations = new ReadOnlyDictionaryInternal<string, string>(copy);
}
}
[DataMember]
public Guid InstanceId
{
get;
internal set;
}
[DataMember]
public long RecordNumber
{
get;
internal set;
}
public DateTime EventTime
{
get
{
return this.eventTime;
}
private set
{
this.eventTime = value;
}
}
public TraceLevel Level
{
get
{
return this.level;
}
protected set
{
this.level = value;
}
}
public IDictionary<string, string> Annotations
{
get
{
if (this.annotations == null)
{
this.annotations = ReadOnlyEmptyAnnotations;
}
return this.annotations;
}
internal set
{
Fx.Assert(value.IsReadOnly, "only readonly dictionary can be set for annotations");
this.annotations = value;
}
}
[DataMember(EmitDefaultValue = false, Name = "annotations")]
internal IDictionary<string, string> SerializedAnnotations
{
get { return this.annotations; }
set { this.annotations = value; }
}
[DataMember(Name = "EventTime")]
internal DateTime SerializedEventTime
{
get { return this.EventTime; }
set { this.EventTime = value; }
}
[DataMember(Name = "Level")]
internal TraceLevel SerializedLevel
{
get { return this.Level; }
set { this.Level = value; }
}
internal EventTraceActivity EventTraceActivity
{
get
{
if (this.eventTraceActivity == null)
{
this.eventTraceActivity = new EventTraceActivity(this.InstanceId);
}
return this.eventTraceActivity;
}
}
static ReadOnlyDictionaryInternal<string, string> ReadOnlyEmptyAnnotations
{
get
{
if (readonlyEmptyAnnotations == null)
{
readonlyEmptyAnnotations = new ReadOnlyDictionaryInternal<string, string>(new Dictionary<string, string>(0));
}
return readonlyEmptyAnnotations;
}
}
internal bool HasAnnotations
{
get
{
return (this.annotations != null && this.annotations.Count > 0);
}
}
protected abstract internal TrackingRecord Clone();
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture,
"InstanceId = {0}, RecordNumber = {1}, EventTime = {2}",
this.InstanceId,
this.RecordNumber,
this.EventTime);
}
}
}
|