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

FetchFileAsync() public method

Gets the data for a given blob from R-Host. Saves the data to filePath. This method adds the blob for clean up by default.
public FetchFileAsync ( IRBlobInfo blob, string filePath, bool doCleanUp, IProgress progress, CancellationToken cancellationToken ) : Task
blob IRBlobInfo Blob from which the data is to be retrieved.
filePath string Path to the file where the retrieved data will be written.
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 FetchFileAsync(IRBlobInfo blob, string filePath, bool doCleanUp, IProgress<long> progress, CancellationToken cancellationToken) {
            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService))
            using (Stream fileStream = _fs.CreateFile(filePath)) {
                await blobStream.CopyToAsync(fileStream, progress, cancellationToken);
            }

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

Usage Example

Beispiel #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::FetchFileAsync