예제 #1
0
        public virtual TClient Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConnectionStringNames.Storage; // default
            }

            // $$$ Where does validation happen?
            IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);

            if (!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.");
            }

            _logForwarder.Start();
            var credential = _componentFactory.CreateTokenCredential(connectionSection);
            var options    = CreateClientOptions(connectionSection);

            return(CreateClient(connectionSection, credential, options));
        }
        public virtual TClient Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConnectionStringNames.Storage; // default
            }

            // $$$ Where does validation happen?
            IConfigurationSection connectionSection = _configuration.GetWebJobsConnectionStringSection(name);

            if (!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.");
            }

            _logForwarder.Start();

            if (!string.IsNullOrWhiteSpace(connectionSection.Value))
            {
                return(CreateClientFromConnectionString(connectionSection.Value, CreateClientOptions(null)));
            }

            var endpoint = connectionSection["endpoint"];

            if (string.IsNullOrWhiteSpace(endpoint))
            {
                // Not found
                throw new InvalidOperationException($"Connection should have an 'endpoint' property or be a string representing a connection string.");
            }

            var credential  = _componentFactory.CreateTokenCredential(connectionSection);
            var endpointUri = new Uri(endpoint);

            return(CreateClientFromTokenCredential(endpointUri, credential, CreateClientOptions(connectionSection)));
        }
        /// <summary>
        /// TODO.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual StorageAccount Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConnectionStringNames.Storage; // default
            }

            // $$$ Where does validation happen?
            string connectionString = _configuration.GetWebJobsConnectionString(name);

            if (connectionString == null)
            {
                // Not found
                throw new InvalidOperationException($"Storage account connection string '{IConfigurationExtensions.GetPrefixedConnectionStringName(name)}' does not exist. Make sure that it is a defined App Setting.");
            }

            return(StorageAccount.NewFromConnectionString(connectionString));
        }