示例#1
0
        /// <summary>
        /// Gets the data for a given blob from R-Host. Saves the data to <paramref name="filePath"/>. This
        /// method adds the blob for clean up by default.
        /// </summary>
        /// <param name="blob">Blob from which the data is to be retrieved.</param>
        /// <param name="filePath">Path to the file where the retrieved data will be written.</param>
        /// <param name="doCleanUp">true to add blob upon transfer for cleanup on dispose, false to ignore it after transfer.</param>
        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);
            }
        }
示例#2
0
        /// <summary>
        /// Gets contents of a remote file and copies it to given stream. This method adds the blob for clean up by default.
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <param name="stream"></param>
        /// <param name="doCleanUp"></param>
        public async Task CopyToFileStreamAsync(string remoteFile, Stream stream, bool doCleanUp = true, IProgress <long> progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            string     filePath = remoteFile.ToRPath().ToRStringLiteral();
            IRBlobInfo blob     = new RBlobInfo(await _session.EvaluateAsync <ulong>($"rtvs:::create_blob(readBin({filePath}, 'raw', file.info({filePath})$size))", REvaluationKind.Normal, cancellationToken));

            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService, cancellationToken)) {
                await blobStream.CopyToAsync(stream, progress, cancellationToken);
            }

            if (doCleanUp)
            {
                _cleanup.Add(blob);
            }
        }
示例#3
0
        /// <summary>
        /// Sends file to R-Host by creating a new blob. This method adds the blob for clean up by default.
        /// </summary>
        /// <param name="filePath">Path to the file to be sent to R-Host.</param>
        /// <param name="doCleanUp">
        /// true to add blob created upon transfer for cleanup on dispose, false to ignore it after transfer.
        /// </param>
        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);
        }
示例#4
0
        /// <summary>
        /// Sends a block of data to R-Host by creating a new blob. This method adds the blob for clean
        /// up by default.
        /// </summary>
        /// <param name="data">Block of data to be sent.</param>
        /// <param name="doCleanUp">
        /// true to add blob created upon transfer for cleanup on dispose, false to ignore it after transfer.
        /// </param>
        public async Task <IRBlobInfo> SendBytesAsync(byte[] data, bool doCleanUp, IProgress <long> progress, CancellationToken cancellationToken)
        {
            IRBlobInfo blob = null;

            using (RBlobStream blobStream = await RBlobStream.CreateAsync(_blobService))
                using (Stream ms = new MemoryStream(data)) {
                    await ms.CopyToAsync(blobStream, progress, cancellationToken);

                    blob = blobStream.GetBlobInfo();
                }

            if (doCleanUp)
            {
                _cleanup.Add(blob);
            }
            return(blob);
        }
示例#5
0
        /// <summary>
        /// Gets the data for a given blob from R-Host. This method adds the blob for clean up by default.
        /// </summary>
        /// <param name="blob">Blob from which the data is to be retrieved.</param>
        /// <param name="doCleanUp">true to add blob upon transfer for cleanup on dispose, false to ignore it after transfer.</param>
        public async Task <byte[]> FetchBytesAsync(IRBlobInfo blob, bool doCleanUp, IProgress <long> progress, CancellationToken cancellationToken)
        {
            byte[] data = null;
            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService, cancellationToken))
                using (MemoryStream ms = new MemoryStream((int)blobStream.Length)) {
                    await blobStream.CopyToAsync(ms, progress, cancellationToken);

                    data = ms.ToArray();
                }

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

            return(data);
        }