/// <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)); }
/// <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);
/// <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()); }
/// <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)); }
/// <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)); }