Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Base / System / Security / permissions / mediapermission.cs / 1 / mediapermission.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // The MediaPermission controls the ability to create rich Media in Avalon. // // // History: // 06/07/05: marka Created. //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.IO; using System.Runtime.Serialization; using System.Collections; using System.Globalization; using System.Diagnostics.CodeAnalysis; using System.Windows; namespace System.Security.Permissions { ////// Enum of audio permission levels. /// public enum MediaPermissionAudio { ////// NoAudio - no sound allowed to play. /// NoAudio, ////// SiteOfOriginAudio - only allow audio from site of origin. /// SiteOfOriginAudio, ////// SafeAudio - allowed to play audio with some restrictions. /// SafeAudio, ////// Allowed to play audio with no restrictions /// AllAudio } ////// Enum of video permission levels. /// public enum MediaPermissionVideo { ////// NoVideo - no video allowed to play. /// NoVideo, ////// SiteOfOriginVideo - only allow video from site of origin. /// SiteOfOriginVideo, ////// SafeVideo - allowed to play video with some restrictions. /// SafeVideo, ////// allowed to play video with no restrictions /// AllVideo, } ////// Enum of image permission levels. /// public enum MediaPermissionImage { ////// NoImage - no images allowed to display /// NoImage, ////// SiteOfOriginImage -only allow image from site of origin. /// SiteOfOriginImage, ////// SafeImage - allowed to display images with some restrictions. /// Only certified codecs allowed. /// SafeImage, ////// Allowed to display images with no restrictions. /// AllImage, } ////// The MediaPermission controls the ability for richMedia to work in partial trust. /// /// There are 3 enum values that control the type of media that can work. /// /// MediaPermissionAudio - controls the level of audio support. /// MediaPermissionVideo - controls the level of video supported. /// MeidaPermissionImage - controls the level of image display supported. /// [Serializable()] sealed public class MediaPermission : CodeAccessPermission, IUnrestrictedPermission { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// MediaPermission ctor. /// public MediaPermission() { InitDefaults(); } ////// MediaPermission ctor. /// public MediaPermission(PermissionState state) { if (state == PermissionState.Unrestricted) { _mediaPermissionAudio = MediaPermissionAudio.AllAudio; _mediaPermissionVideo = MediaPermissionVideo.AllVideo; _mediaPermissionImage = MediaPermissionImage.AllImage; } else if (state == PermissionState.None) { _mediaPermissionAudio = MediaPermissionAudio.NoAudio; _mediaPermissionVideo = MediaPermissionVideo.NoVideo; _mediaPermissionImage = MediaPermissionImage.NoImage; } else { throw new ArgumentException( SR.Get(SRID.InvalidPermissionState) ); } } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionAudio permissionAudio ) { VerifyMediaPermissionAudio( permissionAudio ) ; InitDefaults(); _mediaPermissionAudio = permissionAudio ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionVideo permissionVideo ) { VerifyMediaPermissionVideo( permissionVideo ) ; InitDefaults(); _mediaPermissionVideo = permissionVideo ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionImage permissionImage ) { VerifyMediaPermissionImage( permissionImage ); InitDefaults(); _mediaPermissionImage = permissionImage ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionAudio permissionAudio, MediaPermissionVideo permissionVideo, MediaPermissionImage permissionImage ) { VerifyMediaPermissionAudio( permissionAudio ); VerifyMediaPermissionVideo( permissionVideo ); VerifyMediaPermissionImage( permissionImage ); _mediaPermissionAudio = permissionAudio ; _mediaPermissionVideo = permissionVideo ; _mediaPermissionImage = permissionImage ; } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods // // IUnrestrictedPermission implementation // ////// Is this an unrestricted permisison ? /// public bool IsUnrestricted() { return EqualsLevel( MediaPermissionAudio.AllAudio , MediaPermissionVideo.AllVideo, MediaPermissionImage.AllImage ) ; } // // CodeAccessPermission implementation // ////// Is this a subsetOf the target ? /// public override bool IsSubsetOf(IPermission target) { if (target == null) { return EqualsLevel( MediaPermissionAudio.NoAudio, MediaPermissionVideo.NoVideo, MediaPermissionImage.NoImage ) ; } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { return ( ( this._mediaPermissionAudio <= operand._mediaPermissionAudio) && ( this._mediaPermissionVideo <= operand._mediaPermissionVideo ) && ( this._mediaPermissionImage <= operand._mediaPermissionImage ) ) ; } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Return the intersection with the target /// public override IPermission Intersect(IPermission target) { if (target == null) { return null; } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { // // Construct a permission that is the aggregate of the // least priveleged level of the 3 enums. // MediaPermissionAudio audioIntersectLevel = _mediaPermissionAudio < operand._mediaPermissionAudio ? _mediaPermissionAudio : operand._mediaPermissionAudio; MediaPermissionVideo videoIntersectLevel = _mediaPermissionVideo < operand._mediaPermissionVideo ? _mediaPermissionVideo : operand._mediaPermissionVideo; MediaPermissionImage imageIntersectLevel = _mediaPermissionImage < operand._mediaPermissionImage ? _mediaPermissionImage : operand._mediaPermissionImage ; if ( ( audioIntersectLevel == MediaPermissionAudio.NoAudio ) && ( videoIntersectLevel == MediaPermissionVideo.NoVideo ) && ( imageIntersectLevel == MediaPermissionImage.NoImage ) ) { return null; } else { return new MediaPermission( audioIntersectLevel, videoIntersectLevel, imageIntersectLevel ) ; } } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Return the Union with the target /// public override IPermission Union(IPermission target) { if (target == null) { return this.Copy(); } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { // // Construct a permission that is the aggregate of the // most priveleged level of the 3 enums. // MediaPermissionAudio audioUnionLevel = _mediaPermissionAudio > operand._mediaPermissionAudio ? _mediaPermissionAudio : operand._mediaPermissionAudio; MediaPermissionVideo videoUnionLevel = _mediaPermissionVideo > operand._mediaPermissionVideo ? _mediaPermissionVideo : operand._mediaPermissionVideo; MediaPermissionImage imageUnionLevel = _mediaPermissionImage > operand._mediaPermissionImage ? _mediaPermissionImage : operand._mediaPermissionImage ; if ( ( audioUnionLevel == MediaPermissionAudio.NoAudio ) && ( videoUnionLevel == MediaPermissionVideo.NoVideo ) && ( imageUnionLevel == MediaPermissionImage.NoImage ) ) { return null; } else { return new MediaPermission( audioUnionLevel, videoUnionLevel, imageUnionLevel ) ; } } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Copy this permission. /// public override IPermission Copy() { return new MediaPermission( this._mediaPermissionAudio, this._mediaPermissionVideo, this._mediaPermissionImage ); } ////// Return an XML instantiation of this permisson. /// public override SecurityElement ToXml() { SecurityElement securityElement = new SecurityElement("IPermission"); securityElement.AddAttribute("class", this.GetType().AssemblyQualifiedName); securityElement.AddAttribute("version", "1"); if (IsUnrestricted()) { securityElement.AddAttribute("Unrestricted", Boolean.TrueString); } else { securityElement.AddAttribute("Audio", _mediaPermissionAudio.ToString()); securityElement.AddAttribute("Video", _mediaPermissionVideo.ToString()); securityElement.AddAttribute("Image", _mediaPermissionImage.ToString()); } return securityElement; } ////// Create a permission from XML /// public override void FromXml(SecurityElement securityElement) { if (securityElement == null) { throw new ArgumentNullException("securityElement"); } String className = securityElement.Attribute("class"); if (className == null || className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) == -1) { throw new ArgumentNullException("securityElement"); } String unrestricted = securityElement.Attribute("Unrestricted"); if (unrestricted != null && Boolean.Parse(unrestricted)) { _mediaPermissionAudio = MediaPermissionAudio.AllAudio ; _mediaPermissionVideo = MediaPermissionVideo.AllVideo ; _mediaPermissionImage = MediaPermissionImage.AllImage; return; } InitDefaults(); String audio = securityElement.Attribute("Audio"); if (audio != null) { _mediaPermissionAudio = (MediaPermissionAudio)Enum.Parse(typeof(MediaPermissionAudio), audio ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"audio")); // bad XML } String video = securityElement.Attribute("Video"); if (video != null) { _mediaPermissionVideo = (MediaPermissionVideo)Enum.Parse(typeof(MediaPermissionVideo), video ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"video")); // bad XML } String image = securityElement.Attribute("Image"); if (image != null) { _mediaPermissionImage = (MediaPermissionImage)Enum.Parse(typeof(MediaPermissionImage), image ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"image")); // bad XML } } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties ////// Current value of allowed audio permission level /// public MediaPermissionAudio Audio { get { return _mediaPermissionAudio ; } } ////// Current value of allowed video permission level /// public MediaPermissionVideo Video { get { return _mediaPermissionVideo ; } } ////// Current value of allowed image permission level /// public MediaPermissionImage Image { get { return _mediaPermissionImage ; } } #endregion Public Properties //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal static void VerifyMediaPermissionAudio(MediaPermissionAudio level) { if (level < MediaPermissionAudio.NoAudio || level > MediaPermissionAudio.AllAudio ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } internal static void VerifyMediaPermissionVideo(MediaPermissionVideo level) { if (level < MediaPermissionVideo.NoVideo || level > MediaPermissionVideo.AllVideo ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } internal static void VerifyMediaPermissionImage(MediaPermissionImage level) { if (level < MediaPermissionImage.NoImage || level > MediaPermissionImage.AllImage ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } #endregion Internal Methods //----------------------------------------------------- // // Private Methods // //----------------------------------------------------- #region Private Methods private void InitDefaults() { _mediaPermissionAudio = MediaPermissionAudio.SafeAudio; _mediaPermissionVideo = MediaPermissionVideo.SafeVideo; _mediaPermissionImage = MediaPermissionImage.SafeImage; } ////// Private helper to compare the level of the 3 enum fields. /// private bool EqualsLevel( MediaPermissionAudio audioLevel, MediaPermissionVideo videoLevel, MediaPermissionImage imageLevel ) { return ( ( _mediaPermissionAudio == audioLevel ) && ( _mediaPermissionVideo == videoLevel ) && ( _mediaPermissionImage == imageLevel ) ) ; } #endregion Private Methods // // Private fields: // private MediaPermissionAudio _mediaPermissionAudio ; private MediaPermissionVideo _mediaPermissionVideo ; private MediaPermissionImage _mediaPermissionImage ; } ////// Imperative attribute to create a MediaPermission. /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] sealed public class MediaPermissionAttribute : CodeAccessSecurityAttribute { //----------------------------------------------------- // // Constructors // //------------------------------------------------------ #region Constructors ////// Imperative attribute to create a MediaPermission. /// public MediaPermissionAttribute(SecurityAction action) : base(action) { } #endregion Constructors //----------------------------------------------------- // // Public Methods // //------------------------------------------------------ #region Public Methods ////// Create a MediaPermisison. /// public override IPermission CreatePermission() { if (Unrestricted) { return new MediaPermission(PermissionState.Unrestricted); } else { return new MediaPermission( _mediaPermissionAudio, _mediaPermissionVideo, _mediaPermissionImage ); } } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //----------------------------------------------------- #region Public Properties ////// Current audio level. /// public MediaPermissionAudio Audio { get { return _mediaPermissionAudio ; } set { MediaPermission.VerifyMediaPermissionAudio(value); _mediaPermissionAudio = value; } } ////// Current Video level. /// public MediaPermissionVideo Video { get { return _mediaPermissionVideo ; } set { MediaPermission.VerifyMediaPermissionVideo(value); _mediaPermissionVideo = value; } } ////// Current Image level. /// public MediaPermissionImage Image { get { return _mediaPermissionImage ; } set { MediaPermission.VerifyMediaPermissionImage(value); _mediaPermissionImage = value; } } #endregion Public Properties // // Private fields: // private MediaPermissionAudio _mediaPermissionAudio ; private MediaPermissionVideo _mediaPermissionVideo ; private MediaPermissionImage _mediaPermissionImage ; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // The MediaPermission controls the ability to create rich Media in Avalon. // // // History: // 06/07/05: marka Created. //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.IO; using System.Runtime.Serialization; using System.Collections; using System.Globalization; using System.Diagnostics.CodeAnalysis; using System.Windows; namespace System.Security.Permissions { ////// Enum of audio permission levels. /// public enum MediaPermissionAudio { ////// NoAudio - no sound allowed to play. /// NoAudio, ////// SiteOfOriginAudio - only allow audio from site of origin. /// SiteOfOriginAudio, ////// SafeAudio - allowed to play audio with some restrictions. /// SafeAudio, ////// Allowed to play audio with no restrictions /// AllAudio } ////// Enum of video permission levels. /// public enum MediaPermissionVideo { ////// NoVideo - no video allowed to play. /// NoVideo, ////// SiteOfOriginVideo - only allow video from site of origin. /// SiteOfOriginVideo, ////// SafeVideo - allowed to play video with some restrictions. /// SafeVideo, ////// allowed to play video with no restrictions /// AllVideo, } ////// Enum of image permission levels. /// public enum MediaPermissionImage { ////// NoImage - no images allowed to display /// NoImage, ////// SiteOfOriginImage -only allow image from site of origin. /// SiteOfOriginImage, ////// SafeImage - allowed to display images with some restrictions. /// Only certified codecs allowed. /// SafeImage, ////// Allowed to display images with no restrictions. /// AllImage, } ////// The MediaPermission controls the ability for richMedia to work in partial trust. /// /// There are 3 enum values that control the type of media that can work. /// /// MediaPermissionAudio - controls the level of audio support. /// MediaPermissionVideo - controls the level of video supported. /// MeidaPermissionImage - controls the level of image display supported. /// [Serializable()] sealed public class MediaPermission : CodeAccessPermission, IUnrestrictedPermission { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// MediaPermission ctor. /// public MediaPermission() { InitDefaults(); } ////// MediaPermission ctor. /// public MediaPermission(PermissionState state) { if (state == PermissionState.Unrestricted) { _mediaPermissionAudio = MediaPermissionAudio.AllAudio; _mediaPermissionVideo = MediaPermissionVideo.AllVideo; _mediaPermissionImage = MediaPermissionImage.AllImage; } else if (state == PermissionState.None) { _mediaPermissionAudio = MediaPermissionAudio.NoAudio; _mediaPermissionVideo = MediaPermissionVideo.NoVideo; _mediaPermissionImage = MediaPermissionImage.NoImage; } else { throw new ArgumentException( SR.Get(SRID.InvalidPermissionState) ); } } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionAudio permissionAudio ) { VerifyMediaPermissionAudio( permissionAudio ) ; InitDefaults(); _mediaPermissionAudio = permissionAudio ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionVideo permissionVideo ) { VerifyMediaPermissionVideo( permissionVideo ) ; InitDefaults(); _mediaPermissionVideo = permissionVideo ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionImage permissionImage ) { VerifyMediaPermissionImage( permissionImage ); InitDefaults(); _mediaPermissionImage = permissionImage ; } ////// MediaPermission ctor. /// public MediaPermission(MediaPermissionAudio permissionAudio, MediaPermissionVideo permissionVideo, MediaPermissionImage permissionImage ) { VerifyMediaPermissionAudio( permissionAudio ); VerifyMediaPermissionVideo( permissionVideo ); VerifyMediaPermissionImage( permissionImage ); _mediaPermissionAudio = permissionAudio ; _mediaPermissionVideo = permissionVideo ; _mediaPermissionImage = permissionImage ; } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods // // IUnrestrictedPermission implementation // ////// Is this an unrestricted permisison ? /// public bool IsUnrestricted() { return EqualsLevel( MediaPermissionAudio.AllAudio , MediaPermissionVideo.AllVideo, MediaPermissionImage.AllImage ) ; } // // CodeAccessPermission implementation // ////// Is this a subsetOf the target ? /// public override bool IsSubsetOf(IPermission target) { if (target == null) { return EqualsLevel( MediaPermissionAudio.NoAudio, MediaPermissionVideo.NoVideo, MediaPermissionImage.NoImage ) ; } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { return ( ( this._mediaPermissionAudio <= operand._mediaPermissionAudio) && ( this._mediaPermissionVideo <= operand._mediaPermissionVideo ) && ( this._mediaPermissionImage <= operand._mediaPermissionImage ) ) ; } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Return the intersection with the target /// public override IPermission Intersect(IPermission target) { if (target == null) { return null; } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { // // Construct a permission that is the aggregate of the // least priveleged level of the 3 enums. // MediaPermissionAudio audioIntersectLevel = _mediaPermissionAudio < operand._mediaPermissionAudio ? _mediaPermissionAudio : operand._mediaPermissionAudio; MediaPermissionVideo videoIntersectLevel = _mediaPermissionVideo < operand._mediaPermissionVideo ? _mediaPermissionVideo : operand._mediaPermissionVideo; MediaPermissionImage imageIntersectLevel = _mediaPermissionImage < operand._mediaPermissionImage ? _mediaPermissionImage : operand._mediaPermissionImage ; if ( ( audioIntersectLevel == MediaPermissionAudio.NoAudio ) && ( videoIntersectLevel == MediaPermissionVideo.NoVideo ) && ( imageIntersectLevel == MediaPermissionImage.NoImage ) ) { return null; } else { return new MediaPermission( audioIntersectLevel, videoIntersectLevel, imageIntersectLevel ) ; } } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Return the Union with the target /// public override IPermission Union(IPermission target) { if (target == null) { return this.Copy(); } MediaPermission operand = target as MediaPermission ; if ( operand != null ) { // // Construct a permission that is the aggregate of the // most priveleged level of the 3 enums. // MediaPermissionAudio audioUnionLevel = _mediaPermissionAudio > operand._mediaPermissionAudio ? _mediaPermissionAudio : operand._mediaPermissionAudio; MediaPermissionVideo videoUnionLevel = _mediaPermissionVideo > operand._mediaPermissionVideo ? _mediaPermissionVideo : operand._mediaPermissionVideo; MediaPermissionImage imageUnionLevel = _mediaPermissionImage > operand._mediaPermissionImage ? _mediaPermissionImage : operand._mediaPermissionImage ; if ( ( audioUnionLevel == MediaPermissionAudio.NoAudio ) && ( videoUnionLevel == MediaPermissionVideo.NoVideo ) && ( imageUnionLevel == MediaPermissionImage.NoImage ) ) { return null; } else { return new MediaPermission( audioUnionLevel, videoUnionLevel, imageUnionLevel ) ; } } else { throw new ArgumentException(SR.Get(SRID.TargetNotMediaPermissionLevel)); } } ////// Copy this permission. /// public override IPermission Copy() { return new MediaPermission( this._mediaPermissionAudio, this._mediaPermissionVideo, this._mediaPermissionImage ); } ////// Return an XML instantiation of this permisson. /// public override SecurityElement ToXml() { SecurityElement securityElement = new SecurityElement("IPermission"); securityElement.AddAttribute("class", this.GetType().AssemblyQualifiedName); securityElement.AddAttribute("version", "1"); if (IsUnrestricted()) { securityElement.AddAttribute("Unrestricted", Boolean.TrueString); } else { securityElement.AddAttribute("Audio", _mediaPermissionAudio.ToString()); securityElement.AddAttribute("Video", _mediaPermissionVideo.ToString()); securityElement.AddAttribute("Image", _mediaPermissionImage.ToString()); } return securityElement; } ////// Create a permission from XML /// public override void FromXml(SecurityElement securityElement) { if (securityElement == null) { throw new ArgumentNullException("securityElement"); } String className = securityElement.Attribute("class"); if (className == null || className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) == -1) { throw new ArgumentNullException("securityElement"); } String unrestricted = securityElement.Attribute("Unrestricted"); if (unrestricted != null && Boolean.Parse(unrestricted)) { _mediaPermissionAudio = MediaPermissionAudio.AllAudio ; _mediaPermissionVideo = MediaPermissionVideo.AllVideo ; _mediaPermissionImage = MediaPermissionImage.AllImage; return; } InitDefaults(); String audio = securityElement.Attribute("Audio"); if (audio != null) { _mediaPermissionAudio = (MediaPermissionAudio)Enum.Parse(typeof(MediaPermissionAudio), audio ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"audio")); // bad XML } String video = securityElement.Attribute("Video"); if (video != null) { _mediaPermissionVideo = (MediaPermissionVideo)Enum.Parse(typeof(MediaPermissionVideo), video ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"video")); // bad XML } String image = securityElement.Attribute("Image"); if (image != null) { _mediaPermissionImage = (MediaPermissionImage)Enum.Parse(typeof(MediaPermissionImage), image ); } else { throw new ArgumentException(SR.Get(SRID.BadXml,"image")); // bad XML } } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties ////// Current value of allowed audio permission level /// public MediaPermissionAudio Audio { get { return _mediaPermissionAudio ; } } ////// Current value of allowed video permission level /// public MediaPermissionVideo Video { get { return _mediaPermissionVideo ; } } ////// Current value of allowed image permission level /// public MediaPermissionImage Image { get { return _mediaPermissionImage ; } } #endregion Public Properties //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ #region Internal Methods internal static void VerifyMediaPermissionAudio(MediaPermissionAudio level) { if (level < MediaPermissionAudio.NoAudio || level > MediaPermissionAudio.AllAudio ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } internal static void VerifyMediaPermissionVideo(MediaPermissionVideo level) { if (level < MediaPermissionVideo.NoVideo || level > MediaPermissionVideo.AllVideo ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } internal static void VerifyMediaPermissionImage(MediaPermissionImage level) { if (level < MediaPermissionImage.NoImage || level > MediaPermissionImage.AllImage ) { throw new ArgumentException(SR.Get(SRID.InvalidPermissionLevel)); } } #endregion Internal Methods //----------------------------------------------------- // // Private Methods // //----------------------------------------------------- #region Private Methods private void InitDefaults() { _mediaPermissionAudio = MediaPermissionAudio.SafeAudio; _mediaPermissionVideo = MediaPermissionVideo.SafeVideo; _mediaPermissionImage = MediaPermissionImage.SafeImage; } ////// Private helper to compare the level of the 3 enum fields. /// private bool EqualsLevel( MediaPermissionAudio audioLevel, MediaPermissionVideo videoLevel, MediaPermissionImage imageLevel ) { return ( ( _mediaPermissionAudio == audioLevel ) && ( _mediaPermissionVideo == videoLevel ) && ( _mediaPermissionImage == imageLevel ) ) ; } #endregion Private Methods // // Private fields: // private MediaPermissionAudio _mediaPermissionAudio ; private MediaPermissionVideo _mediaPermissionVideo ; private MediaPermissionImage _mediaPermissionImage ; } ////// Imperative attribute to create a MediaPermission. /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] sealed public class MediaPermissionAttribute : CodeAccessSecurityAttribute { //----------------------------------------------------- // // Constructors // //------------------------------------------------------ #region Constructors ////// Imperative attribute to create a MediaPermission. /// public MediaPermissionAttribute(SecurityAction action) : base(action) { } #endregion Constructors //----------------------------------------------------- // // Public Methods // //------------------------------------------------------ #region Public Methods ////// Create a MediaPermisison. /// public override IPermission CreatePermission() { if (Unrestricted) { return new MediaPermission(PermissionState.Unrestricted); } else { return new MediaPermission( _mediaPermissionAudio, _mediaPermissionVideo, _mediaPermissionImage ); } } #endregion Public Methods //------------------------------------------------------ // // Public Properties // //----------------------------------------------------- #region Public Properties ////// Current audio level. /// public MediaPermissionAudio Audio { get { return _mediaPermissionAudio ; } set { MediaPermission.VerifyMediaPermissionAudio(value); _mediaPermissionAudio = value; } } ////// Current Video level. /// public MediaPermissionVideo Video { get { return _mediaPermissionVideo ; } set { MediaPermission.VerifyMediaPermissionVideo(value); _mediaPermissionVideo = value; } } ////// Current Image level. /// public MediaPermissionImage Image { get { return _mediaPermissionImage ; } set { MediaPermission.VerifyMediaPermissionImage(value); _mediaPermissionImage = value; } } #endregion Public Properties // // Private fields: // private MediaPermissionAudio _mediaPermissionAudio ; private MediaPermissionVideo _mediaPermissionVideo ; private MediaPermissionImage _mediaPermissionImage ; } } // 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
- OleDbException.cs
- RegexFCD.cs
- Terminate.cs
- FileStream.cs
- PointAnimation.cs
- MessageDesigner.cs
- RectangleHotSpot.cs
- ListenerPerfCounters.cs
- MarshalDirectiveException.cs
- ValidatedControlConverter.cs
- EventLogPermissionAttribute.cs
- BulletChrome.cs
- ClientConfigurationHost.cs
- XmlnsPrefixAttribute.cs
- PeerNameRecordCollection.cs
- XslTransform.cs
- DataAccessor.cs
- SynchronizingStream.cs
- ZipIOBlockManager.cs
- ActionItem.cs
- CodeMethodInvokeExpression.cs
- GroupBoxDesigner.cs
- grammarelement.cs
- TableLayoutPanelDesigner.cs
- EdmProperty.cs
- MailBnfHelper.cs
- GridToolTip.cs
- StatusBarPanel.cs
- CurrentChangedEventManager.cs
- DownloadProgressEventArgs.cs
- FilteredDataSetHelper.cs
- WasAdminWrapper.cs
- XsltSettings.cs
- SessionPageStatePersister.cs
- XslCompiledTransform.cs
- AvTraceDetails.cs
- ByteConverter.cs
- ImageDesigner.cs
- ScrollContentPresenter.cs
- SoapSchemaMember.cs
- MaterializeFromAtom.cs
- IPEndPoint.cs
- RuntimeArgumentHandle.cs
- ToolStripItemClickedEventArgs.cs
- WindowsProgressbar.cs
- Event.cs
- DataTemplateKey.cs
- Html32TextWriter.cs
- TagMapInfo.cs
- StructuralType.cs
- Int64AnimationBase.cs
- InstanceNotReadyException.cs
- StringConcat.cs
- ModelPerspective.cs
- PkcsMisc.cs
- IISUnsafeMethods.cs
- MessageQuerySet.cs
- NullableDoubleSumAggregationOperator.cs
- CorrelationKeyCalculator.cs
- IApplicationTrustManager.cs
- XmlSchemaImport.cs
- XmlNodeChangedEventArgs.cs
- PolicyStatement.cs
- SoapAttributeAttribute.cs
- HitTestWithPointDrawingContextWalker.cs
- Thumb.cs
- _Connection.cs
- DataGridViewControlCollection.cs
- DynamicActivityProperty.cs
- Debug.cs
- CaseInsensitiveHashCodeProvider.cs
- DataGridViewCellMouseEventArgs.cs
- LogPolicy.cs
- FocusWithinProperty.cs
- PersonalizationStateInfo.cs
- CapabilitiesRule.cs
- AcceleratedTokenProvider.cs
- QilPatternFactory.cs
- WebConfigurationHostFileChange.cs
- SharedRuntimeState.cs
- CompositeTypefaceMetrics.cs
- KeyFrames.cs
- DescendantQuery.cs
- FormsAuthenticationUserCollection.cs
- LeftCellWrapper.cs
- ToolStripRenderer.cs
- PngBitmapDecoder.cs
- BuildProviderAppliesToAttribute.cs
- InvokeAction.cs
- TagMapInfo.cs
- SecurityResources.cs
- FacetChecker.cs
- InteropAutomationProvider.cs
- XmlSerializationWriter.cs
- AssemblyResourceLoader.cs
- DataGridAddNewRow.cs
- StreamingContext.cs
- DrawingServices.cs
- ElementInit.cs
- TextDecorationCollection.cs