Ejemplo n.º 1
0
        /// <summary>
        /// Formats an error message corresponding to the provided error code and account.
        /// </summary>
        /// <param name="error">The error code as returned by <see cref="TryParseAccount"/> method call.</param>
        /// <param name="connectionStringName">Friendly connection string name used to format error message</param>
        /// <returns>Formatted error message with details about reason of the failure and possible ways of mitigation</returns>
        public static string FormatParseAccountErrorMessage(StorageAccountParseResult error, string connectionStringName)
        {
            switch (error)
            {
            case StorageAccountParseResult.MissingOrEmptyConnectionStringError:
                return(String.Format(CultureInfo.CurrentCulture,
                                     "Microsoft Azure WebJobs SDK '{0}' connection string is missing or empty. " +
                                     "The Microsoft Azure Storage account connection string can be set in the following ways:" + Environment.NewLine +
                                     "1. Set the connection string named '{1}' in the connectionStrings section of the .config file in the following format " +
                                     "<add name=\"{1}\" connectionString=\"DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY\" />, or" + Environment.NewLine +
                                     "2. Set the environment variable named '{1}', or" + Environment.NewLine +
                                     "3. Set corresponding property of JobHostConfiguration.",
                                     connectionStringName,
                                     AmbientConnectionStringProvider.GetPrefixedConnectionStringName(connectionStringName)));

            case StorageAccountParseResult.MalformedConnectionStringError:
                return(String.Format(CultureInfo.CurrentCulture,
                                     "Failed to validate Microsoft Azure WebJobs SDK {0} connection string. " +
                                     "The Microsoft Azure Storage account connection string is not formatted " +
                                     "correctly. Please visit https://go.microsoft.com/fwlink/?linkid=841340 for " +
                                     "details about configuring Microsoft Azure Storage connection strings.",
                                     connectionStringName));
            }

            Debug.Assert(false, "Unsupported case of error message!");
            return(String.Empty);
        }
        /// <summary>
        /// Formats an error message corresponding to the provided error code and account.
        /// </summary>
        /// <param name="error">The error code as returned by <see cref="TryParseAccount"/> method call.</param>
        /// <param name="connectionStringName">Friendly connection string name used to format error message</param>
        /// <returns>Formatted error message with details about reason of the failure and possible ways of mitigation</returns>
        public static string FormatParseAccountErrorMessage(StorageAccountParseResult error, string connectionStringName)
        {
            switch (error)
            {
                case StorageAccountParseResult.MissingOrEmptyConnectionStringError:
                    return String.Format(CultureInfo.CurrentCulture,
                        "Microsoft Azure WebJobs SDK {0} connection string is missing or empty. " +
                        "The Microsoft Azure Storage account connection string can be set in the following ways:" + Environment.NewLine +
                        "1. Set the connection string named '{1}' in the connectionStrings section of the .config file in the following format " +
                        "<add name=\"{1}\" connectionString=\"DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY\" />, or" + Environment.NewLine +
                        "2. Set the environment variable named '{1}', or" + Environment.NewLine +
                        "3. Set corresponding property of JobHostConfiguration.",
                        connectionStringName,
                        AmbientConnectionStringProvider.GetPrefixedConnectionStringName(connectionStringName));

                case StorageAccountParseResult.MalformedConnectionStringError:
                    return String.Format(CultureInfo.CurrentCulture,
                        "Failed to validate Microsoft Azure WebJobs SDK {0} connection string. " +
                        "The Microsoft Azure Storage account connection string is not formatted " +
                        "correctly. Please visit http://msdn.microsoft.com/en-us/library/windowsazure/ee758697.aspx for " +
                        "details about configuring Microsoft Azure Storage connection strings.",
                        connectionStringName);

                case StorageAccountParseResult.EmulatorIsNotSupportedError:
                    return String.Format(CultureInfo.CurrentCulture,
                        "Failed to validate Microsoft Azure WebJobs SDK {0} account. " + 
                        "The Microsoft Azure Storage Emulator is not supported, please use a " +
                        "Microsoft Azure Storage account hosted in Microsoft Azure.",
                        connectionStringName);
            }

            Debug.Assert(false, "Unsupported case of error message!");
            return String.Empty;
        }
Ejemplo n.º 3
0
        public void TryParseAccount_WithMalformed_Fails()
        {
            string connectionString = "DefaultEndpointsProtocol=https;AccountName=[NOVALUE];AccountKey=[NOVALUE]";
            CloudStorageAccount ignore;

            StorageAccountParseResult result = StorageAccountParser.TryParseAccount(connectionString, out ignore);

            Assert.Equal(StorageAccountParseResult.MalformedConnectionStringError, result);
        }
Ejemplo n.º 4
0
        public void TryParseAccount_WithNull_Fails()
        {
            string connectionString = null;
            CloudStorageAccount ignore;

            StorageAccountParseResult result = StorageAccountParser.TryParseAccount(connectionString, out ignore);

            Assert.Equal(StorageAccountParseResult.MissingOrEmptyConnectionStringError, result);
        }
Ejemplo n.º 5
0
        public void TryParseAccount_WithProxiedEmulator_Fails()
        {
            string connectionString = "UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://myProxyUri";
            CloudStorageAccount ignore;

            StorageAccountParseResult result = StorageAccountParser.TryParseAccount(connectionString, out ignore);

            Assert.Equal(StorageAccountParseResult.EmulatorIsNotSupportedError, result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Throwing version of parse account API. It calls TryParseAccount internally, analyzes returned result,
        /// and throws an exception with formatted message in case of error.
        /// </summary>
        /// <param name="connectionString">A Storage account connection string as retrieved from the config</param>
        /// <param name="connectionStringName">Friendly connection string name used to format error message</param>
        /// <param name="services">The <see cref="IServiceProvider"/> to use.</param>
        /// <returns>An instance of <see cref="StorageAccount"/> associated with the given connection string</returns>
        public IStorageAccount ParseAccount(string connectionString, string connectionStringName, IServiceProvider services)
        {
            CloudStorageAccount       account;
            StorageAccountParseResult result = TryParseAccount(connectionString, out account);

            if (result != StorageAccountParseResult.Success)
            {
                string message = FormatParseAccountErrorMessage(result, connectionStringName);
                throw new InvalidOperationException(message);
            }

            return(new StorageAccount(account, services));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Formats an error message corresponding to the provided error code and account.
        /// </summary>
        /// <param name="error">The error code as returned by <see cref="TryParseAccount"/> method call.</param>
        /// <param name="connectionStringName">Friendly connection string name used to format error message</param>
        /// <returns>Formatted error message with details about reason of the failure and possible ways of mitigation</returns>
        public static string FormatParseAccountErrorMessage(StorageAccountParseResult error, string connectionStringName)
        {
            // Users may accidentally use their real connection strings here, so let's be safe before throwing.
            connectionStringName = Sanitizer.Sanitize(connectionStringName);

            switch (error)
            {
            case StorageAccountParseResult.MissingOrEmptyConnectionStringError:

                // We don't want to add 'AzureWebJobs' as a prefix unless it is one of our keys.
                string prefixedConnectionString = connectionStringName;
                if (connectionStringName == ConnectionStringNames.Dashboard ||
                    connectionStringName == ConnectionStringNames.Storage)
                {
                    prefixedConnectionString = AmbientConnectionStringProvider.GetPrefixedConnectionStringName(connectionStringName);
                }

                return(String.Format(CultureInfo.CurrentCulture,
                                     "Microsoft Azure WebJobs SDK '{0}' connection string is missing or empty. " +
                                     "The Microsoft Azure Storage account connection string can be set in the following ways:" + Environment.NewLine +
                                     "1. Set the connection string named '{1}' in the connectionStrings section of the .config file in the following format " +
                                     "<add name=\"{1}\" connectionString=\"DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY\" />, or" + Environment.NewLine +
                                     "2. Set the environment variable named '{1}', or" + Environment.NewLine +
                                     "3. Set corresponding property of JobHostConfiguration.",
                                     connectionStringName,
                                     prefixedConnectionString));

            case StorageAccountParseResult.MalformedConnectionStringError:
                return(String.Format(CultureInfo.CurrentCulture,
                                     "Failed to validate Microsoft Azure WebJobs SDK {0} connection string. " +
                                     "The Microsoft Azure Storage account connection string is not formatted " +
                                     "correctly. Please visit https://go.microsoft.com/fwlink/?linkid=841340 for " +
                                     "details about configuring Microsoft Azure Storage connection strings.",
                                     connectionStringName));
            }

            Debug.Assert(false, "Unsupported case of error message!");
            return(String.Empty);
        }