Esempio n. 1
0
        /// <param name="ticket"></param>
        /// <param name="ticketXMLString">If you wish to read/write to the cache,
        /// this must be set to the result of ticket.ToXmlString().
        /// This an optional performance enhancement.</param>
        private byte[] GetDevmode(PrintTicket ticket, String ticketXMLString)
        {
            Debug.Assert(ticket != null);

            // The cached devmode is not modified by internal printing code
            // and not exposed to client code so it is safe to pass the byte array
            // by reference instead of making a copy
            byte[] result = null;

            if (ticketXMLString != null && m_printTicketCache.TryGetDevMode(ticketXMLString, out result))
            {
            }
            // 10ms slowpath.
            else
            {
                Toolbox.EmitEvent(EventTrace.Event.WClientDRXGetDevModeBegin);

                (new PrintingPermission(PrintingPermissionLevel.DefaultPrinting)).Assert(); // BlessedAssert


                try
                {
                    result = ConvertPrintTicketToDevMode(ticket);

                    if (ticketXMLString != null)
                    {
                        m_printTicketCache.CacheDevMode(ticketXMLString, result);
                    }
                }
                finally
                {
                    PrintingPermission.RevertAssert();
                }

                Toolbox.EmitEvent(EventTrace.Event.WClientDRXGetDevModeEnd);
            }

            return(result);
        }