示例#1
0
        public void ProcessFileNode(IMegaNode node)
        {
            this.FocusedNode = node;

            var existingNode = SavedForOffline.ReadNodeByFingerprint(this.MegaSdk.getNodeFingerprint(node.OriginalMNode));

            if (existingNode != null && !String.IsNullOrWhiteSpace(existingNode.LocalPath) &&
                FileService.FileExists(existingNode.LocalPath))
            {
                var offlineNode = new OfflineFileNodeViewModel(new FileInfo(existingNode.LocalPath));
                offlineNode.Open();
            }
            else
            {
                if (node.IsImage)
                {
                    OnUiThread(() => NavigateService.NavigateTo(typeof(PreviewImagePage), NavigationParameter.Normal, this));
                }
                else
                {
                    this.FocusedNode.Download(TransfersService.MegaTransfers);
                }
            }
        }
示例#2
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);
        }