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
- KeyGestureConverter.cs
- SecurityDescriptor.cs
- MetadataItemSerializer.cs
- Switch.cs
- TextDecorationCollection.cs
- FormatVersion.cs
- CqlBlock.cs
- XmlSchemaComplexContentRestriction.cs
- InputLangChangeEvent.cs
- X509ChainPolicy.cs
- WebScriptServiceHost.cs
- MissingSatelliteAssemblyException.cs
- RoleService.cs
- ScrollPatternIdentifiers.cs
- exports.cs
- StrokeCollectionConverter.cs
- Block.cs
- CompilerErrorCollection.cs
- PromptBuilder.cs
- RichTextBox.cs
- PrinterUnitConvert.cs
- AutomationProperty.cs
- InvalidCastException.cs
- ParserStreamGeometryContext.cs
- SQLGuid.cs
- UpdateCommandGenerator.cs
- DocumentSequence.cs
- XamlReaderHelper.cs
- UnionCodeGroup.cs
- tooltip.cs
- safesecurityhelperavalon.cs
- TextHintingModeValidation.cs
- ValueType.cs
- TypedTableBase.cs
- DesignerLoader.cs
- Rectangle.cs
- ControlParser.cs
- _ProxyChain.cs
- TransformProviderWrapper.cs
- GuidelineSet.cs
- SrgsGrammar.cs
- LoadWorkflowAsyncResult.cs
- UnsafeNativeMethodsTablet.cs
- TabControlEvent.cs
- HttpHandlersInstallComponent.cs
- PersonalizableAttribute.cs
- StrongTypingException.cs
- SqlWebEventProvider.cs
- WebPartConnectionsDisconnectVerb.cs
- CodeEntryPointMethod.cs
- StreamingContext.cs
- Point.cs
- StateWorkerRequest.cs
- RtfToXamlLexer.cs
- ScrollableControl.cs
- HtmlHistory.cs
- ClientRuntimeConfig.cs
- DbQueryCommandTree.cs
- AnimatedTypeHelpers.cs
- ConditionalWeakTable.cs
- DateTimePickerDesigner.cs
- ToolStripContentPanel.cs
- Point.cs
- RefreshEventArgs.cs
- GraphicsState.cs
- ProfileParameter.cs
- DecimalAverageAggregationOperator.cs
- safelinkcollection.cs
- TransformationRules.cs
- WebScriptEnablingElement.cs
- AssemblyAttributesGoHere.cs
- figurelengthconverter.cs
- AlternateViewCollection.cs
- UserControl.cs
- HtmlGenericControl.cs
- ProgressBar.cs
- TcpActivation.cs
- PropertyValueChangedEvent.cs
- Calendar.cs
- PolyLineSegment.cs
- updateconfighost.cs
- List.cs
- TransformerInfo.cs
- BitmapEffect.cs
- XmlILConstructAnalyzer.cs
- XmlReaderSettings.cs
- SqlFactory.cs
- RequiredAttributeAttribute.cs
- Geometry3D.cs
- Compilation.cs
- SqlStatistics.cs
- SqlDesignerDataSourceView.cs
- ActivationArguments.cs
- WmlPageAdapter.cs
- CultureInfo.cs
- QilGeneratorEnv.cs
- ScriptHandlerFactory.cs
- ReferencedCollectionType.cs
- StylusEditingBehavior.cs
- SQLInt32.cs