<commit_before>﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;
using Microsoft.WindowsAzure.Storage;

namespace Microsoft.Azure.Jobs.Host.Executors
{
    internal class DefaultStorageAccountProvider : IStorageAccountProvider, IConnectionStringProvider
    {
        private static readonly IConnectionStringProvider _ambientConnectionStringProvider = new AmbientConnectionStringProvider();

        private CloudStorageAccount _dashboardAccount;
        private bool _dashboardAccountSet;
        private CloudStorageAccount _storageAccount;
        private bool _storageAccountSet;
        private string _serviceBusConnectionString;
        private bool _serviceBusConnectionStringSet;

        /// <summary>
        /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using a single Microsoft Azure
        /// Storage connection string for both reading and writing data as well as logging.
        /// </summary>
        public DefaultStorageAccountProvider()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using a single Microsoft Azure
        /// Storage connection string for both reading and writing data as well as logging.
        /// </summary>
        /// <param name="dashboardAndStorageConnectionString">
        /// The Azure Storage connection string for accessing data and logging.
        /// </param>
        public DefaultStorageAccountProvider(string dashboardAndStorageConnectionString)
        {
            CloudStorageAccount account = ValidateStorageAccount(dashboardAndStorageConnectionString);
            _dashboardAccount = account;
            _dashboardAccountSet = true;
            _storageAccount = account;
            _storageAccountSet = true;
        }

        /// <summary>Gets or sets the Azure Storage connection string used for logging and diagnostics.</summary>
        public string DashboardConnectionString
        {
            get
            {
                return _dashboardAccount != null ? _dashboardAccount.ToString(exportSecrets: true) : null;
            }
            set
            {
                _dashboardAccount = ValidateDashboardAccount(value, explicitlySet: true);
                _dashboardAccountSet = true;
            }
        }

        /// <summary>Gets or sets the Azure Storage connection string used for reading and writing data.</summary>
        public string StorageConnectionString
        {
            get
            {
                return _storageAccount != null ? _storageAccount.ToString(exportSecrets: true) : null;
            }
            set
            {
                _storageAccount = ValidateStorageAccount(value);
                _storageAccountSet = true;
            }
        }

        /// <summary>Gets or sets the Azure Service bus connection string.</summary>
        public string ServiceBusConnectionString
        {
            get { return _serviceBusConnectionString; }
            set
            {
                _serviceBusConnectionString = value;
                _serviceBusConnectionStringSet = true;
            }
        }

        public CloudStorageAccount GetAccount(string connectionStringName)
        {
            if (connectionStringName == ConnectionStringNames.Dashboard)
            {
                if (!_dashboardAccountSet)
                {
                    _dashboardAccount = ValidateDashboardAccount(
                        _ambientConnectionStringProvider.GetConnectionString(connectionStringName),
                        explicitlySet: false);
                    _dashboardAccountSet = true;
                }

                return _dashboardAccount;<commit_msg>Fix Dashboard connection string retrieval.<commit_after>﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;
using Microsoft.WindowsAzure.Storage;

namespace Microsoft.Azure.Jobs.Host.Executors
{
    internal class DefaultStorageAccountProvider : IStorageAccountProvider, IConnectionStringProvider
    {
        private static readonly IConnectionStringProvider _ambientConnectionStringProvider = new AmbientConnectionStringProvider();

        private CloudStorageAccount _dashboardAccount;
        private bool _dashboardAccountSet;
        private CloudStorageAccount _storageAccount;
        private bool _storageAccountSet;
        private string _serviceBusConnectionString;
        private bool _serviceBusConnectionStringSet;

        /// <summary>
        /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using a single Microsoft Azure
        /// Storage connection string for both reading and writing data as well as logging.
        /// </summary>
        public DefaultStorageAccountProvider()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using a single Microsoft Azure
        /// Storage connection string for both reading and writing data as well as logging.
        /// </summary>
        /// <param name="dashboardAndStorageConnectionString">
        /// The Azure Storage connection string for accessing data and logging.
        /// </param>
        public DefaultStorageAccountProvider(string dashboardAndStorageConnectionString)
        {
            CloudStorageAccount account = ValidateStorageAccount(dashboardAndStorageConnectionString);
            _dashboardAccount = account;
            _dashboardAccountSet = true;
            _storageAccount = account;
            _storageAccountSet = true;
        }

        /// <summary>Gets or sets the Azure Storage connection string used for logging and diagnostics.</summary>
        public string DashboardConnectionString
        {
            get
            {
                if (!_dashboardAccountSet)
                {
                    return _ambientConnectionStringProvider.GetConnectionString(ConnectionStringNames.Dashboard);
                }

                return _dashboardAccount != null ? _dashboardAccount.ToString(exportSecrets: true) : null;
            }
            set
            {
                _dashboardAccount = ValidateDashboardAccount(value, explicitlySet: true);
                _dashboardAccountSet = true;
            }
        }

        /// <summary>Gets or sets the Azure Storage connection string used for reading and writing data.</summary>
        public string StorageConnectionString
        {
            get
            {
                if (!_storageAccountSet)
                {
                    return _ambientConnectionStringProvider.GetConnectionString(ConnectionStringNames.Storage);
                }

                return _storageAccount != null ? _storageAccount.ToString(exportSecrets: true) : null;
            }
            set
            {
                _storageAccount = ValidateStorageAccount(value);
                _storageAccountSet = true;
            }
        }

        /// <summary>Gets or sets the Azure Service bus connection string.</summary>
        public string ServiceBusConnectionString
        {
            get
            {
                if (!_serviceBusConnectionStringSet)
                {
                    return _ambientConnectionStringProvider.GetConnectionString(ConnectionStringNames.ServiceBus);
                }

                return _serviceBusConnectionString;
            }
            set
            {
                _serviceBusConnectionString = value;
                _serviceBusConnectionStringSet = true;
            }
        }

        public CloudStorageAccount GetAccount(string connectionStringName)
        {
            if (connectionStringName == ConnectionStringNames.Dashboard)
            {
                if (!_dashboardAccountSet)
                {
                    _dashboardAccount = ValidateDashboardAccount(
                        _ambientConnectionStringProvider.GetConnectionString(connectionStringName),
                        explicitlySet: false);
                    _dashboardAccountSet = true;
                }

                return _dashboardAccount;
{'fraction_non_alphanumeric': 0.05980184005661713, 'fraction_numerical': 0.00047180938900684123, 'mean_word_length': 2.016364283173248, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347842', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1763, 'n_words': 511}