Пример #1
0
        /// <summary>
        /// Queries for all SQL Azure servers bound to the associated Subscription at specific location
        /// </summary>
        public IEnumerable<AzureSQLServer> EnumerateAzureSQLServers(string serverLocation)
        {
            // Query SQL Azure for server info
            AzureManagementClient client = new AzureManagementClient(this.certificate, this.subscriptionId);
            AzureManagementResponse response = client.SubmitSQLAzureRequest(
                RequestType.GET,
                "1.0",
                "servers");

            // Create collection to return
            List<AzureSQLServer> servers = new List<AzureSQLServer>();

            // If there is no servers node in the result, return an empty collection
            XmlNode xmlServers = response.GetSQLXmlNode("Servers");
            if (xmlServers == null)
            {
                return servers;
            }

            // Populate our collection of servers
            foreach (XmlNode xmlServer in xmlServers.ChildNodes)
            {
                AzureSQLServer srv = new AzureSQLServer();

                // Get the server properties
                srv.Name = response.GetSQLXmlValue(xmlServer, "Name");
                srv.AdministratorLogin = response.GetSQLXmlValue(xmlServer, "AdministratorLogin");
                srv.Location = response.GetSQLXmlValue(xmlServer, "Location");

                // if the SQL server is at "serverLocation"
                if (srv.Location.CompareTo(serverLocation) == 0)
                {
                    // Add to the collection
                    servers.Add(srv);
                }
            }

            return servers;
        }
Пример #2
0
        /// <summary>
        /// Creates a SQL Azure server
        /// </summary>
        public string CreateAzureSQLServer(AzureSQLServer config)
        {
            string serverName = null;

            // Create a SQL Azure create server request from this template
            string azureRequest =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                "<Server xmlns=\"http://schemas.microsoft.com/sqlazure/2010/12/\">\r\n" +
                "<AdministratorLogin>{0}</AdministratorLogin>\r\n" +
                "<AdministratorLoginPassword>{1}</AdministratorLoginPassword>\r\n" +
                "<Location>{2}</Location>\r\n" +
                "</Server>";

            // Fill in the request template
            azureRequest = string.Format(
                azureRequest,
                config.AdministratorLogin,
                config.AdministratorLoginPassword,
                config.Location
                );

            // Submit the request
            AzureManagementClient client = new AzureManagementClient(this.certificate, this.subscriptionId);
            AzureManagementResponse response = client.SubmitSQLAzureRequestWithBody(
                RequestType.POST,
                azureRequest,
                "1.0",
                "servers"
                );

            XmlNode xml = response.GetSQLXmlNode("ServerName");
            serverName = xml.InnerText;
            return serverName;
        }