Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / PeerChannelListener.cs / 1 / PeerChannelListener.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System; using System.Net; using System.ServiceModel; using System.ServiceModel.Diagnostics; using System.ServiceModel.Security; using System.Diagnostics; using System.Runtime.Serialization; using System.Xml; using System.Collections.Generic; internal abstract class PeerChannelListenerBase : TransportChannelListener, IPeerFactory { // settings passed to PeerNode IPAddress listenIPAddress; int port; PeerResolver resolver; PeerNode peerNode; PeerNodeImplementation privatePeerNode; PeerNodeImplementation.Registration registration; bool released = false; PeerSecurityManager securityManager; SecurityProtocol securityProtocol; XmlDictionaryReaderQuotas readerQuotas; ISecurityCapabilities securityCapabilities; static UriPrefixTabletransportManagerTable = new UriPrefixTable (true); internal PeerChannelListenerBase(PeerTransportBindingElement bindingElement, BindingContext context, PeerResolver peerResolver) : base(bindingElement, context) { this.listenIPAddress = bindingElement.ListenIPAddress; this.port = bindingElement.Port; this.resolver = peerResolver; this.readerQuotas = new XmlDictionaryReaderQuotas(); BinaryMessageEncodingBindingElement encoder = context.Binding.Elements.Find (); if(encoder != null) encoder.ReaderQuotas.CopyTo(this.readerQuotas); else EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas); securityManager = PeerSecurityManager.Create(bindingElement.Security, context, this.readerQuotas); this.securityCapabilities = bindingElement.GetProperty (context); } public IPAddress ListenIPAddress { get { return listenIPAddress; } } internal PeerNodeImplementation InnerNode { get { return peerNode != null ? peerNode.InnerNode : null; } } internal PeerNodeImplementation.Registration Registration { get { return registration; } } public PeerNodeImplementation PrivatePeerNode { get { return privatePeerNode; } set { privatePeerNode = value; } } public int Port { get { return port; } } public XmlDictionaryReaderQuotas ReaderQuotas { get { return this.readerQuotas; } } public PeerResolver Resolver { get { return resolver; } } public PeerSecurityManager SecurityManager { get { return this.securityManager; } set { this.securityManager = value; } } protected SecurityProtocol SecurityProtocol { get { return this.securityProtocol; } set { this.securityProtocol = value; } } public override string Scheme { get { return PeerStrings.Scheme; } } internal static UriPrefixTable StaticTransportManagerTable { get { return transportManagerTable; } } internal override UriPrefixTable TransportManagerTable { get { return transportManagerTable; } } public override T GetProperty () { if (typeof(T) == typeof(PeerNode)) { return peerNode as T; } else if (typeof(T) == typeof(IOnlineStatus)) { return peerNode as T; } else if (typeof(T) == typeof(ISecurityCapabilities)) { return (T)(object)this.securityCapabilities; } return base.GetProperty (); } protected override void OnAbort() { base.OnAbort(); if (this.State < CommunicationState.Closed && this.peerNode != null) { try { this.peerNode.InnerNode.Abort(); } catch(Exception e) { if(DiagnosticUtility.IsFatal(e)) throw; DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Information); } } } void OnCloseCore(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); peerNode.OnClose(); peerNode.InnerNode.Close(timeoutHelper.RemainingTime()); base.OnClose(timeoutHelper.RemainingTime()); } protected override void OnClose(TimeSpan timeout) { OnCloseCore(timeout); } protected override void OnClosing() { base.OnClosing(); if (!this.released) { bool release = false; lock (ThisLock) { if (!this.released) { release = this.released = true; } } if (release && this.peerNode != null) { this.peerNode.InnerNode.Release(); } } } protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); return new TypedCompletedAsyncResult (timeoutHelper, callback, state); } protected override void OnEndClose(IAsyncResult result) { TypedCompletedAsyncResult r = result as TypedCompletedAsyncResult ; if (r != null) { OnCloseCore(r.Data.RemainingTime()); } else { base.OnEndClose(result); } } void OnOpenCore(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); base.OnOpen(timeoutHelper.RemainingTime()); peerNode.OnOpen(); peerNode.InnerNode.Open(timeoutHelper.RemainingTime(), false); } protected override void OnOpen(TimeSpan timeout) { OnOpenCore(timeout); } protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); return new TypedCompletedAsyncResult (timeoutHelper, callback, state); } protected override void OnEndOpen(IAsyncResult result) { TypedCompletedAsyncResult r = result as TypedCompletedAsyncResult ; if (r != null) { OnOpenCore(r.Data.RemainingTime()); } else { base.OnEndOpen(result); } } protected override void OnFaulted() { OnAbort(); // Fault aborts the PeerNode } internal override IList SelectTransportManagers() { //test override if (peerNode == null) { PeerNodeImplementation foundPeerNode = null; // use the private InnerNode if it has been configured and matches the channel if (privatePeerNode != null && this.Uri.Host == privatePeerNode.MeshId) { foundPeerNode = privatePeerNode; this.registration = null; } else { // find or create a InnerNode for the given Uri this.registration = new PeerNodeImplementation.Registration(this.Uri, this); foundPeerNode = PeerNodeImplementation.Get(this.Uri, registration); } // ensure that the max message size is compatible if (foundPeerNode.MaxReceivedMessageSize < MaxReceivedMessageSize) { foundPeerNode.Release(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR.GetString(SR.PeerMaxReceivedMessageSizeConflict, MaxReceivedMessageSize, foundPeerNode.MaxReceivedMessageSize, this.Uri))); } // associate with the PeerNode and open it peerNode = new PeerNode(foundPeerNode); } return null; } } internal abstract class PeerChannelListener : PeerChannelListenerBase, IChannelListener where TChannel : class, IChannel where TChannelAcceptor : ChannelAcceptor { public PeerChannelListener(PeerTransportBindingElement bindingElement, BindingContext context, PeerResolver peerResolver) : base(bindingElement, context, peerResolver) { } protected abstract TChannelAcceptor ChannelAcceptor { get; } internal override ITransportManagerRegistration CreateTransportManagerRegistration(Uri listenUri) { return null; } public TChannel AcceptChannel() { return this.AcceptChannel(this.DefaultReceiveTimeout); } public IAsyncResult BeginAcceptChannel(AsyncCallback callback, object state) { return this.BeginAcceptChannel(this.DefaultReceiveTimeout, callback, state); } public TChannel AcceptChannel(TimeSpan timeout) { base.ThrowIfNotOpened(); return ChannelAcceptor.AcceptChannel(timeout); } public IAsyncResult BeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state) { base.ThrowIfNotOpened(); return ChannelAcceptor.BeginAcceptChannel(timeout, callback, state); } public TChannel EndAcceptChannel(IAsyncResult result) { return ChannelAcceptor.EndAcceptChannel(result); } void OnCloseCore(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.ChannelAcceptor.Close(timeoutHelper.RemainingTime()); base.OnClose(timeoutHelper.RemainingTime()); } protected override void OnClose(TimeSpan timeout) { OnCloseCore(timeout); } protected override void OnAbort() { if(this.ChannelAcceptor != null) this.ChannelAcceptor.Abort(); base.OnAbort(); } protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); return new TypedCompletedAsyncResult (timeoutHelper, callback, state); } protected override void OnEndClose(IAsyncResult result) { TypedCompletedAsyncResult r = result as TypedCompletedAsyncResult ; if (r != null) { OnCloseCore(r.Data.RemainingTime()); } else { base.OnEndClose(result); } } void OnOpenCore(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); base.OnOpen(timeoutHelper.RemainingTime()); CreateAcceptor(); ChannelAcceptor.Open(timeoutHelper.RemainingTime()); } protected override void OnOpen(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); OnOpenCore(timeoutHelper.RemainingTime()); } protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); return new TypedCompletedAsyncResult (timeoutHelper, callback, state); } protected override void OnEndOpen(IAsyncResult result) { TypedCompletedAsyncResult r = result as TypedCompletedAsyncResult ; if (r != null) { OnOpenCore(r.Data.RemainingTime()); } else { base.OnEndOpen(result); } } protected override bool OnWaitForChannel(TimeSpan timeout) { return ChannelAcceptor.WaitForChannel(timeout); } protected override IAsyncResult OnBeginWaitForChannel(TimeSpan timeout, AsyncCallback callback, object state) { return ChannelAcceptor.BeginWaitForChannel(timeout, callback, state); } protected override bool OnEndWaitForChannel(IAsyncResult result) { return ChannelAcceptor.EndWaitForChannel(result); } protected abstract void CreateAcceptor(); } } // 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
- AsyncOperation.cs
- UriTemplateTrieLocation.cs
- PriorityItem.cs
- Perspective.cs
- ExtendedProperty.cs
- ResetableIterator.cs
- WebPart.cs
- RequestUriProcessor.cs
- EditorServiceContext.cs
- ManipulationCompletedEventArgs.cs
- StateManagedCollection.cs
- Paragraph.cs
- WeakHashtable.cs
- CodeDefaultValueExpression.cs
- XmlSerializerAssemblyAttribute.cs
- HtmlFormAdapter.cs
- SecurityState.cs
- StateMachineDesignerPaint.cs
- SqlWebEventProvider.cs
- HScrollBar.cs
- PathSegmentCollection.cs
- StringFunctions.cs
- StickyNote.cs
- Document.cs
- ipaddressinformationcollection.cs
- Events.cs
- MethodBody.cs
- _SSPIWrapper.cs
- ArrayExtension.cs
- SettingsBindableAttribute.cs
- MessageSmuggler.cs
- QilParameter.cs
- SubqueryTrackingVisitor.cs
- RoutedEventConverter.cs
- While.cs
- BinaryMessageFormatter.cs
- CharacterMetrics.cs
- ValidationRule.cs
- FixedDSBuilder.cs
- Stream.cs
- PrinterUnitConvert.cs
- ServiceOperationHelpers.cs
- CodeGenerator.cs
- Thumb.cs
- DbRetry.cs
- ObjectReferenceStack.cs
- TransformerInfoCollection.cs
- safemediahandle.cs
- SourceFileBuildProvider.cs
- backend.cs
- AsmxEndpointPickerExtension.cs
- XmlSchemaComplexContent.cs
- GlobalProxySelection.cs
- XsltContext.cs
- ReceiveMessageContent.cs
- CounterCreationData.cs
- BrowserCapabilitiesFactory.cs
- ServiceBehaviorElement.cs
- FillErrorEventArgs.cs
- EditorZone.cs
- hresults.cs
- TraceXPathNavigator.cs
- ObjectHandle.cs
- ListControl.cs
- ParameterEditorUserControl.cs
- StreamInfo.cs
- EncoderFallback.cs
- PatternMatcher.cs
- CharacterShapingProperties.cs
- BaseResourcesBuildProvider.cs
- SafeRegistryHandle.cs
- Point.cs
- DockingAttribute.cs
- IncrementalReadDecoders.cs
- mongolianshape.cs
- AppDomainProtocolHandler.cs
- PropertyIDSet.cs
- SvcMapFile.cs
- SqlConnectionPoolProviderInfo.cs
- SecurityHelper.cs
- EditorPartCollection.cs
- TemplateParser.cs
- DefaultSerializationProviderAttribute.cs
- UrlMappingCollection.cs
- CodeAccessPermission.cs
- ListViewGroupConverter.cs
- XsltException.cs
- ListItemCollection.cs
- StringUtil.cs
- StringDictionaryWithComparer.cs
- COM2ExtendedTypeConverter.cs
- DataControlImageButton.cs
- DataGridItemCollection.cs
- DynamicResourceExtension.cs
- Constant.cs
- InputProcessorProfiles.cs
- DeploymentSection.cs
- MarkerProperties.cs
- ICspAsymmetricAlgorithm.cs
- ToolStripItem.cs