internal void Print(PrintDocument document)
 {
     PrintAction printToPreview;
     IntSecurity.SafePrinting.Demand();
     if (this.IsPreview)
     {
         printToPreview = PrintAction.PrintToPreview;
     }
     else
     {
         printToPreview = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
     }
     PrintEventArgs e = new PrintEventArgs(printToPreview);
     document._OnBeginPrint(e);
     if (e.Cancel)
     {
         document._OnEndPrint(e);
     }
     else
     {
         this.OnStartPrint(document, e);
         if (e.Cancel)
         {
             document._OnEndPrint(e);
             this.OnEndPrint(document, e);
         }
         else
         {
             bool flag = true;
             try
             {
                 flag = this.PrintLoop(document);
             }
             finally
             {
                 try
                 {
                     try
                     {
                         document._OnEndPrint(e);
                         e.Cancel = flag | e.Cancel;
                     }
                     finally
                     {
                         this.OnEndPrint(document, e);
                     }
                 }
                 finally
                 {
                     if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                     {
                         IntSecurity.AllPrinting.Assert();
                         document.PrinterSettings.PrintDialogDisplayed = false;
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        // WARNING: if you have nested PrintControllers, this method won't get called on the inner one.
        // Add initialization code to StartPrint or StartPage instead.
        internal void Print(PrintDocument document)
        {
            //
            // Get the PrintAction for this event
            PrintAction printAction;

            if (IsPreview)
            {
                printAction = PrintAction.PrintToPreview;
            }
            else
            {
                printAction = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs(printAction);

            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                return;
            }

            OnStartPrint(document, printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                OnEndPrint(document, printEvent);
                return;
            }

            bool canceled = true;

            try
            {
                // To enable optimization of the preview dialog, add the following to the config file:
                // <runtime >
                //     <!-- AppContextSwitchOverrides values are in the form of 'key1=true|false;key2=true|false  -->
                //     <AppContextSwitchOverrides value = "Switch.System.Drawing.Printing.OptimizePrintPreview=true" />
                // </runtime >
                canceled = LocalAppContextSwitches.OptimizePrintPreview ? PrintLoopOptimized(document) : PrintLoop(document);
            }
            finally
            {
                try
                {
                    document._OnEndPrint(printEvent);
                    printEvent.Cancel = canceled | printEvent.Cancel;
                }
                finally
                {
                    OnEndPrint(document, printEvent);
                }
            }
        }
        // WARNING: if you have nested PrintControllers, this method won't get called on the inner one.
        // Add initialization code to StartPrint or StartPage instead.
        internal void Print(PrintDocument document)
        {
            IntSecurity.SafePrinting.Demand();
            // Most of the printing security is left to the individual print controller

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs();

            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel)
            {
                return;
            }

            OnStartPrint(document, printEvent);
            bool canceled = true;

            try {
                canceled = PrintLoop(document);
            }
            finally {
                try {
                    try {
                        document._OnEndPrint(printEvent);
                        printEvent.Cancel = canceled | printEvent.Cancel;
                    }
                    finally {
                        OnEndPrint(document, printEvent);
                    }
                }
                finally {
                    if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                    {
                        // Ensure programs with SafePrinting only get to print once for each time they
                        // throw up the PrintDialog.
                        IntSecurity.AllPrinting.Assert();
                        document.PrinterSettings.PrintDialogDisplayed = false;
                    }
                }
            }
        }
Esempio n. 4
0
        internal void Print(PrintDocument document)
        {
            //IntSecurity.SafePrinting.Demand();
            // Most of the printing security is left to the individual print controller

            //
            // Get the PrintAction for this event
            PrintAction printAction;

            if (IsPreview)
            {
                printAction = PrintAction.PrintToPreview;
            }
            else
            {
                printAction = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs(printAction);

            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                return;
            }

            OnStartPrint(document, printEvent);
            if (printEvent.Cancel)
            {
                document._OnEndPrint(printEvent);
                OnEndPrint(document, printEvent);
                return;
            }

            bool canceled = true;

            try
            {
                // To enable optimization of the preview dialog, add the following to the config file:
                // <runtime >
                //     <!-- AppContextSwitchOverrides values are in the form of 'key1=true|false;key2=true|false  -->
                //     <AppContextSwitchOverrides value = "Switch.System.Drawing.Printing.OptimizePrintPreview=true" />
                // </runtime >
                //canceled = LocalAppContextSwitches.OptimizePrintPreview ? PrintLoopOptimized(document) : PrintLoop(document);
                canceled = PrintLoop(document);
            }
            finally
            {
                try
                {
                    try
                    {
                        document._OnEndPrint(printEvent);
                        printEvent.Cancel = canceled | printEvent.Cancel;
                    }
                    finally
                    {
                        OnEndPrint(document, printEvent);
                    }
                }
                finally
                {
                    //if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                    //{
                    // Ensure programs with SafePrinting only get to print once for each time they
                    // throw up the PrintDialog.
                    //IntSecurity.AllPrinting.Assert();
                    document.PrinterSettings.PrintDialogDisplayed = false;
                    //}
                }
            }
        }
Esempio n. 5
0
        internal void Print(PrintDocument document) {
            IntSecurity.SafePrinting.Demand();
            // Most of the printing security is left to the individual print controller

            //
            // Get the PrintAction for this event
            PrintAction printAction;
            if (IsPreview)
            {
                printAction = PrintAction.PrintToPreview;
            }
            else {
                printAction = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }

            // Check that user has permission to print to this particular printer
            PrintEventArgs printEvent = new PrintEventArgs(printAction);
            document._OnBeginPrint(printEvent);
            if (printEvent.Cancel) {
                document._OnEndPrint(printEvent);
                return;
            }

            OnStartPrint(document, printEvent);
            if (printEvent.Cancel) {
                document._OnEndPrint(printEvent);
                OnEndPrint(document, printEvent);
                return;
            }

            bool canceled = true;

            try {
                canceled = PrintLoop(document);
            }
            finally {
                try {
                    try {
                        document._OnEndPrint(printEvent);
                        printEvent.Cancel = canceled | printEvent.Cancel;
                    }
                    finally {
                        OnEndPrint(document, printEvent);
                    }
                }
                finally {
                    if (!IntSecurity.HasPermission(IntSecurity.AllPrinting)) {
                        // Ensure programs with SafePrinting only get to print once for each time they
                        // throw up the PrintDialog.
                        IntSecurity.AllPrinting.Assert();
                        document.PrinterSettings.PrintDialogDisplayed = false;
                    }
                }
            }
        }
        internal void Print(PrintDocument document)
        {
            PrintAction printToPreview;

            IntSecurity.SafePrinting.Demand();
            if (this.IsPreview)
            {
                printToPreview = PrintAction.PrintToPreview;
            }
            else
            {
                printToPreview = document.PrinterSettings.PrintToFile ? PrintAction.PrintToFile : PrintAction.PrintToPrinter;
            }
            PrintEventArgs e = new PrintEventArgs(printToPreview);

            document._OnBeginPrint(e);
            if (e.Cancel)
            {
                document._OnEndPrint(e);
            }
            else
            {
                this.OnStartPrint(document, e);
                if (e.Cancel)
                {
                    document._OnEndPrint(e);
                    this.OnEndPrint(document, e);
                }
                else
                {
                    bool flag = true;
                    try
                    {
                        flag = this.PrintLoop(document);
                    }
                    finally
                    {
                        try
                        {
                            try
                            {
                                document._OnEndPrint(e);
                                e.Cancel = flag | e.Cancel;
                            }
                            finally
                            {
                                this.OnEndPrint(document, e);
                            }
                        }
                        finally
                        {
                            if (!IntSecurity.HasPermission(IntSecurity.AllPrinting))
                            {
                                IntSecurity.AllPrinting.Assert();
                                document.PrinterSettings.PrintDialogDisplayed = false;
                            }
                        }
                    }
                }
            }
        }