コード例 #1
0
        /// <summary>
        /// Executes the upload as defined by the input parameters.
        /// </summary>
        public void Execute()
        {
            //load up existing metadata or create a fresh one
            var metadata = GetMetadata();

            if (metadata.SegmentCount < this.Parameters.ThreadCount)
            {
                // reducing the thread count to make it equal to the segment count
                // if it is larger, since those extra threads will not be used.
                this.Parameters.ThreadCount = metadata.SegmentCount;
            }

            //begin (or resume) uploading the file
            UploadFile(metadata);

            if (_frontEnd.StreamExists(metadata.SegmentStreamDirectory))
            {
                // delete the folder that contained the intermediate segments, if there was one (for single segment uploads there will not be)
                _frontEnd.DeleteStream(metadata.SegmentStreamDirectory, true);
            }

            //clean up metadata after a successful upload
            metadata.DeleteFile();
        }
コード例 #2
0
        /// <summary>
        /// Downloads the portion of the InputFilePath to the given TargetStreamPath, starting at the given StartOffset.
        /// The segment is further divided into equally-sized blocks which are downloaded in sequence.
        /// Each such block is attempted a certain number of times; if after that it still cannot be downloaded, the entire segment is aborted (in which case no cleanup is performed on the server).
        /// </summary>
        /// <returns></returns>
        public void Download()
        {
            if (!_frontEnd.StreamExists(_metadata.InputFilePath, !_metadata.IsDownload))
            {
                throw new FileNotFoundException("Unable to locate input file", _metadata.InputFilePath);
            }

            if (_token.IsCancellationRequested)
            {
                _token.ThrowIfCancellationRequested();
            }

            //open a file stream (truncate it if it already exists) for the target segment
            // we always truncate here because overwrite validation should have already been done.
            // always create the directory as well
            Directory.CreateDirectory(Path.GetDirectoryName(_segmentMetadata.Path));
            
            // download the data
            DownloadSegmentContents();

            VerifyDownloadedStream();
            //any exceptions are (re)thrown to be handled by the caller; we do not handle retries or other recovery techniques here
        }