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
- DLinqTableProvider.cs
- PropertyMappingExceptionEventArgs.cs
- TypeLibraryHelper.cs
- ImageFormat.cs
- TreeNodeClickEventArgs.cs
- TableLayoutStyle.cs
- GlyphRunDrawing.cs
- DateBoldEvent.cs
- StorageComplexTypeMapping.cs
- NetSectionGroup.cs
- StrongName.cs
- RenderData.cs
- TextElementEnumerator.cs
- TemplatedWizardStep.cs
- BindingMemberInfo.cs
- Rules.cs
- OdbcEnvironment.cs
- TextWriterTraceListener.cs
- MimeParameters.cs
- AgileSafeNativeMemoryHandle.cs
- FastEncoderWindow.cs
- Type.cs
- RuleCache.cs
- XPathDocumentIterator.cs
- MeasureItemEvent.cs
- DoWorkEventArgs.cs
- AlternateView.cs
- CodeNamespace.cs
- SoapFormatterSinks.cs
- HttpModulesSection.cs
- TextDecorationCollectionConverter.cs
- PropertyTabChangedEvent.cs
- validationstate.cs
- Condition.cs
- DbModificationClause.cs
- RangeValuePatternIdentifiers.cs
- Compiler.cs
- Viewport3DVisual.cs
- HtmlValidatorAdapter.cs
- Converter.cs
- TraceHandlerErrorFormatter.cs
- PenContext.cs
- XmlLanguageConverter.cs
- TypeDelegator.cs
- TypeConverterAttribute.cs
- IgnoreFlushAndCloseStream.cs
- HitTestParameters.cs
- HtmlMobileTextWriter.cs
- BindingCompleteEventArgs.cs
- XmlSignificantWhitespace.cs
- DataServiceKeyAttribute.cs
- TemplateKey.cs
- ImmutableDispatchRuntime.cs
- DynamicEntity.cs
- OneWayBindingElement.cs
- ListBindableAttribute.cs
- LineInfo.cs
- NumberEdit.cs
- _Win32.cs
- NetMsmqBinding.cs
- DataControlFieldCell.cs
- SmiContextFactory.cs
- ClockGroup.cs
- StatusBarPanelClickEvent.cs
- DateTimeUtil.cs
- HtmlElement.cs
- ReachDocumentReferenceSerializerAsync.cs
- EntityDataSourceContainerNameItem.cs
- DataSetFieldSchema.cs
- FieldAccessException.cs
- TemplateKey.cs
- RemoteHelper.cs
- MarshalByRefObject.cs
- XmlReader.cs
- UnrecognizedAssertionsBindingElement.cs
- ViewBase.cs
- _OverlappedAsyncResult.cs
- HttpContextServiceHost.cs
- Context.cs
- EntityModelBuildProvider.cs
- AdapterUtil.cs
- DocumentPageViewAutomationPeer.cs
- HelpKeywordAttribute.cs
- Aggregates.cs
- Grant.cs
- ExpressionEditorAttribute.cs
- SqlNode.cs
- LinearQuaternionKeyFrame.cs
- HttpModulesSection.cs
- SharedHttpTransportManager.cs
- XmlSchemaSimpleContent.cs
- DataGridViewTopRowAccessibleObject.cs
- ActivationArguments.cs
- IntAverageAggregationOperator.cs
- DataGridViewComboBoxColumn.cs
- DataGridSortCommandEventArgs.cs
- WebPartTransformer.cs
- MetadataArtifactLoaderFile.cs
- HandlerFactoryWrapper.cs
- XmlSerializationReader.cs