コード例 #1
0
        private void HandleNewJobMessage(string message)
        {
            var newJobs = message.Split('|')
                          .Skip(1)
                          .Where(s => !string.IsNullOrWhiteSpace(s));

            foreach (var infFile in newJobs)
            {
                try
                {
                    _logger.Debug("NewJob found: " + infFile);
                    if (!File.Exists(infFile))
                    {
                        return;
                    }

                    _logger.Trace("The given file exists.");
                    var jobInfo = _jobInfoManager.ReadFromInfFile(infFile);
                    _jobInfoQueue.Add(jobInfo);
                }
                catch (Exception ex)
                {
                    _logger.Warn(ex, "There was an Exception while adding the print job: ");
                }
            }
        }
コード例 #2
0
        protected override bool StartApplication()
        {
            if (string.IsNullOrEmpty(NewJobInfoFile) || !File.Exists(NewJobInfoFile))
            {
                _logger.Error("No file in InfoDataFile argument or file does not exist.");
                return(false);
            }

            EnsureJobFileIsInSpoolPath();

            _logger.Debug("Adding new job");

            try
            {
                var jobInfo = _jobInfoManager.ReadFromInfFile(NewJobInfoFile);
                _jobInfoQueue.Add(jobInfo);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, $"Could not read the file '{NewJobInfoFile}'!");
                return(false);
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        ///     Creates a testpage in the spool folder and adds it to the JobInfoQueue
        /// </summary>
        public void CreateTestPage(string profile = "")
        {
            var tempPath = Path.Combine(_spoolFolder, Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempPath);

            var psFileContent = _testPageCreator.GetTestFileContent();
            var psFilePath    = Path.Combine(tempPath, "testpage.ps");

            File.WriteAllText(psFilePath, psFileContent);

            var infFileContent = _testPageCreator.GetInfFileContent("testpage.ps");
            var infFilePath    = Path.Combine(tempPath, "testpage.inf");

            File.WriteAllText(infFilePath, infFileContent, Encoding.Unicode);

            var testPageJob = _jobInfoManager.ReadFromInfFile(infFilePath);

            if (!string.IsNullOrEmpty(profile))
            {
                testPageJob.ProfileParameter = profile;
            }

            _jobInfoQueue.Add(testPageJob);
        }
コード例 #4
0
        public void AddFileToQueue(string path)
        {
            PathCheck(path);

            var fileExtension  = _pathSafe.GetExtension(path) ?? string.Empty;
            var legalFileTypes = new List <string> {
                ".ps", ".pdf"
            };

            fileExtension = fileExtension.ToLowerInvariant();
            if (!legalFileTypes.Contains(fileExtension))
            {
                throw new COMException("Only .ps and .pdf files can be directly added to the queue.");
            }

            var spoolFolder = _spoolerProvider.SpoolFolder;

            if (!_spoolFolderAccess.CanAccess())
            {
                throw new COMException("Accessing the spool folder failed.");
            }

            var isPdf      = fileExtension.EndsWith(".pdf");
            var fileHelper = isPdf ? _directConversionProvider.GetPdfConversion() : _directConversionProvider.GetPsConversion();

            var infFile = fileHelper.TransformToInfFile(path, spoolFolder);

            _jobInfoQueue.Add(_jobInfoManager.ReadFromInfFile(infFile));
        }
コード例 #5
0
        public void ConvertDirectly(IList <string> files, AppStartParameters appStartParameters = null)
        {
            var infFile = "";

            if (appStartParameters != null && appStartParameters.Merge)
            {
                infFile = _directConversionInfFileHelper.TransformToInfFileWithMerge(files, appStartParameters);
            }
            else
            {
                infFile = appStartParameters != null?
                          _directConversionInfFileHelper.TransformToInfFile(files.First(), appStartParameters) :
                              _directConversionInfFileHelper.TransformToInfFile(files.First());
            }

            if (string.IsNullOrEmpty(infFile))
            {
                return;
            }

            Logger.Debug("Adding new job.");
            var jobInfo = _jobInfoManager.ReadFromInfFile(infFile);

            _jobInfoQueue.Add(jobInfo);
        }
コード例 #6
0
        protected override bool StartApplication()
        {
            if (string.IsNullOrEmpty(NewInfFile))
            {
                return(false);
            }

            _logger.Debug("Adding new job.");
            var jobInfo = _jobInfoManager.ReadFromInfFile(NewInfFile);

            _jobInfoQueue.Add(jobInfo);

            return(true);
        }
コード例 #7
0
        public void ConvertDirectly(string file)
        {
            var infFile = _directConversionInfFileHelper.TransformToInfFile(file);

            if (string.IsNullOrEmpty(infFile))
            {
                return;
            }

            Logger.Debug("Adding new job.");
            var jobInfo = _jobInfoManager.ReadFromInfFile(infFile);

            _jobInfoQueue.Add(jobInfo);
        }
コード例 #8
0
 protected override bool StartApplication()
 {
     _logger.Debug("Adding new job");
     try
     {
         var jobInfo = _jobInfoManager.ReadFromInfFile(InfFile);
         _jobInfoQueue.Add(jobInfo);
         return(true);
     }
     catch (Exception ex)
     {
         _logger.Warn(ex, $"Could not read the file '{InfFile}'!");
         return(false);
     }
 }
コード例 #9
0
        protected override bool StartApplication()
        {
            if (NewInfFiles.Count <= 0)
            {
                return(false);
            }

            foreach (var infFile in NewInfFiles)
            {
                _logger.Debug("Adding new job.");
                var jobInfo = _jobInfoManager.ReadFromInfFile(infFile);
                _jobInfoQueue.Add(jobInfo);
            }

            return(true);
        }
コード例 #10
0
        private bool TryStartApplication(Func <bool> startApplication, bool startManagePrintJobs)
        {
            var success = false;

            try
            {
                _logger.Debug("Starting pipe server");

                success = _pipeServerManager.StartServer();

                if (!success)
                {
                    return(false);
                }

                _logger.Debug("Reloading settings");
                // Settings may have changed as this may have not been the only instance till now
                _settingsManager.LoadAllSettings();

                if (startManagePrintJobs)
                {
                    _jobInfoQueueManager.ManagePrintJobs();
                }

                _logger.Debug("Finding spooled jobs");

                var spooledJobs = _spooledJobFinder.GetJobs();
                _jobInfoQueue.Add(spooledJobs);

                success = startApplication();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "There was an error while starting the application");
                success = false;
                throw;
            }
            finally
            {
                if (!success)
                {
                    _pipeServerManager.Shutdown();
                }
            }
            return(success);
        }
コード例 #11
0
        public void AddFileToQueue(string path)
        {
            PathCheck(path);

            if (!_directConversionHelper.CanConvertDirectly(path))
            {
                throw new COMException("Only .ps and .pdf files can be directly added to the queue.");
            }

            if (!_spoolFolderAccess.CanAccess())
            {
                throw new COMException("Accessing the spool folder failed.");
            }

            var infFile = _directConversionInfFileHelper.TransformToInfFile(path, new AppStartParameters());

            _jobInfoQueue.Add(_jobInfoManager.ReadFromInfFile(infFile));
        }
コード例 #12
0
ファイル: TestPageHelper.cs プロジェクト: lorddev/PDFCreator
        /// <summary>
        ///     Creates a testpage in the spool folder and adds it to the JobInfoQueue
        /// </summary>
        public void CreateTestPage()
        {
            var tempPath = Path.Combine(_spoolFolder, Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempPath);

            var psFileContent = GetPsFileContent();
            var psFilePath    = Path.Combine(tempPath, "testpage.ps");

            File.WriteAllText(psFilePath, psFileContent);

            var infFileContent = GetInfFileContent();
            var infFilePath    = Path.Combine(tempPath, "testpage.inf");

            File.WriteAllText(infFilePath, infFileContent, Encoding.Unicode);

            var testPageJob = _jobInfoManager.ReadFromInfFile(infFilePath);

            _jobInfoQueue.Add(testPageJob);
        }
コード例 #13
0
        public void ConvertDirectly(string file)
        {
            if (!CanConvertDirectly(file))
            {
                return;
            }

            var converter = GetCorrectConverterForFile(file);

            var infFile = converter.TransformToInfFile(file, _settingsProvider.Settings.ApplicationSettings.PrimaryPrinter);

            if (string.IsNullOrWhiteSpace(infFile))
            {
                return;
            }

            var jobInfo = _jobInfoManager.ReadFromInfFile(infFile);

            _jobInfoQueue.Add(jobInfo);
        }
コード例 #14
0
        private void HandleNewJobMessage(string message)
        {
            var file = message.Substring(7);

            try
            {
                _logger.Debug("NewJob found: " + file);
                if (!File.Exists(file))
                {
                    return;
                }

                _logger.Trace("The given file exists.");
                var jobInfo = _jobInfoManager.ReadFromInfFile(file);
                _jobInfoQueue.Add(jobInfo);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "There was an Exception while adding the print job: ");
            }
        }
コード例 #15
0
        protected override bool StartApplication()
        {
            if (string.IsNullOrEmpty(NewJobInfoFile) || !File.Exists(NewJobInfoFile))
            {
                _logger.Error("No file in InfoDataFile argument or file does not exist.");
                return(false);
            }

            EnsureJobFileIsInSpoolPath();

            _logger.Debug("Adding new job");

            try
            {
                var jobInfo = _jobInfoManager.ReadFromInfFile(NewJobInfoFile);

                if (string.IsNullOrWhiteSpace(jobInfo.ProfileParameter) && string.IsNullOrWhiteSpace(jobInfo.OutputFileParameter))
                {
                    if (_parametersManager.HasPredefinedParameters())
                    {
                        var parameters = _parametersManager.GetAndResetParameters();
                        jobInfo.OutputFileParameter = parameters.Outputfile;
                        jobInfo.ProfileParameter    = parameters.Profile;
                    }
                }

                _jobInfoQueue.Add(jobInfo);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, $"Could not read the file '{NewJobInfoFile}'!");
                return(false);
            }

            return(true);
        }