コード例 #1
0
ファイル: CloudDriveViewModel.cs プロジェクト: chsergey/sdk
 public void OnNodeTap(NodeViewModel node)
 {
     switch (node.Type)
     {
         case MNodeType.TYPE_FOLDER:
             {
                 SelectFolder(node);
                 break;
             }
     }
 }
コード例 #2
0
        private async Task <bool> RecursiveDownloadFolder(String downloadPath, NodeViewModel folderNode)
        {
            if (String.IsNullOrWhiteSpace(folderNode.Name))
            {
                await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                              AppMessages.AM_DownloadNodeFailedNoErrorCode, this.AppInformation).ShowDialogAsync();
                return(false);
            }

            // Check for illegal characters in the folder name
            if (FolderService.HasIllegalChars(folderNode.Name))
            {
                await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                              String.Format(AppMessages.InvalidFolderNameOrPath, folderNode.Name),
                                              this.AppInformation).ShowDialogAsync();
                return(false);
            }

            try
            {
                String newDownloadPath = Path.Combine(downloadPath, folderNode.Name);
                if (!await CheckDownloadPath(newDownloadPath))
                {
                    return(false);
                }

                MNodeList childList = MegaSdk.getChildren(folderNode.OriginalMNode);

                bool result = true; // Default value in case that the folder is empty
                for (int i = 0; i < childList.size(); i++)
                {
                    // To avoid pass null values to CreateNew
                    if (childList.get(i) == null)
                    {
                        continue;
                    }

                    var childNode = NodeService.CreateNew(this.MegaSdk, this.AppInformation, childList.get(i), ContainerType.CloudDrive);

                    // If node creation failed for some reason, continue with the rest and leave this one
                    if (childNode == null)
                    {
                        continue;
                    }

                    bool partialResult;
                    if (childNode.IsFolder)
                    {
                        partialResult = await RecursiveDownloadFolder(newDownloadPath, childNode);
                    }
                    else
                    {
                        partialResult = await DownloadFile(newDownloadPath, childNode);
                    }

                    // Only change the global result if the partial result indicates an error
                    if (!partialResult)
                    {
                        result = partialResult;
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                OnUiThread(() =>
                {
                    new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                            String.Format(AppMessages.DownloadNodeFailed, e.Message),
                                            App.AppInformation).ShowDialog();
                });

                return(false);
            }
        }
コード例 #3
0
ファイル: CloudDriveViewModel.cs プロジェクト: chsergey/sdk
 public void SelectFolder(NodeViewModel selectedNode)
 {
     this.CurrentRootNode = selectedNode;
     // Create unique uri string to navigate
     NavigateService.NavigateTo(typeof(MainPage), NavigationParameter.Browsing, new Dictionary<string, string> {{"Id", Guid.NewGuid().ToString("N")}});
 }
コード例 #4
0
 public DownloadNodeViewModel(NodeViewModel selectedNode)
 {
     SelectedNode = selectedNode;
 }
コード例 #5
0
        private async Task <bool> SaveFileForOffline(TransferQueu transferQueu, String sfoPath, NodeViewModel node)
        {
            if (FileService.FileExists(Path.Combine(sfoPath, node.Name)))
            {
                return(true);
            }

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

            if (existingNode != null)
            {
                bool result = await FileService.CopyFile(existingNode.LocalPath, sfoPath);

                if (!result)
                {
                    return(false);
                }

                SavedForOffline.Insert(node.OriginalMNode, true);
            }
            else
            {
                transferQueu.Add(node.Transfer);
                node.Transfer.DownloadFolderPath = sfoPath;
                node.Transfer.StartTransfer(true);
            }

            return(true);
        }
コード例 #6
0
        private async Task RecursiveSaveForOffline(TransferQueu transferQueu, String sfoPath, NodeViewModel node)
        {
            if (!FolderService.FolderExists(sfoPath))
            {
                FolderService.CreateFolder(sfoPath);
            }

            String newSfoPath = Path.Combine(sfoPath, node.Name);

            if (!FolderService.FolderExists(newSfoPath))
            {
                FolderService.CreateFolder(newSfoPath);
            }

            if (!SavedForOffline.ExistsNodeByLocalPath(newSfoPath))
            {
                SavedForOffline.Insert(node.OriginalMNode, true);
            }
            else
            {
                SavedForOffline.UpdateNode(node.OriginalMNode, true);
            }

            MNodeList childList = MegaSdk.getChildren(node.OriginalMNode);

            for (int i = 0; i < childList.size(); i++)
            {
                // To avoid pass null values to CreateNew
                if (childList.get(i) == null)
                {
                    continue;
                }

                var childNode = NodeService.CreateNew(this.MegaSdk, this.AppInformation, childList.get(i), this.ParentContainerType);

                // If node creation failed for some reason, continue with the rest and leave this one
                if (childNode == null)
                {
                    continue;
                }

                if (childNode.IsFolder)
                {
                    await RecursiveSaveForOffline(transferQueu, newSfoPath, childNode);
                }
                else
                {
                    await SaveFileForOffline(transferQueu, newSfoPath, childNode);
                }
            }
        }
コード例 #7
0
        private async Task <bool> DownloadFile(TransferQueu transferQueu, String downloadPath, NodeViewModel fileNode)
        {
            if (String.IsNullOrWhiteSpace(fileNode.Name))
            {
                await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                              AppMessages.AM_DownloadNodeFailedNoErrorCode, App.AppInformation).ShowDialogAsync();
                return(false);
            }

            if (FileService.HasIllegalChars(fileNode.Name))
            {
                await new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                              String.Format(AppMessages.InvalidFileName, fileNode.Name),
                                              App.AppInformation).ShowDialogAsync();
                return(false);
            }

            try
            {
                if (!await CheckDownloadPath(Path.GetDirectoryName(fileNode.Transfer.FilePath)))
                {
                    return(false);
                }

                fileNode.Transfer.DownloadFolderPath = downloadPath;
                transferQueu.Add(fileNode.Transfer);
                fileNode.Transfer.StartTransfer();
            }
            catch (Exception e)
            {
                String message;
                if (e is ArgumentException || e is NotSupportedException)
                {
                    message = String.Format(AppMessages.InvalidFileName, fileNode.Transfer.FilePath);
                }
                else if (e is PathTooLongException)
                {
                    message = String.Format(AppMessages.PathTooLong, fileNode.Transfer.FilePath);
                }
                else if (e is UnauthorizedAccessException)
                {
                    message = String.Format(AppMessages.FolderUnauthorizedAccess, Path.GetDirectoryName(fileNode.Transfer.FilePath));
                }
                else
                {
                    message = String.Format(AppMessages.DownloadNodeFailed, e.Message);
                }

                OnUiThread(() =>
                {
                    new CustomMessageDialog(AppMessages.DownloadNodeFailed_Title,
                                            message, App.AppInformation).ShowDialog();
                });

                return(false);
            }

            return(true);
        }