/// <summary>
        /// Opens a file.
        /// </summary>
        /// <param name="uri">
        /// The uri of the file.
        /// </param>
        /// <param name="mode">
        /// The file mode.
        /// </param>
        /// <returns>
        /// The stream containing the data of the file.
        /// </returns>
        public Task <Stream> OpenStreamAsync(string uri, UriResolveMode mode)
        {
            if (this.ParentContext.UriResolver == null)
            {
                throw new InvalidOperationException($"No URI resolver registered, cannot open '{uri}'.");
            }

            return(this.ParentContext.UriResolver.ResolveToStream(Path.IsPathRooted(uri) ? uri : Path.Combine(Path.GetDirectoryName(this.Filename), uri), mode));
        }
Example #2
0
 /// <summary>
 /// Resolves an uri to a stream.
 /// </summary>
 /// <param name="uri">The uri to resolve.</param>
 /// <param name="mode">The mode to use when resolving the uri.</param>
 /// <returns>A Task returning a stream.</returns>
 public Task <Stream> ResolveToStream(string uri, UriResolveMode mode) => this.resolveToStream(uri, mode);
Example #3
0
        /// <summary>
        /// Opens the stream.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="mode">
        /// The mode.
        /// </param>
        /// <param name="fileUri">
        /// The file uri.
        /// </param>
        /// <returns>
        /// The <see cref="System.Threading.Tasks.Task"/>.
        /// </returns>
        protected override async Task <Stream> OpenStreamAsync(IExecutionContext context, UriResolveMode mode, string fileUri)
        {
            var blobClient = CloudStorageAccount.Parse(this.connectionString ?? context.GetDefault("CONNECTIONSTRING", this).ToString()).CreateCloudBlobClient();
            var reference  = blobClient.GetContainerReference(this.Uri.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).First());
            var parts      = this.Uri.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
            var block      = reference.GetBlockBlobReference(string.Join("/", parts));

            return(mode == UriResolveMode.Read ? await block.OpenReadAsync() : await block.OpenWriteAsync());
        }
Example #4
0
 /// <summary>
 ///     Opens a file.
 /// </summary>
 /// <param name="uri">
 ///     The uri of the file.
 /// </param>
 /// <param name="uriResolveMode">
 ///     The file mode.
 /// </param>
 /// <returns>
 ///     The stream containing the data of the file.
 /// </returns>
 Task <Stream> IExecutionContext.OpenStreamAsync(string uri, UriResolveMode uriResolveMode)
 {
     return(this.context.OpenStreamAsync(uri, uriResolveMode));
 }
Example #5
0
 /// <summary>
 /// Opens the stream.
 /// </summary>
 /// <param name="context">
 /// The execution context.
 /// </param>
 /// <param name="uriResolveMode">
 /// The file Mode.
 /// </param>
 /// <param name="fileUri">
 /// The uri.
 /// </param>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 protected virtual Task <Stream> OpenStreamAsync([NotNull] IExecutionContext context, UriResolveMode uriResolveMode, string fileUri)
 {
     return(context.OpenStreamAsync(fileUri, uriResolveMode));
 }