Beispiel #1
0
        public async Task <ReturnResult> Redo(IStorageHistory history)
        {
            ReturnResult returnStatus = ReturnResult.InProgress;
            Progress <FileSystemStatusCode> errorCode = new Progress <FileSystemStatusCode>();

            errorCode.ProgressChanged += (s, e) => { returnStatus = e.ToStatus(); };

            switch (history.OperationType)
            {
            case FileOperationType.CreateNew:     // CreateNew PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                for (int i = 0; i < history.Source.Count(); i++)
                {
                    await filesystemOperations.CreateAsync(history.Source.ElementAt(i), errorCode, cancellationToken);
                }

                break;
            }

            case FileOperationType.CreateLink:     // CreateLink PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                await filesystemOperations.CreateShortcutItemsAsync(history.Source, history.Destination.Select(item => item.Path), null, errorCode, cancellationToken);

                break;
            }

            case FileOperationType.Rename:     // Rename PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                NameCollisionOption collision = NameCollisionOption.GenerateUniqueName;
                for (int i = 0; i < history.Source.Count(); i++)
                {
                    await filesystemOperations.RenameAsync(
                        history.Source.ElementAt(i),
                        Path.GetFileName(history.Destination.ElementAt(i).Path),
                        collision,
                        errorCode,
                        cancellationToken);
                }

                break;
            }

            case FileOperationType.Copy:     // Copy PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                return(await filesystemHelpers.CopyItemsAsync(history.Source, history.Destination.Select((item) => item.Path), false, false));
            }

            case FileOperationType.Move:     // Move PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                return(await filesystemHelpers.MoveItemsAsync(history.Source, history.Destination.Select((item) => item.Path), false, false));
            }

            case FileOperationType.Extract:     // Extract PASS
            {
                returnStatus = ReturnResult.Success;
                Debugger.Break();

                break;
            }

            case FileOperationType.Recycle:     // Recycle PASS
            {
                if (IsHistoryNull(history.Destination))
                {
                    break;
                }

                var newHistory = await filesystemOperations.DeleteItemsAsync(history.Source, null, errorCode, false, cancellationToken);

                if (newHistory != null)
                {
                    // We need to change the recycled item paths (since IDs are different) - for Undo() to work
                    App.HistoryWrapper.ModifyCurrentHistory(newHistory);
                }
                else
                {
                    App.HistoryWrapper.RemoveHistory(history, true);
                }

                break;
            }

            case FileOperationType.Restore:     // Restore PASS
            {
                if (IsHistoryNull(history))
                {
                    break;
                }

                for (int i = 0; i < history.Destination.Count(); i++)
                {
                    await filesystemHelpers.RestoreFromTrashAsync(history.Source.ElementAt(i), history.Destination.ElementAt(i).Path, false);
                }

                break;
            }

            case FileOperationType.Delete:     // Delete PASS
            {
                returnStatus = ReturnResult.Success;

                break;
            }
            }

            return(returnStatus);
        }
Beispiel #2
0
        public async Task <ReturnResult> Redo(IStorageHistory history)
        {
            ReturnResult returnStatus = ReturnResult.InProgress;
            Progress <FileSystemStatusCode> errorCode = new();

            errorCode.ProgressChanged += (s, e) => { returnStatus = e.ToStatus(); };

            switch (history.OperationType)
            {
            case FileOperationType.CreateNew:
                if (IsHistoryNull(history))
                {
                    foreach (var source in history.Source)
                    {
                        await operations.CreateAsync(source, errorCode, cancellationToken);
                    }
                }
                break;

            case FileOperationType.CreateLink:
                if (!IsHistoryNull(history))
                {
                    await operations.CreateShortcutItemsAsync(history.Source,
                                                              await history.Destination.Select(item => item.Path).ToListAsync(), null, errorCode, cancellationToken);
                }
                break;

            case FileOperationType.Rename:
                if (!IsHistoryNull(history))
                {
                    NameCollisionOption collision = NameCollisionOption.GenerateUniqueName;
                    for (int i = 0; i < history.Source.Count; i++)
                    {
                        string name = Path.GetFileName(history.Destination[i].Path);
                        await operations.RenameAsync(history.Source[i], name, collision, errorCode, cancellationToken);
                    }
                }
                break;

            case FileOperationType.Copy:
                if (!IsHistoryNull(history))
                {
                    return(await helpers.CopyItemsAsync(history.Source, history.Destination.Select(item => item.Path), false, false));
                }
                break;

            case FileOperationType.Move:
                if (!IsHistoryNull(history))
                {
                    return(await helpers.MoveItemsAsync(history.Source, history.Destination.Select(item => item.Path), false, false));
                }
                break;

            case FileOperationType.Extract:
                returnStatus = ReturnResult.Success;
                Debugger.Break();
                break;

            case FileOperationType.Recycle:     // Recycle PASS
                if (!IsHistoryNull(history.Destination))
                {
                    var newHistory = await operations.DeleteItemsAsync(history.Source, null, errorCode, false, cancellationToken);

                    if (newHistory is null)
                    {
                        App.HistoryWrapper.RemoveHistory(history, true);
                    }
                    else
                    {
                        // We need to change the recycled item paths (since IDs are different) - for Undo() to work
                        App.HistoryWrapper.ModifyCurrentHistory(newHistory);
                    }
                }
                break;

            case FileOperationType.Restore:
                if (!IsHistoryNull(history))
                {
                    await helpers.RestoreItemsFromTrashAsync(history.Source, history.Destination.Select(item => item.Path), false);
                }
                break;

            case FileOperationType.Delete:
                returnStatus = ReturnResult.Success;
                break;
            }

            return(returnStatus);
        }