Example #1
0
        /// <summary>
        /// Retrieves one or more servers in the current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The specific name of the server to retrieve, or <c>null</c> to
        /// retrieve all servers in the current subscription.
        /// </param>
        /// <returns>A list of servers in the subscription.</returns>
        internal IEnumerable <SqlDatabaseServerContext> GetAzureSqlDatabaseServersProcess(string serverName)
        {
            IEnumerable <SqlDatabaseServerContext> processResult = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    SqlDatabaseServerList servers = RetryCall(subscription =>
                                                              Channel.GetServers(subscription));
                    WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                    if (string.IsNullOrEmpty(serverName))
                    {
                        // Server name is not specified, return all servers
                        // in the subscription.
                        processResult = servers.Select(server => new SqlDatabaseServerContext
                        {
                            ServerName           = server.Name,
                            Location             = server.Location,
                            AdministratorLogin   = server.AdministratorLogin,
                            OperationStatus      = operation.Status,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationId          = operation.OperationTrackingId
                        });
                    }
                    else
                    {
                        // Server name is specified, find the one with the
                        // specified rule name and return that.
                        SqlDatabaseServer server = servers.FirstOrDefault(s => s.Name == serverName);
                        if (server != null)
                        {
                            processResult = new List <SqlDatabaseServerContext>
                            {
                                new SqlDatabaseServerContext
                                {
                                    ServerName           = server.Name,
                                    Location             = server.Location,
                                    AdministratorLogin   = server.AdministratorLogin,
                                    OperationStatus      = operation.Status,
                                    OperationDescription = CommandRuntime.ToString(),
                                    OperationId          = operation.OperationTrackingId
                                }
                            };
                        }
                        else
                        {
                            throw new ItemNotFoundException(string.Format(CultureInfo.InvariantCulture, Resources.GetAzureSqlDatabaseServerNotFound, serverName));
                        }
                    }
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(processResult);
        }
        // Windows Azure SQL Database doesn't support async calls
        protected static WAPPSCmdlet.Operation WaitForSqlDatabaseOperation()
        {
            string operationId = RetrieveOperationId();

            WAPPSCmdlet.Operation operation = new WAPPSCmdlet.Operation();
            operation.OperationTrackingId = operationId;
            operation.Status = "Success";
            return(operation);
        }
        /// <summary>
        /// Creates a new firewall rule on the specified server.
        /// </summary>
        /// <param name="parameterSetName">
        /// The parameter set for the command.
        /// </param>
        /// <param name="serverName">
        /// The name of the server in which to create the firewall rule.
        /// </param>
        /// <param name="ruleName">
        /// The name of the new firewall rule.
        /// </param>
        /// <param name="startIpAddress">
        /// The starting IP address for the firewall rule.
        /// </param>
        /// <param name="endIpAddress">
        /// The ending IP address for the firewall rule.
        /// </param>
        /// <returns>The context to the newly created firewall rule.</returns>
        internal SqlDatabaseServerFirewallRuleContext NewAzureSqlDatabaseServerFirewallRuleProcess(string parameterSetName, string serverName, string ruleName, string startIpAddress, string endIpAddress)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.NewAzureSqlDatabaseServerFirewallRuleDescription, ruleName, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.NewAzureSqlDatabaseServerFirewallRuleWarning, ruleName, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            SqlDatabaseServerFirewallRuleContext operationContext = null;

            try
            {
                switch (parameterSetName)
                {
                case "IpRange":
                    InvokeInOperationContext(() =>
                    {
                        RetryCall(subscription =>
                                  Channel.NewServerFirewallRule(subscription, serverName, ruleName, startIpAddress, endIpAddress));
                        WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                        operationContext = new SqlDatabaseServerFirewallRuleContext()
                        {
                            OperationDescription = CommandRuntime.ToString(),
                            OperationStatus      = operation.Status,
                            OperationId          = operation.OperationTrackingId,
                            ServerName           = serverName,
                            RuleName             = ruleName,
                            StartIpAddress       = startIpAddress,
                            EndIpAddress         = endIpAddress
                        };
                    });
                    break;

                default:
                    // Should never get here
                    Debug.Assert(false, "Invalid parameter set!");
                    break;
                }
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(operationContext);
        }
        /// <summary>
        /// Creates a new server in the current subscription.
        /// </summary>
        /// <param name="adminLogin">
        /// The administrator login name for the new server.
        /// </param>
        /// <param name="adminLoginPassword">
        /// The administrator login password for the new server.
        /// </param>
        /// <param name="location">
        /// The location in which to create the new server.
        /// </param>
        /// <returns>The context to the newly created server.</returns>
        internal SqlDatabaseServerContext NewAzureSqlDatabaseServerProcess(string adminLogin, string adminLoginPassword, string location)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    Resources.NewAzureSqlDatabaseServerDescription,
                    Resources.NewAzureSqlDatabaseServerWarning,
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            SqlDatabaseServerContext operationContext = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    XmlElement serverName = RetryCall(subscription =>
                                                      Channel.NewServer(subscription, adminLogin, adminLoginPassword, location));
                    WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                    operationContext = new SqlDatabaseServerContext()
                    {
                        ServerName           = serverName.InnerText,
                        Location             = location,
                        AdministratorLogin   = adminLogin,
                        OperationStatus      = operation.Status,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId          = operation.OperationTrackingId
                    };
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(operationContext);
        }
Example #5
0
        /// <summary>
        /// Removes an existing server in the current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server to remove.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext RemoveAzureSqlDatabaseServerProcess(string serverName)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerDescription, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerWarning, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            SqlDatabaseServerOperationContext operationContext = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    RetryCall(subscription =>
                              Channel.RemoveServer(subscription, serverName));
                    WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                    operationContext = new SqlDatabaseServerOperationContext()
                    {
                        ServerName           = serverName,
                        OperationStatus      = operation.Status,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId          = operation.OperationTrackingId
                    };
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(operationContext);
        }
Example #6
0
        /// <summary>
        /// Retrieves one or more firewall rules on the specified server.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server to retrieve firewall rules for.
        /// </param>
        /// <param name="ruleName">
        /// The specific name of the rule to retrieve, or <c>null</c> to
        /// retrieve all rules on the specified server.
        /// </param>
        /// <returns>A list of firewall rules on the server.</returns>
        internal IEnumerable <SqlDatabaseServerFirewallRuleContext> GetAzureSqlDatabaseServerFirewallRuleProcess(string serverName, string ruleName)
        {
            IEnumerable <SqlDatabaseServerFirewallRuleContext> processResult = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    SqlDatabaseFirewallRulesList firewallRules = RetryCall(subscription =>
                                                                           Channel.GetServerFirewallRules(subscription, this.ServerName));
                    WAPPSCmdlet.Operation operation = WaitForSqlDatabaseOperation();

                    if (string.IsNullOrEmpty(ruleName))
                    {
                        // Firewall rule name is not specified, return all
                        // firewall rules.
                        processResult = firewallRules.Select(p => new SqlDatabaseServerFirewallRuleContext()
                        {
                            OperationDescription = CommandRuntime.ToString(),
                            OperationId          = operation.OperationTrackingId,
                            OperationStatus      = operation.Status,
                            ServerName           = serverName,
                            RuleName             = p.Name,
                            StartIpAddress       = p.StartIPAddress,
                            EndIpAddress         = p.EndIPAddress
                        });
                    }
                    else
                    {
                        // Firewall rule name is specified, find the one
                        // with the specified rule name and return that.
                        SqlDatabaseFirewallRule firewallRule = firewallRules.FirstOrDefault(p => p.Name == ruleName);
                        if (firewallRule != null)
                        {
                            processResult = new List <SqlDatabaseServerFirewallRuleContext>
                            {
                                new SqlDatabaseServerFirewallRuleContext
                                {
                                    OperationDescription = CommandRuntime.ToString(),
                                    OperationId          = operation.OperationTrackingId,
                                    OperationStatus      = operation.Status,
                                    ServerName           = serverName,
                                    RuleName             = firewallRule.Name,
                                    StartIpAddress       = firewallRule.StartIPAddress,
                                    EndIpAddress         = firewallRule.EndIPAddress
                                }
                            };
                        }
                        else
                        {
                            throw new ItemNotFoundException(string.Format(CultureInfo.InvariantCulture, Resources.GetAzureSqlDatabaseServerFirewallRuleNotFound, ruleName, serverName));
                        }
                    }
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(processResult);
        }