Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / PartitionResolver.cs / 2 / PartitionResolver.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web { using System; using System.Configuration; using System.Collections; using System.Threading; using System.IO; using System.Web; using System.Web.Caching; using System.Web.Util; using System.Data; using System.Data.SqlClient; using System.Text; using System.Security.Principal; using System.Xml; using System.Collections.Specialized; using System.Configuration.Provider; using System.Globalization; using System.Web.Management; using System.Web.Hosting; using System.Web.Configuration; using System.Security.Permissions; [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public interface IPartitionResolver { void Initialize(); string ResolvePartition(Object key); } internal interface IPartitionInfo { string GetTracingPartitionString(); } internal delegate IPartitionInfo CreatePartitionInfo(string connectionString); class PartitionManager : IDisposable { internal PartitionManager(CreatePartitionInfo createCallback) { _createCallback = createCallback; } HybridDictionary _partitions = new HybridDictionary(); ReaderWriterLock _lock = new ReaderWriterLock(); CreatePartitionInfo _createCallback; internal object GetPartition(IPartitionResolver partitionResolver, string id) { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_START, HttpContext.Current.WorkerRequest, partitionResolver.GetType().FullName, id); string partitionString = null; string errorMessage = null; IPartitionInfo partitionInfo = null; try { try { partitionString = partitionResolver.ResolvePartition(id); if (partitionString == null) { throw new HttpException( SR.GetString(SR.Bad_partition_resolver_connection_string, partitionResolver.GetType().FullName)); } } catch (Exception e) { errorMessage = e.Message; throw; } try { _lock.AcquireReaderLock(-1); partitionInfo = (IPartitionInfo)_partitions[partitionString]; if (partitionInfo != null) { Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString); return partitionInfo; } } finally { if (_lock.IsReaderLockHeld) { _lock.ReleaseReaderLock(); } } // Not found. Has to add it. try { _lock.AcquireWriterLock(-1); // One more time partitionInfo = (IPartitionInfo)_partitions[partitionString]; if (partitionInfo == null) { partitionInfo = _createCallback(partitionString); Debug.Trace("PartitionManager", "Add a new partition; id=" + id + "; partitionString=" + partitionString); _partitions.Add(partitionString, partitionInfo); } Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString); return partitionInfo; } finally { if (_lock.IsWriterLockHeld) { _lock.ReleaseWriterLock(); } } } finally { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure)) { string msg = errorMessage; if (msg == null) { if (partitionInfo != null) { msg = partitionInfo.GetTracingPartitionString(); } else { msg = String.Empty; } } EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_END, HttpContext.Current.WorkerRequest, msg); } } } public void Dispose() { if (_partitions == null) { return; } try { _lock.AcquireWriterLock(-1); if (_partitions != null) { foreach (PartitionInfo partitionInfo in _partitions.Values) { partitionInfo.Dispose(); } _partitions = null; } } catch { // ignore exceptions in dispose } finally { if (_lock.IsWriterLockHeld) { _lock.ReleaseWriterLock(); } } } } internal class PartitionInfo : IDisposable, IPartitionInfo { ResourcePool _rpool; internal PartitionInfo(ResourcePool rpool) { _rpool = rpool; } internal object RetrieveResource() { return _rpool.RetrieveResource(); } internal void StoreResource(IDisposable o) { _rpool.StoreResource(o); } protected virtual string TracingPartitionString { get { return String.Empty; } } string IPartitionInfo.GetTracingPartitionString() { return TracingPartitionString; } public void Dispose() { if (_rpool == null) { return; } lock (this) { if (_rpool != null) { _rpool.Dispose(); _rpool = null; } } } }; } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web { using System; using System.Configuration; using System.Collections; using System.Threading; using System.IO; using System.Web; using System.Web.Caching; using System.Web.Util; using System.Data; using System.Data.SqlClient; using System.Text; using System.Security.Principal; using System.Xml; using System.Collections.Specialized; using System.Configuration.Provider; using System.Globalization; using System.Web.Management; using System.Web.Hosting; using System.Web.Configuration; using System.Security.Permissions; [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public interface IPartitionResolver { void Initialize(); string ResolvePartition(Object key); } internal interface IPartitionInfo { string GetTracingPartitionString(); } internal delegate IPartitionInfo CreatePartitionInfo(string connectionString); class PartitionManager : IDisposable { internal PartitionManager(CreatePartitionInfo createCallback) { _createCallback = createCallback; } HybridDictionary _partitions = new HybridDictionary(); ReaderWriterLock _lock = new ReaderWriterLock(); CreatePartitionInfo _createCallback; internal object GetPartition(IPartitionResolver partitionResolver, string id) { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure)) EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_START, HttpContext.Current.WorkerRequest, partitionResolver.GetType().FullName, id); string partitionString = null; string errorMessage = null; IPartitionInfo partitionInfo = null; try { try { partitionString = partitionResolver.ResolvePartition(id); if (partitionString == null) { throw new HttpException( SR.GetString(SR.Bad_partition_resolver_connection_string, partitionResolver.GetType().FullName)); } } catch (Exception e) { errorMessage = e.Message; throw; } try { _lock.AcquireReaderLock(-1); partitionInfo = (IPartitionInfo)_partitions[partitionString]; if (partitionInfo != null) { Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString); return partitionInfo; } } finally { if (_lock.IsReaderLockHeld) { _lock.ReleaseReaderLock(); } } // Not found. Has to add it. try { _lock.AcquireWriterLock(-1); // One more time partitionInfo = (IPartitionInfo)_partitions[partitionString]; if (partitionInfo == null) { partitionInfo = _createCallback(partitionString); Debug.Trace("PartitionManager", "Add a new partition; id=" + id + "; partitionString=" + partitionString); _partitions.Add(partitionString, partitionInfo); } Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString); return partitionInfo; } finally { if (_lock.IsWriterLockHeld) { _lock.ReleaseWriterLock(); } } } finally { if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure)) { string msg = errorMessage; if (msg == null) { if (partitionInfo != null) { msg = partitionInfo.GetTracingPartitionString(); } else { msg = String.Empty; } } EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_END, HttpContext.Current.WorkerRequest, msg); } } } public void Dispose() { if (_partitions == null) { return; } try { _lock.AcquireWriterLock(-1); if (_partitions != null) { foreach (PartitionInfo partitionInfo in _partitions.Values) { partitionInfo.Dispose(); } _partitions = null; } } catch { // ignore exceptions in dispose } finally { if (_lock.IsWriterLockHeld) { _lock.ReleaseWriterLock(); } } } } internal class PartitionInfo : IDisposable, IPartitionInfo { ResourcePool _rpool; internal PartitionInfo(ResourcePool rpool) { _rpool = rpool; } internal object RetrieveResource() { return _rpool.RetrieveResource(); } internal void StoreResource(IDisposable o) { _rpool.StoreResource(o); } protected virtual string TracingPartitionString { get { return String.Empty; } } string IPartitionInfo.GetTracingPartitionString() { return TracingPartitionString; } public void Dispose() { if (_rpool == null) { return; } lock (this) { if (_rpool != null) { _rpool.Dispose(); _rpool = null; } } } }; } // 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
- TextBlockAutomationPeer.cs
- TaskFormBase.cs
- XmlSubtreeReader.cs
- GZipStream.cs
- SettingsPropertyValue.cs
- WebPartEditorApplyVerb.cs
- ContainerControl.cs
- OleDbParameter.cs
- SamlSecurityToken.cs
- HandlerBase.cs
- _Win32.cs
- ItemList.cs
- AccessorTable.cs
- ByeOperation11AsyncResult.cs
- DispatchChannelSink.cs
- ModelService.cs
- ArraySegment.cs
- OleDbParameterCollection.cs
- filewebresponse.cs
- MulticastNotSupportedException.cs
- x509utils.cs
- SoapClientMessage.cs
- DefaultSerializationProviderAttribute.cs
- PasswordValidationException.cs
- TableRowGroup.cs
- IdnElement.cs
- VirtualPath.cs
- GrammarBuilderDictation.cs
- CollectionViewGroup.cs
- BitmapEffectState.cs
- input.cs
- SqlBinder.cs
- PageClientProxyGenerator.cs
- GeneralTransform3DTo2DTo3D.cs
- WebPartConnectVerb.cs
- XmlDomTextWriter.cs
- ConfigXmlElement.cs
- SingleStorage.cs
- ExtentKey.cs
- ImageClickEventArgs.cs
- TreeViewHitTestInfo.cs
- MethodImplAttribute.cs
- StructuredTypeInfo.cs
- TraceInternal.cs
- AspCompat.cs
- BuildProvidersCompiler.cs
- WebPartChrome.cs
- PeerHopCountAttribute.cs
- ServiceDeploymentInfo.cs
- ValidationSummary.cs
- StrongNameUtility.cs
- RequestQueryParser.cs
- SqlRowUpdatingEvent.cs
- DateTimePicker.cs
- XmlSchemaObjectTable.cs
- StringFormat.cs
- AsymmetricSignatureFormatter.cs
- DataGridViewEditingControlShowingEventArgs.cs
- ArrayTypeMismatchException.cs
- GetIsBrowserClientRequest.cs
- SubMenuStyle.cs
- TrackBar.cs
- clipboard.cs
- Exceptions.cs
- DesignSurfaceServiceContainer.cs
- RemoteWebConfigurationHostServer.cs
- DoubleAnimationBase.cs
- ResourceReferenceKeyNotFoundException.cs
- DirectoryInfo.cs
- MissingSatelliteAssemblyException.cs
- PipelineModuleStepContainer.cs
- HttpConfigurationSystem.cs
- RawStylusInputReport.cs
- DbParameterCollection.cs
- MailFileEditor.cs
- ObjectPropertyMapping.cs
- TextTrailingCharacterEllipsis.cs
- WebDisplayNameAttribute.cs
- XmlSchemaNotation.cs
- URL.cs
- SmtpMail.cs
- FileAuthorizationModule.cs
- TableHeaderCell.cs
- TextTreePropertyUndoUnit.cs
- PlatformNotSupportedException.cs
- ContextStaticAttribute.cs
- ChildTable.cs
- OverrideMode.cs
- UpDownBase.cs
- Console.cs
- OdbcPermission.cs
- BoolExpressionVisitors.cs
- CheckBoxRenderer.cs
- WebPartTransformer.cs
- Message.cs
- BounceEase.cs
- TemplateBindingExpressionConverter.cs
- filewebresponse.cs
- StringInfo.cs
- CapiSafeHandles.cs