Ejemplo n.º 1
0
        private void doRename()
        {
            List <string> parsedTokens = parseTokensFromPattern();

            DateTimeReference = DateTime.Now;
            foreach (var file in SourceFiles)
            {
                var computedNewName = Pattern;
                foreach (var token in parsedTokens)
                {
                    var tokenKey = token.Substring(0, 1);
                    if (!Tokens.ContainsKey(tokenKey))
                    {
                        throw new UnrecognizedReplacementToken(token);
                    }

                    var replacerFunc = Tokens[tokenKey];
                    computedNewName = replacerFunc(token, file, computedNewName);
                }

                computedNewName = Path.Combine(Path.GetDirectoryName(file), computedNewName);

                if (FileExists(computedNewName))
                {
                    throw new Exception($"Cannot rename {file} to {computedNewName} because the latter already exists");
                }

                FileSystemCommands.FileMove(file, computedNewName);
                SendReport($"Renamed {file} to {computedNewName} using pattern {Pattern}", ReportType.Progress);
                RenamedFiles.Add(file, computedNewName);
            }
        }
        public override bool PreFlightCheck()
        {
            if (FileSystemCommands.DirectoryExists(SourceDirectory) && !PreflightCheckWriteAccessToDirectory(SourceDirectory))
            {
                return(false);
            }

            return(DefaultPreFlightCheckSuccess());
        }
 private bool preFileCopyCallback(string sourceFile, string targetFile)
 {
     if (FileSystemCommands.FileExists(targetFile))
     {
         _atLeastOneTargetFileExists = true;
         SendReport($"Aborted copy of files from {SourceDirectory} to {TargetDirectory} because target file {targetFile} already exists", ReportType.DoneTaskWithFailure);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
 public override bool PreFlightCheck()
 {
     foreach (var file in SourceFiles.Keys)
     {
         var sourceDir = Path.GetDirectoryName(file);
         if (FileSystemCommands.DirectoryExists(sourceDir) && !PreflightCheckWriteAccessToDirectory(sourceDir))
         {
             return(false);
         }
     }
     return(DefaultPreFlightCheckSuccess());
 }
        public override void Undo()
        {
            int filesDeleted = 0;

            foreach (var copiedFile in CopiedFiles)
            {
                FileSystemCommands.FileDelete(copiedFile);
                SendReport($"Deleted file {copiedFile} during DirectoryCopyContentsCommand.Undo()", ReportType.Progress);
                filesDeleted++;
            }
            SendReport($"Deleted {filesDeleted} file(s) on undo", ReportType.UndoneTaskWithSuccess);
        }
        public override void Do()
        {
            SourceFiles.Clear();
            foreach (var dir in SourceDirectories)
            {
                foreach (var file in FileSystemCommands.DirectoryGetFiles(dir))
                {
                    SourceFiles.Add(file);
                }
            }

            base.Do();
        }
 protected override void Delete()
 {
     try {
         SendReport($"Deleting directory {SourceDirectory} ...", ReportType.Progress);
         FileSystemCommands.DirectoryDelete(SourceDirectory);
         SendReport($"Directory {SourceDirectory} deleted", ReportType.DoneTaskWithSuccess);
         DidCommandSucceed = true;
     }
     catch (Exception exc) {
         DidCommandSucceed = false;
         SendReport($"Failed to delete directory {SourceDirectory}. {exc.Message}", ReportType.DoneTaskWithFailure);
     }
 }
        public override bool PreFlightCheck()
        {
            foreach (var dir in SourceDirectories)
            {
                if (!FileSystemCommands.DirectoryExists(dir))
                {
                    SendReport(this, $"{ShortName} is likely to fail because at least one of its source directories {dir} was not found, or application does not have sufficient permissions", ReportType.DonePreFlightWithFailure);
                    return(false);
                }
                if (!PreflightCheckDirectoryReadWriteAccess(dir))
                {
                    return(false);
                }
            }

            return(DefaultPreFlightCheckSuccess());
        }
Ejemplo n.º 9
0
        public override bool PreFlightCheck()
        {
            foreach (var file in SourceFiles)
            {
                if (FileSystemCommands.DirectoryExists(file))
                {
                    if (!PreflightCheckDirectoryReadWriteAccess(file))
                    {
                        return(false);
                    }
                }

                if (!FileExists(file))
                {
                    SendReport($"{ShortName} is likely to FAIL because at least one of its sources ({file}) does not exist, or application does not have sufficient permissions.", ReportType.DonePreFlightWithFailure);
                    return(false);
                }
            }
            return(DefaultPreFlightCheckSuccess());
        }
        public override bool PreFlightCheck()
        {
            if (!FileSystemCommands.DirectoryExists(SourceDirectory))
            {
                SendReport(this, $"DirectoryCopyContentsCommand is likely to FAIL because source directory {SourceDirectory} does not exist",
                           ReportType.DonePreFlightWithFailure);
                return(false);
            }

            if (!PreflightCheckReadAccessFromDirectory(SourceDirectory))
            {
                return(false);
            }


            if (!PreflightCheckWriteAccessToDirectory(TargetDirectory))
            {
                return(false);
            }

            return(DefaultPreFlightCheckSuccess());
        }
        public override void Do()
        {
            if (!FileSystemCommands.DirectoryExists(SourceDirectory))
            {
                SendReport($"Cannot copy contents of source {SourceDirectory} to {TargetDirectory} because source does not exist", ReportType.DoneTaskWithFailure);
                return;
            }

            _atLeastOneTargetFileExists = false;
            CopiedFiles.Clear();
            try {
                SendReport($"Starting copy of files from {SourceDirectory} to {TargetDirectory} ...", ReportType.Progress);
                FileSystemCommands.DirectoryCopyContents(SourceDirectory, TargetDirectory, preFileCopyCallback, postCopyCallback);
                DidCommandSucceed = !_atLeastOneTargetFileExists;
                if (DidCommandSucceed)
                {
                    SendReport($"Finished copy of files from {SourceDirectory} to {TargetDirectory}. File(s) copied: {CopiedFiles.Count}", ReportType.DoneTaskWithSuccess);
                }
            }
            catch (Exception exc) {
                DidCommandSucceed = false;
                SendReport($"Failed to copy files from {SourceDirectory} to {TargetDirectory}. {exc.Message}", ReportType.DoneTaskWithFailure);
            }
        }
 protected override void RunUndo()
 {
     FileSystemCommands.DirectoryMove(BackedUpDirectory, SourceDirectory);
 }
 protected override void RunUndo()
 {
     FileSystemCommands.DirectoryDeleteContentsOnly(SourceDirectory, null);
     FileSystemCommands.DirectoryMoveContents(BackedUpDirectory, SourceDirectory);
 }