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
- DataSysAttribute.cs
- XmlIncludeAttribute.cs
- WorkflowItemPresenter.cs
- FileVersion.cs
- __Error.cs
- AuthenticationModulesSection.cs
- ProviderMetadata.cs
- KoreanLunisolarCalendar.cs
- VoiceInfo.cs
- IApplicationTrustManager.cs
- HtmlWindowCollection.cs
- OleDbEnumerator.cs
- DataGridViewCellStyleConverter.cs
- FigureHelper.cs
- SecurityContextKeyIdentifierClause.cs
- DataBindingCollection.cs
- HMACMD5.cs
- RangeExpression.cs
- SHA384.cs
- Permission.cs
- WebPartEditVerb.cs
- OrderByBuilder.cs
- OutputCacheSettings.cs
- exports.cs
- LogRestartAreaEnumerator.cs
- CodeIndexerExpression.cs
- TreeNodeEventArgs.cs
- TextPointerBase.cs
- LinkClickEvent.cs
- OrderedHashRepartitionStream.cs
- EntityTemplateUserControl.cs
- TreeWalker.cs
- CodeAccessPermission.cs
- BrowserCapabilitiesCodeGenerator.cs
- Context.cs
- CoTaskMemUnicodeSafeHandle.cs
- Math.cs
- CompilerInfo.cs
- PartialCachingControl.cs
- __TransparentProxy.cs
- FieldNameLookup.cs
- DeclarativeCatalogPart.cs
- RedBlackList.cs
- DataTableNameHandler.cs
- ValidatorCompatibilityHelper.cs
- XmlILIndex.cs
- TransformerInfoCollection.cs
- ListViewHitTestInfo.cs
- ProfileProvider.cs
- objectquery_tresulttype.cs
- SubpageParagraph.cs
- _BaseOverlappedAsyncResult.cs
- MLangCodePageEncoding.cs
- GenerateDerivedKeyRequest.cs
- ParseNumbers.cs
- PingReply.cs
- FlowThrottle.cs
- BindingWorker.cs
- DrawingCollection.cs
- Action.cs
- _HeaderInfoTable.cs
- ResponseBodyWriter.cs
- ObjectTag.cs
- TrayIconDesigner.cs
- PropertyGridView.cs
- DataObjectMethodAttribute.cs
- ActiveXHost.cs
- WebConfigurationHost.cs
- NumberSubstitution.cs
- RectangleF.cs
- AbstractExpressions.cs
- CryptoStream.cs
- RoleManagerModule.cs
- RecordConverter.cs
- HttpSysSettings.cs
- arabicshape.cs
- KeySpline.cs
- WorkflowQueuingService.cs
- SystemTcpConnection.cs
- SelectionChangedEventArgs.cs
- ProfileInfo.cs
- SymbolMethod.cs
- SerializableAuthorizationContext.cs
- ComponentResourceKeyConverter.cs
- ConstructorArgumentAttribute.cs
- MultiBindingExpression.cs
- SQLDecimalStorage.cs
- Calendar.cs
- RawAppCommandInputReport.cs
- TraceUtility.cs
- FileSystemInfo.cs
- IntersectQueryOperator.cs
- ExpressionConverter.cs
- ToolBarOverflowPanel.cs
- EventProvider.cs
- ISO2022Encoding.cs
- SingleStorage.cs
- GenericAuthenticationEventArgs.cs
- XmlSchemaSimpleTypeList.cs
- GraphicsPathIterator.cs