コード例 #1
0
ファイル: NodeViewModel.cs プロジェクト: rrsc/uwp
        /// <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);
        }
コード例 #2
0
        private void AddOfflineNodeFromTransfer(TransferObjectModel megaTransfer)
        {
            var parentNode = SdkService.MegaSdk.getParentNode(megaTransfer.SelectedNode.OriginalMNode);

            // Need get the path on the transfer finish because the file name can be changed if already exists in the destiny path.
            var offlineNodePath = Path.Combine(
                OfflineService.GetOfflineParentNodePath(megaTransfer.SelectedNode.OriginalMNode),
                megaTransfer.Transfer.getFileName());

            var sfoNode = new SavedForOfflineDB
            {
                Fingerprint        = SdkService.MegaSdk.getNodeFingerprint(megaTransfer.SelectedNode.OriginalMNode),
                Base64Handle       = megaTransfer.SelectedNode.OriginalMNode.getBase64Handle(),
                LocalPath          = offlineNodePath,
                ParentBase64Handle = parentNode != null?
                                     parentNode.getBase64Handle() : string.Empty
            };

            if (SavedForOfflineDB.ExistsNodeByLocalPath(sfoNode.LocalPath))
            {
                SavedForOfflineDB.UpdateNode(sfoNode);
            }
            else
            {
                SavedForOfflineDB.InsertNode(sfoNode);
            }

            UiService.OnUiThread(() => megaTransfer.SelectedNode.IsSavedForOffline = true);

            OfflineService.CheckOfflineNodePath(megaTransfer.SelectedNode.OriginalMNode);
        }
コード例 #3
0
ファイル: NodeViewModel.cs プロジェクト: rrsc/uwp
        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);
        }