Esempio n. 1
0
        public string ComposeTargetFileName(Job job)
        {
            if (!string.IsNullOrWhiteSpace(job.JobInfo.OutputFileParameter))
            {
                if (_pathUtil.IsValidRootedPath(job.JobInfo.OutputFileParameter))
                {
                    return(job.JobInfo.OutputFileParameter);
                }
            }

            var tr           = job.TokenReplacer;
            var outputFolder = ValidName.MakeValidFolderName(tr.ReplaceTokens(job.Profile.TargetDirectory));
            var fileName     = ComposeOutputFilename(job);
            var filePath     = _pathSafe.Combine(outputFolder, fileName);

            if (!job.Profile.AutoSave.Enabled)
            {
                return(filePath);
            }

            try
            {
                filePath = _pathUtil.EllipsisForTooLongPath(filePath);
                _logger.Debug("FilePath after ellipsis: " + filePath);
            }
            catch (ArgumentException)
            {
                throw new WorkflowException("Filepath is only a directory or the directory itself is already too long to append a usefull filename under the limits of Windows (max " + _pathUtil.MAX_PATH + " characters): " + filePath);
            }

            return(filePath);
        }
        public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var convertedValue = base.Convert(values, targetType, parameter, culture) as string;
            var validName      = new ValidName();

            return(validName.MakeValidFtpPath(convertedValue));
        }
Esempio n. 3
0
        public string ComposeOutputFilename(Job job)
        {
            var outputFilename = ValidName.MakeValidFileName(job.TokenReplacer.ReplaceTokens(job.Profile.FileNameTemplate));

            outputFilename += _outputFormatHelper.GetExtension(job.Profile.OutputFormat);
            return(outputFilename);
        }
Esempio n. 4
0
        public ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel)
        {
            if (!IsEnabled(profile))
            {
                return(new ActionResult());
            }

            var isJobLevelCheck = checkLevel == CheckLevel.Job;

            var account = accounts.GetDropboxAccount(profile);

            if (account == null)
            {
                return(new ActionResult(ErrorCode.Dropbox_AccountNotSpecified));
            }

            var accessToken = account.AccessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                return(new ActionResult(ErrorCode.Dropbox_AccessTokenNotSpecified));
            }

            if (!isJobLevelCheck && TokenIdentifier.ContainsTokens(profile.DropboxSettings.SharedFolder))
            {
                return(new ActionResult());
            }

            if (!ValidName.IsValidDropboxFolder(profile.DropboxSettings.SharedFolder))
            {
                return(new ActionResult(ErrorCode.Dropbox_InvalidFolderName));
            }

            return(new ActionResult());
        }
Esempio n. 5
0
        public string ComposeScriptPath(string path, TokenReplacer tokenReplacer)
        {
            var validName    = new ValidName();
            var composedPath = tokenReplacer.ReplaceTokens(path);

            composedPath = validName.MakeValidFolderName(composedPath);

            return(composedPath);
        }
Esempio n. 6
0
        private string MakeValidPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var validName = new ValidName();

            return(validName.MakeValidFtpPath(path));
        }
Esempio n. 7
0
        public override ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel)
        {
            var actionResult = new ActionResult();

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

            var isFinal = checkLevel == CheckLevel.Job;

            var ftpAccount = accounts.GetFtpAccount(profile);

            if (ftpAccount == null)
            {
                Logger.Error($"The specified FTP account with ID '{profile.Ftp.AccountId}' is not configured.");
                actionResult.Add(ErrorCode.Ftp_NoAccount);

                return(actionResult);
            }

            if (string.IsNullOrEmpty(ftpAccount.Server))
            {
                Logger.Error("No FTP server specified.");
                actionResult.Add(ErrorCode.Ftp_NoServer);
            }

            if (string.IsNullOrEmpty(ftpAccount.UserName))
            {
                Logger.Error("No FTP username specified.");
                actionResult.Add(ErrorCode.Ftp_NoUser);
            }

            if (profile.AutoSave.Enabled && string.IsNullOrEmpty(ftpAccount.Password))
            {
                Logger.Error("Automatic saving without ftp password.");
                actionResult.Add(ErrorCode.Ftp_AutoSaveWithoutPassword);
            }

            if (!isFinal && TokenIdentifier.ContainsTokens(profile.Ftp.Directory))
            {
                return(actionResult);
            }

            if (!ValidName.IsValidFtpPath(profile.Ftp.Directory))
            {
                actionResult.Add(ErrorCode.FtpDirectory_InvalidFtpPath);
            }

            return(actionResult);
        }
Esempio n. 8
0
        public void TestIsValidFilename()
        {
            string[] validPaths   = { @"C:\Test.txt", @"X:\Test\Folder\With\Many\Sub\Folders\test.txt", @"C:\Test,abc.txt" };
            string[] invalidPaths = { @"C:\Test<.txt", @"C:\Test>.txt", @"C:\Test?.txt", @"C:\Test*.txt", @"C:\Test|.txt", @"C:\Test"".txt" };

            foreach (var p in validPaths)
            {
                Assert.IsTrue(ValidName.IsValidPath(p), "Expected '" + p + "' to be a valid path");
            }

            foreach (var p in invalidPaths)
            {
                Assert.IsFalse(ValidName.IsValidPath(p), "Expected '" + p + "' to be an invalid path");
            }
        }
        private string ComposeOutputFilename(Job job)
        {
            var outputFilename = ValidName.MakeValidFileName(job.TokenReplacer.ReplaceTokens(job.Profile.FileNameTemplate));

            //"document" as fallback for interactive
            if (!job.Profile.AutoSave.Enabled)
            {
                if (string.IsNullOrWhiteSpace(outputFilename))
                {
                    outputFilename = "document";
                }
            }

            outputFilename += _outputFormatHelper.GetExtension(job.Profile.OutputFormat);

            return(outputFilename);
        }
        private string CreateTargetDirectory(Job job)
        {
            var validName     = new ValidName();
            var saveDirectory = validName.MakeValidFolderName(job.TokenReplacer.ReplaceTokens(job.Profile.SaveDialog.Folder));

            var directoryHelper = new DirectoryHelper(saveDirectory);

            job.OnJobCompleted += (obj, sender) => directoryHelper.DeleteCreatedDirectories();

            if (directoryHelper.CreateDirectory())
            {
                _logger.Debug("Set directory in save file dialog: " + saveDirectory);
                return(saveDirectory);
            }


            _logger.Warn("Could not create directory for save file dialog. It will be opened with default save location.");
            return("");
        }
        public string ComposeTargetFileName(Job job)
        {
            var tr           = job.TokenReplacer;
            var validName    = new ValidName();
            var outputFolder = validName.MakeValidFolderName(tr.ReplaceTokens(job.Profile.TargetDirectory));
            var filePath     = Path.Combine(outputFolder, _outputFilenameComposer.ComposeOutputFilename(job));

            try
            {
                filePath = _pathUtil.EllipsisForTooLongPath(filePath);
                _logger.Debug("FilePath after ellipsis: " + filePath);
            }
            catch (ArgumentException)
            {
                throw new WorkflowException("Autosave filepath is only a directory or the directory itself is already too long to append a filename under the limits of Windows (max " + _pathUtil.MAX_PATH + " characters): " + filePath);
            }

            return(filePath);
        }
        public string ComposeOutputFilename(Job job)
        {
            var validName      = new ValidName();
            var outputFilename = validName.MakeValidFileName(job.TokenReplacer.ReplaceTokens(job.Profile.FileNameTemplate));

            switch (job.Profile.OutputFormat)
            {
            case OutputFormat.Pdf:
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfX:
                outputFilename += ".pdf";
                break;

            case OutputFormat.Jpeg:
                outputFilename += ".jpg";
                break;

            case OutputFormat.Png:
                outputFilename += ".png";
                break;

            case OutputFormat.Tif:
                outputFilename += ".tif";
                break;

            case OutputFormat.Txt:
                outputFilename += ".txt";
                break;

            default:
                _logger.Warn("Can't find a supported Output format! File format is defaulted to .pdf");
                outputFilename += ".pdf";
                break;
            }

            if (outputFilename.Length > _pathUtil.MAX_PATH)
            {
                outputFilename = _pathUtil.EllipsisForPath(outputFilename, 250);
            }

            return(outputFilename);
        }
Esempio n. 13
0
        public ActionResult Check(ConversionProfile profile, Accounts accounts)
        {
            var actionResult = new ActionResult();

            if (!profile.Scripting.Enabled)
            {
                return(actionResult);
            }

            var tokenReplacer = new TokenReplacer();

            tokenReplacer.AddToken(new EnvironmentToken());

            var validName = new ValidName();

            var scriptFile = ComposeScriptPath(profile.Scripting.ScriptFile, tokenReplacer);

            if (string.IsNullOrEmpty(scriptFile))
            {
                _logger.Error("Missing script file.");
                actionResult.Add(ErrorCode.Script_NoScriptFileSpecified);
                return(actionResult);
            }

            if (!validName.IsValidFilename(scriptFile))
            {
                _logger.Error("The script file \"" + scriptFile + "\" contains illegal characters.");
                actionResult.Add(ErrorCode.Script_IllegalCharacters);
                return(actionResult);
            }

            //Skip check for network path
            if (!scriptFile.StartsWith(@"\\") && !_file.Exists(scriptFile))
            {
                _logger.Error("The script file \"" + scriptFile + "\" does not exist.");
                actionResult.Add(ErrorCode.Script_FileDoesNotExist);
                return(actionResult);
            }

            return(actionResult);
        }
        private string ComposeOutputFolder(Job job)
        {
            var outputFolder = ValidName.MakeValidFolderName(job.TokenReplacer.ReplaceTokens(job.Profile.TargetDirectory));

            //Consider LastSaveDirectory
            if (!job.Profile.AutoSave.Enabled)
            {
                outputFolder = ConsiderLastSaveDirectory(outputFolder, job);
            }

            // MyDocuments folder as fallback for interactive
            if (!job.Profile.AutoSave.Enabled && !job.Profile.SaveFileTemporary)
            {
                if (string.IsNullOrWhiteSpace(outputFolder))
                {
                    outputFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                }
            }

            return(outputFolder);
        }
Esempio n. 15
0
        public void PressiusTestObject_WithValidNameAndConstructorPermutation_ShouldPermutateWithCustomValues()
        {
            var pressius = new Permutor();
            var pressiusTestObjectList = pressius
                                         .AddParameterDefinition(new ValidName())
                                         .AddObjectDefinition(new PressiusTestObjectWithConstructorObjectDefinition())
                                         .WithConstructor()
                                         .GeneratePermutation <PressiusTestObjectWithConstructor>();

            pressiusTestObjectList.ShouldNotBeNull();
            pressiusTestObjectList.ToList().Count.ShouldBeGreaterThan(0);
            var objectList    = pressiusTestObjectList.ToList();
            var integerParams = new IntegerParameter();
            var validName     = new ValidName();

            objectList.ForEach(obj =>
            {
                _output.WriteLine("Obj: {0} {1} {2}", obj.Id, obj.Name, obj.Address);
                integerParams.InputCatalogues.ShouldContain(obj.Id);
                obj.Address.ShouldBe("Default Address");
                validName.InputCatalogues.ShouldContain(obj.Name);
            });
        }
Esempio n. 16
0
        protected override ActionResult DoActionProcessing(Job job)
        {
            var ftpAccount = job.Accounts.GetFtpAccount(job.Profile);

            Logger.Debug("Creating ftp connection.\r\nServer: " + ftpAccount.Server + "\r\nUsername: "******"Can not connect to the internet for login to ftp. Win32Exception Message:\r\n" + ex.Message);
                    ftpConnection.Close();
                    return(new ActionResult(ErrorCode.Ftp_ConnectionError));
                }
                if (ex.NativeErrorCode.Equals(12014))
                {
                    Logger.Error("Can not login to ftp because the password is incorrect. Win32Exception Message:\r\n" + ex.Message);
                    ftpConnection.Close();
                    return(new ActionResult(ErrorCode.PasswordAction_Login_Error));
                }

                Logger.Error("Win32Exception while login to ftp server:\r\n" + ex.Message);
                ftpConnection.Close();
                return(new ActionResult(ErrorCode.Ftp_LoginError));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception while login to ftp server:\r\n" + ex.Message);
                ftpConnection.Close();
                return(new ActionResult(ErrorCode.Ftp_LoginError));
            }

            var fullDirectory = job.TokenReplacer.ReplaceTokens(job.Profile.Ftp.Directory).Trim();

            if (!ValidName.IsValidFtpPath(fullDirectory))
            {
                Logger.Warn("Directory contains invalid characters \"" + fullDirectory + "\"");
                fullDirectory = ValidName.MakeValidFtpPath(fullDirectory);
            }

            Logger.Debug("Directory on ftp server: " + fullDirectory);

            var directories = fullDirectory.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                foreach (var directory in directories)
                {
                    if (!ftpConnection.DirectoryExists(directory))
                    {
                        Logger.Debug("Create folder: " + directory);
                        ftpConnection.CreateDirectory(directory);
                    }
                    Logger.Debug("Move to: " + directory);
                    ftpConnection.SetCurrentDirectory(directory);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception while setting directory on ftp server\r\n:" + ex.Message);
                ftpConnection.Close();
                return(new ActionResult(ErrorCode.Ftp_DirectoryError));
            }

            foreach (var file in job.OutputFiles)
            {
                var targetFile = Path.GetFileName(file);
                targetFile = ValidName.MakeValidFtpPath(targetFile);
                if (job.Profile.Ftp.EnsureUniqueFilenames)
                {
                    Logger.Debug("Make unique filename for " + targetFile);
                    try
                    {
                        var uf = new UniqueFilenameForFtp(targetFile, ftpConnection, _pathUtil);
                        targetFile = uf.CreateUniqueFileName();
                        Logger.Debug("-> The unique filename is \"" + targetFile + "\"");
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Exception while generating unique filename\r\n:" + ex.Message);
                        ftpConnection.Close();
                        return(new ActionResult(ErrorCode.Ftp_DirectoryReadError));
                    }
                }

                try
                {
                    ftpConnection.PutFile(file, targetFile);
                }
                catch (Exception ex)
                {
                    Logger.Error("Exception while uploading the file \"" + file + "\": \r\n" + ex.Message);
                    ftpConnection.Close();
                    return(new ActionResult(ErrorCode.Ftp_UploadError));
                }
            }

            ftpConnection.Close();
            return(new ActionResult());
        }
Esempio n. 17
0
        public override ActionResult Check(ConversionProfile profile, Accounts accounts, CheckLevel checkLevel)
        {
            var actionResult = new ActionResult();

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

            var isFinal = checkLevel == CheckLevel.Job;

            var ftpAccount = accounts.GetFtpAccount(profile);

            if (ftpAccount == null)
            {
                Logger.Error($"The specified FTP account with ID '{profile.Ftp.AccountId}' is not configured.");
                actionResult.Add(ErrorCode.Ftp_NoAccount);

                return(actionResult);
            }

            if (string.IsNullOrEmpty(ftpAccount.Server))
            {
                Logger.Error("No FTP server specified.");
                actionResult.Add(ErrorCode.Ftp_NoServer);
            }

            if (string.IsNullOrEmpty(ftpAccount.UserName))
            {
                Logger.Error("No FTP username specified.");
                actionResult.Add(ErrorCode.Ftp_NoUser);
            }

            if (ftpAccount.AuthenticationType == AuthenticationType.KeyFileAuthentication)
            {
                var pathUtilStatus = _pathUtil.IsValidRootedPathWithResponse(ftpAccount.PrivateKeyFile);
                switch (pathUtilStatus)
                {
                case PathUtilStatus.InvalidRootedPath:
                    return(new ActionResult(ErrorCode.FtpKeyFilePath_InvalidRootedPath));

                case PathUtilStatus.PathTooLongEx:
                    return(new ActionResult(ErrorCode.FtpKeyFilePath_PathTooLong));

                case PathUtilStatus.NotSupportedEx:
                    return(new ActionResult(ErrorCode.FtpKeyFilePath_InvalidRootedPath));

                case PathUtilStatus.ArgumentEx:
                    return(new ActionResult(ErrorCode.FtpKeyFilePath_IllegalCharacters));
                }

                if (!isFinal && ftpAccount.PrivateKeyFile.StartsWith(@"\\"))
                {
                    return(new ActionResult());
                }

                if (!_file.Exists(ftpAccount.PrivateKeyFile))
                {
                    Logger.Error("The private key file \"" + ftpAccount.PrivateKeyFile + "\" does not exist.");
                    return(new ActionResult(ErrorCode.FtpKeyFilePath_FileDoesNotExist));
                }
            }

            if (profile.AutoSave.Enabled && string.IsNullOrEmpty(ftpAccount.Password) || KeyFilePasswordIsRequired(ftpAccount))
            {
                Logger.Error("Automatic saving without ftp password.");
                actionResult.Add(ErrorCode.Ftp_AutoSaveWithoutPassword);
            }

            if (!isFinal && TokenIdentifier.ContainsTokens(profile.Ftp.Directory))
            {
                return(actionResult);
            }

            if (!ValidName.IsValidFtpPath(profile.Ftp.Directory))
            {
                actionResult.Add(ErrorCode.FtpDirectory_InvalidFtpPath);
            }

            return(actionResult);
        }
Esempio n. 18
0
 public override void ApplyPreSpecifiedTokens(Job job)
 {
     job.Profile.Ftp.Directory = job.TokenReplacer.ReplaceTokens(job.Profile.Ftp.Directory);
     job.Profile.Ftp.Directory = ValidName.MakeValidFtpPath(job.Profile.Ftp.Directory);
 }
Esempio n. 19
0
        protected override ActionResult DoActionProcessing(Job job)
        {
            var ftpAccount = job.Accounts.GetFtpAccount(job.Profile);

            Logger.Debug("Creating ftp connection.\r\nServer: " + ftpAccount.Server + "\r\nUsername: "******"Exception while login to ftp server: ");
                ftpClient.Disconnect();
                return(new ActionResult(ErrorCode.Ftp_LoginError));
            }

            var fullDirectory = job.TokenReplacer.ReplaceTokens(job.Profile.Ftp.Directory).Trim();

            if (!ValidName.IsValidFtpPath(fullDirectory))
            {
                Logger.Warn("Directory contains invalid characters \"" + fullDirectory + "\"");
                fullDirectory = ValidName.MakeValidFtpPath(fullDirectory);
            }

            Logger.Debug("Directory on ftp server: " + fullDirectory);

            try
            {
                if (!ftpClient.DirectoryExists(fullDirectory))
                {
                    ftpClient.CreateDirectory(fullDirectory);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Exception while setting directory on ftp server: ");
                ftpClient.Disconnect();
                return(new ActionResult(ErrorCode.Ftp_DirectoryError));
            }

            foreach (var file in job.OutputFiles)
            {
                var targetFile = PathSafe.GetFileName(file);
                targetFile = ValidName.MakeValidFtpPath(targetFile);
                if (job.Profile.Ftp.EnsureUniqueFilenames)
                {
                    Logger.Debug("Make unique filename for " + targetFile);
                    try
                    {
                        var uf = new UniqueFilenameForFtp(targetFile, ftpClient, _pathUtil);
                        targetFile = uf.CreateUniqueFileName();
                        Logger.Debug("-> The unique filename is \"" + targetFile + "\"");
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Exception while generating unique filename: ");
                        ftpClient.Disconnect();
                        return(new ActionResult(ErrorCode.Ftp_DirectoryReadError));
                    }
                }

                try
                {
                    ftpClient.UploadFile(file, fullDirectory + "/" + targetFile);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Exception while uploading the file \"" + file);
                    ftpClient.Disconnect();
                    return(new ActionResult(ErrorCode.Ftp_UploadError));
                }
            }

            ftpClient.Disconnect();
            return(new ActionResult());
        }
 public void Setup()
 {
     _validName = new ValidName();
 }
Esempio n. 21
0
 public void MakeValidFileName_GivenInvalidFilename_ReturnsSanitizedString()
 {
     Assert.AreEqual(@"File_Name", ValidName.MakeValidFileName(@"File:Name"));
 }
Esempio n. 22
0
        private string PreviewForFolder(string s)
        {
            var validName = new ValidName();

            return(validName.MakeValidFolderName(_tokenReplacer.ReplaceTokens(s)));
        }
Esempio n. 23
0
        public void MakeValidFolderName_GivenValidFolder_ReturnsSameString()
        {
            const string filename = @"C:\Some _ !Folder,";

            Assert.AreEqual(filename, ValidName.MakeValidFolderName(filename));
        }
Esempio n. 24
0
 public void MakeValidFolderName_GivenMisplacedColon_ReturnsSanitizedString()
 {
     Assert.AreEqual(@"C:\Some_Folder", ValidName.MakeValidFolderName(@"C:\Some:Folder"));
 }
Esempio n. 25
0
 public void MakeValidFolderName_GivenInvalidFolder_ReturnsSanitizedString()
 {
     Assert.AreEqual(@"C:\Some _ Folder", ValidName.MakeValidFolderName(@"C:\Some | Folder"));
 }
Esempio n. 26
0
        public void MakeValidFileName_GivenValidFilename_ReturnsSameString()
        {
            const string filename = @"Test ! File.txt";

            Assert.AreEqual(filename, ValidName.MakeValidFileName(filename));
        }
Esempio n. 27
0
 private string PreviewForFolder(string s)
 {
     return(ValidName.MakeValidFolderName(_tokenReplacer.ReplaceTokens(s)));
 }