Esempio n. 1
0
        /// <summary>
        /// Remove the node from the offline section.
        /// </summary>
        /// <returns>TRUE if the node was successfully removed or FALSE in other case.</returns>
        public bool RemoveFromOffline()
        {
            var nodePath       = OfflineService.GetOfflineNodePath(this.OriginalMNode);
            var parentNodePath = OfflineService.GetOfflineParentNodePath(this.OriginalMNode);

            // Search if the file has a pending transfer for offline and cancel it on this case
            TransferService.CancelPendingNodeOfflineTransfers(this);

            bool result = true;

            if (this.IsFolder)
            {
                result &= OfflineService.RemoveFolderFromOfflineDB(nodePath);
                result &= FolderService.DeleteFolder(nodePath, true);
            }
            else
            {
                result &= SavedForOfflineDB.DeleteNodeByLocalPath(nodePath);
                result &= FileService.DeleteFile(nodePath);
            }

            result &= OfflineService.CleanOfflineFolderNodePath(parentNodePath);
            this.IsSavedForOffline = !result;

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Remove the node from the offline section.
        /// </summary>
        /// <param name="isMultiSelect">Indicate if is removing multiple nodes.</param>
        /// <returns>NULL if the user cancel the action, TRUE if the node was successfully removed or FALSE in other case.</returns>
        public async Task <bool?> RemoveFromOfflineAsync(bool isMultiSelect = false)
        {
            bool?result = true;

            if (!isMultiSelect)
            {
                var userSelection = await DialogService.ShowOkCancelAsync(
                    ResourceService.AppMessages.GetString("AM_RemoveFromOfflineQuestion_Title"),
                    string.Format(ResourceService.AppMessages.GetString("AM_RemoveFromOfflineQuestion"), this.Name));

                if (!userSelection)
                {
                    return(null);
                }
            }

            // Search if the node has pending transfers for offline and cancel them on this case
            TransferService.CancelPendingNodeOfflineTransfers(this);

            var directoryInfo = new DirectoryInfo(this.NodePath).Parent;

            if (directoryInfo != null)
            {
                var parentFolderPath = directoryInfo.FullName;

                if (this.IsFolder)
                {
                    result &= OfflineService.RemoveFolderFromOfflineDB(this.NodePath);
                    result &= FolderService.DeleteFolder(this.NodePath, true);
                }
                else
                {
                    result &= SavedForOfflineDB.DeleteNodeByLocalPath(this.NodePath);
                    result &= FileService.DeleteFile(this.NodePath);
                }

                result &= OfflineService.CleanOfflineFolderNodePath(parentFolderPath);
            }

            result &= this.Parent?.ItemCollection?.Items?.Remove(this);

            return(result);
        }