1 //---------------------------------------------------------------- 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //---------------------------------------------------------------- 4 5 namespace System.ServiceModel.Activities 6 { 7 using System.Collections.Generic; 8 using System.Diagnostics.CodeAnalysis; 9 using System.Runtime; 10 using System.Runtime.DurableInstancing; 11 using System.Runtime.Serialization; 12 using System.Xml.Linq; 13 14 [DataContract(Name = "InstanceKey", Namespace = XD2.DurableInstancing.Namespace)] 15 class SerializableInstanceKey 16 { 17 Guid value; 18 IDictionary<XName, SerializableInstanceValue> metadata; 19 SerializableInstanceKey(InstanceKey instanceKey)20 public SerializableInstanceKey(InstanceKey instanceKey) 21 { 22 this.value = instanceKey.Value; 23 if (instanceKey.Metadata != null) 24 { 25 this.metadata = new Dictionary<XName, SerializableInstanceValue>(instanceKey.Metadata.Count); 26 foreach (KeyValuePair<XName, InstanceValue> pair in instanceKey.Metadata) 27 { 28 this.metadata.Add(pair.Key, new SerializableInstanceValue(pair.Value)); 29 } 30 } 31 } 32 33 [DataMember(EmitDefaultValue = false)] 34 [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Justification = "Called from Serialization")] 35 internal Guid Value 36 { 37 get 38 { 39 return this.value; 40 } 41 42 set 43 { 44 this.value = value; 45 } 46 } 47 48 [DataMember(EmitDefaultValue = false)] 49 [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Justification = "Called from Serialization")] 50 internal IDictionary<XName, SerializableInstanceValue> Metadata 51 { 52 get 53 { 54 if (this.metadata == null || this.metadata.Count == 0) 55 { 56 return null; 57 } 58 else 59 { 60 return this.metadata; 61 } 62 } 63 64 set 65 { 66 this.metadata = value; 67 } 68 } 69 ToInstanceKey()70 public InstanceKey ToInstanceKey() 71 { 72 IDictionary<XName, InstanceValue> metadata = null; 73 if (this.metadata != null) 74 { 75 metadata = new Dictionary<XName, InstanceValue>(this.metadata.Count); 76 foreach (KeyValuePair<XName, SerializableInstanceValue> pair in this.metadata) 77 { 78 metadata.Add(pair.Key, pair.Value.ToInstanceValue()); 79 } 80 } 81 82 return new InstanceKey(this.value, metadata); 83 } 84 } 85 } 86