Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / HandleDictionary.cs / 1 / HandleDictionary.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{
using System;
using System.Collections.Generic;
using Microsoft.InfoCards.Diagnostics;
using IDT=Microsoft.InfoCards.Diagnostics.InfoCardTrace;
using System.Xml;
//
// Summary:
// Implements a dictionary of Handles. The GetNewHandle method will return a handle value that is guaranteed
// to be unique, an object of type TVal can then be associated with that handle value.
//
internal class HandleDictionary< TVal >
{
const int m_MaxSessionCount = Int32.MaxValue / 2;
Dictionary< int, TVal > m_internalDictionary;
Random m_random;
//
// Summary:
// Returns the max number of handles this dictionary can contain.
//
public int MaxSize
{
get { return m_MaxSessionCount; }
}
//
// Summary:
// Gets the object associated with the handle value passed in as Key.
//
public TVal this[ int Key ]
{
get
{
return m_internalDictionary[ Key ];
}
set
{
if ( !ContainsHandle( Key ) )
{
throw IDT.ThrowHelperError( new KeyNotFoundException() );
}
m_internalDictionary[ Key ] = value;
}
}
public HandleDictionary()
{
m_internalDictionary = new Dictionary< int, TVal >();
m_random = new Random();
}
public int GetNewHandle()
{
//
// Limit the number of crypto sessions to make certain that
// finding a random id is efficient.
//
if( m_internalDictionary.Count >= m_MaxSessionCount )
{
throw IDT.ThrowHelperError( new MaxSessionCountExceededException() );
}
//
// Look for an open slot.
//
int handle = m_random.Next();
while( m_internalDictionary.ContainsKey( handle ) || 0 == handle )
{
handle = m_random.Next();
}
//
// Reserve a spot for this handle.
//
m_internalDictionary[ handle ] = default( TVal );
return handle;
}
//
// Summary:
// Removes a handle and it's value from the collection.
//
public bool Remove( int key )
{
return m_internalDictionary.Remove( key );
}
//
// Summary:
// Returns true if the handle value is contained in the collection.
//
public bool ContainsHandle( int key )
{
return m_internalDictionary.ContainsKey( key );
}
}
}
// 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
- OutputCacheProfileCollection.cs
- WorkflowServiceInstance.cs
- HostedImpersonationContext.cs
- HierarchicalDataSourceIDConverter.cs
- EndpointDiscoveryBehavior.cs
- XmlSchemaGroupRef.cs
- InvokeSchedule.cs
- Hex.cs
- DesignerCategoryAttribute.cs
- OdbcRowUpdatingEvent.cs
- TdsParserStateObject.cs
- ColumnMapProcessor.cs
- messageonlyhwndwrapper.cs
- ContractsBCL.cs
- DrawingAttributes.cs
- DesignerHierarchicalDataSourceView.cs
- ToolStripGrip.cs
- CollectionViewGroup.cs
- DataGridViewRow.cs
- GridViewItemAutomationPeer.cs
- UIElementHelper.cs
- PointConverter.cs
- PropertyGeneratedEventArgs.cs
- DbParameterHelper.cs
- ScriptControlManager.cs
- Win32MouseDevice.cs
- XmlEnumAttribute.cs
- BitStack.cs
- UnmanagedMemoryStreamWrapper.cs
- BaseInfoTable.cs
- OrderedParallelQuery.cs
- Asn1IntegerConverter.cs
- PageThemeParser.cs
- WindowsTreeView.cs
- PermissionToken.cs
- CSharpCodeProvider.cs
- AuthenticatingEventArgs.cs
- HostedTcpTransportManager.cs
- TargetControlTypeAttribute.cs
- HandlerWithFactory.cs
- SymbolType.cs
- DiagnosticsConfiguration.cs
- VectorValueSerializer.cs
- RuntimeEnvironment.cs
- DataConnectionHelper.cs
- ThreadLocal.cs
- SqlResolver.cs
- InvalidFilterCriteriaException.cs
- NativeMethods.cs
- NavigationService.cs
- CodeTypeReferenceSerializer.cs
- GACIdentityPermission.cs
- ProxyWebPart.cs
- SqlUtils.cs
- DateTime.cs
- ImageField.cs
- WhitespaceReader.cs
- OleDbReferenceCollection.cs
- XNodeValidator.cs
- SelectionPattern.cs
- DesignerCapabilities.cs
- ReadOnlyDictionary.cs
- ContainerParagraph.cs
- SelectionWordBreaker.cs
- SharedStatics.cs
- ColumnBinding.cs
- EndpointBehaviorElementCollection.cs
- DataGridToolTip.cs
- DocumentPageHost.cs
- MetadataArtifactLoaderResource.cs
- ClientRolePrincipal.cs
- ClientProtocol.cs
- ColorComboBox.cs
- FixedMaxHeap.cs
- ToolStripItemImageRenderEventArgs.cs
- NumericUpDownAccelerationCollection.cs
- Decimal.cs
- XPathItem.cs
- UrlAuthFailureHandler.cs
- ConstructorArgumentAttribute.cs
- _AutoWebProxyScriptWrapper.cs
- ZoneButton.cs
- WSSecureConversationDec2005.cs
- FormsAuthenticationUserCollection.cs
- LocationUpdates.cs
- FieldTemplateUserControl.cs
- Frame.cs
- TextViewSelectionProcessor.cs
- ScriptDescriptor.cs
- UserPreferenceChangedEventArgs.cs
- FilterFactory.cs
- ProviderConnectionPoint.cs
- RichTextBoxAutomationPeer.cs
- ActivityExecutor.cs
- GPRECTF.cs
- WindowPatternIdentifiers.cs
- XmlArrayAttribute.cs
- DataGridViewLinkCell.cs
- ScrollViewerAutomationPeer.cs
- ProcessingInstructionAction.cs