Esempio n. 1
0
        public void AwsS3FileWriteAllBytes()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory   source = Global.StageTestFilesToAws();
            List <ZephyrFile> files  = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                Console.WriteLine($"File: {file.FullName}");
                byte[]     bytes   = file.ReadAllBytes();
                string     outPath = $"{source.FullName}{Global.RandomFile}";
                ZephyrFile outFile = source.CreateFile(outPath);
                outFile.WriteAllBytes(bytes);
                byte[] outBytes = outFile.ReadAllBytes();
                Assert.AreEqual(bytes.Length, outBytes.Length);
                for (int i = 0; i < bytes.Length; i++)
                {
                    Assert.AreEqual(bytes[i], outBytes[i]);
                }

                outFile.Delete();
            }

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

            ZephyrDirectory   source = Global.StageTestFilesToAws();
            List <ZephyrFile> files  = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                Console.WriteLine($"File: {file.FullName}");
                string     content = file.ReadAllText();
                string     outPath = $"{source.FullName}{Global.RandomFile}";
                ZephyrFile outFile = source.CreateFile(outPath);
                outFile.WriteAllText(content);
                string outText = outFile.ReadAllText();
                Assert.AreEqual(content, outText);

                outFile.Delete();
            }

            source.Delete();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void WindowsFileWriteAllLines()
        {
            if (!Global.TestWindows)
            {
                throw new Exception("Windows Tests Are Not Enabled.  Set Global.TestWindows To True To Enable.");
            }

            ZephyrDirectory   source = Global.StageTestFilesToWindows();
            List <ZephyrFile> files  = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                Console.WriteLine($"File: {file.FullName}");
                string[]   lines   = file.ReadAllLines();
                string     outPath = Path.Combine(source.FullName, Global.RandomFile);
                ZephyrFile outFile = source.CreateFile(outPath);
                outFile.WriteAllLines(lines);
                string[] outLines = outFile.ReadAllLines();
                Assert.AreEqual(lines.Length, outLines.Length);
                for (int i = 0; i < lines.Length; i++)
                {
                    Assert.AreEqual(lines[i], outLines[i]);
                }

                outFile.Delete();
            }

            source.Delete();
        }
Esempio n. 5
0
        public void WindowsFileMoveToWindowsDirectory()
        {
            if (!Global.TestWindows)
            {
                throw new Exception("Windows Tests Are Not Enabled.  Set Global.TestWindows To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToWindows();
            string          path   = Path.Combine(Global.WindowsWorkingPath, $"{Global.RandomDirectory}\\");
            ZephyrDirectory target = new WindowsZephyrDirectory(path);

            List <ZephyrFile> files = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                String filePath = Path.Combine(target.FullName, file.Name);
                file.MoveTo(target);
                Assert.That(File.Exists(filePath));
                Assert.That(!file.Exists);
                Utilities.Delete(filePath, Global.Clients);
            }

            source.Delete();
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public void AwsS3FileMoveToAwsS3Directory()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToAws();
            string          path   = $"{Global.AwsS3WorkingPath}{Global.RandomDirectory}/";
            ZephyrDirectory target = new AwsS3ZephyrDirectory(Global.Clients.aws, path);

            List <ZephyrFile> files = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                String filePath = $"{target.FullName}{file.Name}";
                file.MoveTo(target);
                Assert.That(Utilities.Exists(filePath, Global.Clients));
                Assert.That(!file.Exists);
                Utilities.Delete(filePath, Global.Clients);
            }

            source.Delete();
        }
    public override ExecuteResult Execute(HandlerStartInfo startInfo)
    {
        ExecuteResult result = new ExecuteResult();

        result.Status = StatusType.Success;
        int cheapSequence = 0;

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

        OnProgress("DeleteFileHandler", "Handler Execution Begins.", StatusType.Running, 0, cheapSequence++);
        try
        {
            if (startInfo.Parameters != null)
            {
                parameters = HandlerUtils.Deserialize <DeleteFileHandlerParameters>(startInfo.Parameters);
            }

            bool isValid = Validate();

            if (isValid)
            {
                if (parameters.Targets != null)
                {
                    OnLogMessage("DeleteFileHandler", $"Starting Delete Of [{string.Join(",", parameters.Targets.ToArray())}]");
                    foreach (String target in parameters.Targets)
                    {
                        if (Utilities.IsDirectory(target))
                        {
                            ZephyrDirectory dir = Utilities.GetZephyrDirectory(target, clients);
                            dir.Delete(config.Recurse, config.StopOnError, config.Verbose, "DeleteFileHandler", Logger);
                        }
                        else
                        {
                            ZephyrFile file = Utilities.GetZephyrFile(target, clients);
                            file.Delete(config.StopOnError, config.Verbose, "DeleteFileHandler", Logger);
                        }
                    }
                    OnLogMessage("DeleteFileHandler", $"Finished Delete Of [{string.Join(",", parameters.Targets.ToArray())}]");
                }
            }
            else
            {
                OnLogMessage("DeleteFileHandler", "Validation Failed.", LogLevel.Error);
                throw new Exception("Invalid Input Received");
            }
        }
        catch (Exception e)
        {
            OnProgress("DeleteFileHandler", "Handler Execution Failed.", StatusType.Failed, 0, cheapSequence++, false, e);
            throw e;
        }

        OnProgress("DeleteFileHandler", "Handler Execution Completed.", StatusType.Complete, 0, cheapSequence++);
        return(result);
    }
Esempio n. 9
0
        public void WindowsDirectoryPurge()
        {
            ZephyrDirectory dir = Global.StageTestFilesToWindows();

            Assert.That(!dir.IsEmpty);

            dir.Purge();
            Assert.That(dir.Exists);
            Assert.That(dir.IsEmpty);

            dir.Delete();
        }
Esempio n. 10
0
        public void WindowsDirectoryCreateDirectoryMethod()
        {
            String path = Path.Combine(Global.WindowsWorkingPath, $"{Global.RandomDirectory}\\");

            Console.WriteLine(path);
            ZephyrDirectory dir = Global.WindowsWorkingDirectory.CreateDirectory(path);

            Assert.That(!dir.Exists);
            dir.Create();
            Assert.That(dir.Exists);
            dir.Delete();
        }
Esempio n. 11
0
        public void WindowsDirectoryIsEmpty()
        {
            String path = Path.Combine(Global.WindowsWorkingPath, $"{Global.RandomDirectory}\\");

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

            dir.Create();
            Assert.That(dir.IsEmpty);

            Global.TestFilesDirectory.CopyTo(dir, verbose: false);
            Assert.That(!dir.IsEmpty);

            dir.Delete();
        }
Esempio n. 12
0
        public void WindowsDirectoryGetDirectoriesandGetFiles()
        {
            ZephyrDirectory dir = Global.StageTestFilesToWindows();

            List <ZephyrDirectory> dirs = (List <ZephyrDirectory>)(dir.GetDirectories());

            Console.WriteLine($"Found [{dirs.Count}] Sub-directories.");
            Assert.AreEqual(dirs.Count, 3);

            List <ZephyrFile> files = (List <ZephyrFile>)(dir.GetFiles());

            Console.WriteLine($"Found [{files.Count}] Files.");
            Assert.AreEqual(files.Count, 5);

            dir.Delete(verbose: false);
        }
Esempio n. 13
0
        public void AwsS3DirectoryPurge()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory dir = Global.StageTestFilesToAws();

            Assert.IsFalse(dir.IsEmpty);

            dir.Purge();
            Assert.IsTrue(dir.Exists);
            Assert.IsTrue(dir.IsEmpty);

            dir.Delete();
        }
Esempio n. 14
0
        public void AwsS3DirectoryCreateDirectoryMethod()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

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

            Console.WriteLine(path);
            ZephyrDirectory dir = Global.AwsS3WorkingDirectory.CreateDirectory(path);

            Assert.IsFalse(dir.Exists);
            dir.Create();
            Assert.IsTrue(dir.Exists);
            dir.Delete();
        }
Esempio n. 15
0
        public void AwsS3FileCreateDirectoryMethod()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            String path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";

            Console.WriteLine(path);
            ZephyrFile file = new AwsS3ZephyrFile(Global.Clients.aws, path);

            ZephyrDirectory dir = Global.AwsS3WorkingDirectory.CreateDirectory(path);

            Assert.That(!dir.Exists);
            dir.Create();
            Assert.That(dir.Exists);
            dir.Delete();
            file.Delete();
        }
Esempio n. 16
0
        public void WindowsFileCreateDirectoryMethod()
        {
            if (!Global.TestWindows)
            {
                throw new Exception("Windows Tests Are Not Enabled.  Set Global.TestWindows To True To Enable.");
            }

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

            Console.WriteLine(path);
            ZephyrFile file = new WindowsZephyrFile(path);

            ZephyrDirectory dir = Global.WindowsWorkingDirectory.CreateDirectory(path);

            Assert.That(!dir.Exists);
            dir.Create();
            Assert.That(dir.Exists);
            dir.Delete();
            file.Delete();
        }
Esempio n. 17
0
        public void AwsS3DirectoryIsEmpty()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

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

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

            dir.Create();
            Assert.IsTrue(dir.IsEmpty);

            Global.TestFilesDirectory.CopyTo(dir, verbose: false);
            Assert.IsFalse(dir.IsEmpty);

            dir.Delete();
        }
Esempio n. 18
0
        public void AwsS3DirectoryGetDirectoriesandGetFiles()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory dir = Global.StageTestFilesToAws();

            List <ZephyrDirectory> dirs = (List <ZephyrDirectory>)(dir.GetDirectories());

            Console.WriteLine($"Found [{dirs.Count}] Sub-directories.");
            Assert.AreEqual(dirs.Count, 3);

            List <ZephyrFile> files = (List <ZephyrFile>)(dir.GetFiles());

            Console.WriteLine($"Found [{files.Count}] Files.");
            Assert.AreEqual(files.Count, 5);

            dir.Delete(verbose: false);
        }
Esempio n. 19
0
        public void AwsS3FileReadAllText()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory   source = Global.StageTestFilesToAws();
            List <ZephyrFile> files  = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                Console.WriteLine($"File: {file.FullName}");
                String content = file.ReadAllText();
                Console.WriteLine(content);
                Assert.IsNotEmpty(content);
            }

            source.Delete();
        }
Esempio n. 20
0
        public void WindowsFileCopyToWindowsFile()
        {
            if (!Global.TestWindows)
            {
                throw new Exception("Windows Tests Are Not Enabled.  Set Global.TestWindows To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToWindows();

            List <ZephyrFile> files = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                String     path = Path.Combine(Global.WindowsWorkingPath, Global.RandomFile);
                ZephyrFile dest = new WindowsZephyrFile(path);
                file.CopyTo(dest);
                Assert.That(File.Exists(path));
                dest.Delete();
            }

            source.Delete();
        }
Esempio n. 21
0
        public void AwsS3FileCopyToAwsS3File()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToAws();

            List <ZephyrFile> files = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                String     path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";
                ZephyrFile dest = new AwsS3ZephyrFile(Global.Clients.aws, path);
                file.CopyTo(dest);
                Assert.That(Utilities.Exists(path, Global.Clients));
                dest.Delete();
            }

            source.Delete();
        }
Esempio n. 22
0
        public void WindowsFileReadAllBytes()
        {
            if (!Global.TestWindows)
            {
                throw new Exception("Windows Tests Are Not Enabled.  Set Global.TestWindows To True To Enable.");
            }

            ZephyrDirectory   source = Global.StageTestFilesToWindows();
            List <ZephyrFile> files  = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                Console.WriteLine($"File: {file.FullName}");
                byte[] content = file.ReadAllBytes();
                foreach (byte b in content)
                {
                    Console.Write(b);
                }
                Assert.IsNotEmpty(content);
            }

            source.Delete();
        }