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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ServiceModel.Security;
using System.Xml;
public class ScopedMessagePartSpecification
{
MessagePartSpecification channelParts;
Dictionary<string, MessagePartSpecification> actionParts;
Dictionary<string, MessagePartSpecification> readOnlyNormalizedActionParts;
bool isReadOnly;
public ScopedMessagePartSpecification()
{
this.channelParts = new MessagePartSpecification();
this.actionParts = new Dictionary<string, MessagePartSpecification>();
}
public ICollection<string> Actions
{
get
{
return this.actionParts.Keys;
}
}
public MessagePartSpecification ChannelParts
{
get
{
return this.channelParts;
}
}
public bool IsReadOnly
{
get
{
return this.isReadOnly;
}
}
public ScopedMessagePartSpecification(ScopedMessagePartSpecification other)
: this()
{
if (other == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("other"));
this.channelParts.Union(other.channelParts);
if (other.actionParts != null)
{
foreach (string action in other.actionParts.Keys)
{
MessagePartSpecification p = new MessagePartSpecification();
p.Union(other.actionParts[action]);
this.actionParts[action] = p;
}
}
}
internal ScopedMessagePartSpecification(ScopedMessagePartSpecification other, bool newIncludeBody)
: this(other)
{
this.channelParts.IsBodyIncluded = newIncludeBody;
foreach (string action in this.actionParts.Keys)
this.actionParts[action].IsBodyIncluded = newIncludeBody;
}
public void AddParts(MessagePartSpecification parts)
{
if (parts == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parts"));
ThrowIfReadOnly();
this.channelParts.Union(parts);
}
public void AddParts(MessagePartSpecification parts, string action)
{
if (action == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("action"));
if (parts == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parts"));
ThrowIfReadOnly();
if (!this.actionParts.ContainsKey(action))
this.actionParts[action] = new MessagePartSpecification();
this.actionParts[action].Union(parts);
}
internal void AddParts(MessagePartSpecification parts, XmlDictionaryString action)
{
if (action == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("action"));
AddParts(parts, action.Value);
}
internal bool IsEmpty()
{
bool result;
if (!channelParts.IsEmpty())
{
result = false;
}
else
{
result = true;
foreach (string action in this.Actions)
{
MessagePartSpecification parts;
if (TryGetParts(action, true, out parts))
{
if (!parts.IsEmpty())
{
result = false;
break;
}
}
}
}
return result;
}
public bool TryGetParts(string action, bool excludeChannelScope, out MessagePartSpecification parts)
{
if (action == null)
action = MessageHeaders.WildcardAction;
parts = null;
if (this.isReadOnly)
{
if (this.readOnlyNormalizedActionParts.ContainsKey(action))
if (excludeChannelScope)
parts = this.actionParts[action];
else
parts = this.readOnlyNormalizedActionParts[action];
}
else if (this.actionParts.ContainsKey(action))
{
MessagePartSpecification p = new MessagePartSpecification();
p.Union(this.actionParts[action]);
if (!excludeChannelScope)
p.Union(this.channelParts);
parts = p;
}
return parts != null;
}
internal void CopyTo(ScopedMessagePartSpecification target)
{
if (target == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("target");
}
target.ChannelParts.IsBodyIncluded = this.ChannelParts.IsBodyIncluded;
foreach (XmlQualifiedName headerType in ChannelParts.HeaderTypes)
{
if (!target.channelParts.IsHeaderIncluded(headerType.Name, headerType.Namespace))
{
target.ChannelParts.HeaderTypes.Add(headerType);
}
}
foreach (string action in this.actionParts.Keys)
{
target.AddParts(this.actionParts[action], action);
}
}
public bool TryGetParts(string action, out MessagePartSpecification parts)
{
return this.TryGetParts(action, false, out parts);
}
public void MakeReadOnly()
{
if (!this.isReadOnly)
{
this.readOnlyNormalizedActionParts = new Dictionary<string, MessagePartSpecification>();
foreach (string action in this.actionParts.Keys)
{
MessagePartSpecification p = new MessagePartSpecification();
p.Union(this.actionParts[action]);
p.Union(this.channelParts);
p.MakeReadOnly();
this.readOnlyNormalizedActionParts[action] = p;
}
this.isReadOnly = true;
}
}
void ThrowIfReadOnly()
{
if (this.isReadOnly)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
}
}
}
|