Example #1
0
        public void WindowsDirectoryMoveToWindowsDirectory()
        {
            ZephyrDirectory source = Global.StageTestFilesToWindows();

            Console.WriteLine($"Source : {source.FullName}");

            String path = Path.Combine(Global.WindowsWorkingPath, $"{Global.RandomDirectory}\\");

            Console.WriteLine($"Target : {path}");
            ZephyrDirectory target = Global.WindowsWorkingDirectory.CreateDirectory(path);

            target.Create();

            String sourceCount = Global.DirectoryObjectCounts(source);

            Console.WriteLine($">> Source : [{sourceCount}]");

            source.MoveTo(target);

            String targetCount = Global.DirectoryObjectCounts(target);

            Console.WriteLine($">> Target : [{targetCount}]");

            Assert.AreEqual(sourceCount, targetCount);
            Assert.That(source.IsEmpty);

            target.Delete();
            source.Delete();
        }
Example #2
0
        public void AwsS3DirectoryMoveToWindowsDirectory()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToAws();

            Console.WriteLine($"Source : {source.FullName}");

            String path = $"{Global.AwsS3WorkingPath}{Global.RandomDirectory}/";

            Console.WriteLine($"Target : {path}");
            ZephyrDirectory target = Global.AwsS3WorkingDirectory.CreateDirectory(path);

            target.Create();

            String sourceCount = Global.DirectoryObjectCounts(source);

            Console.WriteLine($">> Source : [{sourceCount}]");

            source.MoveTo(target);

            String targetCount = Global.DirectoryObjectCounts(target);

            Console.WriteLine($">> Target : [{targetCount}]");

            Assert.AreEqual(sourceCount, targetCount);
            Assert.That(source.IsEmpty);

            target.Delete();
            source.Delete();
        }
    public override ExecuteResult Execute(HandlerStartInfo startInfo)
    {
        OnProgress("CopyFileHandler", "Handler Execution Begins.", StatusType.Running, 0, cheapSequence++);
        ExecuteResult result = new ExecuteResult();

        result.Status = StatusType.Success;

        // TODO : Implement DryRun Functionality
        if (startInfo.IsDryRun)
        {
            throw new NotImplementedException("Dry Run Functionality Has Not Yet Been Implemented.");
        }

        try
        {
            if (startInfo.Parameters != null)
            {
                parameters = HandlerUtils.Deserialize <CopyFileHandlerParameters>(startInfo.Parameters);
            }

            bool isValid = Validate();

            if (isValid)
            {
                if (parameters.FileSets != null)
                {
                    foreach (FileSet set in parameters.FileSets)
                    {
                        if (set != null && set.Sources != null && set.Destinations != null)
                        {
                            OnLogMessage("CopyFileHandler", $"Starting {config.Action} From [{string.Join(",", set.Sources.ToArray())}] To [{string.Join(",", set.Destinations)}].");
                            foreach (String destination in set.Destinations)
                            {
                                if (Utilities.IsDirectory(destination) && config.PurgeDestination)
                                {
                                    ZephyrDirectory clearDir = Utilities.GetZephyrDirectory(destination, clients);
                                    clearDir.Purge(config.StopOnError, config.Verbose, "Purge", Logger);
                                    OnLogMessage("CopyFileHandler", $"Directory [{destination}] Was Purged.");
                                }

                                foreach (String source in set.Sources)
                                {
                                    if (Utilities.IsDirectory(source))
                                    {
                                        ZephyrDirectory sourceDir = Utilities.GetZephyrDirectory(source, clients);
                                        if (Utilities.IsDirectory(destination))
                                        {
                                            // Copy/Move Directory To Directory
                                            ZephyrDirectory destDir = Utilities.GetZephyrDirectory(destination, clients);
                                            if (config.Action == FileAction.Copy)
                                            {
                                                sourceDir.CopyTo(destDir, config.Recurse, config.OverwriteExisting, config.StopOnError, config.Verbose, "Copy", Logger);
                                            }
                                            else
                                            {
                                                sourceDir.MoveTo(destDir, config.OverwriteExisting, config.StopOnError, config.Verbose, "Move", Logger);
                                            }
                                        }
                                        else
                                        {
                                            // This should never occur, as this scenario is addressed in "Validate".
                                            throw new Exception($"Can Not Copy Directory [{source}] To File [{destination}]");
                                        }
                                    }
                                    else
                                    {
                                        ZephyrFile sourceFile = Utilities.GetZephyrFile(source, clients);
                                        if (Utilities.IsDirectory(destination))
                                        {
                                            // Copy/Move File To Directory
                                            ZephyrDirectory destDir = Utilities.GetZephyrDirectory(destination, clients);
                                            if (config.Action == FileAction.Copy)
                                            {
                                                sourceFile.CopyTo(destDir, config.OverwriteExisting, true, config.StopOnError, config.Verbose, "Copy", Logger);
                                            }
                                            else
                                            {
                                                sourceFile.MoveTo(destDir, config.OverwriteExisting, true, config.StopOnError, config.Verbose, "Move", Logger);
                                            }
                                        }
                                        else
                                        {
                                            // Copy/Move File To File
                                            ZephyrFile destFile = Utilities.GetZephyrFile(destination, clients);
                                            if (config.Action == FileAction.Copy)
                                            {
                                                sourceFile.CopyTo(destFile, config.OverwriteExisting, true, config.StopOnError, config.Verbose, "Copy", Logger);
                                            }
                                            else
                                            {
                                                sourceFile.MoveTo(destFile, config.OverwriteExisting, true, config.StopOnError, config.Verbose, "Move", Logger);
                                            }
                                        }
                                    }
                                }
                            }
                            OnLogMessage("CopyFileHandler", $"Finished {config.Action} From [{string.Join(",", set.Sources.ToArray())}] To [{string.Join(",", set.Destinations)}].");
                        }
                    }
                }
            }
            else
            {
                OnLogMessage("CopyFileHandler", "Validation Failed.", LogLevel.Error);
                throw new Exception("Validation Failed.");
            }
        }
        catch (Exception e)
        {
            OnProgress("CopyFileHandler", "Handler Execution Failed.", StatusType.Failed, 0, cheapSequence++, false, e);
            throw e;
        }

        OnProgress("CopyFileHandler", "Handler Execution Completed.", StatusType.Complete, 0, cheapSequence++);
        return(result);
    }