コード例 #1
0
 public bool FileExists(string filename)
 {
     if (FileSystemCommands != null)
     {
         return(FileSystemCommands.FileExists(filename));
     }
     throw new NullFileSystemCommandsStrategyException();
 }
コード例 #2
0
 public Zip7CompressCommand(string exeLocation, string targetZipfilename, params string[] sourcesToZip)
 {
     ExeLocation                = exeLocation;
     TargetZipfilename          = targetZipfilename;
     SourcesToZip               = sourcesToZip;
     FileSystemCommandsStrategy = new FileSystemCommands();
     FileCompressionStrategy    = this;
 }
コード例 #3
0
 public void FileCopy(string sourceFile, string destinationFile)
 {
     if (FileSystemCommands != null)
     {
         FileSystemCommands.FileCopy(sourceFile, destinationFile);
         return;
     }
     throw new NullFileSystemCommandsStrategyException();
 }
コード例 #4
0
 public void FileDelete(string filename)
 {
     if (FileSystemCommands != null)
     {
         FileSystemCommands.FileDelete(filename);
         return;
     }
     throw new NullFileSystemCommandsStrategyException();
 }
コード例 #5
0
 private bool sourceDirExists()
 {
     if (!FileSystemCommands.DirectoryExists(SourceDirectory))
     {
         SendReport($"Cannot delete directory {SourceDirectory} because it doesn't exist", ReportType.DoneTaskWithSuccess);
         DidCommandSucceed = true;
         return(false);
     }
     return(true);
 }
コード例 #6
0
        protected bool TryWriteAccessToDirectory(string destinationDirectory)
        {
            int counter      = 0;
            var tempFileName = Path.Combine(destinationDirectory, $"cc_test_file{counter}.tmp");

            while (FileExists(tempFileName))
            {
                counter++;
                tempFileName = Path.Combine(destinationDirectory, $"cc_test_file{counter}.tmp");
            }
            FileSystemCommands.FileCreate(tempFileName);
            FileSystemCommands.FileDelete(tempFileName);
            return(true);
        }
コード例 #7
0
        public override void Cleanup()
        {
            if (!FileSystemCommands.DirectoryExists(BackedUpDirectory))
            {
                SendReport($"Cannot delete contents of folder {SourceDirectory} during cleanup because it does not exist", ReportType.DoneTaskWithSuccess);
                return;
            }

            try {
                FileSystemCommands.DirectoryDelete(BackedUpDirectory);
                SendReport($"Deleted backup folder {BackedUpDirectory} during cleanup", ReportType.DoneCleanupWithSuccess);
            }
            catch (Exception exc) {
                SendReport($"Failed to delete backup folder {BackedUpDirectory} during cleanup. {exc.Message}", ReportType.DoneCleanupWithFailure);
            }
        }
コード例 #8
0
        /// <summary>
        /// Implements the copy path for selecteditems command(s) for
        /// left view A and right view B.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="isFromA">Whether the selection parameter should be interpreted
        /// for left view A or right view B.</param>
        private static void CopySelectedItemsPathIntoClipboard(object p, bool isFromA)
        {
            var param = (p as string);

            if (param != null)
            {
                FileSystemCommands.CopyString(param);
            }
            else
            {
                var list = p as IEnumerable <IDirEntryViewModel>;
                if (list != null)
                {
                    var scopy = new StringBuilder();
                    foreach (var item in list)
                    {
                        if (isFromA)
                        {
                            if (item.IsItemInA)
                            {
                                scopy.Append(item.ItemPathA + '\n');
                            }
                            else
                            {
                                scopy.Append('\n');
                            }
                        }
                        else
                        {
                            if (item.IsItemInB)
                            {
                                scopy.Append(item.ItemPathB + '\n');
                            }
                            else
                            {
                                scopy.Append('\n');
                            }
                        }
                    }

                    FileSystemCommands.CopyString(scopy.ToString());
                }
            }
        }
コード例 #9
0
        private bool createBackup()
        {
            BackedUpDirectory = Path.Combine(BackupDirectory, $"{new DirectoryInfo(SourceDirectory).Name}");
            var counter = 0;

            while (FileSystemCommands.DirectoryExists(BackedUpDirectory))
            {
                BackedUpDirectory = Path.Combine(BackupDirectory, $"{new DirectoryInfo(SourceDirectory).Name}{counter}");
                counter++;
            }
            try {
                SendReport($"Creating backup of folder {SourceDirectory} to {BackedUpDirectory} ...", ReportType.Progress);
                FileSystemCommands.DirectoryCopyContents(SourceDirectory, BackedUpDirectory, null, null);
                SendReport($"Created backup of folder {SourceDirectory} to {BackedUpDirectory}", ReportType.Progress);
                return(true);
            }
            catch (Exception exc) {
                SendReport($"Directory delete aborted because attempt to backup folder {SourceDirectory} to {BackedUpDirectory} failed: {exc.Message}", ReportType.DoneTaskWithFailure);
                return(false);
            }
        }
コード例 #10
0
        private static void CopyHyperlinkUri(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                if (sender == null || e == null)
                {
                    return;
                }

                e.Handled = true;

                PathTrimmingFileHyperlink whLink = sender as PathTrimmingFileHyperlink;

                if (whLink == null)
                {
                    return;
                }

                FileSystemCommands.CopyPath(whLink.NavigateUri);
            }
            catch { }
        }
コード例 #11
0
        /// <summary>
        /// Process command when a hyperlink has been clicked.
        /// Start a web browser and let it browse to where this points to...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Hyperlink_CommandNavigateTo(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                if (sender == null || e == null)
                {
                    return;
                }

                e.Handled = true;

                FileHyperlink whLink = sender as FileHyperlink;

                if (whLink == null)
                {
                    return;
                }

                FileSystemCommands.OpenInWindows(whLink.NavigateUri);
            }
            catch {}
        }
コード例 #12
0
 protected bool TryReadAccessFromDirectory(string sourceDirectory)
 {
     FileSystemCommands.DirectoryGetFiles(sourceDirectory);
     return(true);
 }
コード例 #13
0
 public BaseFileCommand()
 {
     FileSystemCommands = new FileSystemCommands();
 }
コード例 #14
0
 public static ITask NewDirectory(Action <FileSystemNewDirectoryParameters> parameters)
 {
     return(FileSystemCommands.NewDirectory().Execute(parameters));
 }
コード例 #15
0
 public static ITask Delete(Action <FileSystemDeleteParameters> parameters)
 {
     return(FileSystemCommands.Delete().Execute(parameters));
 }