Esempio n. 1
0
        // Uploads a file to blob storage.
        public async Task SaveAsync(
            IOutputKind kind,
            DirectoryInfo baseFolder,
            string relativePath,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            Debug.Assert(baseFolder != null);

            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            Validate.IsNotNullOrEmpty(relativePath, nameof(relativePath));

            if (Path.IsPathRooted(relativePath))
            {
                throw new ArgumentException($"{nameof(relativePath)} must not be a relative path", nameof(relativePath));
            }

            string sourcePath      = Path.Combine(baseFolder.FullName, relativePath);
            string destinationPath = GetDestinationBlobPath(relativePath);

            await SaveAsync(kind, sourcePath, destinationPath, cancellationToken);
        }
Esempio n. 2
0
        public IEnumerable <OutputFileReference> List(IOutputKind kind)
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            return(_jobOutputContainer.ListBlobs(BlobNamePrefix(kind), useFlatBlobListing: true)
                   .OfType <ICloudBlob>()
                   .Select(b => new OutputFileReference(b)));
        }
Esempio n. 3
0
        public async Task <OutputFileReference> GetOutputAsync(IOutputKind kind, string filePath, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            Validate.IsNotNullOrEmpty(filePath, nameof(filePath));

            var blob = await _jobOutputContainer.GetBlobReferenceFromServerAsync(BlobName(kind, filePath), cancellationToken);

            return(new OutputFileReference(blob));
        }
Esempio n. 4
0
        // Uploads a file and tracks appends to that file. The implementation creates an append blob to
        // contain the file contents, then creates a file tracking object which runs a background operation
        // to upload the file to the append blob, then track appends to the file and append them to the blob.
        public async Task <TrackedFile> SaveTrackedAsync(IOutputKind kind, string sourcePath, string destinationRelativePath, TimeSpan flushInterval)
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            Validate.IsNotNullOrEmpty(sourcePath, nameof(sourcePath));
            Validate.IsNotNullOrEmpty(destinationRelativePath, nameof(destinationRelativePath));

            var blobName = BlobName(kind, destinationRelativePath);
            var blob     = _jobOutputContainer.GetAppendBlobReference(blobName);
            await blob.EnsureExistsAsync();

            return(new TrackedFile(sourcePath, blob, flushInterval));
        }
Esempio n. 5
0
        // Uploads a file and tracks appends to that file. The implementation creates an append blob to
        // contain the file contents, then creates a file tracking object which runs a background operation
        // to upload the file to the append blob, then track appends to the file and append them to the blob.
        public async Task <TrackedFile> SaveTrackedAsync(IOutputKind kind, string relativePath, TimeSpan flushInterval)
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            Validate.IsNotNullOrEmpty(relativePath, nameof(relativePath));

            if (Path.IsPathRooted(relativePath))
            {
                throw new ArgumentException($"{nameof(relativePath)} must not be a relative path", nameof(relativePath));
            }

            var destinationPath = GetDestinationBlobPath(relativePath);

            return(await SaveTrackedAsync(kind, relativePath, destinationPath, flushInterval));
        }
Esempio n. 6
0
        // Uploads a file to blob storage.
        public async Task SaveAsync(
            IOutputKind kind,
            string sourcePath,
            string destinationRelativePath,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }

            Validate.IsNotNullOrEmpty(sourcePath, nameof(sourcePath));
            Validate.IsNotNullOrEmpty(destinationRelativePath, nameof(destinationRelativePath));

            var blobName = BlobName(kind, destinationRelativePath);
            var blob     = _jobOutputContainer.GetBlockBlobReference(blobName);
            await blob.UploadFromFileAsync(sourcePath, FileMode.Open, cancellationToken);
        }
        // Uploads text to blob storage.
        public async Task SaveTextAsync(
            IOutputKind kind,
            string text,
            string destinationRelativePath,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            if (kind == null)
            {
                throw new ArgumentNullException(nameof(kind));
            }
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            Validate.IsNotNullOrEmpty(destinationRelativePath, nameof(destinationRelativePath));

            var blobName = BlobName(kind, destinationRelativePath);
            var blob     = _jobOutputContainer.GetBlockBlobReference(blobName);
            await blob.UploadTextAsync(text, null, null, null, null, cancellationToken);
        }
Esempio n. 8
0
 internal override string BlobNamePrefix(IOutputKind kind)
 => $"{_taskId}/${kind.Text}/";
Esempio n. 9
0
 internal string BlobName(IOutputKind kind, string relativePath)
 => $"{BlobNamePrefix(kind)}{relativePath}";
Esempio n. 10
0
 // Gets the string that should be prefixed to a blob name to locate it correctly
 // in the container. This is the equivalent of a file system directory path - for
 // example a prefix might be "$JobOutput/" or "MyTask/$TaskOutput" - but Azure
 // Storage does not have the notion of directories under a container, only of prefixes.
 internal abstract string BlobNamePrefix(IOutputKind kind);
Esempio n. 11
0
 internal static string BlobNamePrefixImpl(IOutputKind kind, string taskId) => $"{taskId}/${kind.Text}";
Esempio n. 12
0
 internal override string BlobNamePrefix(IOutputKind kind) => BlobNamePrefixImpl(kind, _taskId);
Esempio n. 13
0
 internal static string BlobNamePrefixImpl(IOutputKind kind) => $"${kind.Text}";