Example #1
0
        /// <summary>
        /// Move the node from its current location to a new folder destination
        /// </summary>
        /// <param name="newParentNode">The new destination folder</param>
        /// <returns>Result of the action</returns>
        public async Task <NodeActionResult> MoveAsync(MNode newParentNode)
        {
            // User must be online to perform this operation
            if (!await IsUserOnlineAsync())
            {
                return(NodeActionResult.NotOnline);
            }

            if (MegaSdk.checkMove(OriginalMNode, newParentNode).getErrorCode() != MErrorType.API_OK)
            {
                return(NodeActionResult.Failed);
            }

            var moveNode = new MoveNodeRequestListenerAsync();
            var result   = await moveNode.ExecuteAsync(() =>
                                                       MegaSdk.moveNode(OriginalMNode, newParentNode, moveNode));

            return(result ? NodeActionResult.Succeeded : NodeActionResult.Failed);
        }
Example #2
0
        public async Task <bool> RemoveAsync(bool isMultiSelect = false)
        {
            // User must be online to perform this operation
            if (!await IsUserOnlineAsync())
            {
                return(false);
            }

            if (this.OriginalMNode == null)
            {
                return(false);
            }

            if (!isMultiSelect && !(this is IncomingSharedFolderNodeViewModel))
            {
                string title, message;
                switch (this.Parent?.Type)
                {
                case ContainerType.CloudDrive:
                case ContainerType.CameraUploads:
                case ContainerType.ContactInShares:
                case ContainerType.InShares:
                case ContainerType.OutShares:
                    title   = ResourceService.AppMessages.GetString("AM_MoveToRubbishBinQuestion_Title");
                    message = string.Format(ResourceService.AppMessages.GetString("AM_MoveToRubbishBinQuestion"), this.Name);
                    break;

                case ContainerType.RubbishBin:
                    title   = ResourceService.AppMessages.GetString("AM_RemoveItemQuestion_Title");
                    message = string.Format(ResourceService.AppMessages.GetString("AM_RemoveItemQuestion"), this.Name);
                    break;

                default:
                    return(false);
                }

                var dialogResult = await DialogService.ShowOkCancelAsync(title, message);

                if (!dialogResult)
                {
                    return(true);
                }
            }

            bool result;

            if (this is IncomingSharedFolderNodeViewModel)
            {
                var leaveShare = new RemoveNodeRequestListenerAsync();
                result = await leaveShare.ExecuteAsync(() =>
                                                       this.MegaSdk.remove(this.OriginalMNode, leaveShare));
            }
            else
            {
                switch (this.Parent?.Type)
                {
                case ContainerType.CloudDrive:
                case ContainerType.CameraUploads:
                case ContainerType.ContactInShares:
                case ContainerType.InShares:
                case ContainerType.OutShares:
                    var moveNode = new MoveNodeRequestListenerAsync();
                    result = await moveNode.ExecuteAsync(() =>
                                                         this.MegaSdk.moveNode(this.OriginalMNode, this.MegaSdk.getRubbishNode(), moveNode));

                    break;

                case ContainerType.RubbishBin:
                    var removeNode = new RemoveNodeRequestListenerAsync();
                    result = await removeNode.ExecuteAsync(() =>
                                                           this.MegaSdk.remove(this.OriginalMNode, removeNode));

                    break;

                default:
                    return(false);
                }

                if (result)
                {
                    this.Parent.ClosePanels();
                }
            }

            return(result);
        }