Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / Security / Policy / ApplicationDirectoryMembershipCondition.cs / 1 / ApplicationDirectoryMembershipCondition.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// ApplicationDirectoryMembershipCondition.cs
//
// Implementation of membership condition for "application directories"
//
namespace System.Security.Policy {
using System;
using SecurityElement = System.Security.SecurityElement;
using System.Security.Policy;
using URLString = System.Security.Util.URLString;
using System.Collections;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class ApplicationDirectoryMembershipCondition : IMembershipCondition, IConstantMembershipCondition, IReportMatchMembershipCondition
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//-----------------------------------------------------
//-----------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//-----------------------------------------------------
public ApplicationDirectoryMembershipCondition()
{
}
//------------------------------------------------------
//
// 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;
IEnumerator enumerator = evidence.GetHostEnumerator();
while (enumerator.MoveNext())
{
ApplicationDirectory dir = enumerator.Current as ApplicationDirectory;
if (dir != null)
{
IEnumerator innerEnumerator = evidence.GetHostEnumerator();
while (innerEnumerator.MoveNext())
{
Url url = innerEnumerator.Current as Url;
if (url != null)
{
// We need to add a wildcard at the end because IsSubsetOf
// keys off of it.
String appDir = dir.Directory;
if (appDir != null && appDir.Length > 1)
{
if (appDir[appDir.Length-1] == '/')
appDir += "*";
else
appDir += "/*"; // comment
URLString appDirString = new URLString(appDir);
if (url.GetURLString().IsSubsetOf(appDirString))
{
usedEvidence = dir;
return true;
}
}
}
}
}
}
return false;
}
public IMembershipCondition Copy()
{
return new ApplicationDirectoryMembershipCondition();
}
public SecurityElement ToXml()
{
return ToXml( null );
}
public void FromXml( SecurityElement e )
{
FromXml( e, null );
}
public SecurityElement ToXml( PolicyLevel level )
{
SecurityElement root = new SecurityElement( "IMembershipCondition" );
System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.ApplicationDirectoryMembershipCondition" );
// 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.
BCLDebug.Assert( this.GetType().FullName.Equals( "System.Security.Policy.ApplicationDirectoryMembershipCondition" ), "Class name changed!" );
root.AddAttribute( "version", "1" );
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" ) );
}
}
public override bool Equals( Object o )
{
return (o is ApplicationDirectoryMembershipCondition);
}
public override int GetHashCode()
{
return typeof( ApplicationDirectoryMembershipCondition ).GetHashCode();
}
public override String ToString()
{
return Environment.GetResourceString( "ApplicationDirectory_ToString" );
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// ApplicationDirectoryMembershipCondition.cs
//
// Implementation of membership condition for "application directories"
//
namespace System.Security.Policy {
using System;
using SecurityElement = System.Security.SecurityElement;
using System.Security.Policy;
using URLString = System.Security.Util.URLString;
using System.Collections;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class ApplicationDirectoryMembershipCondition : IMembershipCondition, IConstantMembershipCondition, IReportMatchMembershipCondition
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//-----------------------------------------------------
//-----------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//-----------------------------------------------------
public ApplicationDirectoryMembershipCondition()
{
}
//------------------------------------------------------
//
// 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;
IEnumerator enumerator = evidence.GetHostEnumerator();
while (enumerator.MoveNext())
{
ApplicationDirectory dir = enumerator.Current as ApplicationDirectory;
if (dir != null)
{
IEnumerator innerEnumerator = evidence.GetHostEnumerator();
while (innerEnumerator.MoveNext())
{
Url url = innerEnumerator.Current as Url;
if (url != null)
{
// We need to add a wildcard at the end because IsSubsetOf
// keys off of it.
String appDir = dir.Directory;
if (appDir != null && appDir.Length > 1)
{
if (appDir[appDir.Length-1] == '/')
appDir += "*";
else
appDir += "/*"; // comment
URLString appDirString = new URLString(appDir);
if (url.GetURLString().IsSubsetOf(appDirString))
{
usedEvidence = dir;
return true;
}
}
}
}
}
}
return false;
}
public IMembershipCondition Copy()
{
return new ApplicationDirectoryMembershipCondition();
}
public SecurityElement ToXml()
{
return ToXml( null );
}
public void FromXml( SecurityElement e )
{
FromXml( e, null );
}
public SecurityElement ToXml( PolicyLevel level )
{
SecurityElement root = new SecurityElement( "IMembershipCondition" );
System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.ApplicationDirectoryMembershipCondition" );
// 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.
BCLDebug.Assert( this.GetType().FullName.Equals( "System.Security.Policy.ApplicationDirectoryMembershipCondition" ), "Class name changed!" );
root.AddAttribute( "version", "1" );
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" ) );
}
}
public override bool Equals( Object o )
{
return (o is ApplicationDirectoryMembershipCondition);
}
public override int GetHashCode()
{
return typeof( ApplicationDirectoryMembershipCondition ).GetHashCode();
}
public override String ToString()
{
return Environment.GetResourceString( "ApplicationDirectory_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
- ActiveXSerializer.cs
- LookupBindingPropertiesAttribute.cs
- ObjectItemConventionAssemblyLoader.cs
- ApplicationId.cs
- PropertyInformationCollection.cs
- Property.cs
- InputScopeAttribute.cs
- TdsEnums.cs
- smtppermission.cs
- FamilyMap.cs
- MbpInfo.cs
- DataGridViewCellLinkedList.cs
- IApplicationTrustManager.cs
- RawKeyboardInputReport.cs
- StylusShape.cs
- DropTarget.cs
- ToolStripInSituService.cs
- IndexOutOfRangeException.cs
- BoundPropertyEntry.cs
- PartBasedPackageProperties.cs
- CDSCollectionETWBCLProvider.cs
- AesCryptoServiceProvider.cs
- Maps.cs
- TableRowCollection.cs
- CustomErrorCollection.cs
- PagePropertiesChangingEventArgs.cs
- MaskedTextBoxTextEditor.cs
- RecognizerInfo.cs
- SafeMILHandleMemoryPressure.cs
- CodeCatchClause.cs
- MimeMapping.cs
- ValidatedControlConverter.cs
- RequestResizeEvent.cs
- ObjectQueryState.cs
- RichTextBox.cs
- KerberosTicketHashIdentifierClause.cs
- ITextView.cs
- WindowsContainer.cs
- SafeCryptoHandles.cs
- ASCIIEncoding.cs
- PrintingPermissionAttribute.cs
- RegexMatch.cs
- TreeNodeEventArgs.cs
- Logging.cs
- SimpleParser.cs
- WindowsComboBox.cs
- EdmFunction.cs
- Filter.cs
- ObjectDataSourceDisposingEventArgs.cs
- TreeNodeEventArgs.cs
- WinFormsSecurity.cs
- JulianCalendar.cs
- DeflateStream.cs
- AutomationPropertyChangedEventArgs.cs
- AnimationException.cs
- ObjectCloneHelper.cs
- RuntimeEnvironment.cs
- RoleGroupCollection.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- ViewSimplifier.cs
- CmsInterop.cs
- TypeProvider.cs
- OdbcParameter.cs
- UntrustedRecipientException.cs
- InlineObject.cs
- ToolBarTray.cs
- Route.cs
- GCHandleCookieTable.cs
- PagedDataSource.cs
- RegexParser.cs
- HtmlPageAdapter.cs
- DataColumnCollection.cs
- ASCIIEncoding.cs
- BamlRecordHelper.cs
- ReturnType.cs
- ConvertersCollection.cs
- MergeFailedEvent.cs
- SystemException.cs
- SiteOfOriginPart.cs
- ManagedWndProcTracker.cs
- ExceptionHandlersDesigner.cs
- XmlSerializerSection.cs
- Int32Rect.cs
- DomainUpDown.cs
- SchemaTableOptionalColumn.cs
- DateTime.cs
- CharKeyFrameCollection.cs
- ImportOptions.cs
- Error.cs
- RepeaterItemEventArgs.cs
- Italic.cs
- TextClipboardData.cs
- Popup.cs
- Monitor.cs
- DataGridViewColumnEventArgs.cs
- X509RecipientCertificateServiceElement.cs
- JournalEntryStack.cs
- SQLStringStorage.cs
- GridItemCollection.cs
- ContextMenu.cs