SendFileAsync() публичный Метод

Sends file to R-Host by creating a new blob. This method adds the blob for clean up by default.
public SendFileAsync ( string filePath, bool doCleanUp, IProgress progress, CancellationToken cancellationToken ) : Task
filePath string Path to the file to be sent to R-Host.
doCleanUp bool /// true to add blob created upon transfer for cleanup on dispose, false to ignore it after transfer. ///
progress IProgress
cancellationToken System.Threading.CancellationToken
Результат Task
Пример #1
0
 private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage, IApplicationShell appShell) {
     using (var fts = new DataTransferSession(session, fs)) {
         string currentStatusText = string.Empty;
         uint cookie = 0;
         IVsStatusbar statusBar = null;
         appShell.DispatchOnUIThread(() => {
             statusBar = appShell.GetGlobalService<IVsStatusbar>(typeof(SVsStatusbar));
             statusBar.GetText(out currentStatusText);
             statusBar.Progress(ref cookie, 1, "", 0, 0);
         });
         
         try {
             // TODO: progress and cancellation handling
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
             var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
             var publishResult = await session.EvaluateAsync<ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
             await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);
             appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
         } finally {
             appShell.DispatchOnUIThread(() => {
                 statusBar?.Progress(ref cookie, 0, "", 0, 0);
                 statusBar?.SetText(currentStatusText);
             });
         }
     }
 }
Пример #2
0
        private async Task<bool> SendToRemoteWorkerAsync(IEnumerable<string> files, string projectDir, string projectName, string remotePath, IVsStatusbar statusBar, CancellationToken cancellationToken) {
            await TaskUtilities.SwitchToBackgroundThread();

            string currentStatusText;
            statusBar.GetText(out currentStatusText);

            var workflow = _interactiveWorkflowProvider.GetOrCreate();
            var outputWindow = workflow.ActiveWindow.InteractiveWindow;
            uint cookie = 0;
            try {
                var session = workflow.RSession;
                statusBar.SetText(Resources.Info_CompressingFiles);
                statusBar.Progress(ref cookie, 1, "", 0, 0);

                int count = 0;
                uint total = (uint)files.Count() * 2; // for compressing and sending
                string compressedFilePath = string.Empty;
                await Task.Run(() => {
                    compressedFilePath = _fs.CompressFiles(files, projectDir, new Progress<string>((p) => {
                        Interlocked.Increment(ref count);
                        statusBar.Progress(ref cookie, 1, string.Format(Resources.Info_CompressingFile, Path.GetFileName(p)), (uint)count, total);
                        string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                        _appShell.DispatchOnUIThread(() => {
                            outputWindow.WriteLine(string.Format(Resources.Info_LocalFilePath, p));
                            outputWindow.WriteLine(string.Format(Resources.Info_RemoteFilePath, dest));
                        });
                    }), CancellationToken.None);
                    statusBar.Progress(ref cookie, 0, "", 0, 0);
                });

                using (var fts = new DataTransferSession(session, _fs)) {
                    cookie = 0;
                    statusBar.SetText(Resources.Info_TransferringFiles);

                    total = (uint)_fs.FileSize(compressedFilePath);

                    var remoteFile = await fts.SendFileAsync(compressedFilePath, true, new Progress<long>((b) => {
                        statusBar.Progress(ref cookie, 1, Resources.Info_TransferringFiles, (uint)b, total);
                    }), cancellationToken);

                    statusBar.SetText(Resources.Info_ExtractingFilesInRHost);
                    await session.EvaluateAsync<string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, cancellationToken);

                    _appShell.DispatchOnUIThread(() => {
                        outputWindow.WriteLine(Resources.Info_TransferringFilesDone);
                    });
                }
            } catch(Exception ex) when (ex is UnauthorizedAccessException || ex is IOException) {
                _appShell.ShowErrorMessage(Resources.Error_CannotTransferFile.FormatInvariant(ex.Message));
            } catch (RHostDisconnectedException rhdex) {
                _appShell.DispatchOnUIThread(() => {
                    outputWindow.WriteErrorLine(Resources.Error_CannotTransferNoRSession.FormatInvariant(rhdex.Message));
                });
            } finally {
                statusBar.Progress(ref cookie, 0, "", 0, 0);
                statusBar.SetText(currentStatusText);
            }

            return true;
        }
Пример #3
0
        private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString, CancellationToken cancellationToken) {
            ProgressOutputWriter.WriteLine(Resources.Info_PreparingProjectForTransfer);

            var projectDir = Path.GetDirectoryName(project.FullName);
            var projectName = Path.GetFileNameWithoutExtension(project.FullName);

            string[] filterSplitter = { ";" };
            Matcher matcher = new Matcher(StringComparison.InvariantCultureIgnoreCase);
            matcher.AddIncludePatterns(filterString.Split(filterSplitter, StringSplitOptions.RemoveEmptyEntries));

            ProgressOutputWriter.WriteLine(Resources.Info_RemoteDestination.FormatInvariant(remotePath));
            ProgressOutputWriter.WriteLine(Resources.Info_FileTransferFilter.FormatInvariant(filterString));
            ProgressOutputWriter.WriteLine(Resources.Info_CompressingFiles);

            var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress<string>((p) => {
                ProgressOutputWriter.WriteLine(Resources.Info_LocalFilePath.FormatInvariant(p));
                string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                ProgressOutputWriter.WriteLine(Resources.Info_RemoteFilePath.FormatInvariant(dest));
            }), CancellationToken.None);
            
            using (var fts = new DataTransferSession(Session, FileSystem)) {
                ProgressOutputWriter.WriteLine(Resources.Info_TransferringFiles);
                var remoteFile = await fts.SendFileAsync(compressedFilePath, true, null, cancellationToken);
                await Session.EvaluateAsync<string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, cancellationToken);
            }

            ProgressOutputWriter.WriteLine(Resources.Info_TransferringFilesDone);
        }