public static bool VerifyClonedFileSystemStructure(FileSystemSite source, FileSystemSite destination, IStringlyTypedPathOperator stringlyTypedPathOperator, TextWriter writer) { var sourcePaths = source.FileSystemOperator.EnumerateFileSystemEntryPaths(source.DirectoryPath, true); var sourceRelativePaths = sourcePaths.Select(path => stringlyTypedPathOperator.GetRelativePath(source.DirectoryPath, path)); var expectedDestinationPaths = sourceRelativePaths.Select(path => stringlyTypedPathOperator.Combine(destination.DirectoryPath, path)); var actualDestinationPaths = destination.FileSystemOperator.EnumerateFileSystemEntryPaths(destination.DirectoryPath, true); var output = true; var missingDestinationPaths = expectedDestinationPaths.Except(actualDestinationPaths); if (missingDestinationPaths.Count() > 0) { output = false; writer.WriteLine($"Paths missing (count: {missingDestinationPaths.Count()}):"); foreach (var missingDestinationPath in missingDestinationPaths) { writer.WriteLine(missingDestinationPath); } } return(output); }
/// <summary> /// Create a directory structure for use in testing. /// </summary> /// <param name="site"></param> public static void CreateExampleDirectoryStructure(FileSystemSite site, IStringlyTypedPathOperator stringlyTypedPathOperator) { var fileSystemOperator = site.FileSystemOperator; var baseDirectoryPath = site.DirectoryPath; // Create directories. var directory01Path = stringlyTypedPathOperator.GetDirectoryPath(baseDirectoryPath, ExampleDirectoryNames.Directory01); var directory02Path = stringlyTypedPathOperator.GetDirectoryPath(baseDirectoryPath, ExampleDirectoryNames.Directory02); var directory03Path = stringlyTypedPathOperator.GetDirectoryPath(directory02Path, ExampleDirectoryNames.Directory03); var directory04Path = stringlyTypedPathOperator.GetDirectoryPath(directory03Path, ExampleDirectoryNames.Directory04); foreach (var directoryPath in new string[] { directory01Path, directory02Path, directory03Path, directory04Path }) { fileSystemOperator.CreateDirectoryOnlyIfNotExists(directoryPath); } // Create files. var file01Path = stringlyTypedPathOperator.GetFilePath(baseDirectoryPath, ExampleFileNames.File01Name); var file02Path = stringlyTypedPathOperator.GetFilePath(directory01Path, ExampleFileNames.File02Name); var file03Path = stringlyTypedPathOperator.GetFilePath(directory02Path, ExampleFileNames.File03Name); var file04Path = stringlyTypedPathOperator.GetFilePath(directory02Path, ExampleFileNames.File04Name); var file05Path = stringlyTypedPathOperator.GetFilePath(directory03Path, ExampleFileNames.File05Name); var file06Path = stringlyTypedPathOperator.GetFilePath(directory04Path, ExampleFileNames.File06Name); foreach (var filePath in new string[] { file01Path, file02Path, file03Path, file04Path, file05Path, file06Path }) { using (var writer = fileSystemOperator.CreateFileText(filePath)) { writer.WriteLine("CONTENT!"); } } }
public FileSystemSite GetDeploymentSourceSecretsDirectoryFileSystemSite() { var secretsDirectoryPath = this.SecretsDirectoryPathProvider.GetSecretsDirectoryPath(); var secretsDirectoryFileSystemSite = new FileSystemSite(secretsDirectoryPath, this.LocalFileSystemOperator); return(secretsDirectoryFileSystemSite); }
public FileSystemSite GetDeploymentSourceFileSystemSite() { var projectOutputBinariesDirectoryPath = this.ProjectBuildOutputBinariesDirectoryPathProvider.GetProjectBuildOutputBinariesDirectoryPath(); var ensuredProjectOutputBinariesDirectoryPath = this.StringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(projectOutputBinariesDirectoryPath); var projectOutputBinariesLocalFileSystemSite = new FileSystemSite(ensuredProjectOutputBinariesDirectoryPath, this.LocalFileSystemOperator); return(projectOutputBinariesLocalFileSystemSite); }
public FileSystemSite GetDeploymentDestinationSecretsDirectoryFileSystemSite() { var remoteDeploymentSecretsSerialization = this.RemoteDeploymentSecretsSerializationProvider.GetRemoteDeploymentSecretsSerialization(); var remoteSecretsDirectoryPath = remoteDeploymentSecretsSerialization.DirectoryPath; // Put secrets files into the same directory as all the code. var remoteSecretsDirectoryFileSystemSite = new FileSystemSite(remoteSecretsDirectoryPath, this.RemoteFileSystemOperator); return(remoteSecretsDirectoryFileSystemSite); }
public FileSystemSite GetDeploymentDestinationFileSystemSite() { var localDeploymentSecretsSerialization = this.LocalDeploymentSecretsSerializationProvider.GetLocalDeploymentSecretsSerialization(); var ensuredDeploymentDirectoryPath = this.StringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(localDeploymentSecretsSerialization.DirectoryPath); var deploymentDestinationSite = new FileSystemSite(ensuredDeploymentDirectoryPath, this.LocalFileSystemOperator); return(deploymentDestinationSite); }
private static FileSystemSite GetFileSystemSite(string directoryPath, IFileSystemOperator fileSystemOperator, IServiceProvider serviceProvider) { var stringlyTypedPathOperator = serviceProvider.GetRequiredService <IStringlyTypedPathOperator>(); var ensuredDirectoryPath = stringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(directoryPath); var site = new FileSystemSite(ensuredDirectoryPath, fileSystemOperator); return(site); }
public FileSystemCloningOperatorTestFixture(FileSystemSite source, FileSystemSite destination, IFileSystemCloningOperator fileSystemCloningOperator, FileSystemCloningOptions options, IStringlyTypedPathOperator stringlyTypedPathOperator, TextWriter writer) { this.Source = source; this.Destination = destination; this.FileSystemCloningOperator = fileSystemCloningOperator; this.Options = options; this.StringlyTypedPathOperator = stringlyTypedPathOperator; this.Writer = writer; }
public static FileSystemSite EnsureSiteDirectoryPathIsDirectoryIndicated(this FileSystemSite site, IStringlyTypedPathOperator stringlyTypedPathOperator) { var directoryPathIsDirectoryIndicated = stringlyTypedPathOperator.IsDirectoryIndicatedPath(site.DirectoryPath); if (directoryPathIsDirectoryIndicated) { return(site); } else { var directoryIndicatedDirectoryPath = stringlyTypedPathOperator.EnsureDirectoryPathIsDirectoryIndicated(site.DirectoryPath); var output = new FileSystemSite(directoryIndicatedDirectoryPath, site.FileSystemOperator); return(output); } }
/// <summary> /// Clones the file-system source to the destination using <see cref="FileSystemCloningOptions.Default"/> options. /// </summary> public static void Clone(this IFileSystemCloningOperator fileSystemCloningOperator, FileSystemSite source, FileSystemSite destination) { fileSystemCloningOperator.Clone(source, destination, FileSystemCloningOptions.Default); }
public void Clone(FileSystemSite source, FileSystemSite destination, FileSystemCloningOptions options) { // Ensure the source and destination directories are directory indicated. var ensuredSource = source.EnsureSiteDirectoryPathIsDirectoryIndicated(this.StringlyTypedPathOperator); var ensuredDestination = destination.EnsureSiteDirectoryPathIsDirectoryIndicated(this.StringlyTypedPathOperator); // Get all source file-system entries. var sourceFileSystemEntries = ensuredSource.FileSystemOperator.EnumerateFileSystemEntries(ensuredSource.DirectoryPath, true) .ToList(); // Get all destination file-system entries. var destinationFileSystemEntries = ensuredDestination.FileSystemOperator.EnumerateFileSystemEntries(ensuredDestination.DirectoryPath, true) .ToList(); // Create relative-path source and destination file-system entries. FileSystemEntry MakeRelativeEntry(string baseDirectoryPath, FileSystemEntry entry) { var sourceBaseDirectoryRelativeEntryPath = this.StringlyTypedPathOperator.GetRelativePath(baseDirectoryPath, entry.Path); var relativeEntry = FileSystemEntry.New(sourceBaseDirectoryRelativeEntryPath, entry.Type, entry.LastModifiedUTC); return(relativeEntry); } var sourceBaseDirectoryRelativePathEntries = sourceFileSystemEntries.Select(entry => MakeRelativeEntry(ensuredSource.DirectoryPath, entry)) .Select(fileSystemEntry => { // Make sure we are using a common path format. var standardPathFileSystemEntry = fileSystemEntry.GetStandardPathFormatEntry(this.StringlyTypedPathOperator); return(standardPathFileSystemEntry); }) .ToList(); var destinationBaseDirectoryRelativePathEntries = destinationFileSystemEntries.Select(entry => MakeRelativeEntry(ensuredDestination.DirectoryPath, entry)) .Select(fileSystemEntry => { // Make sure we are using a common path format. var standardPathFileSystemEntry = fileSystemEntry.GetStandardPathFormatEntry(this.StringlyTypedPathOperator); return(standardPathFileSystemEntry); }) .ToList(); // Write out source and destination data. // Get the file-system cloning difference. var difference = this.FileSystemCloningDifferencer.PerformDifference(sourceBaseDirectoryRelativePathEntries, destinationBaseDirectoryRelativePathEntries, options); // Create a list of operations, using absolute paths. var operations = new List <IFileSystemCloningOperation>(); // Special case: the destination directory does not exist. If so, make sure it is created first to allow files to be copied into it! var destinationDirectoryExists = ensuredDestination.FileSystemOperator.ExistsDirectory(ensuredDestination.DirectoryPath); if (!destinationDirectoryExists) { var createDestinationDirectoryOperation = new CreateDirectoryOperation(ensuredDestination.DirectoryPath); operations.Add(createDestinationDirectoryOperation); } foreach (var directoryToCreate in difference.RelativeDirectoryPathsToCreate) { string destinationDirectoryToCreate = this.StringlyTypedPathOperator.Combine(ensuredDestination.DirectoryPath, directoryToCreate); var createDirectoryOperation = new CreateDirectoryOperation(destinationDirectoryToCreate); operations.Add(createDirectoryOperation); } foreach (var directoryToDelete in difference.RelativeDirectoryPathsToDelete) { string destinationDirectoryToDelete = this.StringlyTypedPathOperator.Combine(ensuredDestination.DirectoryPath, directoryToDelete); var deleteDirectoryOperation = new DeleteDirectoryOperation(destinationDirectoryToDelete); operations.Add(deleteDirectoryOperation); } foreach (var fileToCopy in difference.RelativeFilePathsToCopy) { string sourceFilePath = this.StringlyTypedPathOperator.Combine(ensuredSource.DirectoryPath, fileToCopy); string destinationFilePath = this.StringlyTypedPathOperator.Combine(ensuredDestination.DirectoryPath, fileToCopy); var copyFileOperation = new CopyFileOperation(sourceFilePath, destinationFilePath); operations.Add(copyFileOperation); } foreach (var fileToUpdate in difference.RelativeFilePathsToUpdate) { string sourceFilePath = this.StringlyTypedPathOperator.Combine(ensuredSource.DirectoryPath, fileToUpdate); string destinationFilePath = this.StringlyTypedPathOperator.Combine(ensuredDestination.DirectoryPath, fileToUpdate); var copyFileOperation = new CopyFileOperation(sourceFilePath, destinationFilePath); operations.Add(copyFileOperation); } foreach (var fileToDelete in difference.RelativeFilePathsToDelete) { string destinationFilePath = this.StringlyTypedPathOperator.Combine(ensuredDestination.DirectoryPath, fileToDelete); var deleteFileOperation = new DeleteFileOperation(destinationFilePath); operations.Add(deleteFileOperation); } // Write out and allow approval of the list of operations? // Execute the list of operations. foreach (var operation in operations) { operation.Execute(ensuredSource.FileSystemOperator, ensuredDestination.FileSystemOperator); } }
public Task CloneAsync(FileSystemSite source, FileSystemSite destination, FileSystemCloningOptions options, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public FileSystemCloningOperatorTestFixture(FileSystemSite source, FileSystemSite destination, IFileSystemCloningOperator fileSystemCloningOperator, IStringlyTypedPathOperator stringlyTypedPathOperator) : this(source, destination, fileSystemCloningOperator, FileSystemCloningOptions.Default, stringlyTypedPathOperator, Console.Out) { }
public static void TestFixtureClassCleanup(FileSystemSite source, FileSystemSite destination) { // Do nothing. }
public static void TestFixtureClassInitialize(FileSystemSite source, FileSystemSite destination) { // Do nothing. }