Esempio n. 1
0
        public static async Task <WatchableCloudBlobStream> BindStreamAsync(BlobWithContainer <BlobBaseClient> blob,
                                                                            ValueBindingContext context, IBlobWrittenWatcher blobWrittenWatcher)
        {
            var blockBlob = blob.BlobClient as BlockBlobClient;

            if (blockBlob == null)
            {
                throw new InvalidOperationException("Cannot bind to page or append blobs using 'out string', 'TextWriter', or writable 'Stream' parameters.");
            }
            var            functionID = context.FunctionInstanceId;
            BlobProperties properties = await blockBlob.FetchPropertiesOrNullIfNotExistAsync().ConfigureAwait(false);

            Dictionary <string, string> metadata = new Dictionary <string, string>();

            if (properties != null && properties.Metadata != null)
            {
                metadata = new Dictionary <string, string>(properties.Metadata);
            }

            BlobCausalityManager.SetWriter(metadata, functionID);
            BlockBlobOpenWriteOptions options = new BlockBlobOpenWriteOptions()
            {
                Metadata = metadata,
            };
            Stream rawStream = await blockBlob.OpenWriteAsync(true, options).ConfigureAwait(false);

            IBlobCommitedAction committedAction = new BlobCommittedAction(blob, blobWrittenWatcher);

            return(await Task.FromResult(new WatchableCloudBlobStream(rawStream, committedAction)).ConfigureAwait(false));
        }
        public static async Task<WatchableCloudBlobStream> BindStreamAsync(IStorageBlob blob,
            ValueBindingContext context, IBlobWrittenWatcher blobWrittenWatcher)
        {
            IStorageBlockBlob blockBlob = blob as IStorageBlockBlob;

            if (blockBlob == null)
            {
                throw new InvalidOperationException("Cannot bind a page blob using an out string.");
            }

            BlobCausalityManager.SetWriter(blob.Metadata, context.FunctionInstanceId);

            CloudBlobStream rawStream = await blockBlob.OpenWriteAsync(context.CancellationToken);
            IBlobCommitedAction committedAction = new BlobCommittedAction(blob, blobWrittenWatcher);
            return new WatchableCloudBlobStream(rawStream, committedAction);
        }
        public static async Task <WatchableCloudBlobStream> BindStreamAsync(IStorageBlob blob,
                                                                            ValueBindingContext context, IBlobWrittenWatcher blobWrittenWatcher)
        {
            IStorageBlockBlob blockBlob = blob as IStorageBlockBlob;

            if (blockBlob == null)
            {
                throw new InvalidOperationException("Cannot bind a page blob using an out string.");
            }

            BlobCausalityManager.SetWriter(blob.Metadata, context.FunctionInstanceId);

            CloudBlobStream rawStream = await blockBlob.OpenWriteAsync(context.CancellationToken);

            IBlobCommitedAction committedAction = new BlobCommittedAction(blob, blobWrittenWatcher);

            return(new WatchableCloudBlobStream(rawStream, committedAction));
        }
        public static async Task <WatchableCloudBlobStream> BindStreamAsync(ICloudBlob blob,
                                                                            ValueBindingContext context, IBlobWrittenWatcher blobWrittenWatcher)
        {
            var blockBlob = blob as CloudBlockBlob;

            if (blockBlob == null)
            {
                throw new InvalidOperationException("Cannot bind to page or append blobs using 'out string', 'TextWriter', or writable 'Stream' parameters.");
            }

            BlobCausalityManager.SetWriter(blob.Metadata, context.FunctionInstanceId);

            CloudBlobStream rawStream = await blockBlob.OpenWriteAsync(context.CancellationToken);

            IBlobCommitedAction committedAction = new BlobCommittedAction(blob, blobWrittenWatcher);

            return(new WatchableCloudBlobStream(rawStream, committedAction));
        }