예제 #1
0
        public void TestExecuteWithLogFile(RobocopyShared.ModeOption modeOptions)
        {
            string logFilePath = Path.Combine(this.fixtureBaseFolderPath, "robocopy_log.txt");

            SetPropertyValue(RobocopyShared.IncludeEmptySubdirectoriesPropertyName, false);
            SetParameterValue(RobocopyShared.SourceDirectoryPropertyName, fixtureSourceFolderPath);
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);
            SetParameterValue(RobocopyShared.LogFilePropertyName, logFilePath);
            SetParameterValue(RobocopyShared.FilePatternPropertyName, "*.txt");

            List <dynamic> result = Execute();

            Assert.IsTrue(Directory.Exists(fixtureDestinationFolderPath));
            Assert.AreEqual(2, Directory.GetFiles(fixtureDestinationFolderPath).Count());
            if (modeOptions == RobocopyShared.ModeOption.Mirror)
            {
                Assert.AreEqual(0, Directory.GetDirectories(fixtureDestinationFolderPath).Count());
            }
            else
            {
                Assert.AreEqual(1, Directory.GetDirectories(fixtureDestinationFolderPath).Count());
            }
            Assert.IsTrue(System.IO.File.Exists(logFilePath));
            Assert.That(System.IO.File.ReadAllText(logFilePath), Is.Not.Null.Or.Empty);
        }
예제 #2
0
        public void TestExecuteWithSourceFolderIsEmpty(RobocopyShared.ModeOption modeOptions)
        {
            SetPropertyValue(RobocopyShared.IncludeEmptySubdirectoriesPropertyName, true);
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);

            Assert.That(() => Execute(),
                        Throws.Exception.TypeOf <ExecuteException>()
                        .With.Property("Message").EqualTo("Source directory cannot be null or empty.\r\nSee Code and Parameter properties for more information."));
        }
예제 #3
0
        public override void GenerateCode(IFunctionBuilder functionBuilder)
        {
            RobocopyShared.ModeOption modeOption = FunctionData.Properties[RobocopyShared.ModePropertyName].GetValue <RobocopyShared.ModeOption>();

            functionBuilder.AddCode(string.Format("Twenty57.Linx.Components.File.RobocopyX.Execute({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37},{38},message => {39}.Log(message));",
                                                  functionBuilder.GetParamName(RobocopyShared.SourceDirectoryPropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.TargetDirectoryPropertyName)
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.CopySubdirectoriesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludeEmptySubdirectoriesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.RestartModePropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.BackupModePropertyName].GetValue <bool>())
                                                  , functionBuilder.GetParamName(RobocopyShared.NumberOfRetriesPropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.TimeBetweenRetriesPropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.FilePatternPropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.ExcludeFilesPropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.ExcludeDirectoriesPropertyName)
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludesChangedFilesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludesNewerFilesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludesOlderFilesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludesExtraFilesAndDirectoriesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludesLonelyFilesAndDirectoriesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludesSameFilesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludesTweakedFilesPropertyName].GetValue <bool>())
                                                  , functionBuilder.GetParamName(RobocopyShared.MaxFileSizePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.MinFileSizePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.MaxAgePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.MinAgePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.MaxLastAccessDatePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.MinLastAccessDatePropertyName)
                                                  , functionBuilder.GetParamName(RobocopyShared.LogFilePropertyName)
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.OverwriteFilePropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ListFilesOnlyPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.LogAllExtraFilesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.VerbosePropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludeSourceFileTimestampsPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludeFullPathPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.LogSizeAsBytesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludeFileSizePropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludeFileClassPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludeFileNamesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludeDirectoryNamesPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.ExcludeProgressPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.BoolAsString(FunctionData.Properties[RobocopyShared.IncludeETAPropertyName].GetValue <bool>())
                                                  , CSharpUtilities.EnumAsString(modeOption)
                                                  , functionBuilder.ContextParamName));

            functionBuilder.AddAssemblyReference(typeof(Robocopy));
        }
예제 #4
0
        public void TestExecuteWithListFilesSourceDirectoryDoesNotExists(RobocopyShared.ModeOption modeOptions)
        {
            SetPropertyValue(RobocopyShared.ListFilesOnlyPropertyName, true);
            SetParameterValue(RobocopyShared.SourceDirectoryPropertyName, Path.Combine(Path.GetTempPath(), "newfolder"));
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);

            if (!Directory.Exists(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory")))
            {
                Directory.CreateDirectory(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory"));
            }

            Assert.That(() => Execute(),
                        Throws.Exception.TypeOf <ExecuteException>()
                        .With.Property("Message").EqualTo(string.Format("Source directory [{0}] does not exist.\r\nSee Code and Parameter properties for more information.", Path.Combine(Path.GetTempPath(), "newfolder"))));
        }
예제 #5
0
        public void TestExecuteWithTrailingBackslash(RobocopyShared.ModeOption modeOptions)
        {
            SetPropertyValue(RobocopyShared.ListFilesOnlyPropertyName, true);
            SetParameterValue(RobocopyShared.SourceDirectoryPropertyName, fixtureSourceFolderPath + Path.DirectorySeparatorChar);
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath + Path.DirectorySeparatorChar);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);

            if (!Directory.Exists(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory")))
            {
                Directory.CreateDirectory(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory"));
            }
            List <dynamic> result = Execute();

            Assert.IsTrue(Directory.Exists(fixtureDestinationFolderPath));
            Assert.AreEqual(0, Directory.GetFiles(fixtureDestinationFolderPath).Count());
            Assert.AreEqual(1, Directory.GetDirectories(fixtureDestinationFolderPath).Count());
        }
예제 #6
0
        public void TestExecuteWithInvalidParameter(RobocopyShared.ModeOption modeOptions)
        {
            SetPropertyValue(RobocopyShared.ListFilesOnlyPropertyName, true);
            SetParameterValue(RobocopyShared.SourceDirectoryPropertyName, fixtureSourceFolderPath);
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);
            SetParameterValue(RobocopyShared.MaxAgePropertyName, "-1");

            if (!Directory.Exists(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory")))
            {
                Directory.CreateDirectory(Path.Combine(this.fixtureSourceFolderPath, "NewDirectory"));
            }

            Assert.That(() => Execute(),
                        Throws.Exception.TypeOf <ExecuteException>()
                        .With.Property("Message").Contains("Robocopy error: ERROR : Invalid Parameter"));
        }
예제 #7
0
        public void TestExecuteWithIncludeEmptySubDirectoriesFalse(RobocopyShared.ModeOption modeOptions)
        {
            SetPropertyValue(RobocopyShared.IncludeEmptySubdirectoriesPropertyName, false);
            SetParameterValue(RobocopyShared.SourceDirectoryPropertyName, fixtureSourceFolderPath);
            SetParameterValue(RobocopyShared.TargetDirectoryPropertyName, fixtureDestinationFolderPath);
            SetPropertyValue(RobocopyShared.ModePropertyName, modeOptions);

            List <dynamic> result = Execute();

            Assert.IsTrue(Directory.Exists(fixtureDestinationFolderPath));
            Assert.AreEqual(3, Directory.GetFiles(fixtureDestinationFolderPath).Count());
            if (modeOptions != RobocopyShared.ModeOption.Mirror)
            {
                Assert.AreEqual(1, Directory.GetDirectories(fixtureDestinationFolderPath).Count());
            }
            else
            {
                Assert.AreEqual(0, Directory.GetDirectories(fixtureDestinationFolderPath).Count());
            }
        }
예제 #8
0
        public static void Execute(string sourceDirectory, string targetDirectory, bool copySubdirectories, bool includeEmptySubdirectories, bool restartMode, bool backupMode, int numberofRetries, int timeBetweenRetries,
                                   string filePattern, string excludeFiles, string excludDirectories, bool excludesChangedFiles, bool excludesNewerFiles, bool excludesOlderFiles, bool excludesExtraFilesAndDirectories, bool excludesLonelyFilesAndDirectories, bool includesSameFiles, bool includesTweakedFiles, int maxFileSize, int minFileSize, string maxAge, string minAge, string maxLastAccessDate, string minLastAccessDate,
                                   string logFile, bool overwriteFile, bool listFilesOnly, bool logAllExtraFiles, bool verbose, bool includeSourceFileTimestamps, bool includeFullPath, bool logSizeAsBytes, bool excludeFileSize, bool excludeFileClass, bool excludeFileNames,
                                   bool excludeDirectoryNames, bool excludeProgress, bool includeETA, RobocopyShared.ModeOption modeOption, Action <string> logger)
        {
            if (string.IsNullOrEmpty(sourceDirectory))
            {
                throw new Exception("Source directory cannot be null or empty.");
            }

            if (string.IsNullOrEmpty(targetDirectory))
            {
                throw new Exception("Target directory cannot be null or empty.");
            }

            if (!Directory.Exists(sourceDirectory))
            {
                throw new DirectoryNotFoundException(string.Format("Source directory [{0}] does not exist.", sourceDirectory));
            }

            sourceDirectory = sourceDirectory.TrimEnd(Path.DirectorySeparatorChar);
            targetDirectory = targetDirectory.TrimEnd(Path.DirectorySeparatorChar);

            StringBuilder commandLine = new StringBuilder();

            commandLine.Append(string.Format("\"{0}\" \"{1}\" ", sourceDirectory, targetDirectory));

            if (modeOption == RobocopyShared.ModeOption.Mirror)
            {
                commandLine.Append(" /mir");
            }
            if (modeOption == RobocopyShared.ModeOption.MoveFiles)
            {
                commandLine.Append(" /mov");
            }
            if (modeOption == RobocopyShared.ModeOption.MoveFilesAndDirs)
            {
                commandLine.Append(" /move");
            }
            if (copySubdirectories)
            {
                commandLine.Append(" /s");
            }
            if (includeEmptySubdirectories)
            {
                commandLine.Append(" /e");
            }
            if (restartMode)
            {
                commandLine.Append(" /z");
            }
            if (backupMode)
            {
                commandLine.Append(" /b");
            }
            if (numberofRetries > 0)
            {
                commandLine.AppendFormat(" /r:{0}", numberofRetries);
            }
            if (timeBetweenRetries > 0)
            {
                commandLine.AppendFormat(" /w:{0}", timeBetweenRetries);
            }

            if (!string.IsNullOrEmpty(filePattern))
            {
                commandLine.AppendFormat(" {0}", filePattern);
            }
            if (!string.IsNullOrEmpty(excludeFiles))
            {
                commandLine.AppendFormat(" /xf {0}", excludeFiles);
            }
            if (!string.IsNullOrEmpty(excludDirectories))
            {
                commandLine.AppendFormat(" /xd {0}", excludDirectories);
            }
            if (excludesChangedFiles)
            {
                commandLine.Append(" /xct");
            }
            if (excludesNewerFiles)
            {
                commandLine.Append(" /xn");
            }
            if (excludesOlderFiles)
            {
                commandLine.Append(" /xo");
            }
            if (excludesExtraFilesAndDirectories)
            {
                commandLine.Append(" /xx");
            }
            if (excludesLonelyFilesAndDirectories)
            {
                commandLine.Append(" /xl");
            }
            if (includesSameFiles)
            {
                commandLine.Append(" /is");
            }
            if (includesTweakedFiles)
            {
                commandLine.Append(" /it");
            }

            if (maxFileSize > 0)
            {
                commandLine.AppendFormat(" /max:{0}", maxFileSize);
            }
            if (minFileSize > 0)
            {
                commandLine.AppendFormat(" /min:{0}", minFileSize);
            }
            if (!string.IsNullOrEmpty(maxAge))
            {
                commandLine.AppendFormat(" /maxage:{0}", maxAge);
            }
            if (!string.IsNullOrEmpty(minAge))
            {
                commandLine.AppendFormat(" /minage:{0}", minAge);
            }
            if (!string.IsNullOrEmpty(maxLastAccessDate))
            {
                commandLine.AppendFormat(" /maxlad:{0}", maxLastAccessDate);
            }
            if (!string.IsNullOrEmpty(minLastAccessDate))
            {
                commandLine.AppendFormat(" /maxlad:{0}", minLastAccessDate);
            }
            if (!string.IsNullOrEmpty(logFile) && (!overwriteFile))
            {
                commandLine.AppendFormat(" /log+:{0}", logFile);
            }
            if (overwriteFile)
            {
                commandLine.AppendFormat(" /log:{0}", logFile);
            }
            if (listFilesOnly)
            {
                commandLine.Append(" /l");
            }
            if (logAllExtraFiles)
            {
                commandLine.Append(" /x");
            }
            if (verbose)
            {
                commandLine.Append(" /v");
            }
            if (includeSourceFileTimestamps)
            {
                commandLine.Append(" /ts");
            }
            if (includeFullPath)
            {
                commandLine.Append(" /fp");
            }
            if (logSizeAsBytes)
            {
                commandLine.Append(" /bytes");
            }
            if (excludeFileSize)
            {
                commandLine.Append(" /ns");
            }
            if (excludeFileClass)
            {
                commandLine.Append(" /nc");
            }
            if (excludeFileNames)
            {
                commandLine.Append(" /nfl");
            }
            if (excludeDirectoryNames)
            {
                commandLine.Append(" /ndl");
            }
            if (excludeProgress)
            {
                commandLine.Append(" /np");
            }
            if (includeETA)
            {
                commandLine.Append(" /eta");
            }

            ExecuteProcess(commandLine.ToString(), logger);
        }