Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Routing / System / ServiceModel / Routing / SessionChannels.cs / 1305376 / SessionChannels.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Routing { using System; using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Runtime; using System.ServiceModel.Description; using System.ServiceModel.Channels; using System.ComponentModel; using System.Threading; class SessionChannels { Guid activityID; [Fx.Tag.SynchronizationObject] Dictionarysessions; List sessionList; [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Justification = "gets called in RoutingService.ctor()")] public SessionChannels(Guid activityID) { this.activityID = activityID; this.sessions = new Dictionary (); this.sessionList = new List (); } void ChannelFaulted(object sender, EventArgs args) { FxTrace.Trace.SetAndTraceTransfer(this.activityID, true); IRoutingClient client = (IRoutingClient)sender; if (TD.RoutingServiceChannelFaultedIsEnabled()) { TD.RoutingServiceChannelFaulted(client.Key.ToString()); } this.AbortChannel(client.Key); } [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode, Justification = "BeginClose is called by RoutingChannelExtension.AttachService")] public IAsyncResult BeginClose(TimeSpan timeout, AsyncCallback callback, object state) { List localClients = null; lock(this.sessions) { if (this.sessions.Count > 0) { localClients = this.sessionList.ConvertAll ((client) => (ICommunicationObject)client); this.sessionList.Clear(); this.sessions.Clear(); } } if (localClients != null && localClients.Count > 0) { localClients.ForEach((client) => { if (TD.RoutingServiceClosingClientIsEnabled()) { TD.RoutingServiceClosingClient(((IRoutingClient)client).Key.ToString()); } }); return new CloseCollectionAsyncResult(timeout, callback, state, localClients); } else { return new CompletedAsyncResult(callback, state); } } public void EndClose(IAsyncResult asyncResult) { if (asyncResult is CloseCollectionAsyncResult) { CloseCollectionAsyncResult.End(asyncResult); } else { CompletedAsyncResult.End(asyncResult); } } internal IRoutingClient GetOrCreateClient (RoutingEndpointTrait key, RoutingService service, bool impersonating) { IRoutingClient value; lock (this.sessions) { if (!this.sessions.TryGetValue(key, out value)) { //Create the client here value = ClientFactory.Create(key, service, impersonating); value.Faulted += ChannelFaulted; this.sessions[key] = value; sessionList.Add(value); } } return value; } public void AbortAll() { List clients = new List (); lock (this.sessions) { foreach (IRoutingClient client in this.sessions.Values) { clients.Add(client); } this.sessions.Clear(); this.sessionList.Clear(); } foreach (IRoutingClient client in clients) { RoutingUtilities.Abort((ICommunicationObject)client, client.Key); } } public void AbortChannel(RoutingEndpointTrait key) { IRoutingClient client; lock (this.sessions) { if (this.sessions.TryGetValue(key, out client)) { this.sessions.Remove(key); this.sessionList.Remove(client); } } if (client != null) { RoutingUtilities.Abort((ICommunicationObject)client, client.Key); } } public IRoutingClient ReleaseChannel() { IRoutingClient client = null; lock (this.sessions) { int count = this.sessionList.Count; if (count > 0) { client = this.sessionList[count - 1]; this.sessionList.RemoveAt(count - 1); this.sessions.Remove(client.Key); } } return client; } } } // 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
- ColorTranslator.cs
- DataGridViewHeaderCell.cs
- ArgumentValue.cs
- ContextItem.cs
- SettingsBindableAttribute.cs
- DataGridViewTextBoxEditingControl.cs
- DisplayNameAttribute.cs
- DSACryptoServiceProvider.cs
- OdbcUtils.cs
- EllipseGeometry.cs
- WebPartConnectionsEventArgs.cs
- MobileTextWriter.cs
- mansign.cs
- Attributes.cs
- FocusTracker.cs
- ColumnResizeAdorner.cs
- ListViewGroupItemCollection.cs
- DBConnection.cs
- Mapping.cs
- MLangCodePageEncoding.cs
- Calendar.cs
- WebPartsPersonalizationAuthorization.cs
- TextUtf8RawTextWriter.cs
- WmlListAdapter.cs
- BooleanStorage.cs
- DesignerUtility.cs
- EventlogProvider.cs
- Options.cs
- ResourceReferenceExpression.cs
- EntityDataSourceDesigner.cs
- shaperfactory.cs
- TextAction.cs
- UIElement3D.cs
- CookieParameter.cs
- PenThread.cs
- SqlBuffer.cs
- ClientTargetSection.cs
- UpdateManifestForBrowserApplication.cs
- ProcessHostConfigUtils.cs
- HierarchicalDataSourceDesigner.cs
- ContainerActivationHelper.cs
- BlockCollection.cs
- oledbconnectionstring.cs
- SqlDataReaderSmi.cs
- SerializationSectionGroup.cs
- CodeAttachEventStatement.cs
- DrawingBrush.cs
- HtmlTableRow.cs
- FontStretch.cs
- Rect3D.cs
- TextInfo.cs
- NamespaceCollection.cs
- SslSecurityTokenParameters.cs
- CheckBox.cs
- GroupJoinQueryOperator.cs
- OdbcHandle.cs
- DataControlImageButton.cs
- BaseAsyncResult.cs
- MetadataCache.cs
- NavigationCommands.cs
- TableProvider.cs
- BitmapInitialize.cs
- Version.cs
- SRGSCompiler.cs
- UnknownMessageReceivedEventArgs.cs
- WindowsEditBox.cs
- ThreadExceptionEvent.cs
- ScriptHandlerFactory.cs
- LinqDataSourceUpdateEventArgs.cs
- cookie.cs
- RewritingProcessor.cs
- ResourcePermissionBaseEntry.cs
- DiscoveryServerProtocol.cs
- CompilerLocalReference.cs
- OleDbRowUpdatingEvent.cs
- HttpListenerRequest.cs
- TransactionManager.cs
- dbdatarecord.cs
- Ops.cs
- SelfIssuedTokenFactoryCredential.cs
- DataBindingCollection.cs
- AutomationPropertyInfo.cs
- ManualResetEvent.cs
- StackBuilderSink.cs
- SafeUserTokenHandle.cs
- MonikerHelper.cs
- RequestCacheValidator.cs
- KnownTypeDataContractResolver.cs
- LayoutInformation.cs
- RijndaelManaged.cs
- SMSvcHost.cs
- TypeReference.cs
- ScriptingScriptResourceHandlerSection.cs
- ExitEventArgs.cs
- SchemaConstraints.cs
- LayoutUtils.cs
- VariableQuery.cs
- SmiMetaData.cs
- AssemblyName.cs
- XmlSchemaIdentityConstraint.cs