示例#1
0
        /// <summary>
        /// Converts the given PrintTicket into Win32 DEVMODE.
        /// </summary>
        /// <param name="printTicket">MemoryStream containing the XML PrintTicket.</param>
        /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
        /// <param name="scope">scope that the input PrintTicket will be limited to</param>
        /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
        /// <exception cref="ObjectDisposedException">
        /// The PTProvider instance has already been disposed.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
        /// </exception>
        /// <exception cref="PrintQueueException">
        /// The PTProvider instance failed to convert the PrintTicket to a DEVMODE.
        /// </exception>
        public override byte[] ConvertPrintTicketToDevMode(MemoryStream printTicket,
                                                           BaseDevModeType baseType,
                                                           PrintTicketScope scope)
        {
            VerifyAccess();

            InternalPrintTicket ticket = (printTicket != null) ? new InternalPrintTicket(printTicket) : null;

            DevMode result = GetDEVMODE(baseType);

            DevModeFields supportedFields;
            WinSpoolPrinterCapabilities capabilities = GetCapabilities(result);

            try
            {
                supportedFields = capabilities.Fields;
            }
            finally
            {
                capabilities.Release();
            }

            PrintTicketToDevMode(result, ticket, scope, supportedFields);

            return(result.ByteData);
        }
        internal static byte[] InternalConvertPrintTicketToDevMode(PTProviderBase provider,
                                                                   PrintTicket printTicket,
                                                                   BaseDevModeType baseType,
                                                                   PrintTicketScope scope)
        {
            // Input PrinTicket can't be null.
            if (printTicket == null)
            {
                throw new ArgumentNullException(nameof(printTicket));
            }

            // Validate the base type value.
            if ((baseType != BaseDevModeType.UserDefault) &&
                (baseType != BaseDevModeType.PrinterDefault))
            {
                throw new ArgumentOutOfRangeException(nameof(baseType));
            }

            // Validate scope value.
            if ((scope != PrintTicketScope.PageScope) &&
                (scope != PrintTicketScope.DocumentScope) &&
                (scope != PrintTicketScope.JobScope))
            {
                throw new ArgumentOutOfRangeException(nameof(scope));
            }

            MemoryStream ptStream = printTicket.GetXmlStream();

            return(provider.ConvertPrintTicketToDevMode(ptStream, baseType, scope));
        }
示例#3
0
        /// <summary>
        /// Converts the given PrintTicket into Win32 DEVMODE.
        /// </summary>
        /// <param name="printTicket">The PrintTicket to be converted.</param>
        /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
        /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
        public byte[] ConvertPrintTicketToDevMode(PrintTicket printTicket,
                                                  BaseDevModeType baseType)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("PrintTicketManager");
            }

            return(PrintTicketConverter.InternalConvertPrintTicketToDevMode(_ptProvider,
                                                                            printTicket,
                                                                            baseType,
                                                                            PrintTicketScope.JobScope));
        }
        /// <summary>
        /// Converts the given PrintTicket into Win32 DEVMODE.
        /// </summary>
        /// <param name="printTicket">The PrintTicket to be converted.</param>
        /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
        /// <param name="scope">scope that the input PrintTicket will be limited to</param>
        /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
        /// <exception cref="ObjectDisposedException">
        /// The PrintTicketConverter instance has already been disposed.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="printTicket"/> parameter is null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The <paramref name="baseType"/> parameter is not one of the standard <see cref="BaseDevModeType"/> values.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The <paramref name="scope"/> parameter is not one of the standard <see cref="PrintTicketScope"/> values.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
        /// </exception>
        /// <exception cref="PrintQueueException">
        /// The PrintTicketConverter instance failed to convert the PrintTicket to a DEVMODE.
        /// </exception>
        public byte[] ConvertPrintTicketToDevMode(PrintTicket printTicket,
                                                  BaseDevModeType baseType,
                                                  PrintTicketScope scope)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("PrintTicketConverter");
            }

            //Check to insure that the PrintTicketConverter is being called from the same thread that instantiated it
            VerifyAccess();

            return(InternalConvertPrintTicketToDevMode(_ptProvider, printTicket, baseType, scope));
        }
示例#5
0
        ///<summary>
        /// Obtain a DEVMODE from a printer
        ///</summary>
        ///<param name="pHandle">Printer handle</param>
        ///<param name="baseType">Type of DEVMODE (printer default or user default)</param>
        ///<param name="devModeBytes">DEVMODE bytes</param>
        ///<returns>False if the call fails</returns>
        private DevMode GetDEVMODE(BaseDevModeType baseType)
        {
            DevMode result;

            switch (baseType)
            {
            case BaseDevModeType.PrinterDefault:
            {
                PRINTER_INFO_2 info = GetPrinterInfo2W();
                result = info.pDevMode;
                break;
            }

            case BaseDevModeType.UserDefault:
            {
                PRINTER_INFO_8_AND_9 info = GetPrinterInfo8Or9W(true);
                if (info.pDevMode != null)
                {
                    result = info.pDevMode;
                }
                else
                {
                    // No user default devmode, try the printer default, which is
                    // effectively the user default if their isn't a per user default
                    // overriding it.
                    result = GetDEVMODE(BaseDevModeType.PrinterDefault);
                }

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException("baseType");
            }
            }

            if (result == null)
            {
                throw new PrintSystemException();
            }

            return(result);
        }
示例#6
0
 /// <summary>
 /// Converts the given PrintTicket into Win32 DEVMODE.
 /// </summary>
 /// <param name="printTicket">MemoryStream containing the XML PrintTicket.</param>
 /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
 /// <param name="scope">scope that the input PrintTicket will be limited to</param>
 /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
 public abstract byte[] ConvertPrintTicketToDevMode(MemoryStream printTicket, BaseDevModeType baseType, PrintTicketScope scope);
示例#7
0
        /// <summary>
        /// Converts the given PrintTicket into Win32 DEVMODE.
        /// </summary>
        /// <param name="printTicket">MemoryStream containing the XML PrintTicket.</param>
        /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
        /// <param name="scope">scope that the input PrintTicket will be limited to</param>
        /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
        /// <exception cref="ObjectDisposedException">
        /// The PTProvider instance has already been disposed.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
        /// </exception>
        /// <exception cref="PrintQueueException">
        /// The PTProvider instance failed to convert the PrintTicket to a DEVMODE.
        /// </exception>
        /// <exception cref="PrintingNotSupportedException">
        /// Printing components are not installed on the client
        /// </exception>
        public override byte[] ConvertPrintTicketToDevMode(MemoryStream printTicket,
                                                           BaseDevModeType baseType,
                                                           PrintTicketScope scope)
        {
            VerifyAccess();

            uint   hResult  = 0;
            string errorMsg = null;

            IntPtr umDevMode = IntPtr.Zero;

            try
            {
                IStream printTicketStream = IStreamFromMemoryStream(printTicket);
                try
                {
                    uint umDevModeLen = 0;
                    hResult = UnsafeNativeMethods.PTConvertPrintTicketToDevMode(_providerHandle,
                                                                                printTicketStream,
                                                                                (uint)baseType,
                                                                                (uint)scope,
                                                                                out umDevModeLen,
                                                                                out umDevMode,
                                                                                out errorMsg);

                    if (PTUtility.IsSuccessCode(hResult))
                    {
                        byte[] devMode = new byte[umDevModeLen];
                        Marshal.Copy(umDevMode, devMode, 0, (int)umDevModeLen);
                        return(devMode);
                    }
                }
                finally
                {
                    DeleteIStream(ref printTicketStream);
                }
            }
            finally
            {
                if (umDevMode != IntPtr.Zero)
                {
                    UnsafeNativeMethods.PTReleaseMemory(new HandleRef(this, umDevMode));
                    umDevMode = IntPtr.Zero;
                }
            }

            if ((hResult == (uint)NativeErrorCode.E_XML_INVALID) ||
                (hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                                                          "{0} {1} {2}",
                                                          PrintSchemaTags.Framework.PrintTicketRoot,
                                                          PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
                                                          errorMsg),
                                            "printTicket");
            }

            throw new PrintQueueException((int)hResult,
                                          "PrintConfig.Provider.PT2DevModeFail",
                                          _deviceName,
                                          errorMsg);
        }
 /// <summary>
 /// Converts the given PrintTicket into Win32 DEVMODE.
 /// </summary>
 /// <param name="printTicket">The PrintTicket to be converted.</param>
 /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param>
 /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns>
 /// <exception cref="ObjectDisposedException">
 /// The PrintTicketConverter instance has already been disposed.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// The <paramref name="printTicket"/> parameter is null.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// The <paramref name="baseType"/> parameter is not one of the standard <see cref="BaseDevModeType"/> values.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// The PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
 /// </exception>
 /// <exception cref="PrintQueueException">
 /// The PrintTicketConverter instance failed to convert the PrintTicket to a DEVMODE.
 /// </exception>
 public byte[] ConvertPrintTicketToDevMode(PrintTicket printTicket,
                                           BaseDevModeType baseType)
 {
     return(ConvertPrintTicketToDevMode(printTicket, baseType, PrintTicketScope.JobScope));
 }