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
- OleDbConnection.cs
- SourceSwitch.cs
- TemplatePropertyEntry.cs
- MessageLogTraceRecord.cs
- Point3DValueSerializer.cs
- TextRange.cs
- AutoGeneratedFieldProperties.cs
- DataBoundControl.cs
- shaperfactoryquerycachekey.cs
- FixedSOMSemanticBox.cs
- SAPIEngineTypes.cs
- EditorPartDesigner.cs
- WindowsListViewItem.cs
- BuilderPropertyEntry.cs
- XamlInt32CollectionSerializer.cs
- OdbcFactory.cs
- BindingMemberInfo.cs
- SimpleWorkerRequest.cs
- Site.cs
- RoleService.cs
- RoleManagerModule.cs
- XamlBrushSerializer.cs
- _HTTPDateParse.cs
- PartialCachingControl.cs
- ProfileProvider.cs
- InternalConfigRoot.cs
- CopyOfAction.cs
- PrincipalPermission.cs
- TransactionManager.cs
- PagedDataSource.cs
- GenericsInstances.cs
- DefaultEvaluationContext.cs
- OleDbWrapper.cs
- ListChunk.cs
- MemoryResponseElement.cs
- WinEventQueueItem.cs
- PerspectiveCamera.cs
- RandomNumberGenerator.cs
- DrawingBrush.cs
- CustomCredentialPolicy.cs
- ColorContextHelper.cs
- Transform3D.cs
- UnsafeNetInfoNativeMethods.cs
- SchemaTableColumn.cs
- DateTimeFormatInfo.cs
- IntSecurity.cs
- LinqDataView.cs
- ReadOnlyHierarchicalDataSourceView.cs
- Win32.cs
- Array.cs
- DesignerExtenders.cs
- OpenFileDialog.cs
- PeerFlooder.cs
- EventPropertyMap.cs
- ProviderIncompatibleException.cs
- ScriptingWebServicesSectionGroup.cs
- LingerOption.cs
- XmlObjectSerializerReadContextComplexJson.cs
- AsyncResult.cs
- Odbc32.cs
- PingReply.cs
- CSharpCodeProvider.cs
- ChannelSinkStacks.cs
- SqlNotificationRequest.cs
- Utils.cs
- SingleObjectCollection.cs
- HtmlLink.cs
- SetStoryboardSpeedRatio.cs
- RoamingStoreFileUtility.cs
- ConnectionProviderAttribute.cs
- ReflectPropertyDescriptor.cs
- ConfigXmlAttribute.cs
- Odbc32.cs
- DocumentOutline.cs
- CacheMemory.cs
- TraceSection.cs
- ListSortDescription.cs
- EditorZone.cs
- ToolStripDropDownClosedEventArgs.cs
- ping.cs
- XmlException.cs
- XmlException.cs
- BlurBitmapEffect.cs
- Utils.cs
- ComponentEvent.cs
- SerializerDescriptor.cs
- ProcessProtocolHandler.cs
- CrossContextChannel.cs
- ApplicationInfo.cs
- ToolStripControlHost.cs
- PersonalizationState.cs
- GeneralTransform3DTo2D.cs
- TransformerConfigurationWizardBase.cs
- ReachSerializerAsync.cs
- CompositeCollection.cs
- DataTableClearEvent.cs
- HotCommands.cs
- MenuItemStyle.cs
- TextTreeNode.cs
- SchemaType.cs