예제 #1
0
        /// <summary>
        /// Blocking call to return the contents of the file as a string.
        /// </summary>
        /// <param name="encoding">The encoding used to interpret the file data. If no value or null is specified, UTF8 is used.</param>
        /// <param name="byteRange">The file byte range to retrieve. If null, the entire file is retrieved.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <returns>A string containing the contents of the file.</returns>
        public string ReadAsString(Encoding encoding = null, GetFileRequestByteRange byteRange = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null)
        {
            Task <string> asyncTask    = ReadAsStringAsync(encoding, byteRange, additionalBehaviors);
            string        readAsString = asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors);

            // return result
            return(readAsString);
        }
예제 #2
0
        /// <summary>
        /// Reads the contents of a file in the task's directory on its compute node into a string.
        /// </summary>
        /// <param name="filePath">The path of the file to retrieve.</param>
        /// <param name="encoding">The encoding to use. If no value or null is specified, UTF8 is used.</param>
        /// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <returns>A bound <see cref="NodeFile"/> object.</returns>
        public string CopyNodeFileContentToString(
            string filePath,
            Encoding encoding = null,
            GetFileRequestByteRange byteRange = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null)
        {
            Task <string> asyncTask = this.CopyNodeFileContentToStringAsync(filePath, encoding, byteRange, additionalBehaviors);

            return(asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors));
        }
예제 #3
0
        /// <summary>
        /// Copies the contents of a file in the task's directory from the node to the given <see cref="Stream"/>.
        /// </summary>
        /// <param name="filePath">The path of the file to retrieve.</param>
        /// <param name="stream">The stream to copy the file contents to.</param>
        /// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <returns>A bound <see cref="NodeFile"/> object.</returns>
        public void CopyNodeFileContentToStream(
            string filePath,
            Stream stream,
            GetFileRequestByteRange byteRange = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null)
        {
            Task asyncTask = this.CopyNodeFileContentToStreamAsync(filePath, stream, byteRange, additionalBehaviors);

            asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors);
        }
예제 #4
0
 /// <summary>
 /// Begins asynchronous call to return the contents of the file as a string.
 /// </summary>
 /// <param name="encoding">The encoding used to interpret the file data. If no value or null is specified, UTF8 is used.</param>
 /// <param name="byteRange">The file byte range to retrieve. If null, the entire file is retrieved.</param>
 /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
 /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
 public Task <string> ReadAsStringAsync(
     Encoding encoding = null,
     GetFileRequestByteRange byteRange = null,
     IEnumerable <BatchClientBehavior> additionalBehaviors = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UtilitiesInternal.ReadNodeFileAsStringAsync(
                CopyToStreamAsync,
                encoding,
                byteRange,
                additionalBehaviors,
                cancellationToken));
 }
예제 #5
0
        /// <summary>
        /// Reads the contents of a file in the task's directory on its compute node into a string.
        /// </summary>
        /// <param name="filePath">The path of the file to retrieve.</param>
        /// <param name="encoding">The encoding to use. If no value or null is specified, UTF8 is used.</param>
        /// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public Task <string> CopyNodeFileContentToStringAsync(
            string filePath,
            Encoding encoding = null,
            GetFileRequestByteRange byteRange = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // create the behavior manager
            BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors);

            return(this.parentBatchClient.JobOperations.CopyNodeFileContentToStringAsyncImpl(
                       this.parentJobId,
                       this.Id,
                       filePath,
                       encoding,
                       byteRange,
                       bhMgr,
                       cancellationToken));
        }
        /// <summary>
        /// Copies the contents of a file from the node to the given <see cref="Stream"/>.
        /// </summary>
        /// <param name="filePath">The path of the file to retrieve.</param>
        /// <param name="stream">The stream to copy the file contents to.</param>
        /// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        public Task CopyNodeFileContentToStreamAsync(
            string filePath,
            Stream stream,
            GetFileRequestByteRange byteRange = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // create the behavior manager
            BehaviorManager bhMgr     = new BehaviorManager(this.CustomBehaviors, additionalBehaviors);
            Task            asyncTask = this.parentBatchClient.PoolOperations.CopyNodeFileContentToStreamAsyncImpl(
                this.parentPoolId,
                this.Id,
                filePath,
                stream,
                byteRange,
                bhMgr,
                cancellationToken);

            return(asyncTask);
        }
        /// <summary>
        /// Begins asynchronous call to return the contents of the file as a string.
        /// </summary>
        /// <param name="copyStreamFunc">The stream copy function.</param>
        /// <param name="encoding">The encoding used to interpret the file data. If no value or null is specified, UTF8 is used.</param>
        /// <param name="byteRange">The file byte range to retrieve. If null, the entire file is retrieved.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        internal static async Task <string> ReadNodeFileAsStringAsync(
            Func <Stream, GetFileRequestByteRange, IEnumerable <BatchClientBehavior>, CancellationToken, Task> copyStreamFunc,
            Encoding encoding,
            GetFileRequestByteRange byteRange,
            IEnumerable <BatchClientBehavior> additionalBehaviors,
            CancellationToken cancellationToken)
        {
            using (Stream streamToUse = new MemoryStream())
            {
                // get the data
                Task asyncTask = copyStreamFunc(streamToUse, byteRange, additionalBehaviors, cancellationToken);

                // wait for completion
                await asyncTask.ConfigureAwait(continueOnCapturedContext : false);

                streamToUse.Seek(0, SeekOrigin.Begin); //We just wrote to this stream, have to seek to the beginning
                // convert to string
                return(StreamToString(streamToUse, encoding));
            }
        }
        public override async System.Threading.Tasks.Task CopyToStreamAsync(
            Stream stream,
            GetFileRequestByteRange byteRange = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // craft the behavior manager for this call
            BehaviorManager bhMgr = new BehaviorManager(base.CustomBehaviors, additionalBehaviors);

            System.Threading.Tasks.Task <AzureOperationResponse <Models.NodeFile, Models.FileGetFromComputeNodeHeaders> > asyncTask =
                this._poolOperations.ParentBatchClient.ProtocolLayer.GetNodeFileByNode(
                    _poolId,
                    _computeNodeId,
                    base.Path,
                    stream,
                    byteRange,
                    bhMgr,
                    cancellationToken);

            await asyncTask.ConfigureAwait(continueOnCapturedContext : false);
        }
예제 #9
0
        /// <summary>
        /// Blocking call to copy the contents of the file into the given Stream.
        /// </summary>
        /// <param name="stream">The stream into which the contents of the file are copied.</param>
        /// <param name="byteRange">The file byte range to retrieve. If null, the entire file is retrieved.</param>
        /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
        public virtual void CopyToStream(Stream stream, GetFileRequestByteRange byteRange = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null)
        {
            Task asyncTask = CopyToStreamAsync(stream, byteRange, additionalBehaviors);

            asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors);
        }
예제 #10
0
 /// <summary>
 /// Begins an asynchronous call to copy the contents of the file into the given Stream.
 /// </summary>
 /// <param name="stream">The stream into which the contents of the file are copied.</param>
 /// <param name="byteRange">The file byte range to retrieve. If null, the entire file is retrieved.</param>
 /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
 /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
 public abstract Task CopyToStreamAsync(Stream stream,
                                        GetFileRequestByteRange byteRange = null,
                                        IEnumerable <BatchClientBehavior> additionalBehaviors = null,
                                        CancellationToken cancellationToken = default(CancellationToken));