Ejemplo n.º 1
0
        public async Task <string> EditFileAsync(string content, string fileName, CancellationToken cancellationToken = default(CancellationToken))
        {
            TaskUtilities.AssertIsOnBackgroundThread();
            var editor = _coreShell.GetService <IFileEditor>();

            if (!string.IsNullOrEmpty(content))
            {
                return(await editor.EditFileAsync(content, null, cancellationToken));
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                if (_session.IsRemote)
                {
                    using (var dts = new DataTransferSession(_session, _fileSystem)) {
                        // TODO: handle progress for large files
                        try {
                            await dts.FetchFileToLocalTempAsync(fileName.ToRPath(), null, cancellationToken);

                            fileName = _fileSystem.GetDownloadsPath(Path.GetFileName(fileName));
                            return(await editor.EditFileAsync(null, fileName, cancellationToken));
                        } catch (OperationCanceledException) { }
                    }
                }
                return(await editor.EditFileAsync(null, fileName, cancellationToken));
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public async Task ViewFile(string fileName, string tabName, bool deleteFile, CancellationToken cancellationToken = default(CancellationToken))
        {
            var viewer = _coreShell.GetService <IObjectViewer>();
            var task   = Task.CompletedTask;

            if (_session.IsRemote)
            {
                using (var dts = new DataTransferSession(_session, _fileSystem)) {
                    // TODO: handle progress for large files
                    try {
                        await dts.FetchFileToLocalTempAsync(fileName.ToRPath(), null, cancellationToken);

                        fileName = _fileSystem.GetDownloadsPath(Path.GetFileName(fileName));
                        await viewer?.ViewFile(fileName, tabName, deleteFile, cancellationToken);
                    } catch (REvaluationException) { } catch (RHostDisconnectedException) { }
                }
            }
            else
            {
                await viewer?.ViewFile(fileName, tabName, deleteFile, cancellationToken);
            }
        }