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 / Site.cs / 1 / Site.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// Site.cs
//
// Site is an IIdentity representing internet sites.
//
namespace System.Security.Policy {
using System.Security.Util;
using System.Globalization;
using SiteIdentityPermission = System.Security.Permissions.SiteIdentityPermission;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class Site : IIdentityPermissionFactory, IBuiltInEvidence
{
private SiteString m_name;
internal Site()
{
m_name = null;
}
public Site(String name)
{
if (name == null)
throw new ArgumentNullException("name");
m_name = new SiteString( name );
}
internal Site( byte[] id, String name )
{
m_name = ParseSiteFromUrl( name );
}
public static Site CreateFromUrl( String url )
{
Site site = new Site();
site.m_name = ParseSiteFromUrl( url );
return site;
}
private static SiteString ParseSiteFromUrl( String name )
{
URLString urlString = new URLString( name );
if (String.Compare( urlString.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0)
throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidSite" ) );
return new SiteString( new URLString( name ).Host );
}
public String Name
{
get
{
if (m_name != null)
return m_name.ToString();
else
return null;
}
}
internal SiteString GetSiteString()
{
return m_name;
}
public IPermission CreateIdentityPermission( Evidence evidence )
{
return new SiteIdentityPermission( Name );
}
public override bool Equals(Object o)
{
if (o is Site)
{
Site s = (Site) o;
if (Name == null)
return (s.Name == null);
return String.Compare( Name, s.Name, StringComparison.OrdinalIgnoreCase) == 0;
}
return false;
}
public override int GetHashCode()
{
String name = this.Name;
if (name == null)
return 0;
else
return name.GetHashCode();
}
public Object Copy()
{
return new Site(this.Name);
}
internal SecurityElement ToXml()
{
SecurityElement elem = new SecurityElement( "System.Security.Policy.Site" );
// 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.Site" ), "Class name changed!" );
elem.AddAttribute( "version", "1" );
if(m_name != null)
elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) );
return elem;
}
///
int IBuiltInEvidence.OutputToBuffer( char[] buffer, int position, bool verbose )
{
buffer[position++] = BuiltInEvidenceHelper.idSite;
String name = this.Name;
int length = name.Length;
if (verbose)
{
BuiltInEvidenceHelper.CopyIntToCharArray(length, buffer, position);
position += 2;
}
name.CopyTo( 0, buffer, position, length );
return length + position;
}
///
int IBuiltInEvidence.GetRequiredSize(bool verbose)
{
if (verbose)
return this.Name.Length + 3;
else
return this.Name.Length + 1;
}
///
int IBuiltInEvidence.InitFromBuffer( char[] buffer, int position)
{
int length = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);
position += 2;
m_name = new SiteString( new String(buffer, position, length ));
return position + length;
}
public override String ToString()
{
return ToXml().ToString();
}
// INormalizeForIsolatedStorage is not implemented for startup perf
// equivalent to INormalizeForIsolatedStorage.Normalize()
internal Object Normalize()
{
return m_name.ToString().ToUpper(CultureInfo.InvariantCulture);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// Site.cs
//
// Site is an IIdentity representing internet sites.
//
namespace System.Security.Policy {
using System.Security.Util;
using System.Globalization;
using SiteIdentityPermission = System.Security.Permissions.SiteIdentityPermission;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class Site : IIdentityPermissionFactory, IBuiltInEvidence
{
private SiteString m_name;
internal Site()
{
m_name = null;
}
public Site(String name)
{
if (name == null)
throw new ArgumentNullException("name");
m_name = new SiteString( name );
}
internal Site( byte[] id, String name )
{
m_name = ParseSiteFromUrl( name );
}
public static Site CreateFromUrl( String url )
{
Site site = new Site();
site.m_name = ParseSiteFromUrl( url );
return site;
}
private static SiteString ParseSiteFromUrl( String name )
{
URLString urlString = new URLString( name );
if (String.Compare( urlString.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0)
throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidSite" ) );
return new SiteString( new URLString( name ).Host );
}
public String Name
{
get
{
if (m_name != null)
return m_name.ToString();
else
return null;
}
}
internal SiteString GetSiteString()
{
return m_name;
}
public IPermission CreateIdentityPermission( Evidence evidence )
{
return new SiteIdentityPermission( Name );
}
public override bool Equals(Object o)
{
if (o is Site)
{
Site s = (Site) o;
if (Name == null)
return (s.Name == null);
return String.Compare( Name, s.Name, StringComparison.OrdinalIgnoreCase) == 0;
}
return false;
}
public override int GetHashCode()
{
String name = this.Name;
if (name == null)
return 0;
else
return name.GetHashCode();
}
public Object Copy()
{
return new Site(this.Name);
}
internal SecurityElement ToXml()
{
SecurityElement elem = new SecurityElement( "System.Security.Policy.Site" );
// 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.Site" ), "Class name changed!" );
elem.AddAttribute( "version", "1" );
if(m_name != null)
elem.AddChild( new SecurityElement( "Name", m_name.ToString() ) );
return elem;
}
///
int IBuiltInEvidence.OutputToBuffer( char[] buffer, int position, bool verbose )
{
buffer[position++] = BuiltInEvidenceHelper.idSite;
String name = this.Name;
int length = name.Length;
if (verbose)
{
BuiltInEvidenceHelper.CopyIntToCharArray(length, buffer, position);
position += 2;
}
name.CopyTo( 0, buffer, position, length );
return length + position;
}
///
int IBuiltInEvidence.GetRequiredSize(bool verbose)
{
if (verbose)
return this.Name.Length + 3;
else
return this.Name.Length + 1;
}
///
int IBuiltInEvidence.InitFromBuffer( char[] buffer, int position)
{
int length = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);
position += 2;
m_name = new SiteString( new String(buffer, position, length ));
return position + length;
}
public override String ToString()
{
return ToXml().ToString();
}
// INormalizeForIsolatedStorage is not implemented for startup perf
// equivalent to INormalizeForIsolatedStorage.Normalize()
internal Object Normalize()
{
return m_name.ToString().ToUpper(CultureInfo.InvariantCulture);
}
}
}
// 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
- XmlConvert.cs
- DataGridViewCheckBoxColumn.cs
- DataServices.cs
- KeyboardNavigation.cs
- WsatRegistrationHeader.cs
- VariableAction.cs
- ImageFormatConverter.cs
- ApplyTemplatesAction.cs
- Rect3DValueSerializer.cs
- NumberFunctions.cs
- ServiceNameElementCollection.cs
- PageCodeDomTreeGenerator.cs
- FilterElement.cs
- RectConverter.cs
- RtfFormatStack.cs
- SmiRecordBuffer.cs
- ExpressionBuilder.cs
- HtmlInputControl.cs
- JoinTreeNode.cs
- QilIterator.cs
- Hex.cs
- TextRunTypographyProperties.cs
- ChildDocumentBlock.cs
- CqlGenerator.cs
- CompositeControl.cs
- ChangeDirector.cs
- DataGridViewCellEventArgs.cs
- DmlSqlGenerator.cs
- TabRenderer.cs
- DataControlFieldCollection.cs
- AtlasWeb.Designer.cs
- SecurityUtils.cs
- WinEventQueueItem.cs
- ActivatableWorkflowsQueryResult.cs
- DefaultBindingPropertyAttribute.cs
- ScrollBar.cs
- GroupBoxDesigner.cs
- TransactionTable.cs
- CreationContext.cs
- SchemaNotation.cs
- SourceChangedEventArgs.cs
- AutoResetEvent.cs
- PersonalizableTypeEntry.cs
- TypeConverterAttribute.cs
- UIElementIsland.cs
- GradientBrush.cs
- OdbcUtils.cs
- wgx_sdk_version.cs
- followingsibling.cs
- Inline.cs
- RequestCacheEntry.cs
- OverflowException.cs
- TemplateNameScope.cs
- InputReport.cs
- Normalization.cs
- MimeBasePart.cs
- HttpFileCollection.cs
- ByteViewer.cs
- CardSpaceSelector.cs
- SqlNodeAnnotations.cs
- DataGridViewToolTip.cs
- TraceLog.cs
- SchemaNotation.cs
- WorkflowHostingEndpoint.cs
- DrawingImage.cs
- CodeTypeDeclarationCollection.cs
- BuildProvider.cs
- ReadOnlyActivityGlyph.cs
- SiteMembershipCondition.cs
- GeneralTransform3DTo2D.cs
- ContainerUtilities.cs
- ServiceContractDetailViewControl.cs
- BindingEntityInfo.cs
- OleDbInfoMessageEvent.cs
- XPathSelectionIterator.cs
- ListBoxAutomationPeer.cs
- DefaultAutoFieldGenerator.cs
- OdbcRowUpdatingEvent.cs
- _NativeSSPI.cs
- ButtonRenderer.cs
- HandlerFactoryCache.cs
- MobileTextWriter.cs
- MailMessageEventArgs.cs
- SystemDiagnosticsSection.cs
- AttachInfo.cs
- DbParameterCollection.cs
- XmlDocumentFieldSchema.cs
- LinkDesigner.cs
- OracleParameterBinding.cs
- HttpCapabilitiesBase.cs
- handlecollector.cs
- Attributes.cs
- CultureMapper.cs
- PathSegmentCollection.cs
- LingerOption.cs
- KeyTimeConverter.cs
- DocumentViewerHelper.cs
- RequestResizeEvent.cs
- BaseValidator.cs
- ServiceOperation.cs