示例#1
0
        public async Task <(ReturnResult, IStorageItem)> CreateAsync(IStorageItemWithPath source, bool registerHistory)
        {
            var returnCode = FileSystemStatusCode.InProgress;
            var errorCode  = new Progress <FileSystemStatusCode>();

            errorCode.ProgressChanged += (s, e) => returnCode = e;

            var result = await filesystemOperations.CreateAsync(source, errorCode, cancellationToken);

            if (registerHistory && !string.IsNullOrWhiteSpace(source.Path))
            {
                App.HistoryWrapper.AddHistory(result.Item1);
            }

            return(returnCode.ToStatus(), result.Item2);
        }
示例#2
0
        public async Task <ReturnResult> CreateAsync(IStorageItemWithPath source, bool registerHistory)
        {
            FilesystemErrorCode            returnCode = FilesystemErrorCode.ERROR_INPROGRESS;
            Progress <FilesystemErrorCode> errorCode  = new Progress <FilesystemErrorCode>();

            errorCode.ProgressChanged += (s, e) => returnCode = e;

            IStorageHistory history = await filesystemOperations.CreateAsync(source, errorCode, cancellationToken);

            if (registerHistory && !string.IsNullOrWhiteSpace(source.Path))
            {
                App.HistoryWrapper.AddHistory(history);
            }

            return(returnCode.ToStatus());
        }
        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.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;
                }

                List <IStorageHistory> rawStorageHistory = new List <IStorageHistory>();
                for (int i = 0; i < history.Source.Count(); i++)
                {
                    rawStorageHistory.Add(await filesystemOperations.DeleteAsync(
                                              history.Source.ElementAt(i),
                                              null,
                                              errorCode,
                                              false,
                                              cancellationToken));
                }

                if (rawStorageHistory.TrueForAll((item) => item != null))
                {
                    IStorageHistory newHistory = new StorageHistory(
                        FileOperationType.Recycle,
                        rawStorageHistory.SelectMany((item) => item?.Source).ToList(),
                        rawStorageHistory.SelectMany((item) => item?.Destination).ToList());

                    // 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);
        }
示例#4
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);
        }