Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / Net / _SpnDictionary.cs / 1 / _SpnDictionary.cs
/*++ Copyright (c) Microsoft Corporation Module Name: _SpnDictionary.cs Abstract: This internal class implements a static mutlithreaded dictionary for user-registered SPNs. An SPN is mapped based on a Uri prefix that contains scheme, host and port. Author: Alexei Vopilov 15-Nov-2003 Revision History: --*/ namespace System.Net { using System; using System.Collections; using System.Collections.Specialized; using System.Security.Permissions; internal class SpnDictionary : StringDictionary { // //A Hashtable can support one writer and multiple readers concurrently // private Hashtable m_SyncTable = Hashtable.Synchronized(new Hashtable()); // // internal SpnDictionary():base() { } // // // public override int Count { get { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable.Count; } } // // We are thread safe // public override bool IsSynchronized { get { return true; } } // // Internal lookup, bypasses security checks // internal string InternalGet(string canonicalKey) { int lastLength = 0; string key = null; foreach (object o in m_SyncTable.Keys){ string s = (string) o; if(s != null && s.Length > lastLength){ if(String.Compare(s,0,canonicalKey,0,s.Length,StringComparison.OrdinalIgnoreCase) == 0){ lastLength = s.Length; key = s; } } } return (key != null) ? (string)m_SyncTable[key]: null; } internal void InternalSet(string canonicalKey, string spn) { m_SyncTable[canonicalKey] = spn; } // // Public lookup method // public override string this[string key] { get { key = GetCanonicalKey(key); return InternalGet(key); } set { key = GetCanonicalKey(key); InternalSet(key, value); } } // public override ICollection Keys { get { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable.Keys; } } // public override object SyncRoot { [HostProtection(Synchronization=true)] get { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable; } } // public override ICollection Values { get { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable.Values; } } // public override void Add(string key, string value) { key = GetCanonicalKey(key); m_SyncTable.Add(key, value); } // public override void Clear() { ExceptionHelper.WebPermissionUnrestricted.Demand(); m_SyncTable.Clear(); } // public override bool ContainsKey(string key) { key = GetCanonicalKey(key); return m_SyncTable.ContainsKey(key); } // public override bool ContainsValue(string value) { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable.ContainsValue(value); } // public override void CopyTo(Array array, int index) { ExceptionHelper.WebPermissionUnrestricted.Demand(); m_SyncTable.CopyTo(array, index); } // public override IEnumerator GetEnumerator() { ExceptionHelper.WebPermissionUnrestricted.Demand(); return m_SyncTable.GetEnumerator(); } // public override void Remove(string key) { key = GetCanonicalKey(key); m_SyncTable.Remove(key); } // // Private stuff: We want to serialize on updates on one thread // private static string GetCanonicalKey(string key) { if( key == null ) { throw new ArgumentNullException("key"); } try { Uri uri = new Uri(key); key = uri.GetParts(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped); new WebPermission(NetworkAccess.Connect, new Uri(key)).Demand(); } catch(UriFormatException e) { throw new ArgumentException(SR.GetString(SR.net_mustbeuri, "key"), "key", e); } return key; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeCommentStatement.cs
- ContainerParaClient.cs
- XMLUtil.cs
- FontStyleConverter.cs
- ComplexType.cs
- WindowsFormsSynchronizationContext.cs
- XmlSchemaElement.cs
- SqlMethodAttribute.cs
- MenuItemAutomationPeer.cs
- PerformanceCounterPermission.cs
- SHA384Cng.cs
- XslAst.cs
- GeometryModel3D.cs
- FixedSOMTable.cs
- SqlRowUpdatedEvent.cs
- VariableQuery.cs
- XPathDocumentIterator.cs
- CqlParserHelpers.cs
- LassoSelectionBehavior.cs
- OrderedDictionaryStateHelper.cs
- SaveFileDialogDesigner.cs
- OutputCacheProfileCollection.cs
- Types.cs
- AsyncOperationContext.cs
- _IPv4Address.cs
- DataGridColumnEventArgs.cs
- ResourceSet.cs
- FilteredReadOnlyMetadataCollection.cs
- ComponentSerializationService.cs
- StylusPlugin.cs
- entityreference_tresulttype.cs
- OptimizerPatterns.cs
- AuditLogLocation.cs
- BindMarkupExtensionSerializer.cs
- DataBoundControlAdapter.cs
- ForAllOperator.cs
- LoginUtil.cs
- CustomWebEventKey.cs
- RegularExpressionValidator.cs
- DynamicQueryableWrapper.cs
- FileNotFoundException.cs
- CodeEventReferenceExpression.cs
- MultiByteCodec.cs
- TextRangeEditTables.cs
- RSAPKCS1KeyExchangeFormatter.cs
- XmlObjectSerializerReadContextComplexJson.cs
- UnsignedPublishLicense.cs
- WizardPanel.cs
- TypeGenericEnumerableViewSchema.cs
- Events.cs
- LayoutSettings.cs
- _TimerThread.cs
- StateFinalizationActivity.cs
- FragmentQueryProcessor.cs
- EntityDataSourceWizardForm.cs
- CategoryAttribute.cs
- EventDescriptor.cs
- VariableAction.cs
- MemoryStream.cs
- Message.cs
- Material.cs
- RawStylusActions.cs
- TextCollapsingProperties.cs
- TraceSection.cs
- RouteParser.cs
- TableLayoutSettings.cs
- MeasureItemEvent.cs
- TreeViewEvent.cs
- Debug.cs
- CheckBox.cs
- BuildProvidersCompiler.cs
- ResourceCategoryAttribute.cs
- TransformCryptoHandle.cs
- Trace.cs
- XPathAxisIterator.cs
- UserPrincipalNameElement.cs
- DataGridViewRowsRemovedEventArgs.cs
- PointLightBase.cs
- OuterGlowBitmapEffect.cs
- CrossSiteScriptingValidation.cs
- MsmqIntegrationChannelFactory.cs
- FunctionImportMapping.ReturnTypeRenameMapping.cs
- NumericUpDown.cs
- PermissionAttributes.cs
- FlowDocumentPage.cs
- DependentList.cs
- DrawingContextWalker.cs
- VisualStateManager.cs
- CodeIndexerExpression.cs
- NullableDecimalSumAggregationOperator.cs
- UriTemplateTableMatchCandidate.cs
- WbemException.cs
- TextEditorSpelling.cs
- ClientTargetCollection.cs
- ActivityDesignerAccessibleObject.cs
- XDRSchema.cs
- X509ThumbprintKeyIdentifierClause.cs
- EntityCommand.cs
- XmlBinaryWriterSession.cs
- DataGridView.cs