TrackingRecord.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Tracking / TrackingRecord.cs / 1305376 / TrackingRecord.cs

                            //------------------------------------------------------------------------------ 
// 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.Globalization;

    [Fx.Tag.XamlVisible(false)] 
    [DataContract]
    public abstract class TrackingRecord 
    { 
        [DataMember(EmitDefaultValue = false)]
        IDictionary annotations; 

        static ReadOnlyDictionary readonlyEmptyAnnotations;

        protected TrackingRecord(Guid instanceId) 
        {
            this.InstanceId = instanceId; 
            this.EventTime = DateTime.UtcNow; 
            this.Level = TraceLevel.Info;
        } 

        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)
            { 
                this.annotations = new ReadOnlyDictionary(record.annotations); 
            }
        } 


        [DataMember]
        public Guid InstanceId 
        {
            get; 
            internal set; 
        }
 
        [DataMember]
        public long RecordNumber
        {
            get; 
            internal set;
        } 
 
        [DataMember]
        public DateTime EventTime 
        {
            get;
            private set;
        } 

        [DataMember] 
        public TraceLevel Level 
        {
            get; 
            protected set;
        }

        public IDictionary 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;
            } 
        }

        static ReadOnlyDictionary ReadOnlyEmptyAnnotations
        { 
            get
            { 
                if (readonlyEmptyAnnotations == null) 
                {
                    readonlyEmptyAnnotations = new ReadOnlyDictionary(new Dictionary(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); 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK