コード例 #1
0
        private static async Task <string> GetOrCreateHostIdAsync(string sharedHostName, CloudBlobDirectory directory,
                                                                  CancellationToken cancellationToken)
        {
            Debug.Assert(directory != null);

            var  blob           = directory.SafeGetBlockBlobReference(sharedHostName);
            Guid?possibleHostId = await TryGetExistingIdAsync(blob, cancellationToken);

            if (possibleHostId.HasValue)
            {
                return(possibleHostId.Value.ToString("N"));
            }

            Guid newHostId = Guid.NewGuid();

            if (await TryInitializeIdAsync(blob, newHostId, cancellationToken))
            {
                return(newHostId.ToString("N"));
            }

            possibleHostId = await TryGetExistingIdAsync(blob, cancellationToken);

            if (possibleHostId.HasValue)
            {
                return(possibleHostId.Value.ToString("N"));
            }

            // Not expected - valid host ID didn't exist before, couldn't be created, and still didn't exist after.
            throw new InvalidOperationException("Unable to determine host ID.");
        }
コード例 #2
0
        public CloudBlockBlob CreateReference(string hostId, string functionId, string containerName,
                                              string blobName, string eTag)
        {
            // Put the ETag before the blob name to prevent ambiguity since the blob name can contain embedded slashes.
            string receiptName = String.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}/{3}/{4}", hostId, functionId,
                                               eTag, containerName, blobName);

            return(_directory.SafeGetBlockBlobReference(receiptName));
        }
コード例 #3
0
        private static LocalBlobDescriptor CreateDescriptor(CloudBlobDirectory directory, string name)
        {
            var blob = directory.SafeGetBlockBlobReference(name);

            return(new LocalBlobDescriptor
            {
                ContainerName = blob.Container.Name,
                BlobName = blob.Name
            });
        }