Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Routing / System / ServiceModel / Dispatcher / StrictAndMessageFilter.cs / 1305376 / StrictAndMessageFilter.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Linq; using System.Runtime; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Collections; using System.ServiceModel.Routing; [SuppressMessage(FxCop.Category.Xaml, FxCop.Rule.TypesMustHaveXamlCallableConstructors)] [SuppressMessage(FxCop.Category.Xaml, FxCop.Rule.TypesShouldHavePublicParameterlessConstructors)] public class StrictAndMessageFilter : MessageFilter { MessageFilter filter1; MessageFilter filter2; public StrictAndMessageFilter(MessageFilter filter1, MessageFilter filter2) { if (filter1 == null || filter2 == null) { throw FxTrace.Exception.ArgumentNull(filter1 == null ? "filter1" : "filter2"); } this.filter1 = filter1; this.filter2 = filter2; } public override bool Match(Message message) { throw FxTrace.Exception.AsError(new NotSupportedException()); } public override bool Match(MessageBuffer buffer) { throw FxTrace.Exception.AsError(new NotSupportedException()); } protected internal override IMessageFilterTableCreateFilterTable () { StrictAndMessageFilterTable table = new StrictAndMessageFilterTable (); return table; } class StrictAndMessageFilterTable : IMessageFilterTable { Dictionary andFilters; MessageFilterTable filterTable; public StrictAndMessageFilterTable() { this.andFilters = new Dictionary (); this.filterTable = new MessageFilterTable (); } public int Count { get { return this.andFilters.Count; } } public bool IsReadOnly { get { return true; } } public ICollection Keys { get { return this.andFilters.Keys; } } public ICollection Values { get { return this.andFilters.Values; } } public TFilterData this[MessageFilter key] { get { return this.andFilters[key]; } set { this.andFilters[key] = value; } } public bool GetMatchingFilter(MessageBuffer messageBuffer, out MessageFilter filter) { throw FxTrace.Exception.AsError(new NotImplementedException()); } public bool GetMatchingFilter(Message message, out MessageFilter filter) { throw FxTrace.Exception.AsError(new NotImplementedException()); } public bool GetMatchingFilters(MessageBuffer messageBuffer, ICollection results) { if (messageBuffer == null) { throw FxTrace.Exception.ArgumentNull("messageBuffer"); } List firstPassResults = new List (); if (this.filterTable.GetMatchingFilters(messageBuffer, firstPassResults)) { IList matchingFilters = FindMatchingAndFilters(firstPassResults); foreach (StrictAndMessageFilter andFilter in matchingFilters) { results.Add(andFilter); } return (matchingFilters.Count > 0); } return false; } public bool GetMatchingFilters(Message message, ICollection results) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } List firstPassResults = new List (); if (this.filterTable.GetMatchingFilters(message, firstPassResults)) { IList matchingFilters = FindMatchingAndFilters(firstPassResults); foreach (StrictAndMessageFilter andFilter in matchingFilters) { results.Add(andFilter); } return (matchingFilters.Count > 0); } return false; } public bool GetMatchingValue(MessageBuffer messageBuffer, out TFilterData value) { value = default(TFilterData); List results = new List (); bool result = this.GetMatchingValues(messageBuffer, results); if (results.Count == 1) { value = results[0]; } if (results.Count > 1) { throw FxTrace.Exception.AsError(new MultipleFilterMatchesException()); } return result; } public bool GetMatchingValue(Message message, out TFilterData value) { value = default(TFilterData); List results = new List (); bool result = this.GetMatchingValues(message, results); if (results.Count == 1) { value = results[0]; } else if (results.Count > 1) { throw FxTrace.Exception.AsError(new MultipleFilterMatchesException()); } return result; } public bool GetMatchingValues(MessageBuffer messageBuffer, ICollection results) { if (messageBuffer == null) { throw FxTrace.Exception.ArgumentNull("messageBuffer"); } List firstPassResults = new List (); if (this.filterTable.GetMatchingFilters(messageBuffer, firstPassResults)) { IList matchingFilters = FindMatchingAndFilters(firstPassResults); foreach (StrictAndMessageFilter andFilter in matchingFilters) { results.Add(this.andFilters[andFilter]); } return (matchingFilters.Count > 0); } return false; } public bool GetMatchingValues(Message message, ICollection results) { if (message == null) { throw FxTrace.Exception.ArgumentNull("message"); } List firstPassResults = new List (); if (this.filterTable.GetMatchingFilters(message, firstPassResults)) { IList matchingFilters = FindMatchingAndFilters(firstPassResults); foreach (StrictAndMessageFilter andFilter in matchingFilters) { results.Add(this.andFilters[andFilter]); } return (matchingFilters.Count > 0); } return false; } IList FindMatchingAndFilters(List firstPassResults) { IList matchingFilters = new List (); foreach (MessageFilter filter in firstPassResults) { StrictAndMessageFilter andFilter = this.filterTable[filter]; // Check if this StrictAndMessageFilter is already in our result set if (!matchingFilters.Contains(andFilter)) { if (firstPassResults.Contains(andFilter.filter1) && firstPassResults.Contains(andFilter.filter2)) { matchingFilters.Add(andFilter); } } } return matchingFilters; } public void Add(MessageFilter key, TFilterData value) { StrictAndMessageFilter andFilter = (StrictAndMessageFilter)key; this.andFilters.Add(andFilter, value); this.filterTable.Add(andFilter.filter1, andFilter); this.filterTable.Add(andFilter.filter2, andFilter); } public bool ContainsKey(MessageFilter key) { return this.andFilters.ContainsKey(key); } public bool Remove(MessageFilter key) { StrictAndMessageFilter andFilter = (StrictAndMessageFilter)key; if (this.andFilters.Remove(andFilter)) { this.filterTable.Remove(andFilter.filter1); this.filterTable.Remove(andFilter.filter2); return true; } return false; } public bool TryGetValue(MessageFilter key, out TFilterData value) { return this.andFilters.TryGetValue(key, out value); } public void Add(KeyValuePair item) { this.Add(item.Key, item.Value); } public void Clear() { this.andFilters.Clear(); this.filterTable.Clear(); } public bool Contains(KeyValuePair item) { return this.andFilters.Contains(item); } public void CopyTo(KeyValuePair [] array, int arrayIndex) { throw FxTrace.Exception.AsError(new NotImplementedException()); } public bool Remove(KeyValuePair item) { return this.andFilters.Remove(item.Key); } public IEnumerator > GetEnumerator() { throw FxTrace.Exception.AsError(new NotImplementedException()); } IEnumerator IEnumerable.GetEnumerator() { throw FxTrace.Exception.AsError(new NotImplementedException()); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StoreConnection.cs
- AudioException.cs
- MessageSmuggler.cs
- ImageSource.cs
- ProfilePropertyNameValidator.cs
- PresentationAppDomainManager.cs
- ArithmeticException.cs
- ObjectStateFormatter.cs
- DTCTransactionManager.cs
- ISO2022Encoding.cs
- Separator.cs
- CopyAttributesAction.cs
- BindingRestrictions.cs
- ResourcePool.cs
- HttpRuntimeSection.cs
- Journaling.cs
- Function.cs
- ConfigUtil.cs
- MachineSettingsSection.cs
- FullTextLine.cs
- GridViewUpdatedEventArgs.cs
- Types.cs
- DataGridRelationshipRow.cs
- CfgArc.cs
- WMIGenerator.cs
- EventData.cs
- Sentence.cs
- PropertyGridCommands.cs
- IdentityModelDictionary.cs
- ListViewInsertionMark.cs
- ObservableDictionary.cs
- AdjustableArrowCap.cs
- HtmlTitle.cs
- InProcStateClientManager.cs
- ObjectSelectorEditor.cs
- IdentifierCollection.cs
- ReadOnlyDataSourceView.cs
- DataStreams.cs
- SessionPageStatePersister.cs
- FontFamilyIdentifier.cs
- DefaultTextStoreTextComposition.cs
- UserMapPath.cs
- RowTypeElement.cs
- CustomPopupPlacement.cs
- Int16AnimationBase.cs
- SqlDataSourceEnumerator.cs
- DataGridViewButtonCell.cs
- WebPartManager.cs
- TdsParser.cs
- FrameAutomationPeer.cs
- ModifierKeysConverter.cs
- TextDpi.cs
- UserControl.cs
- X509CertificateEndpointIdentity.cs
- OleDbWrapper.cs
- BoundPropertyEntry.cs
- ComAdminInterfaces.cs
- EventLogQuery.cs
- userdatakeys.cs
- Normalization.cs
- SqlParameterizer.cs
- CodeAttributeDeclaration.cs
- InheritanceContextHelper.cs
- HtmlString.cs
- ServiceSecurityContext.cs
- XmlNotation.cs
- Compiler.cs
- SerializableAttribute.cs
- SessionParameter.cs
- WorkflowExecutor.cs
- securitymgrsite.cs
- HMAC.cs
- CompositeControl.cs
- DbConnectionInternal.cs
- OletxTransactionManager.cs
- GridProviderWrapper.cs
- OdbcReferenceCollection.cs
- CompensateDesigner.cs
- RootProfilePropertySettingsCollection.cs
- LineSegment.cs
- UriScheme.cs
- ZipIOCentralDirectoryBlock.cs
- ThreadBehavior.cs
- InlineCollection.cs
- QueryExpression.cs
- Calendar.cs
- FontConverter.cs
- BindingManagerDataErrorEventArgs.cs
- RemotingClientProxy.cs
- UnsafeNativeMethods.cs
- ColumnHeaderConverter.cs
- Calendar.cs
- WebBrowserContainer.cs
- QilUnary.cs
- EdmToObjectNamespaceMap.cs
- SqlVersion.cs
- CriticalExceptions.cs
- ThreadAbortException.cs
- ReferencedType.cs
- ConsumerConnectionPoint.cs