示例#1
0
        public bool PrintReport(PrinterJob printerJob)
        {
            Logger.LogInfo(Message.PrintingPrintReport, printerJob.ReportType);
            var eventArgs = new PrintReportEventArgs(printerJob);

            try
            {
                PrintReportStarting.RaiseEvent(this, eventArgs);
                ExecutePrinterJob(printerJob);
                return(true);
            }
            catch (ThreadAbortException)
            {
                return(false);
            }
            catch (Exception ex)
            {
                if (ex is CupsFailureException)
                {
                    CancelJobs(_findPrinterName);
                    EnablePrinter(_findPrinterName);
                }
                Logger.LogError(Message.PrintingError, ex, printerJob.FilePath);
                return(false);
            }
            finally
            {
                PrintReportFinished.RaiseEvent(this, eventArgs);
            }
        }
示例#2
0
文件: Printing.cs 项目: nico-izo/KOIB
 public NextActivityKey CreateReport( 
     WorkflowExecutionContext context, ActivityParameterDictionary parameters)
 {
     _scannerManager.SetIndicator("Подготовка печати...");
     if (_printerJob == null)
     {
         _printerJob = _isPrinterRemote
                           ? _syncManager.RemoteScanner.CreateReport(ReportType, ReportParameters, CopiesNumber)
                           : _printingManager.CreateReport(ReportType, ReportParameters, CopiesNumber);
     }
     return _printerJob == null
                ? BpcNextActivityKeys.No     // если отчет так и не сформировался то ошибка
                : BpcNextActivityKeys.Yes;
 }
示例#3
0
文件: Printing.cs 项目: nico-izo/KOIB
 public NextActivityKey CheckGenerateNewReport(WorkflowExecutionContext context, ActivityParameterDictionary parameters)
 {
     if (_printerJob != null && (_printerJob.ReportType != ReportType || !NotGenerateNewReport))
         _printerJob = null;
     return context.DefaultNextActivityKey;
 }
示例#4
0
 private void ExecutePrinterJob(PrinterJob printerJob)
 {
     Logger.LogVerbose(Message.Common_DebugCall);
     const int WAIT_INTERVAL = 5;
     const int WAIT_END_PRINT = 3 * 60;
     if (PlatformDetector.IsUnix)
     {
         GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
         ProcessHelper.ExecCommand(_config.Commands.BeforePrinting);
         try
         {
             const string LP_CMD_ARGS_FORMAT =
                 "-o Resolution=300dpi -o Quality=Draft -o PrintQuality=Draft -o ColorModel=Black -n {{3}} " +
                 "-d {{0}} {0} {{2}}";
             var lpCmdArgsFormat = string.Format(
                 LP_CMD_ARGS_FORMAT, (_config.PrintByPage.Value ? "-P {1} " : ""));
             var process = new Process
                               {
                                   StartInfo =
                                       {
                                           FileName = "lp",
                                           CreateNoWindow = true,
                                           UseShellExecute = false
                                       }
                               };
             process.StartInfo.EnvironmentVariables["LANG"] = "en";
             process.StartInfo.EnvironmentVariables["LC_CTYPE"] = "en_US.iso885915";
             var pageCount = _config.PrintByPage.Value ? printerJob.PageCont : 1;
             for (var pageNum = 1; pageNum <= pageCount; ++pageNum)
             {
                 process.StartInfo.Arguments =
                     string.Format(lpCmdArgsFormat, _findPrinterName, pageNum, printerJob.FilePath,
                                   printerJob.Copies);
                 Logger.LogInfo(Message.PrintingStartPagePrint, pageNum, printerJob.FilePath, printerJob.Copies);
                 try
                 {
                     process.Start();
                 }
                 catch (Exception ex)
                 {
                     Logger.LogError(Message.PrintingError, ex, printerJob.FilePath);
                 }
                 process.WaitForExit();
                 Thread.Sleep(WAIT_INTERVAL * 1000);
                 var waitCounter = 1;
                 while (!IsPrinterIdle(_findPrinterName))
                 {
                     Thread.Sleep(WAIT_INTERVAL * 1000);
                     waitCounter++;
                     if (waitCounter * WAIT_INTERVAL > WAIT_END_PRINT)
                     {
                         throw new CupsFailureException("Истек таймаут ожидания выполнения печати " +
                                                        WAIT_END_PRINT);
                     }
                 }
             }
         }
         finally
         {
             ProcessHelper.ExecCommand(_config.Commands.AfterPrinting);
         }
     }
     else
     {
         Thread.Sleep(TimeSpan.FromSeconds(3));
         var process = new Process
                           {
                               StartInfo =
                                   {
                                       FileName = printerJob.FilePath,
                                       CreateNoWindow = true,
                                       UseShellExecute = true
                                   }
                           };
         process.Start();
     }
 }
示例#5
0
 public bool PrintReport(PrinterJob printerJob)
 {
     Logger.LogInfo(Message.PrintingPrintReport, printerJob.ReportType);
     var eventArgs = new PrintReportEventArgs(printerJob);
     try
     {
         PrintReportStarting.RaiseEvent(this, eventArgs);
         ExecutePrinterJob(printerJob);
         return true;
     }
     catch (ThreadAbortException)
     {
         return false;
     }
     catch (Exception ex)
     {
         if (ex is CupsFailureException)
         {
             CancelJobs(_findPrinterName);
             EnablePrinter(_findPrinterName);
         }
         Logger.LogError(Message.PrintingError, ex, printerJob.FilePath);
         return false;
     }
     finally
     {
         PrintReportFinished.RaiseEvent(this, eventArgs);
     }
 }
示例#6
0
        private void ExecutePrinterJob(PrinterJob printerJob)
        {
            Logger.LogVerbose(Message.Common_DebugCall);
            const int WAIT_INTERVAL  = 5;
            const int WAIT_END_PRINT = 3 * 60;

            if (PlatformDetector.IsUnix)
            {
                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                ProcessHelper.ExecCommand(_config.Commands.BeforePrinting);
                try
                {
                    const string LP_CMD_ARGS_FORMAT =
                        "-o Resolution=300dpi -o Quality=Draft -o PrintQuality=Draft -o ColorModel=Black -n {{3}} " +
                        "-d {{0}} {0} {{2}}";
                    var lpCmdArgsFormat = string.Format(
                        LP_CMD_ARGS_FORMAT, (_config.PrintByPage.Value ? "-P {1} " : ""));
                    var process = new Process
                    {
                        StartInfo =
                        {
                            FileName        = "lp",
                            CreateNoWindow  = true,
                            UseShellExecute = false
                        }
                    };
                    process.StartInfo.EnvironmentVariables["LANG"]     = "en";
                    process.StartInfo.EnvironmentVariables["LC_CTYPE"] = "en_US.iso885915";
                    var pageCount = _config.PrintByPage.Value ? printerJob.PageCont : 1;
                    for (var pageNum = 1; pageNum <= pageCount; ++pageNum)
                    {
                        process.StartInfo.Arguments =
                            string.Format(lpCmdArgsFormat, _findPrinterName, pageNum, printerJob.FilePath,
                                          printerJob.Copies);
                        Logger.LogInfo(Message.PrintingStartPagePrint, pageNum, printerJob.FilePath, printerJob.Copies);
                        try
                        {
                            process.Start();
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError(Message.PrintingError, ex, printerJob.FilePath);
                        }
                        process.WaitForExit();
                        Thread.Sleep(WAIT_INTERVAL * 1000);
                        var waitCounter = 1;
                        while (!IsPrinterIdle(_findPrinterName))
                        {
                            Thread.Sleep(WAIT_INTERVAL * 1000);
                            waitCounter++;
                            if (waitCounter * WAIT_INTERVAL > WAIT_END_PRINT)
                            {
                                throw new CupsFailureException("Истек таймаут ожидания выполнения печати " +
                                                               WAIT_END_PRINT);
                            }
                        }
                    }
                }
                finally
                {
                    ProcessHelper.ExecCommand(_config.Commands.AfterPrinting);
                }
            }
            else
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));
                var process = new Process
                {
                    StartInfo =
                    {
                        FileName        = printerJob.FilePath,
                        CreateNoWindow  = true,
                        UseShellExecute = true
                    }
                };
                process.Start();
            }
        }
示例#7
0
 public PrintReportEventArgs(PrinterJob printerJob)
 {
     CodeContract.Requires(printerJob != null);
     Job = printerJob;
 }
示例#8
0
 bool IScannerInteractionChannel.PrintReport(PrinterJob printerJob)
 {
     return _printingManager.PrintReport(printerJob);
 }
示例#9
0
 public PrintReportEventArgs(PrinterJob printerJob)
 {
     CodeContract.Requires(printerJob != null);
     Job = printerJob;
 }
示例#10
0
 public bool PrintReport(PrinterJob printerJob)
 {
     return _localScannerChannel.PrintReport(printerJob);
 }