CorrelationKey.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.DurableInstancing / System / Activities / DurableInstancing / CorrelationKey.cs / 1305376 / CorrelationKey.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.Activities.DurableInstancing 
{
    using System; 
    using System.Collections.Generic; 
    using System.Globalization;
    using System.Linq; 
    using System.Runtime;
    using System.Xml;
    using System.Xml.Linq;
    using System.Xml.Serialization; 
    using System.Runtime.DurableInstancing;
 
    sealed class CorrelationKey 
    {
        public CorrelationKey(Guid keyId) 
            : this(keyId, null, InstanceEncodingOption.None)
        {
        }
 
        public CorrelationKey(Guid keyId, IDictionary keyMetadata, InstanceEncodingOption encodingOption)
        { 
            this.KeyId = keyId; 
            this.BinaryData = SerializationUtilities.SerializeKeyMetadata(keyMetadata, encodingOption);
        } 

        public Guid KeyId
        {
            get; 
            set;
        } 
 
        public long StartPosition
        { 
            get;
            set;
        }
 
        public ArraySegment BinaryData
        { 
            get; 
            set;
        } 

        public void SerializeToXmlElement(XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("CorrelationKey"); 
            xmlWriter.WriteAttributeString("KeyId", this.KeyId.ToString());
 
            if (this.BinaryData.Array != null) 
            {
                xmlWriter.WriteAttributeString("StartPosition", this.StartPosition.ToString(CultureInfo.InvariantCulture)); 
                xmlWriter.WriteAttributeString("BinaryLength", this.BinaryData.Count.ToString(CultureInfo.InvariantCulture));
            }

            xmlWriter.WriteEndElement(); 
        }
 
        public static List BuildKeyList(ICollection keys) 
        {
            List result = null; 

            if (keys != null)
            {
                result = new List(keys.Count); 

                foreach (Guid guid in keys) 
                { 
                    result.Add(new CorrelationKey(guid));
                } 
            }
            else
            {
                result = new List(); 
            }
 
            return result; 
        }
 
        public static List BuildKeyList(IDictionary> keys, InstanceEncodingOption encodingOption)
        {
            List result = new List();
 
            if (keys != null)
            { 
                foreach (KeyValuePair> keyValuePair in keys) 
                {
                    result.Add(new CorrelationKey(keyValuePair.Key, keyValuePair.Value, encodingOption)); 
                }
            }

            return result; 
        }
    } 
} 

// 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