Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / PeerMessageDispatcher.cs / 1 / PeerMessageDispatcher.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System; using System.Diagnostics; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Diagnostics; using System.ServiceModel.Dispatcher; using System.ServiceModel.Security; class PeerMessageDispatcher: CommunicationObject where ChannelInterfaceType : class, IChannel where TChannel : InputQueueChannel { public class PeerMessageQueueAdapter { SingletonChannelAcceptor singletonChannelAcceptor; InputQueueChannel inputQueueChannel; public PeerMessageQueueAdapter(SingletonChannelAcceptor singletonChannelAcceptor) { this.singletonChannelAcceptor = singletonChannelAcceptor; } public PeerMessageQueueAdapter(InputQueueChannel inputQueueChannel) { this.inputQueueChannel = inputQueueChannel; } public void EnqueueAndDispatch(Message message, ItemDequeuedCallback callback) { if (singletonChannelAcceptor != null) { singletonChannelAcceptor.Enqueue(message, callback); } else if(inputQueueChannel != null) { inputQueueChannel.EnqueueAndDispatch(message, callback); } } } Uri via; EndpointAddress to; SecurityProtocol securityProtocol; PeerNodeImplementation peerNode; PeerMessageQueueAdapter queueHandler; ChannelManagerBase channelManager; PeerQuotaHelper quotaHelper = new PeerQuotaHelper(Int32.MaxValue); bool registered; public PeerMessageDispatcher(PeerMessageQueueAdapter queueHandler, PeerNodeImplementation peerNode, ChannelManagerBase channelManager, EndpointAddress to, Uri via) { PeerNodeImplementation.ValidateVia(via); this.queueHandler = queueHandler; this.peerNode = peerNode; this.to = to; this.via = via; this.channelManager = channelManager; EndpointAddress filterTo = null; this.securityProtocol = ((IPeerFactory)channelManager).SecurityManager.CreateSecurityProtocol (to, ServiceDefaults.SendTimeout); if( typeof(IDuplexChannel).IsAssignableFrom(typeof(ChannelInterfaceType))) filterTo = to; //Register this handler PeerMessageFilter[] filters = new PeerMessageFilter[] { new PeerMessageFilter(via, filterTo) }; peerNode.RegisterMessageFilter(this, this.via, filters, (ITransportFactorySettings)this.channelManager, new PeerNodeImplementation.MessageAvailableCallback(OnMessageAvailable),securityProtocol); registered = true; } protected override TimeSpan DefaultCloseTimeout { get { return channelManager.InternalCloseTimeout; } } protected override TimeSpan DefaultOpenTimeout { get { return channelManager.InternalOpenTimeout; } } public SecurityProtocol SecurityProtocol { get { return securityProtocol; } } protected override void OnAbort() { } protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) { this.OnClose(timeout); return new CompletedAsyncResult(callback, state); } protected override void OnEndClose(IAsyncResult result) { CompletedAsyncResult.End(result); } protected override void OnClose(TimeSpan timeout) { Unregister(true); } internal void Unregister() { Unregister(false); } internal void Unregister(bool release) { PeerNodeImplementation node = this.peerNode; if (node != null) { if(registered) { node.UnregisterMessageFilter(this, via); registered = false; } if(release) node.Release(); } } protected override void OnOpen(TimeSpan timeout) { } protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { return new CompletedAsyncResult(callback, state); } protected override void OnEndOpen(IAsyncResult result) { CompletedAsyncResult.End(result); } public void OnMessageAvailable(Message message) { quotaHelper.ReadyToEnqueueItem(); queueHandler.EnqueueAndDispatch(message, quotaHelper.ItemDequeued); } } class PeerMessageFilter { Uri via; Uri actingAs; public PeerMessageFilter(Uri via):this(via, null){} public PeerMessageFilter(Uri via, EndpointAddress to) { DiagnosticUtility.DebugAssert(via != null, "PeerMessageFilter via can not be set to null"); this.via = via; if(to != null) this.actingAs = to.Uri; } public bool Match(Uri peerVia, Uri toCond) { bool result = false; if (peerVia == null) { result = false; } else if (Uri.Compare(this.via, peerVia, (UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path), UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) != 0) { result = false; } else if (this.actingAs != null) { result = Uri.Compare(this.actingAs, toCond, (UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path), UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0; } else result = true; return result; } } } // 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
- WinEventQueueItem.cs
- ScriptManager.cs
- FieldInfo.cs
- XmlSchemaObjectCollection.cs
- GeometryGroup.cs
- ParagraphVisual.cs
- XmlSubtreeReader.cs
- NetworkStream.cs
- OledbConnectionStringbuilder.cs
- fixedPageContentExtractor.cs
- DateTimeFormatInfoScanner.cs
- ConstraintEnumerator.cs
- ConcurrentDictionary.cs
- CompareInfo.cs
- VirtualPathProvider.cs
- SqlProfileProvider.cs
- PipeStream.cs
- XsltSettings.cs
- MonikerBuilder.cs
- TextRangeEdit.cs
- XmlCharCheckingReader.cs
- XmlSchemaSimpleContentExtension.cs
- NativeObjectSecurity.cs
- cryptoapiTransform.cs
- SqlDataSourceQueryEditor.cs
- WindowClosedEventArgs.cs
- WindowsAuthenticationModule.cs
- SafeSecurityHelper.cs
- BinaryUtilClasses.cs
- DictionaryContent.cs
- XmlSchemas.cs
- SymDocumentType.cs
- OleDbTransaction.cs
- RelatedImageListAttribute.cs
- ChannelFactoryBase.cs
- OutOfProcStateClientManager.cs
- FormsAuthenticationEventArgs.cs
- ObjectDataSourceDisposingEventArgs.cs
- InvalidPrinterException.cs
- DataGridRow.cs
- ObjectDataSourceStatusEventArgs.cs
- _ProxyRegBlob.cs
- Configuration.cs
- Sequence.cs
- FontUnit.cs
- SqlDataSourceCache.cs
- MetabaseSettingsIis7.cs
- ExtentJoinTreeNode.cs
- ActivityBuilderHelper.cs
- UrlPropertyAttribute.cs
- smtppermission.cs
- Rect3D.cs
- NamedPipeTransportBindingElement.cs
- CodeArgumentReferenceExpression.cs
- DiscoveryExceptionDictionary.cs
- RefExpr.cs
- AutomationAttributeInfo.cs
- DataObjectCopyingEventArgs.cs
- ToolboxItemCollection.cs
- StylusShape.cs
- glyphs.cs
- DataGridViewComboBoxCell.cs
- FocusManager.cs
- Avt.cs
- FrameworkReadOnlyPropertyMetadata.cs
- StorageTypeMapping.cs
- WebPartCatalogAddVerb.cs
- DeviceSpecificDesigner.cs
- SpecialTypeDataContract.cs
- UInt64Converter.cs
- CanonicalFontFamilyReference.cs
- WorkflowApplicationTerminatedException.cs
- EventHandlerService.cs
- ToolStripInSituService.cs
- TextProperties.cs
- Timeline.cs
- Helpers.cs
- ZipIOLocalFileHeader.cs
- ResourceCategoryAttribute.cs
- FormattedTextSymbols.cs
- _BufferOffsetSize.cs
- ToolStripDropDownClosedEventArgs.cs
- ObservableCollectionDefaultValueFactory.cs
- CodeDirectiveCollection.cs
- ClientTargetCollection.cs
- Cursors.cs
- InfoCardBaseException.cs
- UriPrefixTable.cs
- XmlSerializableWriter.cs
- QilValidationVisitor.cs
- ProcessHostMapPath.cs
- messageonlyhwndwrapper.cs
- DynamicResourceExtensionConverter.cs
- RuleDefinitions.cs
- WsatAdminException.cs
- TraceXPathNavigator.cs
- SecurityException.cs
- ControlPaint.cs
- LinkUtilities.cs
- HttpCacheParams.cs