/// <summary> /// Gets the data for a given blob from R-Host. Decompresses it and saves the data to <paramref name="filePath"/>. This /// method adds the blob for clean up by default. /// </summary> /// <param name="blobId">Data block on remote machine</param> /// <param name="filePath">Path to the file where the retrieved data will be written.</param> public async Task FetchAndDecompressFileAsync(ulong blobId, string filePath, IProgress <ProgressDialogData> progress, string progressMessage, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var total = await _session.GetBlobSizeAsync(blobId, cancellationToken); progress.Report(new ProgressDialogData(0, statusBarText: progressMessage, waitMessage: progressMessage)); await FetchAndDecompressFileAsync(new RBlobInfo(blobId), filePath, true, new Progress <long>(b => { var step = (int)(b * 100 / total); progress.Report(new ProgressDialogData(step, statusBarText: progressMessage, waitMessage: progressMessage)); }), cancellationToken); progress.Report(new ProgressDialogData(100, statusBarText: progressMessage, waitMessage: progressMessage)); }
private static async Task CreateCsvAndStartProcess(IREvaluationResultInfo result, IRSession session, string fileName, IFileSystem fileSystem, IProgress <ProgressDialogData> progress) { await TaskUtilities.SwitchToBackgroundThread(); var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; var dec = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; using (var e = await session.BeginEvaluationAsync()) { var csvDataBlobId = await e.EvaluateAsync <ulong>($"rtvs:::export_to_csv({result.Expression}, sep={sep.ToRStringLiteral()}, dec={dec.ToRStringLiteral()})", REvaluationKind.Normal); using (DataTransferSession dts = new DataTransferSession(session, fileSystem)) { var total = await session.GetBlobSizeAsync(csvDataBlobId, CancellationToken.None); progress.Report(new ProgressDialogData(0, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); await dts.FetchFileAsync(new RBlobInfo(csvDataBlobId), fileName, true, new Progress <long>(b => { var step = (int)(b * 100 / total); progress.Report(new ProgressDialogData(step, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); })); progress.Report(new ProgressDialogData(100, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); } } }
private static async Task CreateCsvAndStartProcess( IREvaluationResultInfo result, IRSession session, string fileName, IFileSystem fileSystem, IProgress<ProgressDialogData> progress, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; var dec = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; 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)) { var total = await session.GetBlobSizeAsync(csvDataBlobId, cancellationToken); progress.Report(new ProgressDialogData(0, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); await dts.FetchAndDecompressFileAsync(new RBlobInfo(csvDataBlobId), fileName, true, new Progress<long>(b => { var step = (int)(b * 100 / total); progress.Report(new ProgressDialogData(step, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); }), cancellationToken); progress.Report(new ProgressDialogData(100, statusBarText: Resources.Status_WritingCSV, waitMessage: Resources.Status_WritingCSV)); } }