Exemplo n.º 1
0
        public CmdLine Parse(string fullPath, string printerName, short duplexMode)
        {
            int     successExitCode;
            bool    successExitCodeSpecified = SuccessExitCode(out successExitCode);
            string  arguments = Arguments(fullPath, printerName, duplexMode);
            CmdLine cmdLine   = new CmdLine(Path, Name, arguments, successExitCodeSpecified, successExitCode);

            return(cmdLine);
        }
Exemplo n.º 2
0
        private void HandleCmdLineTimedOut(string fullPath, ArrayList queueSorted, CmdLine cmdLine, int timeoutInMinutes, FileManifest fileManifest)
        {
            MoveDocumentToFailed(fullPath, fileManifest);
            RemoveDocumentFromQueues(fullPath, queueSorted);

            string message = string.Format("{0} timed out after {1} minutes.\nDocument {2} has been moved to the failed documents folder",
                                           cmdLine.ExecutableFullName, timeoutInMinutes, fullPath);

            m_Utils.WriteEventLogEntry(message, EventLogEntryType.Error, Utils.EVENT_LOG_SOURCE);
        }
Exemplo n.º 3
0
        private void HandleCmdLine(string fullPath, ArrayList queueSorted, CmdLine cmdLine, int exitCode, FileManifest fileManifest)
        {
            bool handleAsSuccess = !cmdLine.SuccessExitCodeSpecified || exitCode == cmdLine.SuccessExitCode;

            if (handleAsSuccess)
            {
                MoveDocumentToPrinted(fullPath, fileManifest);
                RemoveDocumentFromQueues(fullPath, queueSorted);
            }
            else
            {
                MoveDocumentToFailed(fullPath, fileManifest);
                RemoveDocumentFromQueues(fullPath, queueSorted);

                string message = string.Format("{0} returned exit code {1} (success exit code is specified as {2})\nDocument {3} has been moved to the failed documents folder",
                                               cmdLine.ExecutableFullName, exitCode.ToString(), cmdLine.SuccessExitCode.ToString(), fullPath);
                m_Utils.WriteEventLogEntry(message, EventLogEntryType.Error, Utils.EVENT_LOG_SOURCE);
            }
        }
Exemplo n.º 4
0
        private void PrintFile(string fullPath, ArrayList queueSorted, ref bool firstAttempt, FileManifest fileManifest)
        {
            SetCurrentPrintFile(fullPath);

            AlterXFDF(fullPath);

            string printerName  = m_Utils.ReadPrinterName(fileManifest);
            short  duplexMode   = m_Utils.ReadPrintOnBothSides(fileManifest);
            bool   runAsService = m_Utils.ReadRunAsService();

            string  cmdLineString = m_Utils.ReadCmdLine();
            CmdLine cmdLine       = null;

            if (!string.IsNullOrEmpty(cmdLineString))
            {
                cmdLine = ParseCmdLine(fullPath, printerName, duplexMode, cmdLineString);
            }

            if (cmdLine != null && cmdLine.RunAsFireAndForget)
            {
                PrintOrOtherwiseHandleFileUsingFireAndForgetCmdLine(cmdLine, runAsService, fullPath, queueSorted, fileManifest);
            }
            else
            {
                SetAdobeAcrobatReaderDefaults();
                if (runAsService)
                {
                    PrintFileUsingDppPrint(fullPath, printerName, duplexMode, queueSorted, ref firstAttempt, fileManifest);
                }
                else
                {
                    PrintFileUsingAdobeReader(fullPath, queueSorted, fileManifest);
                }

                ReSetAdobeAcrobatReaderDefaults();
            }

            SetCurrentPrintFile(null);
        }
Exemplo n.º 5
0
        private void PrintOrOtherwiseHandleFileUsingFireAndForgetCmdLine(CmdLine cmdLine, bool runAsService, string fullPath, ArrayList queueSorted, FileManifest fileManifest)
        {
            int  timeoutInMinutes = m_Utils.ReadTimeout();
            bool timedOut         = false;
            bool showErrorDialog  = !runAsService;
            int  exitCode         = 0;

            try
            {
                lock (this)
                {
                    m_processCmdLine = new Process();

                    m_processCmdLine.StartInfo.FileName  = cmdLine.ExecutableFullName;
                    m_processCmdLine.StartInfo.Arguments = cmdLine.Arguments;

                    m_processCmdLine.StartInfo.UseShellExecute  = true;
                    m_processCmdLine.StartInfo.WorkingDirectory = m_strPrintDirectory;
                    m_processCmdLine.StartInfo.CreateNoWindow   = true;
                    m_processCmdLine.StartInfo.ErrorDialog      = showErrorDialog;

                    if (logAllEvents)
                    {
                        string message = string.Format("Launching command line: {0} {1} in folder {2}",
                                                       m_processCmdLine.StartInfo.FileName, m_processCmdLine.StartInfo.Arguments, m_strPrintDirectory);
                        m_Utils.WriteEventLogEntry(message, EventLogEntryType.Information, Utils.EVENT_LOG_SOURCE);
                    }

                    m_processCmdLine.Start();
                    m_processAborted = false;
                }

                if (timeoutInMinutes == 0)
                {
                    //No timeout.
                    m_processCmdLine.WaitForExit();
                    exitCode = m_processCmdLine.ExitCode;
                }
                else if (!m_processCmdLine.WaitForExit(timeoutInMinutes * 60000))
                {
                    timedOut = true;
                    m_processCmdLine.Kill();
                    m_processCmdLine.WaitForExit(timeoutInMinutes * 60000);
                }
                else
                {
                    exitCode = m_processCmdLine.ExitCode;
                }

                if (!m_processAborted)
                {
                    if (timedOut)
                    {
                        HandleCmdLineTimedOut(fullPath, queueSorted, cmdLine, timeoutInMinutes, fileManifest);
                    }
                    else
                    {
                        HandleCmdLine(fullPath, queueSorted, cmdLine, exitCode, fileManifest);
                    }
                }
            }
            finally
            {
                lock (this)
                {
                    if (m_processCmdLine != null)
                    {
                        m_processCmdLine.Dispose();
                        m_processCmdLine = null;
                    }
                }
            }
        }