public async Task <string> FetchFileAsync(string remoteFileName, ulong remoteBlobId, string localPath, CancellationToken cancellationToken) { await _coreShell.SwitchToMainThreadAsync(cancellationToken); if (!string.IsNullOrEmpty(localPath)) { if (_fileSystem.DirectoryExists(localPath)) { localPath = Path.Combine(localPath, remoteFileName); } } else { localPath = _fileSystem.GetDownloadsPath(remoteFileName); } try { var message = Resources.Progress_FetchingFile.FormatInvariant(remoteFileName); _coreShell.ProgressDialog().Show(async(progress, ct) => { using (DataTransferSession dts = new DataTransferSession(_session, _fileSystem)) { await dts.FetchAndDecompressFileAsync(remoteBlobId, localPath, progress, message, cancellationToken); } }, message); } catch (Exception ex) { _coreShell.ShowErrorMessage(Resources.Error_UnableToTransferFile.FormatInvariant(localPath, ex.Message)); return(string.Empty); } return(localPath); }
private static async Task CreateCsvAndStartProcess( IREvaluationResultInfo result, IRSession session, ICoreShell coreShell, string fileName, IFileSystem fileSystem, IProgress <ProgressDialogData> progress, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; var dec = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; try { var csvDataBlobId = await session.EvaluateAsync <ulong>($"rtvs:::export_to_csv({result.Expression}, sep={sep.ToRStringLiteral()}, dec={dec.ToRStringLiteral()})", REvaluationKind.Normal, cancellationToken); using (DataTransferSession dts = new DataTransferSession(session, fileSystem)) { await dts.FetchAndDecompressFileAsync(csvDataBlobId, fileName, progress, Resources.Status_WritingCSV, cancellationToken); } } catch (RException) { await coreShell.ShowErrorMessageAsync(Resources.Error_CannotExportToCsv, cancellationToken); } }