| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //------------------------------------------------------------
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //------------------------------------------------------------
- namespace System.ServiceModel.Channels
- {
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- [TypeForwardedFrom("System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
- [Serializable]
- public class ContextMessageProperty : IMessageProperty
- {
- internal const string InstanceIdKey = "instanceId";
- const string PropertyName = "ContextMessageProperty";
- static ContextMessageProperty empty;
- IDictionary<string, string> contextStore;
- public ContextMessageProperty()
- {
- this.contextStore = new ContextDictionary();
- }
- public ContextMessageProperty(IDictionary<string, string> context)
- {
- if (context == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
- }
- this.contextStore = new ContextDictionary(context);
- }
- public static string Name
- {
- get
- {
- return PropertyName;
- }
- }
- public IDictionary<string, string> Context
- {
- get
- {
- return this.contextStore;
- }
- }
- internal static ContextMessageProperty Empty
- {
- get
- {
- if (empty == null)
- {
- ContextMessageProperty context = new ContextMessageProperty();
- context.contextStore = ContextDictionary.Empty;
- empty = context;
- }
- return empty;
- }
- }
- public static bool TryCreateFromHttpCookieHeader(string httpCookieHeader, out ContextMessageProperty context)
- {
- return ContextProtocol.HttpCookieToolbox.TryCreateFromHttpCookieHeader(httpCookieHeader, out context);
- }
- public static bool TryGet(Message message, out ContextMessageProperty contextMessageProperty)
- {
- if (message == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
- }
- return TryGet(message.Properties, out contextMessageProperty);
- }
- public static bool TryGet(MessageProperties properties, out ContextMessageProperty contextMessageProperty)
- {
- if (properties == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
- }
- object value = null;
- if (properties.TryGetValue(PropertyName, out value))
- {
- contextMessageProperty = value as ContextMessageProperty;
- }
- else
- {
- contextMessageProperty = null;
- }
- return contextMessageProperty != null;
- }
- public void AddOrReplaceInMessage(Message message)
- {
- if (message == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
- }
- this.AddOrReplaceInMessageProperties(message.Properties);
- }
- public void AddOrReplaceInMessageProperties(MessageProperties properties)
- {
- if (properties == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
- }
- properties[PropertyName] = this;
- }
- public IMessageProperty CreateCopy()
- {
- return new ContextMessageProperty(this.Context);
- }
- }
- }
|