Microsoft.R.Host.Client.DataTransferSession.CopyFileToRemoteTempAsync C# (CSharp) Method

CopyFileToRemoteTempAsync() public method

Copies file from local file path to Temp folder on the remote session.
public CopyFileToRemoteTempAsync ( string filePath, bool doCleanUp, IProgress progress, CancellationToken cancellationToken ) : Task
filePath string Path to the file to be sent to remote session.
doCleanUp bool true to add blob upon transfer for cleanup on dispose, false to ignore it after transfer.
progress IProgress
cancellationToken System.Threading.CancellationToken
return Task
        public async Task<string> CopyFileToRemoteTempAsync(string filePath, bool doCleanUp, IProgress<long> progress, CancellationToken cancellationToken) {
            string fileName = Path.GetFileName(filePath);
            var blobinfo = await SendFileAsync(filePath, doCleanUp, progress, cancellationToken);
            return await _session.EvaluateAsync<string>(Invariant($"rtvs:::save_to_temp_folder({blobinfo.Id}, {fileName.ToRStringLiteral()})"), REvaluationKind.Normal, cancellationToken);
        }

Usage Example

Beispiel #1
0
        public async Task<CommandResult> InvokeAsync() {
            string filePath = GetFilePath();
            if (filePath == null) {
                return CommandResult.NotSupported;
            }

            var textView = GetActiveTextView();
            var activeWindow = _interactiveWorkflow.ActiveWindow;
            if (textView == null || activeWindow == null) {
                return CommandResult.NotSupported;
            }

            _interactiveWorkflow.Shell.SaveFileIfDirty(filePath);
            activeWindow.Container.Show(focus: false, immediate: false);

            var session = _interactiveWorkflow.RSession;
            if (session.IsRemote) {
                using (DataTransferSession dts = new DataTransferSession(_interactiveWorkflow.RSession, new FileSystem())) {
                    // TODO: add progress indication and cancellation
                    string remotePath = await dts.CopyFileToRemoteTempAsync(filePath, true, null, CancellationToken.None);
                    await _interactiveWorkflow.Operations.SourceFileAsync(remotePath, _echo, textView.TextBuffer.GetEncoding());
                }
            } else {
                await _interactiveWorkflow.Operations.SourceFileAsync(filePath, _echo, textView.TextBuffer.GetEncoding());
            }
            return CommandResult.Executed;
        }