Exemple #1
0
 public ActionConverter(
     IEnumerable <IActionFactory> actionFactories,
     IFileSystemOperator fileSystemOperator)
 {
     _actionFactories    = actionFactories;
     _fileSystemOperator = fileSystemOperator;
 }
        // Extensions for filtering enumerated files/directories.

        // Extensions for reading/writing text lines.
        public static TextWriter CreateFileText(this IFileSystemOperator fileSystemOperator, string filePath, bool overwrite = true)
        {
            var writerStream     = fileSystemOperator.CreateFile(filePath, overwrite);
            var writerTextStream = new StreamWriter(writerStream); // Will close the stream, so ok!

            return(writerTextStream);
        }
 public static void Copy(this IFileSystemOperator sourceFileSystem, string sourceFilePath, IFileSystemOperator destinationFileSystem, string destinationFilePath, bool overwrite = true)
 {
     using (var source = sourceFileSystem.ReadFile(sourceFilePath))
     {
         destinationFileSystem.CopyTo(source, destinationFilePath, overwrite);
     }
 }
 protected BaseAction(IFileSystemOperator fileSystemOperator, string pattern)
 {
     _fileSystemOperator = fileSystemOperator;
     if (pattern != null)
     {
         _pattern = ToRegex(pattern);
     }
 }
        public static DateTime GetLastModifiedTimeUTC(this IFileSystemOperator fileSystemOperator, string path)
        {
            var output = fileSystemOperator.FileOrDirectorySwitch(path,
                                                                  () => fileSystemOperator.GetFileLastModifiedTimeUTC(path),
                                                                  () => fileSystemOperator.GetDirectoryLastModifiedTimeUTC(path));

            return(output);
        }
Exemple #6
0
        public static Task <IDictionary <string, string> > ReadContentsByFilePath(this IFileSystemOperator @operator, IDistinctEnumerable <string> filePaths)
        {
            var filePathsByFilePath = filePaths.ToDictionarySameKeyAndValue().AsDistinctValued();

            var contentsByFilePath = @operator.ReadContentsByKey(filePathsByFilePath);

            return(contentsByFilePath);
        }
        public static DateTime GetFileLastModifiedTime(this IFileSystemOperator fileSystemOperator, string filePath)
        {
            var lastModifiedTimeUTC = fileSystemOperator.GetFileLastModifiedTimeUTC(filePath);

            var lastModifiedTime = lastModifiedTimeUTC.ToLocalTime();

            return(lastModifiedTime);
        }
 public static async Task WriteTextFile(this IFileSystemOperator fileSystemOperator, string textFilePath, string text)
 {
     using (var fileStream = fileSystemOperator.OpenFile(textFilePath))
         using (var textWriter = new StreamWriter(fileStream))
         {
             await textWriter.WriteAsync(text);
         }
 }
        public static bool Exists(this IFileSystemOperator fileSystemOperator, string path)
        {
            var output = fileSystemOperator.FileOrDirectorySwitch(path,
                                                                  () => true,                                      // If the path is a file, then it exists.
                                                                  () => fileSystemOperator.ExistsDirectory(path)); // Else the path is either a directory, or does not exist.

            return(output);
        }
        public FileSystemOperatorSelfTestFixture(IFileSystemOperator fileSystemOperator, string rootDirectoryPath, IStringlyTypedPathOperator stringlyTypedPathOperator)
        {
            this.FileSystemOperator        = fileSystemOperator;
            this.RootDirectoryPath         = rootDirectoryPath;
            this.StringlyTypedPathOperator = stringlyTypedPathOperator;

            // Ensure the root directory is created.
            this.FileSystemOperator.CreateDirectoryOnlyIfNotExists(this.RootDirectoryPath);
        }
        public static async Task <string> ReadTextFile(this IFileSystemOperator fileSystemOperator, string textFilePath)
        {
            using (var fileStream = fileSystemOperator.ReadFile(textFilePath))
                using (var textReader = new StreamReader(fileStream))
                {
                    var text = await textReader.ReadToEndAsync();

                    return(text);
                }
        }
Exemple #12
0
        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);
        }
Exemple #13
0
 public DirectoryAction(
     IFileSystemOperator fileSystemOperator,
     IAction selfAction,
     IEnumerable <IAction> filesActions,
     IEnumerable <IAction> directoriesActions,
     string pattern) : base(fileSystemOperator, pattern)
 {
     _selfAction         = selfAction;
     _filesActions       = filesActions;
     _directoriesActions = directoriesActions;
 }
        public static void FileOrDirectorySwitch(this IFileSystemOperator fileSystemOperator, string path, Action fileAction, Action directoryAction)
        {
            var pathIsFile = fileSystemOperator.ExistsFile(path);

            if (pathIsFile)
            {
                fileAction();
            }
            else
            {
                directoryAction();
            }
        }
        public static T FileOrDirectorySwitch <T>(this IFileSystemOperator fileSystemOperator, string path, Func <T> fileFunction, Func <T> directoryFunction)
        {
            var pathIsFile = fileSystemOperator.ExistsFile(path);

            if (pathIsFile)
            {
                var output = fileFunction();
                return(output);
            }
            else
            {
                var output = directoryFunction();
                return(output);
            }
        }
Exemple #16
0
        public static async Task <IDictionary <TKey, bool> > ExistsFilesByKey <TKey>(this IFileSystemOperator @operator, IDistinctValuedDictionary <TKey, string> filePathsByKey)
        {
            var keysByFilePath = filePathsByKey.Invert();

            var existsByFilePath = await @operator.ExistsFiles(keysByFilePath.Keys.AsDistinct());

            var output = keysByFilePath.Join(existsByFilePath,
                                             keys => keys.Key,
                                             exists => exists.Key,
                                             (keys, exists) => (Key: keys.Value, Exists: exists.Value))
                         .ToDictionary(
                x => x.Key,
                x => x.Exists);

            return(output);
        }
 public void Execute(IFileSystemOperator sourceFileSystemOperator, IFileSystemOperator destinationFileSystemOperator)
 {
     destinationFileSystemOperator.DeleteDirectoryOnlyIfExists(this.DirectoryPath);
 }
Exemple #18
0
 public RemoveSymbolicLinkAction(IFileSystemOperator fileSystemOperator, string pattern) : base(fileSystemOperator, pattern)
 {
 }
 public CheckEmptyDirectoryAndRemoveActionFactory(IFileSystemOperator fileSystemOperator)
 {
     _fileSystemOperator = fileSystemOperator;
 }
 public CheckEmptyDirectoryAndHideAction(IFileSystemOperator fileSystemOperator, string pattern) : base(fileSystemOperator, pattern)
 {
 }
Exemple #21
0
 public CheckHiddenActionFactory(IFileSystemOperator fileSystemOperator)
 {
     _fileSystemOperator = fileSystemOperator;
 }
Exemple #22
0
 public void Execute(IFileSystemOperator sourceFileSystemOperator, IFileSystemOperator destinationFileSystemOperator)
 {
     sourceFileSystemOperator.Copy(this.SourceFilePath, destinationFileSystemOperator, this.DestinationFilePath);
 }
 public static void Move(this IFileSystemOperator fileSystemOperator, string sourcePath, string destinationPath, bool overwrite = true)
 {
     fileSystemOperator.FileOrDirectorySwitch(sourcePath,
                                              () => fileSystemOperator.MoveFile(sourcePath, destinationPath, overwrite),
                                              () => fileSystemOperator.MoveDirectory(sourcePath, destinationPath));
 }
 public RemoveSymbolicLinkActionFactory(IFileSystemOperator fileSystemOperator)
 {
     _fileSystemOperator = fileSystemOperator;
 }
        public static IOException GetCannotOverwriteFileIOException(this IFileSystemOperator fileSystemOperator, string filePath)
        {
            var output = CommonFileSystem.GetCannotOverwriteFileIOException(filePath);

            return(output);
        }
        public static bool IsFile(this IFileSystemOperator fileSystemOperator, string path)
        {
            var output = fileSystemOperator.ExistsFile(path);

            return(output);
        }
        public static bool IsExistingDirectory(this IFileSystemOperator fileSystemOperator, string path)
        {
            var output = fileSystemOperator.ExistsDirectory(path);

            return(output);
        }
 public QuietRemoveAction(IFileSystemOperator fileSystemOperator, string pattern) : base(fileSystemOperator, pattern)
 {
 }
 protected BaseDirectoryAction(IFileSystemOperator fileSystemOperator, string pattern) : base(fileSystemOperator, pattern)
 {
 }
 public IgnoreActionFactory(IFileSystemOperator fileSystemOperator)
 {
     _fileSystemOperator = fileSystemOperator;
 }