public virtual TClient Create(string name, IConfiguration configuration) { if (string.IsNullOrWhiteSpace(name)) { name = ConnectionStringNames.Storage; // default } IConfigurationSection connectionSection = configuration?.GetWebJobsConnectionSection(name); if (connectionSection == null || !connectionSection.Exists()) { // Not found throw new InvalidOperationException($"Storage account connection string '{IConfigurationExtensions.GetPrefixedConnectionStringName(name)}' does not exist. Make sure that it is a defined App Setting."); } var credential = _componentFactory.CreateTokenCredential(connectionSection); var options = CreateClientOptions(connectionSection); return(CreateClient(connectionSection, credential, options)); }
public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { var parameter = context.Parameter; var parameterName = context.Parameter.Name; var parameterType = context.Parameter.ParameterType; var attribute = parameter.GetCustomAttribute <GenesysAttribute>(); if (attribute == null) { return(null); } if (parameterType != typeof(string) && parameterType != typeof(IGenesysAccessToken)) { throw new InvalidOperationException("Can't bind entity to type '" + parameterType + "'."); } var connectionString = GetConnectionString(attribute.Connection); if (!TableStorageAccount.TryParse(connectionString, out TableStorageAccount tableStorageAccount)) { throw new InvalidOperationException($"Storage account connection string for '{IConfigurationExtensions.GetPrefixedConnectionStringName(attribute.Connection)}' is invalid"); } var tableClient = tableStorageAccount.CreateCloudTableClient(); var table = tableClient.GetTableReference(attribute.TokenTable ?? GenesysConfigNames.GenesysTokensTable); await table.CreateIfNotExistsAsync(); var tokenCtx = new GenesysTokenContext { TokenTable = table, ClientId = attribute.ClientId, ClientSecret = attribute.ClientSecret, Environment = attribute.Environment, }; IBinding binding = new GenesysAttributeBinding(parameterName, parameterType, _tokenProvider, tokenCtx); return(binding); }