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

SendFileAsync() public method

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
return Task
        public async Task<IRBlobInfo> SendFileAsync(string filePath, bool doCleanUp, IProgress<long> progress, CancellationToken cancellationToken) {
            IRBlobInfo blob = null;
            using (RBlobStream blobStream = await RBlobStream.CreateAsync(_blobService))
            using (Stream fileStream = _fs.FileOpen(filePath, FileMode.Open)){
                await fileStream.CopyToAsync(blobStream, progress, cancellationToken);
                blob = blobStream.GetBlobInfo();
            }

            if (doCleanUp) {
                _cleanup.Add(blob);
            }
            return blob;
        }

Usage Example

示例#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);
             });
         }
     }
 }
All Usage Examples Of Microsoft.R.Host.Client.DataTransferSession::SendFileAsync