Exemple #1
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);
        }