Ejemplo n.º 1
0
        private async void RemoveItem(object obj)
        {
            if (await FocusedNode.RemoveAsync(false) != NodeActionResult.Cancelled)
            {
                String parentNodePath = ((new DirectoryInfo(FocusedNode.NodePath)).Parent).FullName;

                String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                  AppResources.DownloadsDirectory.Replace("\\", ""));

                // Check if the previous folders of the path are empty and
                // remove from the offline and the DB on this case
                while (String.Compare(parentNodePath, sfoRootPath) != 0)
                {
                    var folderPathToRemove = parentNodePath;
                    parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                    if (FolderService.IsEmptyFolder(folderPathToRemove))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => GoFolderUp());
                        FolderService.DeleteFolder(folderPathToRemove);
                        SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                    }
                }

                Refresh();
            }
        }
Ejemplo n.º 2
0
        public async Task RemoveForOffline(AutoResetEvent waitEventRequest = null)
        {
            String parentNodePath = ((new DirectoryInfo(this.NodePath)).Parent).FullName;

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            if (this.IsFolder)
            {
                await RecursiveRemoveForOffline(parentNodePath, this.Name);

                FolderService.DeleteFolder(this.NodePath, true);
            }
            else
            {
                // Search if the file has a pending transfer for offline and cancel it on this case
                TransfersService.CancelPendingNodeOfflineTransfers(this.NodePath, this.IsFolder);

                FileService.DeleteFile(this.NodePath);
            }

            SavedForOffline.DeleteNodeByLocalPath(this.NodePath);

            if (this.ParentCollection != null)
            {
                this.ParentCollection.Remove((IOfflineNode)this);
            }

            if (waitEventRequest != null)
            {
                waitEventRequest.Set();
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void DeleteFolder(int FolderID, int ProjectID)
 {
     // If the user can open the project he can delete files.
     if (Pservice.CanUserOpenProject(ProjectID, User.Identity.Name))
     {
         if (!FoService.DeleteFolder(FolderID))
         {
             // If the delete fails we throw an exception.
             throw new Exception();
         }
     }
 }
Ejemplo n.º 5
0
        public IHttpActionResult DeleteFolder(string folderName)
        {
            var folder = _context.Folders.SingleOrDefault(x => x.Name == folderName);

            if (folder != null)
            {
                FolderService.DeleteFolder(_context, folder);

                return(Ok("Folder, subfolders and files in associated folders are deleted."));
            }

            return(BadRequest("Folder with provided name doesn't exist."));
        }
Ejemplo n.º 6
0
        private void MultipleRemoveItems(int count)
        {
            var helperList = new List <IOfflineNode>(count);

            helperList.AddRange(ChildNodes.Where(n => n.IsMultiSelected));

            Task.Run(async() =>
            {
                WaitHandle[] waitEventRequests = new WaitHandle[count];

                int index = 0;

                foreach (var node in helperList)
                {
                    waitEventRequests[index] = new AutoResetEvent(false);
                    await node.RemoveAsync(true, (AutoResetEvent)waitEventRequests[index]);
                    index++;
                }

                WaitHandle.WaitAll(waitEventRequests);

                String parentNodePath = Path.GetDirectoryName(this.FolderRootNode.NodePath);

                String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                  AppResources.DownloadsDirectory.Replace("\\", ""));

                // Check if the previous folders of the path are empty and
                // remove from the offline and the DB on this case
                while (String.Compare(parentNodePath, sfoRootPath) != 0)
                {
                    var folderPathToRemove = parentNodePath;
                    parentNodePath         = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                    if (FolderService.IsEmptyFolder(folderPathToRemove))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => GoFolderUp());
                        FolderService.DeleteFolder(folderPathToRemove);
                        SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                    }
                }

                Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.SetProgressIndicator(false));

                Refresh();
            });

            this.IsMultiSelectActive = false;
        }
Ejemplo n.º 7
0
        public async Task <bool> RemoveForOffline()
        {
            bool result;

            MNode parentNode = SdkService.MegaSdk.getParentNode(this.OriginalMNode);

            String parentNodePath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                 AppResources.DownloadsDirectory.Replace("\\", ""),
                                                 (SdkService.MegaSdk.getNodePath(parentNode)).Remove(0, 1).Replace("/", "\\"));

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            var nodePath = Path.Combine(parentNodePath, this.Name);

            if (this.IsFolder)
            {
                await RecursiveRemoveForOffline(parentNodePath, this.Name);

                result = FolderService.DeleteFolder(nodePath, true);
            }
            else
            {
                // Search if the file has a pending transfer for offline and cancel it on this case
                TransfersService.CancelPendingNodeOfflineTransfers(nodePath, this.IsFolder);

                result = FileService.DeleteFile(nodePath);
            }

            SavedForOffline.DeleteNodeByLocalPath(nodePath);
            this.IsAvailableOffline = this.IsSelectedForOffline = false;

            // Check if the previous folders of the path are empty and
            // remove from the offline and the DB on this case
            while (String.Compare(parentNodePath, sfoRootPath) != 0)
            {
                var folderPathToRemove = parentNodePath;
                parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                if (FolderService.IsEmptyFolder(folderPathToRemove))
                {
                    result = result & FolderService.DeleteFolder(folderPathToRemove);
                    SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                }
            }

            return(result);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Load the nodes for this specific folder
        /// </summary>
        public void LoadChildNodes()
        {
            // First cancel any other loading task that is busy
            CancelLoad();

            // FolderRootNode should not be null
            if (FolderRootNode == null)
            {
                OnUiThread(() =>
                {
                    new CustomMessageDialog(
                        AppMessages.LoadNodesFailed_Title,
                        AppMessages.LoadNodesFailed,
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();
                });
                return;
            }

            SetProgressIndication(true);

            // Process is started so we can set the empty content template to loading already
            SetEmptyContentTemplate(true);

            // Clear the child nodes to make a fresh start
            ClearChildNodes();

            // Set the correct view for the main drive. Do this after the childs are cleared to speed things up
            SetViewOnLoad();

            // Build the bread crumbs. Do this before loading the nodes so that the user can click on home
            OnUiThread(BuildBreadCrumbs);

            // Create the option to cancel
            CreateLoadCancelOption();

            // Load and create the childnodes for the folder
            Task.Factory.StartNew(() =>
            {
                try
                {
                    ObservableCollection <IOfflineNode> tempChildNodes = new ObservableCollection <IOfflineNode>();

                    String[] childFolders = Directory.GetDirectories(FolderRootNode.NodePath);
                    foreach (var folder in childFolders)
                    {
                        var childNode = new OfflineFolderNodeViewModel(new DirectoryInfo(folder), tempChildNodes);
                        if (childNode == null)
                        {
                            continue;
                        }

                        if (FolderService.IsEmptyFolder(childNode.NodePath))
                        {
                            FolderService.DeleteFolder(childNode.NodePath, true);
                            continue;
                        }

                        Deployment.Current.Dispatcher.BeginInvoke(() => tempChildNodes.Add(childNode));
                    }

                    String[] childFiles = Directory.GetFiles(FolderRootNode.NodePath);
                    foreach (var file in childFiles)
                    {
                        var fileInfo = new FileInfo(file);

                        if (FileService.IsPendingTransferFile(fileInfo.Name))
                        {
                            if (!(TransfersService.MegaTransfers.Downloads.Count > 0))
                            {
                                FileService.DeleteFile(fileInfo.FullName);
                            }
                            continue;
                        }

                        var childNode = new OfflineFileNodeViewModel(fileInfo, tempChildNodes);
                        if (childNode == null)
                        {
                            continue;
                        }

                        Deployment.Current.Dispatcher.BeginInvoke(() => tempChildNodes.Add(childNode));
                    }

                    OrderChildNodes(tempChildNodes);

                    // Show the user that processing the childnodes is done
                    SetProgressIndication(false);

                    // Set empty content to folder instead of loading view
                    SetEmptyContentTemplate(false);

                    OnUiThread(() => OnPropertyChanged("HasChildNodesBinding"));
                }
                catch (OperationCanceledException)
                {
                    // Do nothing. Just exit this background process because a cancellation exception has been thrown
                }
            }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Load the nodes for this specific folder
        /// </summary>
        public override void LoadChildNodes()
        {
            // First cancel any other loading task that is busy
            CancelLoad();

            // FolderRootNode should not be null
            if (FolderRootNode == null)
            {
                OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_LoadNodesFailed_Title"),
                        ResourceService.AppMessages.GetString("AM_LoadNodesFailed"));
                });
                return;
            }

            SetProgressIndication(true);

            // Process is started so we can set the empty content template to loading already
            SetEmptyContent(true);

            // Clear the child nodes to make a fresh start
            ClearChildNodes();

            // Set the correct view for the main drive. Do this after the childs are cleared to speed things up
            SetViewOnLoad();

            // Build the bread crumbs. Do this before loading the nodes so that the user can click on home
            OnUiThread(() => this.BreadCrumb.Create(this));

            // Create the option to cancel
            CreateLoadCancelOption();

            // Load and create the childnodes for the folder
            Task.Factory.StartNew(() =>
            {
                try
                {
                    // We will not add nodes one by one in the dispatcher but in groups
                    List <IOfflineNode> helperList;
                    try { helperList = new List <IOfflineNode>(1024); }
                    catch (ArgumentOutOfRangeException) { helperList = new List <IOfflineNode>(); }

                    this.ItemCollection.DisableCollectionChangedDetection();

                    string[] childFolders = Directory.GetDirectories(FolderRootNode.NodePath);
                    foreach (var folder in childFolders)
                    {
                        var childNode = new OfflineFolderNodeViewModel(new DirectoryInfo(folder), this, this.ItemCollection.Items);
                        if (childNode == null)
                        {
                            continue;
                        }

                        if (FolderService.IsEmptyFolder(childNode.NodePath))
                        {
                            FolderService.DeleteFolder(childNode.NodePath, true);
                            continue;
                        }

                        OnUiThread(() => this.ItemCollection.Items.Add(childNode));
                    }

                    string[] childFiles = Directory.GetFiles(FolderRootNode.NodePath);
                    foreach (var file in childFiles)
                    {
                        var fileInfo = new FileInfo(file);

                        if (FileService.IsPendingTransferFile(fileInfo.Name))
                        {
                            if (!(TransferService.MegaTransfers.Downloads.Count > 0))
                            {
                                FileService.DeleteFile(fileInfo.FullName);
                            }
                            continue;
                        }

                        var childNode = new OfflineFileNodeViewModel(fileInfo, this, this.ItemCollection.Items);

                        OnUiThread(() => this.ItemCollection.Items.Add(childNode));
                    }

                    this.ItemCollection.EnableCollectionChangedDetection();

                    this.OrderChildNodes();

                    // Show the user that processing the childnodes is done
                    SetProgressIndication(false);

                    // Set empty content to folder instead of loading view
                    SetEmptyContent(false);
                }
                catch (OperationCanceledException)
                {
                    // Do nothing. Just exit this background process because a cancellation exception has been thrown
                }
            }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current);
        }