예제 #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();
            }
        }
예제 #2
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;
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }