PrtCap_Public.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / PrintConfig / PrtCap_Public.cs / 1 / PrtCap_Public.cs

                            /*++ 

Copyright (C) 2003-2005 Microsoft Corporation
All rights reserved.
 
Module Name:
 
    PrtCap_Public.cs 

Abstract: 

    Definition and implementation of public PrintCapabilities class.

Author: 

    [....] ([....]) 06/22/2003 
 
--*/
 
using System;
using System.IO;
using System.Xml;
using System.Collections; 
using System.Reflection;
using System.Runtime.InteropServices; 
using System.Diagnostics; 
using System.Globalization;
 
using System.Printing;
using MS.Internal.Printing.Configuration;

namespace MS.Internal.Printing.Configuration 
{
    ///  
    /// Represents a device's printing capabilities. 
    /// 
    internal class InternalPrintCapabilities 
    {
        #region Constructors

        ///  
        /// Constructs a new instance of the InternalPrintCapabilities class with capabilities based on the XML form of PrintCapabilities.
        ///  
        /// Stream object containing the XML form of PrintCapabilities. 
        /// 
        /// The  parameter is null. 
        /// 
        /// 
        /// The stream object specified by  parameter doesn't contain a well-formed XML PrintCapabilities.
        /// The exception object's  property describes why the XML is not well-formed. And if not 
        /// null, the exception object's  property provides more details.
        ///  
        public InternalPrintCapabilities(Stream xmlStream) 
        {
            // Verify input parameter 
            if (xmlStream == null)
            {
                throw new ArgumentNullException("xmlStream");
            } 

            #if _DEBUG 
            // Direct Trace output to console 
            Trace.Listeners.Clear();
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); 
            #endif

            // Calculate the read-only counter values (this rely on the internal rules listed at
            // PrintSchema.Features type) 
            _countRootFeatures = Enum.GetNames(typeof(CapabilityName)).Length;
            _countLocalParamDefs = Enum.GetNames(typeof(PrintSchemaLocalParameterDefs)).Length; 
 
            try
            { 
                // Construct a builder instance
                _builder = new PrintCapBuilder(xmlStream);

                // Construct the feature and local-parameter arrays. 
                // (all elements should be null at this stage)
                _pcRootFeatures = new object[_countRootFeatures]; 
                _pcLocalParamDefs = new ParameterDefinition[_countLocalParamDefs]; 
                _baLocalParamRequired = new bool[_countLocalParamDefs];
                for (int i=0; i<_countLocalParamDefs; i++) 
                {
                    _baLocalParamRequired[i] = false;
                }
 
                // Ask the builder to populate the PrintCapabilities object states
                _builder.Build(this); 
 
                // Populate aggregated states based on builder's result
                PostBuildProcessing(); 
            }
            catch (XmlException e)
            {
                // Translate XMLException into FormatException so client only needs 
                // to catch FormatException for non-well-formed XML PrintCapabilities (the non-well-formness
                // could be either non-well-formed raw XML or non-well-formed PrintCapabilities content). 
                throw NewPrintCapFormatException(e.Message, e); 
            }
 
            // Notice we are not catching FormatException here, so it will surface to the client.
            // (Only the PrintCapBuilder constructor should throw FormatException for invalid PrintCapabilities
            // root element)
        } 

        #endregion Constructors 
 
        #region Public Methods
 
        /// 
        /// Gets a Boolean value indicating whether the device supports a specific capability.
        /// 
        /// Capability feature to check for device support. 
        /// True if the capability is supported. False otherwise.
        ///  
        /// The  parameter is not a standard feature defined in . 
        /// 
        public bool SupportsCapability(CapabilityName feature) 
        {
            // Verify input parameter
            if (feature < PrintSchema.CapabilityNameEnumMin ||
                feature > PrintSchema.CapabilityNameEnumMax) 
            {
                throw new ArgumentOutOfRangeException("feature"); 
            } 

            return (_pcRootFeatures[(int)feature] != null); 
        }

        #endregion Public Methods
 
        #region Public Properties
 
        ///  
        /// Gets a  object that specifies the device's document collate capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public DocumentCollateCapability DocumentCollateCapability
        { 
            get 
            {
                return (DocumentCollateCapability)_pcRootFeatures[(int)CapabilityName.DocumentCollate]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's job duplex capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public JobDuplexCapability JobDuplexCapability
        {
            get 
            {
                return (JobDuplexCapability)_pcRootFeatures[(int)CapabilityName.JobDuplex]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's job NUp capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public JobNUpCapability JobNUpCapability
        { 
            get
            {
                return (JobNUpCapability)_pcRootFeatures[(int)CapabilityName.JobNUp];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's job output stapling capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public JobStapleCapability JobStapleCapability
        { 
            get 
            {
                return (JobStapleCapability)_pcRootFeatures[(int)CapabilityName.JobStaple]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's page device font substitution capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public PageDeviceFontSubstitutionCapability PageDeviceFontSubstitutionCapability
        {
            get 
            {
                return (PageDeviceFontSubstitutionCapability)_pcRootFeatures[(int)CapabilityName.PageDeviceFontSubstitution]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's page media size capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public PageMediaSizeCapability PageMediaSizeCapability
        { 
            get
            {
                return (PageMediaSizeCapability)_pcRootFeatures[(int)CapabilityName.PageMediaSize];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's page media type capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public PageMediaTypeCapability PageMediaTypeCapability
        { 
            get 
            {
                return (PageMediaTypeCapability)_pcRootFeatures[(int)CapabilityName.PageMediaType]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's page orientation capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public PageOrientationCapability PageOrientationCapability
        {
            get 
            {
                return (PageOrientationCapability)_pcRootFeatures[(int)CapabilityName.PageOrientation]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's page output color capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public PageOutputColorCapability PageOutputColorCapability
        { 
            get
            {
                return (PageOutputColorCapability)_pcRootFeatures[(int)CapabilityName.PageOutputColor];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's page resolution capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public PageResolutionCapability PageResolutionCapability
        { 
            get 
            {
                return (PageResolutionCapability)_pcRootFeatures[(int)CapabilityName.PageResolution]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's page scaling capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public PageScalingCapability PageScalingCapability
        {
            get 
            {
                return (PageScalingCapability)_pcRootFeatures[(int)CapabilityName.PageScaling]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's page TrueType font handling mode capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public PageTrueTypeFontModeCapability PageTrueTypeFontModeCapability
        { 
            get
            {
                return (PageTrueTypeFontModeCapability)_pcRootFeatures[(int)CapabilityName.PageTrueTypeFontMode];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's job page ordering capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public JobPageOrderCapability JobPageOrderCapability
        { 
            get 
            {
                return (JobPageOrderCapability)_pcRootFeatures[(int)CapabilityName.JobPageOrder]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's page photo printing intent capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public PagePhotoPrintingIntentCapability PagePhotoPrintingIntentCapability
        {
            get 
            {
                return (PagePhotoPrintingIntentCapability)_pcRootFeatures[(int)CapabilityName.PagePhotoPrintingIntent]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's page borderless capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public PageBorderlessCapability PageBorderlessCapability
        { 
            get
            {
                return (PageBorderlessCapability)_pcRootFeatures[(int)CapabilityName.PageBorderless];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's page output quality capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public PageOutputQualityCapability PageOutputQualityCapability
        { 
            get 
            {
                return (PageOutputQualityCapability)_pcRootFeatures[(int)CapabilityName.PageOutputQuality]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's job input bins capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public JobInputBinCapability JobInputBinCapability
        {
            get 
            {
                return (JobInputBinCapability)_pcRootFeatures[(int)CapabilityName.JobInputBin]; 
            } 
        }
 
        /// 
        /// Gets a  object that specifies the device's document input bins capability.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public DocumentInputBinCapability DocumentInputBinCapability
        { 
            get
            {
                return (DocumentInputBinCapability)_pcRootFeatures[(int)CapabilityName.DocumentInputBin];
            } 
        }
 
        ///  
        /// Gets a  object that specifies the device's page input bins capability.
        ///  
        /// 
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference.
        ///  
        public PageInputBinCapability PageInputBinCapability
        { 
            get 
            {
                return (PageInputBinCapability)_pcRootFeatures[(int)CapabilityName.PageInputBin]; 
            }
        }

        ///  
        /// Gets a  object that specifies the device's job copy count capability.
        ///  
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        /// 
        public JobCopyCountCapability JobCopyCountCapability
        {
            get 
            {
                return (JobCopyCountCapability)_pcRootFeatures[(int)CapabilityName.JobCopyCount]; 
            } 
        }
 
        /// 
        /// Gets a  object that describes the imaged canvas for layout and rendering.
        /// 
        ///  
        /// If the device doesn't support this capability, null reference will be returned.
        /// You should use  to check the capability is supported before accessing the returned reference. 
        ///  
        public ImageableSizeCapability PageImageableSizeCapability
        { 
            get
            {
                return (ImageableSizeCapability)_pcRootFeatures[(int)CapabilityName.PageImageableSize];
            } 
        }
 
        #endregion Public Properties 

        #region Internal Methods 

        /// 
        /// Returns a new FormatException instance for not-well-formed PrintCapabilities XML.
        ///  
        /// detailed message about the violation of well-formness
        /// the new FormatException instance 
        internal static FormatException NewPrintCapFormatException(string detailMsg) 
        {
            return NewPrintCapFormatException(detailMsg, null); 
        }

        /// 
        /// Returns a new FormatException instance for not-well-formed PrintCapabilities XML. 
        /// 
        /// detailed message about the violation of well-formness 
        /// the exception that causes the violation of well-formness 
        /// the new FormatException instance
        internal static FormatException NewPrintCapFormatException(string detailMsg, Exception innerException) 
        {
            return new FormatException(String.Format(CultureInfo.CurrentCulture,
                                                     "{0} {1} {2}",
                                                     PrintSchemaTags.Framework.PrintCapRoot, 
                                                     PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
                                                     detailMsg), 
                                       innerException); 
        }
 
        internal void SetLocalParameterDefAsRequired(int paramDefIndex, bool isRequired)
        {
            _baLocalParamRequired[paramDefIndex] = isRequired;
        } 

        #endregion internal Methods 
 
        #region Internal Fields
 
        // array of Print Capabilities features (feature or global-parameter-def or root-level property)
        internal object[]              _pcRootFeatures;

        // array of Print Capabilities local parameter definitions 
        internal ParameterDefinition[] _pcLocalParamDefs;
 
        #endregion Internal Fields 

        #region Private Methods 

        /// 
        /// Post-process states populated by the builder and populate aggregates states
        ///  
        /// thrown if XML PrintCapabilities is not well-formed
        private void PostBuildProcessing() 
        { 
            for (int i=0; i<_countLocalParamDefs; i++)
            { 
                if (_baLocalParamRequired[i])
                {
                    // If a parameter definition has be referenced, then the parameter definition must be present in the XML.
                    if (_pcLocalParamDefs[i] == null) 
                    {
                        throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, 
                                                                       PTUtility.GetTextFromResource("FormatException.ParameterDefMissOrInvalid"), 
                                                                       PrintSchemaTags.Framework.ParameterDef,
                                                                       (PrintSchemaLocalParameterDefs)i)); 
                    }
                }
            }
        } 

        #endregion Private Methods 
 
        #region Private Fields
 
        // number of root features
        private readonly int _countRootFeatures;

        // number of local parameter definitions 
        private readonly int _countLocalParamDefs;
 
        // array of Boolean values to indicate whether a local parameter-def is required or not 
        private bool[] _baLocalParamRequired;
 
        private PrintCapBuilder _builder;

        #endregion Private Fields
    } 
}

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

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