예제 #1
0
        private void runServer()
        {
            while (!this.cancelToken.IsCancellationRequested)
            {
                string tempOutputFilePath;
                string tempPclPath;
                try
                {
                    this.logger.Invoke("Waiting for incoming job...");
                    tempPclPath = this.printJobReader.ReadJobToFile();
                    var jobProperties = PrintJobReader.GetProperties(tempPclPath);
                    this.logger.Invoke(String.Format("Converting PCL file to {0}...", this.conversionKind));
                    try
                    {
                        tempOutputFilePath = jobConverter.Convert(tempPclPath, this.conversionKind);
                    }
                    finally
                    {
                        this.logger.Invoke("Deleting temporary PCL file...");
                        File.Delete(tempPclPath);
                    }
                    if (this.postScriptPrinter == null)
                    {
                        continue;
                    }
                    // if we're here, then the user selected a printer to physically print to
                    this.logger.Invoke(String.Format("Color mode for job: {0}", jobProperties.ColorMode));
                    this.logger.Invoke(String.Format("Duplex/simplex mode for job: {0}", jobProperties.PlexMode));
                    string outputPrinterName;
                    if (!this.propertyMappings.TryGetValue(jobProperties, out outputPrinterName))
                    {
                        throw new InvalidOperationException("Unsupported print job properties");
                    }

                    this.logger.Invoke("Sending PostScript file to be printed...");
                    try
                    {
                        if (outputPrinterName == null)
                        {
                            this.logger.Invoke("ERROR: No printer selected for the print job's properties");
                        }
                        else
                        {
                            this.postScriptPrinter.Print(tempOutputFilePath, outputPrinterName, jobProperties.PlexMode);
                            this.logger.Invoke("Print job complete!");
                        }
                    }
                    finally
                    {
                        this.logger.Invoke("Deleting temporary PostScript file...");
                        File.Delete(tempOutputFilePath);
                    }
                }
                catch (OperationCanceledException) { }
                catch (Exception e)
                {
                    this.logger.Invoke(String.Format("EXCEPTION OCCURRED: {0}", e));
                }
            }
        }
예제 #2
0
        public Server(Action <string> logger, CancellationToken cancelToken, Configuration config)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            this.logger      = logger;
            this.cancelToken = cancelToken;
            this.config      = config;

            string programFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            this.jobConverter   = new JobConverter(this.logger, programFolder, this.config.OutputFolder);
            this.printJobReader = new PrintJobReader(this.logger, this.cancelToken);
            this.snmpAgent      = new SnmpPrinterAgent(this.logger);
            if (!this.config.VirtualOnly)
            {
                this.postScriptPrinter = new PostScriptPrinter(this.logger, programFolder, this.cancelToken);
                this.conversionKind    = JobConversionKind.PostScript;
            }
            else
            {
                this.conversionKind = JobConversionKind.Pdf;
            }
            this.createJobPropertyMappings();
        }
        public Server(Action<string> logger, CancellationToken cancelToken, Configuration config)
        {
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            this.logger = logger;
            this.cancelToken = cancelToken;
            this.config = config;

            string programFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            this.jobConverter = new JobConverter(this.logger, programFolder, this.config.OutputFolder);
            this.printJobReader = new PrintJobReader(this.logger, this.cancelToken);
            this.snmpAgent = new SnmpPrinterAgent(this.logger);
            if (!this.config.VirtualOnly)
            {
                this.postScriptPrinter = new PostScriptPrinter(this.logger, programFolder, this.cancelToken);
                this.conversionKind = JobConversionKind.PostScript;
            }
            else
            {
                this.conversionKind = JobConversionKind.Pdf;
            }
            this.createJobPropertyMappings();
        }