Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / SecurityListenerSettingsLifetimeManager.cs / 1 / SecurityListenerSettingsLifetimeManager.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System; using System.Threading; using System.ServiceModel; using System.ServiceModel.Channels; using System.Collections.Generic; namespace System.ServiceModel.Security { class SecurityListenerSettingsLifetimeManager { SecurityProtocolFactory securityProtocolFactory; SecuritySessionServerSettings sessionSettings; bool sessionMode; IChannelListener innerListener; int referenceCount; public SecurityListenerSettingsLifetimeManager(SecurityProtocolFactory securityProtocolFactory, SecuritySessionServerSettings sessionSettings, bool sessionMode, IChannelListener innerListener) { this.securityProtocolFactory = securityProtocolFactory; this.sessionSettings = sessionSettings; this.sessionMode = sessionMode; this.innerListener = innerListener; // have a reference right from the start so that the state can be aborted before open referenceCount = 1; } public void Abort() { if (Interlocked.Decrement(ref this.referenceCount) == 0) { AbortCore(); } } public void AddReference() { Interlocked.Increment(ref this.referenceCount); } public void Open(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (this.securityProtocolFactory != null) { this.securityProtocolFactory.Open(false, timeoutHelper.RemainingTime()); } if (this.sessionMode && this.sessionSettings != null) { this.sessionSettings.Open(timeoutHelper.RemainingTime()); } this.innerListener.Open(timeoutHelper.RemainingTime()); } public IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { ListbeginOperations = new List (3); List endOperations = new List (3); if (this.securityProtocolFactory != null) { beginOperations.Add(new OperationWithTimeoutBeginCallback(this.BeginOpenSecurityProtocolFactory)); endOperations.Add(new OperationEndCallback(this.EndOpenSecurityProtocolFactory)); } if (this.sessionMode && this.sessionSettings != null) { beginOperations.Add(new OperationWithTimeoutBeginCallback(this.sessionSettings.BeginOpen)); endOperations.Add(new OperationEndCallback(this.sessionSettings.EndOpen)); } beginOperations.Add(new OperationWithTimeoutBeginCallback(this.innerListener.BeginOpen)); endOperations.Add(new OperationEndCallback(this.innerListener.EndOpen)); return OperationWithTimeoutComposer.BeginComposeAsyncOperations(timeout, beginOperations.ToArray(), endOperations.ToArray(), callback, state); } public void EndOpen(IAsyncResult result) { OperationWithTimeoutComposer.EndComposeAsyncOperations(result); } IAsyncResult BeginOpenSecurityProtocolFactory(TimeSpan timeout, AsyncCallback callback, object state) { return this.securityProtocolFactory.BeginOpen(false, timeout, callback, state); } void EndOpenSecurityProtocolFactory(IAsyncResult result) { this.securityProtocolFactory.EndOpen(result); } public void Close(TimeSpan timeout) { if (Interlocked.Decrement(ref this.referenceCount) == 0) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); bool throwing = true; try { if (this.securityProtocolFactory != null) { this.securityProtocolFactory.Close(false, timeoutHelper.RemainingTime()); } if (sessionMode && sessionSettings != null) { this.sessionSettings.Close(timeoutHelper.RemainingTime()); } this.innerListener.Close(timeoutHelper.RemainingTime()); throwing = false; } finally { if (throwing) { AbortCore(); } } } } public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state) { if (Interlocked.Decrement(ref this.referenceCount) == 0) { bool throwing = true; try { List beginOperations = new List (3); List endOperations = new List (3); if (this.securityProtocolFactory != null) { beginOperations.Add(new OperationWithTimeoutBeginCallback(this.securityProtocolFactory.BeginClose)); endOperations.Add(new OperationEndCallback(this.securityProtocolFactory.EndClose)); } if (this.sessionMode && this.sessionSettings != null) { beginOperations.Add(new OperationWithTimeoutBeginCallback(this.sessionSettings.BeginClose)); endOperations.Add(new OperationEndCallback(this.sessionSettings.EndClose)); } beginOperations.Add(new OperationWithTimeoutBeginCallback(this.innerListener.BeginClose)); endOperations.Add(new OperationEndCallback(this.innerListener.EndClose)); IAsyncResult result = OperationWithTimeoutComposer.BeginComposeAsyncOperations(timeout, beginOperations.ToArray(), endOperations.ToArray(), callback, state); throwing = false; return result; } finally { if (throwing) { AbortCore(); } } } else { return new DummyCloseAsyncResult(callback, state); } } public void EndClose(IAsyncResult result) { if (result is DummyCloseAsyncResult) { DummyCloseAsyncResult.End(result); } else { bool throwing = true; try { OperationWithTimeoutComposer.EndComposeAsyncOperations(result); throwing = false; } finally { if (throwing) { AbortCore(); } } } } void AbortCore() { if (this.securityProtocolFactory != null) { this.securityProtocolFactory.Close(true, TimeSpan.Zero); } if (sessionMode && this.sessionSettings != null) { this.sessionSettings.Abort(); } this.innerListener.Abort(); } class DummyCloseAsyncResult : CompletedAsyncResult { public DummyCloseAsyncResult(AsyncCallback callback, object state) : base(callback, state) { } new public static void End(IAsyncResult result) { AsyncResult.End (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
- Bold.cs
- DmlSqlGenerator.cs
- JumpTask.cs
- ReflectPropertyDescriptor.cs
- GridEntry.cs
- TransactionFlowOption.cs
- Decorator.cs
- PreservationFileReader.cs
- GiveFeedbackEvent.cs
- SendSecurityHeader.cs
- NumericExpr.cs
- MediaTimeline.cs
- SqlExpander.cs
- ApplicationId.cs
- counter.cs
- _BaseOverlappedAsyncResult.cs
- EnumValAlphaComparer.cs
- RowBinding.cs
- ExceptionWrapper.cs
- DataTableNewRowEvent.cs
- XmlArrayItemAttribute.cs
- SortKey.cs
- ManifestResourceInfo.cs
- DbDataReader.cs
- DbProviderFactories.cs
- XPathSelfQuery.cs
- X509Certificate.cs
- DefaultPropertiesToSend.cs
- SizeChangedInfo.cs
- CodeBlockBuilder.cs
- ToolStripContextMenu.cs
- DockAndAnchorLayout.cs
- IPPacketInformation.cs
- CalculatedColumn.cs
- FilteredXmlReader.cs
- Utils.cs
- ChannelManager.cs
- FrameworkReadOnlyPropertyMetadata.cs
- HandlerBase.cs
- WebEventCodes.cs
- StorageTypeMapping.cs
- Point.cs
- HtmlWindowCollection.cs
- ListBoxItemAutomationPeer.cs
- future.cs
- SyndicationSerializer.cs
- HtmlInputControl.cs
- PointLight.cs
- FlowDocumentPaginator.cs
- XmlSchemaSequence.cs
- ListItemCollection.cs
- DependencyPropertyAttribute.cs
- FormsIdentity.cs
- StylusCaptureWithinProperty.cs
- ExtensionQuery.cs
- TemplateAction.cs
- XsltQilFactory.cs
- EditingCommands.cs
- TransformerTypeCollection.cs
- Size3DValueSerializer.cs
- ELinqQueryState.cs
- HeaderUtility.cs
- Matrix3DConverter.cs
- ModulesEntry.cs
- SortQuery.cs
- MetadataSerializer.cs
- AutomationEventArgs.cs
- SortDescriptionCollection.cs
- TableLayoutStyle.cs
- UnsafeNativeMethods.cs
- XslAstAnalyzer.cs
- Tile.cs
- OperatingSystem.cs
- DragDeltaEventArgs.cs
- ConfigurationFileMap.cs
- SegmentInfo.cs
- MatrixTransform3D.cs
- BinaryExpression.cs
- NativeCompoundFileAPIs.cs
- CompilerScope.cs
- ListDataBindEventArgs.cs
- ScrollData.cs
- SynthesizerStateChangedEventArgs.cs
- JapaneseLunisolarCalendar.cs
- LabelLiteral.cs
- NCryptSafeHandles.cs
- ActivityExecutionContextCollection.cs
- ToolStripLocationCancelEventArgs.cs
- StateDesignerConnector.cs
- StrongNameIdentityPermission.cs
- GcSettings.cs
- SiteMapProvider.cs
- MultiDataTrigger.cs
- DataColumnSelectionConverter.cs
- XmlQualifiedName.cs
- HttpRuntime.cs
- Validator.cs
- FactoryGenerator.cs
- StorageComplexTypeMapping.cs
- Point3DCollectionValueSerializer.cs