private bool ConfirmCommand(FileOperation type, bool isPlural)
        {
            var title   = Resx.ResourceManager.GetString(type.ToString());
            var message = Resx.ResourceManager.GetString(string.Format(isPlural ? "{0}ConfirmationPlural" : "{0}ConfirmationSingular", type));

            return(WindowManager.Confirm(title, message));
        }
Example #2
0
        public FileSystemCompareOperation(int?step = null, FileOperation operation = FileOperation.None, FileSystemItem item = null, string message = null)
        {
            Step      = step;
            Operation = operation;
            Item      = item ?? new FileSystemItem(FileType.None, null); //initialize empty object
            Message   = message;

            OperationText = operation == FileOperation.None ? string.Empty : string.Concat(operation.ToString().ToUpper(), " ", item.Type.ToString().ToUpper());
        }
Example #3
0
        /// <summary>
        /// Actually does the file moves.
        /// </summary>
        protected override void DoFileOperations()
        {
            // If the operation map is empty, exit (return) the method.
            if (OperationMap.Count <= 0)
            {
                return;
            }

            // loop thru our file list
            for (int i = 0; i < OperationMap.Count; i++)
            {
                // Setup a temporary var to hold the current file operation
                // details.
                FileOperation currentOperation = OperationMap[i];
                if (currentOperation.SourceIsIdenticalToTarget())
                {
                    Log(Level.Warning, String.Format("Skipping self-move of {0}.",
                                                     currentOperation.Source));
                    continue;
                }

                try
                {
                    Log(Level.Verbose, "Moving {0}.", currentOperation.ToString());

                    string destinationDirectory = null;

                    switch (currentOperation.OperationType)
                    {
                    case OperationType.FileToFile:
                        // Setup the dest directory var
                        destinationDirectory =
                            Path.GetDirectoryName(currentOperation.Target);

                        // create directory if not present
                        if (!Directory.Exists(destinationDirectory))
                        {
                            Directory.CreateDirectory(destinationDirectory);
                            Log(Level.Verbose, "Created directory '{0}'.",
                                destinationDirectory);
                        }

                        // Ensure the target file is removed before
                        // attempting to move.
                        if (File.Exists(currentOperation.Target))
                        {
                            File.Delete(currentOperation.Target);
                        }

                        // move the file with filters
                        FileUtils.MoveFile(currentOperation.Source,
                                           currentOperation.Target, Filters,
                                           InputEncoding, OutputEncoding);

                        break;

                    case OperationType.FileToDirectory:
                        // Setup the dest directory var
                        destinationDirectory = currentOperation.Target;

                        // Setup a local var that combines the directory
                        // of the target path with the source file name.
                        string targetFile = Path.Combine(destinationDirectory,
                                                         Path.GetFileName(currentOperation.Source));

                        // create directory if not present
                        if (!Directory.Exists(destinationDirectory))
                        {
                            Directory.CreateDirectory(destinationDirectory);
                            Log(Level.Verbose, "Created directory '{0}'.",
                                destinationDirectory);
                        }

                        // Ensure the target file is removed before
                        // attempting to move.
                        if (File.Exists(targetFile))
                        {
                            File.Delete(targetFile);
                        }

                        // move the file with filters
                        FileUtils.MoveFile(currentOperation.Source,
                                           targetFile, Filters, InputEncoding, OutputEncoding);

                        break;

                    case OperationType.DirectoryToDirectory:

                        // Move over the entire directory with filters
                        FileUtils.MoveDirectory(currentOperation.Source,
                                                currentOperation.Target, Filters, InputEncoding,
                                                OutputEncoding);
                        break;

                    default:
                        throw new
                              BuildException("Unrecognized move operation. " +
                                             "The move task can only move a file to file, " +
                                             "file to directory, or directory to directory.");
                    }
                }
                catch (IOException ex)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Failed to move {0}.", currentOperation.ToString()),
                                             Location, ex);
                }
            }

            int fileMovements = OperationMap.CountFileOperations();
            int dirMovements  = OperationMap.CountDirectoryOperations();

            if (fileMovements > 0)
            {
                Log(Level.Info, "{0} file{1} moved.", fileMovements,
                    fileMovements != 1 ? "s" : "");
            }
            if (dirMovements > 0)
            {
                Log(Level.Info, "{0} {1} moved.", dirMovements,
                    dirMovements != 1 ? "directories" : "directory");
            }
        }
        public void InitializeTransfer(Queue <QueueItem> queue, FileOperation mode)
        {
            _queue = queue;
            _paneCache.Clear();
            _isPaused                    = false;
            _isAborted                   = false;
            _isContinued                 = false;
            _deleteAll                   = false;
            _skipAll                     = null;
            UserAction                   = mode;
            TransferAction               = mode == FileOperation.Copy ? GetCopyActionText() : Resx.ResourceManager.GetString(mode.ToString());
            _rememberedCopyAction        = CopyAction.CreateNew;
            _currentFileBytesTransferred = 0;
            CurrentFileProgress          = 0;
            FilesTransferred             = 0;
            FileCount                    = _queue.Count;
            BytesTransferred             = 0;
            TotalBytes                   = _queue.Where(item => item.FileSystemItem.Type == ItemType.File).Sum(item => item.FileSystemItem.Size ?? 0);
            Speed         = 0;
            ElapsedTime   = new TimeSpan(0);
            RemainingTime = new TimeSpan(0);

            WorkHandler.Run(BeforeTransferStart, BeforeTransferStartCallback);
        }
 public override string ToString()
 {
     //MODE: File Branch@Repo
     return(string.Format("{0}: \'{1}\'\t\t{2}@{3}", FileOperation.ToString(), FileName, Branch, Repository));
 }
 private bool ConfirmCommand(FileOperation type, bool isPlural)
 {
     var title = Resx.ResourceManager.GetString(type.ToString());
     var message = Resx.ResourceManager.GetString(string.Format(isPlural ? "{0}ConfirmationPlural" : "{0}ConfirmationSingular", type));
     return WindowManager.Confirm(title, message);
 }