InvalidPrinterException.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CommonUI / System / Drawing / Printing / InvalidPrinterException.cs / 1 / InvalidPrinterException.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 */ 
namespace System.Drawing.Printing {
 
    using System.Diagnostics;
    using System;
    using System.Security;
    using System.Security.Permissions; 
    using System.Runtime.Serialization;
    using System.ComponentModel; 
    using System.Runtime.InteropServices; 
    using Microsoft.Win32;
 
    /// 
    /// 
    ///    
    ///       Represents 
    ///       the
    ///       exception that is thrown when trying to access a printer using invalid printer settings. 
    ///     
    /// 
    [Serializable()] 
    public class InvalidPrinterException : SystemException {
        private PrinterSettings settings;

        ///  
        /// 
        ///     
        ///       Initializes a new instance of the  class. 
        ///    
        ///  
        public InvalidPrinterException(PrinterSettings settings)
        : base(GenerateMessage(settings))
        {
            this.settings = settings; 
        }
 
        ///  
        protected InvalidPrinterException(SerializationInfo info, StreamingContext context) : base (info, context) {
            settings = (PrinterSettings)info.GetValue("settings", typeof(PrinterSettings)); 
        }

        /// 
        [SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)] 
        public override void GetObjectData(SerializationInfo info, StreamingContext context) {
            if (info==null) { 
                throw new ArgumentNullException("info"); 
            }
            IntSecurity.AllPrinting.Demand(); 
            info.AddValue("settings", settings);
            base.GetObjectData(info, context);
        }
 
        static string GenerateMessage(PrinterSettings settings) {
            if (settings.IsDefaultPrinter) { 
                return SR.GetString(SR.InvalidPrinterException_NoDefaultPrinter); 
            }
            else { 
                try {
                    return SR.GetString(SR.InvalidPrinterException_InvalidPrinter, settings.PrinterName);
                }
                catch (SecurityException) { 
                    return SR.GetString(SR.InvalidPrinterException_InvalidPrinter, SR.GetString(SR.CantTellPrinterName));
                } 
            } 
        }
    } 
}


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 */ 
namespace System.Drawing.Printing {
 
    using System.Diagnostics;
    using System;
    using System.Security;
    using System.Security.Permissions; 
    using System.Runtime.Serialization;
    using System.ComponentModel; 
    using System.Runtime.InteropServices; 
    using Microsoft.Win32;
 
    /// 
    /// 
    ///    
    ///       Represents 
    ///       the
    ///       exception that is thrown when trying to access a printer using invalid printer settings. 
    ///     
    /// 
    [Serializable()] 
    public class InvalidPrinterException : SystemException {
        private PrinterSettings settings;

        ///  
        /// 
        ///     
        ///       Initializes a new instance of the  class. 
        ///    
        ///  
        public InvalidPrinterException(PrinterSettings settings)
        : base(GenerateMessage(settings))
        {
            this.settings = settings; 
        }
 
        ///  
        protected InvalidPrinterException(SerializationInfo info, StreamingContext context) : base (info, context) {
            settings = (PrinterSettings)info.GetValue("settings", typeof(PrinterSettings)); 
        }

        /// 
        [SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)] 
        public override void GetObjectData(SerializationInfo info, StreamingContext context) {
            if (info==null) { 
                throw new ArgumentNullException("info"); 
            }
            IntSecurity.AllPrinting.Demand(); 
            info.AddValue("settings", settings);
            base.GetObjectData(info, context);
        }
 
        static string GenerateMessage(PrinterSettings settings) {
            if (settings.IsDefaultPrinter) { 
                return SR.GetString(SR.InvalidPrinterException_NoDefaultPrinter); 
            }
            else { 
                try {
                    return SR.GetString(SR.InvalidPrinterException_InvalidPrinter, settings.PrinterName);
                }
                catch (SecurityException) { 
                    return SR.GetString(SR.InvalidPrinterException_InvalidPrinter, SR.GetString(SR.CantTellPrinterName));
                } 
            } 
        }
    } 
}


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK