Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / MessageFilter.cs / 1 / MessageFilter.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{
using System;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.ServiceModel.Diagnostics;
///
/// Abstract base class for different classes of message filters
///
[DataContract]
[KnownType(typeof(XPathMessageFilter))]
[KnownType(typeof(ActionMessageFilter))]
[KnownType(typeof(MatchAllMessageFilter))]
[KnownType(typeof(MatchNoneMessageFilter))]
//[KnownType(typeof(EndpointAddressMessageFilter))]
public abstract class MessageFilter
{
protected MessageFilter()
{
}
protected internal virtual IMessageFilterTable CreateFilterTable()
{
return null;
}
///
/// Tests whether the filter matches the given message.
///
public abstract bool Match(MessageBuffer buffer);
///
/// Tests whether the filter matches the given message without examining its body.
/// Note: since this method never probes the message body, it should NOT close the message
/// If the filter probes the message body, then the filter must THROW an Exception. The filter should not return false
/// This is deliberate - we don't want to produce false positives.
///
public abstract bool Match(Message message);
}
internal class SequentialMessageFilterTable : IMessageFilterTable
{
Dictionary filters;
public SequentialMessageFilterTable()
{
this.filters = new Dictionary();
}
//
// IMessageFilterTable methods
//
public int Count
{
get
{
return this.filters.Count;
}
}
public void Clear()
{
this.filters.Clear();
}
public bool GetMatchingValue(Message message, out FilterData data)
{
bool dataSet = false;
MessageFilter filter = null;
data = default(FilterData);
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(message))
{
if(dataSet)
{
Collection f = new Collection();
f.Add(filter);
f.Add(item.Key);
throw TraceUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.GetString(SR.FilterMultipleMatches), null, f), message);
}
filter = item.Key;
data = item.Value;
dataSet = true;
}
}
return dataSet;
}
public bool GetMatchingValue(MessageBuffer buffer, out FilterData data)
{
bool dataSet = false;
MessageFilter filter = null;
data = default(FilterData);
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(buffer))
{
if(dataSet)
{
Collection f = new Collection();
f.Add(filter);
f.Add(item.Key);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.GetString(SR.FilterMultipleMatches), null, f));
}
filter = item.Key;
data = item.Value;
dataSet = true;
}
}
return dataSet;
}
public bool GetMatchingValues(Message message, ICollection results)
{
int count = results.Count;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(message))
{
results.Add(item.Value);
}
}
return count != results.Count;
}
public bool GetMatchingValues(MessageBuffer buffer, ICollection results)
{
int count = results.Count;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(buffer))
{
results.Add(item.Value);
}
}
return count != results.Count;
}
public bool GetMatchingFilter(Message message, out MessageFilter filter)
{
filter = null;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(message))
{
if(filter != null)
{
Collection f = new Collection();
f.Add(filter);
f.Add(item.Key);
throw TraceUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.GetString(SR.FilterMultipleMatches), null, f), message);
}
filter = item.Key;
}
}
return filter != null;
}
public bool GetMatchingFilter(MessageBuffer buffer, out MessageFilter filter)
{
filter = null;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(buffer))
{
if(filter != null)
{
Collection f = new Collection();
f.Add(filter);
f.Add(item.Key);
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.GetString(SR.FilterMultipleMatches), null, f));
}
filter = item.Key;
}
}
return filter != null;
}
public bool GetMatchingFilters(Message message, ICollection results)
{
int count = results.Count;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(message))
{
results.Add(item.Key);
}
}
return count != results.Count;
}
public bool GetMatchingFilters(MessageBuffer buffer, ICollection results)
{
int count = results.Count;
foreach(KeyValuePair item in this.filters)
{
if(item.Key.Match(buffer))
{
results.Add(item.Key);
}
}
return count != results.Count;
}
//
// IDictionary methods
//
public FilterData this[MessageFilter key]
{
get
{
return this.filters[key];
}
set
{
this.filters[key] = value;
}
}
public ICollection Keys
{
get
{
return this.filters.Keys;
}
}
public ICollection Values
{
get
{
return this.filters.Values;
}
}
public bool ContainsKey(MessageFilter key)
{
return this.filters.ContainsKey(key);
}
public void Add(MessageFilter key, FilterData value)
{
this.filters.Add(key, value);
}
public bool Remove(MessageFilter key)
{
return this.filters.Remove(key);
}
//
// ICollection> methods
//
bool ICollection>.IsReadOnly
{
get
{
return false;
}
}
void ICollection>.Add(KeyValuePair item)
{
((ICollection>)this.filters).Add(item);
}
bool ICollection>.Contains(KeyValuePair item)
{
return ((ICollection>)this.filters).Contains(item);
}
void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex)
{
((ICollection>)this.filters).CopyTo(array, arrayIndex);
}
bool ICollection>.Remove(KeyValuePair item)
{
return ((ICollection>)this.filters).Remove(item);
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable>)this).GetEnumerator();
}
IEnumerator> IEnumerable>.GetEnumerator()
{
return ((ICollection>)this.filters).GetEnumerator();
}
public bool TryGetValue(MessageFilter filter, out FilterData data)
{
return this.filters.TryGetValue(filter, out data);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IntPtr.cs
- DependencyPropertyHelper.cs
- TableAutomationPeer.cs
- UnaryOperationBinder.cs
- ResourceBinder.cs
- PackWebRequest.cs
- SizeChangedInfo.cs
- TextServicesProperty.cs
- OleDbException.cs
- FileSystemInfo.cs
- TreeNodeEventArgs.cs
- TriggerActionCollection.cs
- OleDbException.cs
- PageClientProxyGenerator.cs
- RtfControls.cs
- ProfilePropertyMetadata.cs
- HttpFileCollection.cs
- Parser.cs
- DateTimeConverter2.cs
- DrawingVisualDrawingContext.cs
- WindowsNonControl.cs
- DrawingContextDrawingContextWalker.cs
- SqlStream.cs
- CodeExporter.cs
- unsafenativemethodsother.cs
- KeyValueSerializer.cs
- AnnotationObservableCollection.cs
- Transform3D.cs
- SqlGatherProducedAliases.cs
- ICollection.cs
- InternalBufferOverflowException.cs
- VisualTarget.cs
- DesignerEditorPartChrome.cs
- ImageSource.cs
- ListBoxItemWrapperAutomationPeer.cs
- FunctionParameter.cs
- UnsafeNativeMethods.cs
- NaturalLanguageHyphenator.cs
- ListViewAutomationPeer.cs
- AttributeQuery.cs
- SafeProcessHandle.cs
- PropertyEmitterBase.cs
- ExpandCollapsePattern.cs
- TypeResolver.cs
- DataBindingValueUIHandler.cs
- HtmlImage.cs
- WindowsSecurityTokenAuthenticator.cs
- SqlSupersetValidator.cs
- CodeTypeConstructor.cs
- ContextMarshalException.cs
- ImageBrush.cs
- MDIClient.cs
- DateTimeConverter.cs
- EmbeddedMailObjectsCollection.cs
- SelectionItemPatternIdentifiers.cs
- DatePicker.cs
- StringUtil.cs
- StrongName.cs
- ShutDownListener.cs
- ListView.cs
- IISMapPath.cs
- ValidationPropertyAttribute.cs
- TileBrush.cs
- VectorAnimation.cs
- CustomSignedXml.cs
- PageWrapper.cs
- ScriptControl.cs
- CultureSpecificCharacterBufferRange.cs
- RbTree.cs
- XmlNode.cs
- FileInfo.cs
- DataError.cs
- WpfSharedBamlSchemaContext.cs
- InputReportEventArgs.cs
- CallInfo.cs
- HelpKeywordAttribute.cs
- ExtentCqlBlock.cs
- RadialGradientBrush.cs
- NumberFunctions.cs
- DateRangeEvent.cs
- XmlSchema.cs
- ComponentChangedEvent.cs
- WebPartConnectionsDisconnectVerb.cs
- HandlerBase.cs
- TargetInvocationException.cs
- HttpFileCollection.cs
- MeasureData.cs
- CanonicalFormWriter.cs
- DBCSCodePageEncoding.cs
- MediaTimeline.cs
- EntityDesignerBuildProvider.cs
- TypeLoadException.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- WizardPanelChangingEventArgs.cs
- SiteMapNodeItem.cs
- DefaultPropertyAttribute.cs
- CanonicalFormWriter.cs
- SessionKeyExpiredException.cs
- DesignerObject.cs
- ServiceProviders.cs