示例#1
0
        /// <summary>
        ///     Check if Ghostscript is installed with a given version. It does a lookup in the registry and checks if the paths
        ///     exist.
        /// </summary>
        /// <param name="version">Name of the version to check, i.e. "9.05"</param>
        /// <returns>A GhostscriptVersion object if a version has been found, null otherwise</returns>
        private GhostscriptVersion IsGhostscriptInstalled(string version)
        {
            try
            {
                IRegistryKey myKey = _registry.LocalMachine.OpenSubKey(RegistryPath + "\\" + version);
                if (myKey == null)
                {
                    return(null);
                }

                var gsDll = (string)myKey.GetValue("GS_DLL");
                var gsLib = (string)myKey.GetValue("GS_LIB");

                var gsExe = _pathSafe.Combine(_pathSafe.GetDirectoryName(gsDll), "gswin32c.exe");

                myKey.Close();
                if (_file.Exists(gsExe))
                {
                    return(new GhostscriptVersion(version, gsExe, gsLib));
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        ///     Calls the script
        /// </summary>
        /// <param name="job">The current job</param>
        /// <returns>An ActionResult to determine the success and a list of errors</returns>
        public ActionResult ProcessJob(Job job)
        {
            _logger.Debug("Launched Script-Action");

            ApplyPreSpecifiedTokens(job);
            var actionResult = Check(job.Profile, job.Accounts, CheckLevel.Job);

            if (!actionResult)
            {
                return(actionResult);
            }

            var scriptFile = job.Profile.Scripting.ScriptFile;

            _logger.Debug("Script-File: " + scriptFile);

            IProcess process = _processStarter.CreateProcess(scriptFile);

            var parameters = ComposeScriptParameters(job.Profile.Scripting.ParameterString, job.OutputFiles, job.TokenReplacer);

            process.StartInfo.Arguments = parameters;
            _logger.Debug("Script-Parameters: " + parameters);

            var scriptDir = _pathSafe.GetDirectoryName(scriptFile);

            if (scriptDir != null)
            {
                process.StartInfo.WorkingDirectory = scriptDir;
            }

            _logger.Debug("Script-Working Directory: " + scriptDir);

            process.EnableRaisingEvents = true;
            process.Exited += (sender, args) => process.Close();

            try
            {
                _logger.Debug("Launching script...");
                process.Start();

                if (job.Profile.Scripting.WaitForScript)
                {
                    _logger.Debug("Waiting for script to end");
                    process.WaitForExit();
                    _logger.Debug("Script execution ended");
                }
                else
                {
                    _logger.Debug("The script is executed in the background");
                }

                return(new ActionResult());
            }
            catch (Exception ex)
            {
                _logger.Error("Exception while running the script file \"" + scriptFile + "\"\r\n" + ex.Message);
                return(new ActionResult(ErrorCode.Script_GenericError));
            }
        }
示例#3
0
        private string DetermineOutfileBody()
        {
            var outputDir    = PathSafe.GetDirectoryName(OutputFilenameTemplate) ?? "";
            var filenameBase = PathSafe.GetFileNameWithoutExtension(OutputFilenameTemplate) ?? "output";

            //var outfilebody = PathSafe.Combine(outputDir, filenameBase);
            return(PathSafe.Combine(outputDir, filenameBase));
        }
示例#4
0
        private void CreateOutputDirectory(string outputFilenameTemplate)
        {
            var directory = PathSafe.GetDirectoryName(outputFilenameTemplate);

            if (directory != null && !DirectoryWrap.Exists(directory))
            {
                DirectoryWrap.CreateDirectory(directory);
            }
        }
示例#5
0
        /// <summary>
        ///     Creates a directory that does not exist yet. It takes a path and appends a counting number (_2, _3, etc) to ensure
        ///     this in a readable way.
        /// </summary>
        /// <returns>The uniqified directory path</returns>
        public string MakeUniqueDirectory()
        {
            var directory = _pathSafe.GetDirectoryName(_path) ?? "";
            var fileBody  = _pathSafe.GetFileName(_path);

            var i = 2;

            while (_directoryWrap.Exists(_path) || _fileWrap.Exists(_path))
            {
                _path = _pathSafe.Combine(directory, fileBody + "_" + i);
                i++;
            }

            return(_path);
        }
示例#6
0
        /// <param name="originalFilename">Original file name</param>
        public UniqueFilenameBase(string originalFilename, IPathUtil pathUtil)
        {
            if (originalFilename == null)
            {
                throw new ArgumentNullException(nameof(originalFilename));
            }

            _pathUtil = pathUtil;

            OriginalFilename   = originalFilename;
            LastUniqueFilename = originalFilename;
            _directory         = _pathSafe.GetDirectoryName(OriginalFilename) ?? "";
            _fileBody          = _pathSafe.GetFileNameWithoutExtension(OriginalFilename);
            _extension         = _pathSafe.GetExtension(OriginalFilename);
        }
示例#7
0
        private IList <HistoricFile> CreateHistoricFiles(Job job)
        {
            var historicFiles = new List <HistoricFile>();

            foreach (var file in job.OutputFiles)
            {
                var fileName     = _pathSafe.GetFileName(file);
                var directory    = _pathSafe.GetDirectoryName(file);
                var hash         = BuildHash(file);
                var historicFile = new HistoricFile(file, fileName, directory, hash);
                historicFiles.Add(historicFile);
            }

            return(historicFiles);
        }
示例#8
0
        public UniqueFilename(string originalFilename, IDirectory directory, IFile file)
        {
            if (originalFilename == null)
            {
                throw new ArgumentNullException("originalFilename");
            }

            _directoryWrap = directory;
            _fileWrap      = file;

            OriginalFilename   = originalFilename;
            LastUniqueFilename = originalFilename;
            _directory         = _pathSafe.GetDirectoryName(OriginalFilename) ?? "";
            _fileBody          = _pathSafe.GetFileNameWithoutExtension(OriginalFilename);
            _extension         = _pathSafe.GetExtension(OriginalFilename);
        }
示例#9
0
        /// <summary>
        ///     Sets the location where the job should be converted to and the jobs full name
        /// </summary>
        /// <param name="fileName">Specifies the location and the name of the converted file</param>
        private string DetermineOutputFilename(string fileName)
        {
            if (fileName == null)
            {
                throw new COMException("The output filename was not set");
            }

            var tmpPath = _pathSafe.GetDirectoryName(fileName);

            if (tmpPath == null || !_directory.Exists(tmpPath))
            {
                throw new COMException("Invalid path. Please check if the directory exists.");
            }

            Logger.Trace("COM: Setting the full name of the job:" + fileName);

            return(_outputFormatHelper.EnsureValidExtension(fileName, Job.Profile.OutputFormat));
        }
示例#10
0
        private string ComposeFilename(Job job)
        {
            var filePath = _targetFileNameComposer.ComposeTargetFileName(job);

            var folderName = _pathSafe.GetDirectoryName(filePath);

            if (string.IsNullOrEmpty(folderName))
            {
                folderName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            var filename = _pathSafe.GetFileName(filePath);

            if (string.IsNullOrEmpty(filename))
            {
                filename = "document.pdf";
            }

            return(_pathSafe.Combine(folderName, filename));
        }