Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Policy / URLMembershipCondition.cs / 1305376 / URLMembershipCondition.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //[....] // // // UrlMembershipCondition.cs // // Implementation of membership condition for urls // namespace System.Security.Policy { using System; using System.Collections; using System.Globalization; using System.Security; using System.Security.Util; using System.Diagnostics.Contracts; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] sealed public class UrlMembershipCondition : IMembershipCondition, IConstantMembershipCondition, IReportMatchMembershipCondition { //------------------------------------------------------ // // PRIVATE STATE DATA // //----------------------------------------------------- private URLString m_url; private SecurityElement m_element; //----------------------------------------------------- // // PUBLIC CONSTRUCTORS // //----------------------------------------------------- internal UrlMembershipCondition() { m_url = null; } public UrlMembershipCondition( String url ) { if (url == null) throw new ArgumentNullException( "url" ); Contract.EndContractBlock(); // Parse the Url to check that it's valid. m_url = new URLString(url, false /* not parsed */, true /* parse eagerly */); if (m_url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"), "url"); } //------------------------------------------------------ // // PUBLIC ACCESSOR METHODS // //----------------------------------------------------- public String Url { set { if (value == null) throw new ArgumentNullException("value"); Contract.EndContractBlock(); URLString url = new URLString(value); if (url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"), "value"); m_url = url; } get { if (m_url == null && m_element != null) ParseURL(); return m_url.ToString(); } } //------------------------------------------------------ // // IMEMBERSHIPCONDITION IMPLEMENTATION // //------------------------------------------------------ public bool Check( Evidence evidence ) { object usedEvidence = null; return (this as IReportMatchMembershipCondition).Check(evidence, out usedEvidence); } bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence) { usedEvidence = null; if (evidence == null) return false; Url url = evidence.GetHostEvidence(); if (url != null) { if (m_url == null && m_element != null) { ParseURL(); } if (url.GetURLString().IsSubsetOf(m_url)) { usedEvidence = url; return true; } } return false; } public IMembershipCondition Copy() { if (m_url == null && m_element != null) ParseURL(); UrlMembershipCondition mc = new UrlMembershipCondition(); mc.m_url = new URLString( m_url.ToString() ); return mc; } public SecurityElement ToXml() { return ToXml( null ); } public void FromXml( SecurityElement e ) { FromXml( e, null ); } public SecurityElement ToXml( PolicyLevel level ) { if (m_url == null && m_element != null) ParseURL(); SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.UrlMembershipCondition" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.UrlMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_url != null) root.AddAttribute( "Url", m_url.ToString() ); return root; } public void FromXml( SecurityElement e, PolicyLevel level ) { if (e == null) throw new ArgumentNullException("e"); if (!e.Tag.Equals( "IMembershipCondition" )) { throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) ); } Contract.EndContractBlock(); lock (this) { m_element = e; m_url = null; } } private void ParseURL() { lock (this) { if (m_element == null) return; String elurl = m_element.Attribute( "Url" ); if (elurl == null) { throw new ArgumentException(Environment.GetResourceString("Argument_UrlCannotBeNull")); } else { URLString url = new URLString(elurl); if (url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition")); m_url = url; } m_element = null; } } public override bool Equals( Object o ) { UrlMembershipCondition that = (o as UrlMembershipCondition); if (that != null) { if (this.m_url == null && this.m_element != null) this.ParseURL(); if (that.m_url == null && that.m_element != null) that.ParseURL(); if (Equals( this.m_url, that.m_url )) { return true; } } return false; } public override int GetHashCode() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) { return m_url.GetHashCode(); } else { return typeof( UrlMembershipCondition ).GetHashCode(); } } public override String ToString() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) return String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Url_ToStringArg" ), m_url.ToString() ); else return Environment.GetResourceString( "Url_ToString" ); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // [....] // // // UrlMembershipCondition.cs // // Implementation of membership condition for urls // namespace System.Security.Policy { using System; using System.Collections; using System.Globalization; using System.Security; using System.Security.Util; using System.Diagnostics.Contracts; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] sealed public class UrlMembershipCondition : IMembershipCondition, IConstantMembershipCondition, IReportMatchMembershipCondition { //------------------------------------------------------ // // PRIVATE STATE DATA // //----------------------------------------------------- private URLString m_url; private SecurityElement m_element; //----------------------------------------------------- // // PUBLIC CONSTRUCTORS // //----------------------------------------------------- internal UrlMembershipCondition() { m_url = null; } public UrlMembershipCondition( String url ) { if (url == null) throw new ArgumentNullException( "url" ); Contract.EndContractBlock(); // Parse the Url to check that it's valid. m_url = new URLString(url, false /* not parsed */, true /* parse eagerly */); if (m_url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"), "url"); } //------------------------------------------------------ // // PUBLIC ACCESSOR METHODS // //----------------------------------------------------- public String Url { set { if (value == null) throw new ArgumentNullException("value"); Contract.EndContractBlock(); URLString url = new URLString(value); if (url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"), "value"); m_url = url; } get { if (m_url == null && m_element != null) ParseURL(); return m_url.ToString(); } } //------------------------------------------------------ // // IMEMBERSHIPCONDITION IMPLEMENTATION // //------------------------------------------------------ public bool Check( Evidence evidence ) { object usedEvidence = null; return (this as IReportMatchMembershipCondition).Check(evidence, out usedEvidence); } bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence) { usedEvidence = null; if (evidence == null) return false; Url url = evidence.GetHostEvidence(); if (url != null) { if (m_url == null && m_element != null) { ParseURL(); } if (url.GetURLString().IsSubsetOf(m_url)) { usedEvidence = url; return true; } } return false; } public IMembershipCondition Copy() { if (m_url == null && m_element != null) ParseURL(); UrlMembershipCondition mc = new UrlMembershipCondition(); mc.m_url = new URLString( m_url.ToString() ); return mc; } public SecurityElement ToXml() { return ToXml( null ); } public void FromXml( SecurityElement e ) { FromXml( e, null ); } public SecurityElement ToXml( PolicyLevel level ) { if (m_url == null && m_element != null) ParseURL(); SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.UrlMembershipCondition" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.UrlMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); if (m_url != null) root.AddAttribute( "Url", m_url.ToString() ); return root; } public void FromXml( SecurityElement e, PolicyLevel level ) { if (e == null) throw new ArgumentNullException("e"); if (!e.Tag.Equals( "IMembershipCondition" )) { throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) ); } Contract.EndContractBlock(); lock (this) { m_element = e; m_url = null; } } private void ParseURL() { lock (this) { if (m_element == null) return; String elurl = m_element.Attribute( "Url" ); if (elurl == null) { throw new ArgumentException(Environment.GetResourceString("Argument_UrlCannotBeNull")); } else { URLString url = new URLString(elurl); if (url.IsRelativeFileUrl) throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition")); m_url = url; } m_element = null; } } public override bool Equals( Object o ) { UrlMembershipCondition that = (o as UrlMembershipCondition); if (that != null) { if (this.m_url == null && this.m_element != null) this.ParseURL(); if (that.m_url == null && that.m_element != null) that.ParseURL(); if (Equals( this.m_url, that.m_url )) { return true; } } return false; } public override int GetHashCode() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) { return m_url.GetHashCode(); } else { return typeof( UrlMembershipCondition ).GetHashCode(); } } public override String ToString() { if (m_url == null && m_element != null) ParseURL(); if (m_url != null) return String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Url_ToStringArg" ), m_url.ToString() ); else return Environment.GetResourceString( "Url_ToString" ); } } } // 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
- PowerModeChangedEventArgs.cs
- ProfilePropertySettings.cs
- WebPartConnection.cs
- DrawingContextDrawingContextWalker.cs
- RemotingAttributes.cs
- Transaction.cs
- SvcFileManager.cs
- cookiecollection.cs
- CollectionType.cs
- AutoGeneratedField.cs
- UnsafeNativeMethods.cs
- BitmapCacheBrush.cs
- FloatUtil.cs
- VerificationAttribute.cs
- EventHandlingScope.cs
- AspCompat.cs
- SqlCommandSet.cs
- AuthenticodeSignatureInformation.cs
- BackgroundWorker.cs
- OpenFileDialog.cs
- SqlCachedBuffer.cs
- MetadataExchangeBindings.cs
- DoubleStorage.cs
- ContextMenuAutomationPeer.cs
- CardSpaceSelector.cs
- Stylesheet.cs
- _OSSOCK.cs
- InvalidCastException.cs
- ConsoleTraceListener.cs
- OleDbParameterCollection.cs
- MemberProjectedSlot.cs
- WebCategoryAttribute.cs
- CommonGetThemePartSize.cs
- Emitter.cs
- RuntimeVariablesExpression.cs
- StylusPoint.cs
- Utils.cs
- DesignUtil.cs
- AutoResizedEvent.cs
- Line.cs
- DataContractAttribute.cs
- DataBindingCollection.cs
- OleDbError.cs
- DataFormats.cs
- InputElement.cs
- PackageProperties.cs
- BrowserCapabilitiesFactory.cs
- DataObject.cs
- BaseDataListDesigner.cs
- ChtmlImageAdapter.cs
- DataControlImageButton.cs
- Point3DAnimationUsingKeyFrames.cs
- DataSourceBooleanViewSchemaConverter.cs
- CompositeActivityCodeGenerator.cs
- cryptoapiTransform.cs
- WindowInteropHelper.cs
- ValidationError.cs
- SR.cs
- SafeProcessHandle.cs
- DbMetaDataCollectionNames.cs
- BrowserCapabilitiesCompiler.cs
- ReadOnlyDictionary.cs
- ListenerUnsafeNativeMethods.cs
- WebControlAdapter.cs
- ForeignConstraint.cs
- PackUriHelper.cs
- ListViewGroup.cs
- CookieParameter.cs
- Trace.cs
- ContextStack.cs
- SHA384.cs
- QuaternionIndependentAnimationStorage.cs
- EntityWithKeyStrategy.cs
- ModelServiceImpl.cs
- DiscoveryDocumentLinksPattern.cs
- RegexStringValidatorAttribute.cs
- IdentityNotMappedException.cs
- NativeMethods.cs
- XmlSerializerImportOptions.cs
- AccessedThroughPropertyAttribute.cs
- WebPartDescription.cs
- latinshape.cs
- IntegerFacetDescriptionElement.cs
- QuaternionAnimationBase.cs
- DesignerVerb.cs
- DataSourceControlBuilder.cs
- FixedSOMPage.cs
- ObjectTag.cs
- DiscoveryClientReferences.cs
- GlyphInfoList.cs
- FixedPosition.cs
- Debugger.cs
- ZipIOExtraField.cs
- DynamicILGenerator.cs
- FormsIdentity.cs
- BaseUriHelper.cs
- ReferencedCollectionType.cs
- MediaPlayer.cs
- DeadLetterQueue.cs
- ProcessMonitor.cs