Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CommonUI / System / Drawing / Printing / PrintingPermission.cs / 1 / PrintingPermission.cs
/*
* Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
* Microsoft Confidential.
*/
namespace System.Drawing.Printing {
using System;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Runtime.Serialization;
using System.Reflection;
using System.Collections;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
///
///
/// Controls the ability to use the printer. This class cannot be inherited.
///
[Serializable]
public sealed class PrintingPermission : CodeAccessPermission, IUnrestrictedPermission {
private PrintingPermissionLevel printingLevel;
///
///
/// Initializes a new instance of the PrintingPermission class with either fully restricted
/// or unrestricted access, as specified.
///
public PrintingPermission(PermissionState state) {
if (state == PermissionState.Unrestricted) {
printingLevel = PrintingPermissionLevel.AllPrinting;
}
else if (state == PermissionState.None) {
printingLevel = PrintingPermissionLevel.NoPrinting;
}
else {
throw new ArgumentException(SR.GetString(SR.InvalidPermissionState));
}
}
///
///
/// [To be supplied.]
///
public PrintingPermission(PrintingPermissionLevel printingLevel) {
VerifyPrintingLevel(printingLevel);
this.printingLevel = printingLevel;
}
///
///
/// [To be supplied.]
///
public PrintingPermissionLevel Level {
get {
return printingLevel;
}
set {
VerifyPrintingLevel(value);
printingLevel = value;
}
}
private static void VerifyPrintingLevel(PrintingPermissionLevel level) {
if (level < PrintingPermissionLevel.NoPrinting || level > PrintingPermissionLevel.AllPrinting) {
throw new ArgumentException(SR.GetString(SR.InvalidPermissionLevel));
}
}
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//-----------------------------------------------------
///
///
/// Gets a
/// value indicating whether permission is unrestricted.
///
public bool IsUnrestricted() {
return printingLevel == PrintingPermissionLevel.AllPrinting;
}
//-----------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//-----------------------------------------------------
///
///
/// Determines whether the current permission object is a subset of
/// the specified permission.
///
public override bool IsSubsetOf(IPermission target) {
if (target == null) {
return printingLevel == PrintingPermissionLevel.NoPrinting;
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
return this.printingLevel <= operand.printingLevel;
}
///
///
/// Creates and returns a permission that is the intersection of the current
/// permission object and a target permission object.
///
public override IPermission Intersect(IPermission target) {
if (target == null) {
return null;
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
PrintingPermissionLevel isectLevels = printingLevel < operand.printingLevel ? printingLevel : operand.printingLevel;
if (isectLevels == PrintingPermissionLevel.NoPrinting)
return null;
else
return new PrintingPermission(isectLevels);
}
///
///
/// Creates a permission that is the union of the permission object
/// and the target parameter permission object.
///
public override IPermission Union(IPermission target) {
if (target == null) {
return this.Copy();
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
PrintingPermissionLevel isectLevels = printingLevel > operand.printingLevel ? printingLevel : operand.printingLevel;
if (isectLevels == PrintingPermissionLevel.NoPrinting)
return null;
else
return new PrintingPermission(isectLevels);
}
///
///
/// Creates and returns an identical copy of the current permission
/// object.
///
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")]
public override IPermission Copy() {
return new PrintingPermission(this.printingLevel);
}
///
///
/// Creates an XML encoding of the security object and its current
/// state.
///
public override SecurityElement ToXml() {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
securityElement.AddAttribute("version", "1");
if (!IsUnrestricted()) {
securityElement.AddAttribute("Level", Enum.GetName(typeof(PrintingPermissionLevel), printingLevel));
}
else {
securityElement.AddAttribute("Unrestricted", "true");
}
return securityElement;
}
///
///
/// Reconstructs a security object with a specified state from an XML
/// encoding.
///
[SuppressMessage("Microsoft.Performance", "CA1808:AvoidCallsThatBoxValueTypes")]
public override void FromXml(SecurityElement esd) {
if (esd == null) {
throw new ArgumentNullException("esd");
}
String className = esd.Attribute("class");
if (className == null || className.IndexOf(this.GetType().FullName) == -1) {
throw new ArgumentException(SR.GetString(SR.InvalidClassName));
}
String unrestricted = esd.Attribute("Unrestricted");
if (unrestricted != null && String.Equals(unrestricted, "true", StringComparison.OrdinalIgnoreCase))
{
printingLevel = PrintingPermissionLevel.AllPrinting;
return;
}
printingLevel = PrintingPermissionLevel.NoPrinting;
String printing = esd.Attribute("Level");
if (printing != null)
{
printingLevel = (PrintingPermissionLevel)Enum.Parse(typeof(PrintingPermissionLevel), printing);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/*
* Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
* Microsoft Confidential.
*/
namespace System.Drawing.Printing {
using System;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Runtime.Serialization;
using System.Reflection;
using System.Collections;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
///
///
/// Controls the ability to use the printer. This class cannot be inherited.
///
[Serializable]
public sealed class PrintingPermission : CodeAccessPermission, IUnrestrictedPermission {
private PrintingPermissionLevel printingLevel;
///
///
/// Initializes a new instance of the PrintingPermission class with either fully restricted
/// or unrestricted access, as specified.
///
public PrintingPermission(PermissionState state) {
if (state == PermissionState.Unrestricted) {
printingLevel = PrintingPermissionLevel.AllPrinting;
}
else if (state == PermissionState.None) {
printingLevel = PrintingPermissionLevel.NoPrinting;
}
else {
throw new ArgumentException(SR.GetString(SR.InvalidPermissionState));
}
}
///
///
/// [To be supplied.]
///
public PrintingPermission(PrintingPermissionLevel printingLevel) {
VerifyPrintingLevel(printingLevel);
this.printingLevel = printingLevel;
}
///
///
/// [To be supplied.]
///
public PrintingPermissionLevel Level {
get {
return printingLevel;
}
set {
VerifyPrintingLevel(value);
printingLevel = value;
}
}
private static void VerifyPrintingLevel(PrintingPermissionLevel level) {
if (level < PrintingPermissionLevel.NoPrinting || level > PrintingPermissionLevel.AllPrinting) {
throw new ArgumentException(SR.GetString(SR.InvalidPermissionLevel));
}
}
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//-----------------------------------------------------
///
///
/// Gets a
/// value indicating whether permission is unrestricted.
///
public bool IsUnrestricted() {
return printingLevel == PrintingPermissionLevel.AllPrinting;
}
//-----------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//-----------------------------------------------------
///
///
/// Determines whether the current permission object is a subset of
/// the specified permission.
///
public override bool IsSubsetOf(IPermission target) {
if (target == null) {
return printingLevel == PrintingPermissionLevel.NoPrinting;
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
return this.printingLevel <= operand.printingLevel;
}
///
///
/// Creates and returns a permission that is the intersection of the current
/// permission object and a target permission object.
///
public override IPermission Intersect(IPermission target) {
if (target == null) {
return null;
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
PrintingPermissionLevel isectLevels = printingLevel < operand.printingLevel ? printingLevel : operand.printingLevel;
if (isectLevels == PrintingPermissionLevel.NoPrinting)
return null;
else
return new PrintingPermission(isectLevels);
}
///
///
/// Creates a permission that is the union of the permission object
/// and the target parameter permission object.
///
public override IPermission Union(IPermission target) {
if (target == null) {
return this.Copy();
}
PrintingPermission operand = target as PrintingPermission;
if(operand == null) {
throw new ArgumentException(SR.GetString(SR.TargetNotPrintingPermission));
}
PrintingPermissionLevel isectLevels = printingLevel > operand.printingLevel ? printingLevel : operand.printingLevel;
if (isectLevels == PrintingPermissionLevel.NoPrinting)
return null;
else
return new PrintingPermission(isectLevels);
}
///
///
/// Creates and returns an identical copy of the current permission
/// object.
///
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")]
public override IPermission Copy() {
return new PrintingPermission(this.printingLevel);
}
///
///
/// Creates an XML encoding of the security object and its current
/// state.
///
public override SecurityElement ToXml() {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
securityElement.AddAttribute("version", "1");
if (!IsUnrestricted()) {
securityElement.AddAttribute("Level", Enum.GetName(typeof(PrintingPermissionLevel), printingLevel));
}
else {
securityElement.AddAttribute("Unrestricted", "true");
}
return securityElement;
}
///
///
/// Reconstructs a security object with a specified state from an XML
/// encoding.
///
[SuppressMessage("Microsoft.Performance", "CA1808:AvoidCallsThatBoxValueTypes")]
public override void FromXml(SecurityElement esd) {
if (esd == null) {
throw new ArgumentNullException("esd");
}
String className = esd.Attribute("class");
if (className == null || className.IndexOf(this.GetType().FullName) == -1) {
throw new ArgumentException(SR.GetString(SR.InvalidClassName));
}
String unrestricted = esd.Attribute("Unrestricted");
if (unrestricted != null && String.Equals(unrestricted, "true", StringComparison.OrdinalIgnoreCase))
{
printingLevel = PrintingPermissionLevel.AllPrinting;
return;
}
printingLevel = PrintingPermissionLevel.NoPrinting;
String printing = esd.Attribute("Level");
if (printing != null)
{
printingLevel = (PrintingPermissionLevel)Enum.Parse(typeof(PrintingPermissionLevel), printing);
}
}
}
}
// 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
- ItemContainerProviderWrapper.cs
- MetricEntry.cs
- Expression.cs
- MenuCommandService.cs
- DataTableReader.cs
- EntityDataSourceWrapper.cs
- ExceptionRoutedEventArgs.cs
- SmiEventStream.cs
- TdsRecordBufferSetter.cs
- ParserContext.cs
- QilInvokeLateBound.cs
- WsdlInspector.cs
- ObjectDataSourceFilteringEventArgs.cs
- FontStyles.cs
- SecurityUtils.cs
- safesecurityhelperavalon.cs
- ListSortDescriptionCollection.cs
- OleDbSchemaGuid.cs
- UniqueIdentifierService.cs
- XmlBaseReader.cs
- CompilationLock.cs
- WinFormsComponentEditor.cs
- DragSelectionMessageFilter.cs
- XmlCompatibilityReader.cs
- EventLogEntryCollection.cs
- DataGridViewImageColumn.cs
- RadioButtonRenderer.cs
- Utils.cs
- AnnotationResource.cs
- EntitySqlQueryBuilder.cs
- DataGridRow.cs
- MimeMultiPart.cs
- FontDriver.cs
- QueryConverter.cs
- ImageClickEventArgs.cs
- AppDomainResourcePerfCounters.cs
- HtmlToClrEventProxy.cs
- AttributeCollection.cs
- DbXmlEnabledProviderManifest.cs
- HtmlShimManager.cs
- FontSizeConverter.cs
- VoiceSynthesis.cs
- SystemParameters.cs
- DeadLetterQueue.cs
- TogglePattern.cs
- Baml2006SchemaContext.cs
- ContextDataSourceView.cs
- DrawingBrush.cs
- LostFocusEventManager.cs
- ExpressionNormalizer.cs
- VScrollProperties.cs
- OracleBFile.cs
- CommandBindingCollection.cs
- IsolatedStorage.cs
- SystemColorTracker.cs
- SamlConditions.cs
- CounterCreationData.cs
- CompositeCollectionView.cs
- RuntimeArgumentHandle.cs
- Oid.cs
- PassportPrincipal.cs
- ListViewCommandEventArgs.cs
- SettingsAttributes.cs
- RelationshipEndMember.cs
- Run.cs
- WindowsFormsHost.cs
- ErrorTolerantObjectWriter.cs
- FontStyle.cs
- CompositionCommandSet.cs
- XmlEncodedRawTextWriter.cs
- SqlUserDefinedTypeAttribute.cs
- EventMappingSettings.cs
- CngKeyBlobFormat.cs
- ResourceContainer.cs
- AsymmetricSignatureFormatter.cs
- ScriptMethodAttribute.cs
- XPathNavigator.cs
- WSTrustDec2005.cs
- DesignBindingConverter.cs
- DispatcherOperation.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- CacheChildrenQuery.cs
- CaretElement.cs
- TextEffectCollection.cs
- QueryCreatedEventArgs.cs
- LocalizedNameDescriptionPair.cs
- Interlocked.cs
- OLEDB_Util.cs
- NameValueConfigurationCollection.cs
- SmtpMail.cs
- StringFreezingAttribute.cs
- AutomationIdentifier.cs
- SqlVersion.cs
- TypeForwardedToAttribute.cs
- MouseBinding.cs
- XmlEnumAttribute.cs
- DbSourceParameterCollection.cs
- ProcessHostServerConfig.cs
- WriteTimeStream.cs
- base64Transforms.cs