示例#1
0
        /// <summary>
        /// Provisions all the firewall rules in the <see cref="IEnumerable{T}"/> of <see cref="SqlFirewallRule"/>.
        /// </summary>
        /// <param name="rules">The list of <see cref="SqlFirewallRule"/> to provision.</param>
        /// <param name="client">The <see cref="SqlManagementClient"/> that is performing the operation.</param>
        /// <returns>The async <see cref="Task"/> wrapper.</returns>
        public static IEnumerable <Task> ProvisionAllAsync(this IEnumerable <SqlFirewallRule> rules, SqlManagementClient client)
        {
            Contract.Requires(rules != null);
            Contract.Requires(client != null);

            return(rules.Select(r =>
                                Task.Factory.StartNew(() => client.CreateFirewallRuleIfNotExistsAsync(r).Wait())));
        }
        /// <summary>
        /// Checks for the existence of a specific Azure Sql Firewall rule, if it doesn't exist it will create it.
        /// </summary>
        /// <param name="client">The <see cref="SqlManagementClient"/> that is performing the operation.</param>
        /// <param name="model">The DevOpsFlex rich model object that contains everything there is to know about this database spec.</param>
        /// <returns>The async <see cref="Task"/> wrapper.</returns>
        public static async Task CreateFirewallRuleIfNotExistsAsync(this SqlManagementClient client, SqlFirewallRule model)
        {
            Contract.Requires(client != null);
            Contract.Requires(model != null);

            await client.CreateFirewallRuleIfNotExistsAsync(
                await FlexConfiguration.SqlServerChooser.Choose(client, model.System.Location.GetEnumDescription()),
                model.AzureParameters);
        }
        /// <summary>
        /// Provisions all the firewall rules in the <see cref="IEnumerable{T}"/> of <see cref="SqlFirewallRule"/>.
        /// </summary>
        /// <param name="rules">The list of <see cref="SqlFirewallRule"/> to provision.</param>
        /// <param name="client">The <see cref="SqlManagementClient"/> that is performing the operation.</param>
        /// <returns>The async <see cref="Task"/> wrapper.</returns>
        public static async Task ProvisionAllAsync(this IEnumerable <SqlFirewallRule> rules, SqlManagementClient client)
        {
            Contract.Requires(rules != null);
            Contract.Requires(client != null);

            var tasks = rules.Select(
                async r =>
            {
                await client.CreateFirewallRuleIfNotExistsAsync(r);
            });

            await Task.WhenAll(tasks);
        }