Esempio n. 1
0
        public async Task <bool> SaveForOffline()
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return(false);
            }

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

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

            String parentNodePath;

            if (ParentContainerType != ContainerType.PublicLink)
            {
                parentNodePath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""),
                                              (SdkService.MegaSdk.getNodePath(parentNode)).Remove(0, 1).Replace("/", "\\"));
            }
            else
            {
                // If is a public node (link) the destination folder is the SFO root
                parentNodePath = sfoRootPath;
            }

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

            if (this.IsFolder)
            {
                await RecursiveSaveForOffline(parentNodePath, this);
            }
            else
            {
                await SaveFileForOffline(parentNodePath, this);
            }

            this.IsAvailableOffline = this.IsSelectedForOffline = true;

            // Check and add to the DB if necessary the previous folders of the path
            while (String.Compare(parentNodePath, sfoRootPath) != 0)
            {
                var folderPathToAdd = parentNodePath;
                parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                if (!SavedForOffline.ExistsNodeByLocalPath(folderPathToAdd))
                {
                    SavedForOffline.Insert(parentNode);
                }

                parentNode = SdkService.MegaSdk.getParentNode(parentNode);
            }

            return(true);
        }
Esempio n. 2
0
        private async Task RecursiveSaveForOffline(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(newSfoPath, childNode);
                }
                else
                {
                    await SaveFileForOffline(newSfoPath, childNode);
                }
            }
        }
Esempio n. 3
0
        public async void SaveForOffline()
        {
            // User must be online to perform this operation
            if (!await IsUserOnlineAsync())
            {
                return;
            }

            var offlineParentNodePath = OfflineService.GetOfflineParentNodePath(this.OriginalMNode);

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

            var existingNode = SavedForOfflineDB.SelectNodeByFingerprint(MegaSdk.getNodeFingerprint(this.OriginalMNode));

            if (existingNode != null)
            {
                bool result = this.IsFolder ?
                              await FolderService.CopyFolderAsync(existingNode.LocalPath, offlineParentNodePath) :
                              await FileService.CopyFileAsync(existingNode.LocalPath, offlineParentNodePath);

                if (result)
                {
                    SavedForOfflineDB.InsertNode(this.OriginalMNode);
                }
            }
            else
            {
                TransferService.MegaTransfers.Add(this.OfflineTransfer);
                this.OfflineTransfer.StartTransfer(true);
            }

            this.IsSavedForOffline = true;

            OfflineService.CheckOfflineNodePath(this.OriginalMNode);
        }
 public async Task <IActionResult> CreateFolder([FromBody] Folder folder)
 {
     return(Ok(await _folderService.CreateFolder(folder)));
 }