示例#1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                throw new ArgumentNullException("publish settings informations");
            }
            SubscriptionCloudCredentials cred = GetCredentials(args[0]);

            //WATM
            TrafficManagerManagementClient watmClient = new TrafficManagerManagementClient(cred);
            string atmDns = "adxsdk12345.trafficmanager.net";
            DnsPrefixAvailabilityCheckResponse watmResp =
                watmClient.Profiles.CheckDnsPrefixAvailability("adxsdk12345.trafficmanager.net");

            Console.WriteLine("Invoke WATM->CheckDnsPrefixAvailability(\'{0}\'). Result: {1}", atmDns, watmResp.Result);

            //Compute
            ComputeManagementClient computeClient = new ComputeManagementClient(cred);
            string hostServiceName = "adxsdk12345";
            HostedServiceCheckNameAvailabilityResponse computeResp =
                computeClient.HostedServices.CheckNameAvailability(hostServiceName);

            Console.WriteLine("Invoke Compute->CheckNameAvailability(\'{0}\'). Result: {1}",
                              hostServiceName, computeResp.IsAvailable);

            //Websites
            WebSiteManagementClient websiteClient = new WebSiteManagementClient(cred);
            string webSiteName = "adxsdk12345";
            WebSiteIsHostnameAvailableResponse webSiteResp = websiteClient.WebSites.IsHostnameAvailable(webSiteName);

            Console.WriteLine("Invoke WebSite->IsHostnameAvailable(\'{0}\'). Result: {1}",
                              webSiteName, webSiteResp.IsAvailable);

            //Scheduler
            SchedulerManagementClient schedulerClient = new SchedulerManagementClient(cred);
            string schedulerCloudServiceName          = "foobarrr";
            string expectedSchedulerException         = string.Format(
                "ResourceNotFound: The cloud service with name {0} was not found.", schedulerCloudServiceName);
            bool exceptionFromSchedulerServiceOccurred = false;

            try
            {
                schedulerClient.JobCollections.CheckNameAvailability(schedulerCloudServiceName, "doesnotmatter");
            }
            catch (Exception ex)
            {
                if (ex.Message == expectedSchedulerException)
                {
                    exceptionFromSchedulerServiceOccurred = true;
                    Console.WriteLine("Invoke Scheduler->CheckNameAvailability(\'{0}\'). Get back correct exception",
                                      schedulerCloudServiceName, expectedSchedulerException);
                }
            }
            if (!exceptionFromSchedulerServiceOccurred)
            {
                throw new Exception("we didn't get expected exception message from scheduler service");
            }

            Console.WriteLine("Smoke test is good");
        }
示例#2
0
        public void CheckDnsPrefixesAvailability()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                //Arrange
                using (TrafficManagerTestBase _testFixture = new TrafficManagerTestBase())
                {
                    string randomDomainName = _testFixture.GenerateRandomDomainName();

                    //Act
                    DnsPrefixAvailabilityCheckResponse response =
                        _testFixture.TrafficManagerClient.Profiles.CheckDnsPrefixAvailability(randomDomainName);

                    //Assert
                    Assert.True(response.Result);
                }
            }
        }
        /// <summary>
        /// The DNS name that you want to use. You must include
        /// .trafficmanager.net in the name.  (see
        /// http://msdn.microsoft.com/en-us/library/dn510368.aspx for more
        /// information)
        /// </summary>
        /// <param name='dnsName'>
        /// Required. DNS name that you want to use
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response to the request for a listing of namespaces.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.TrafficManager.Models.DnsPrefixAvailabilityCheckResponse> CheckDnsPrefixAvailabilityAsync(string dnsName, CancellationToken cancellationToken)
        {
            // Validate
            if (dnsName == null)
            {
                throw new ArgumentNullException("dnsName");
            }

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("dnsName", dnsName);
                Tracing.Enter(invocationId, this, "CheckDnsPrefixAvailabilityAsync", tracingParameters);
            }

            // Construct URL
            string url     = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/WATM/operations/isavailable/" + dnsName.Trim();
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    DnsPrefixAvailabilityCheckResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new DnsPrefixAvailabilityCheckResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement availabilityResponseElement = responseDoc.Element(XName.Get("AvailabilityResponse", "http://schemas.microsoft.com/windowsazure"));
                    if (availabilityResponseElement != null)
                    {
                        XElement resultElement = availabilityResponseElement.Element(XName.Get("Result", "http://schemas.microsoft.com/windowsazure"));
                        if (resultElement != null)
                        {
                            bool resultInstance = bool.Parse(resultElement.Value);
                            result.Result = resultInstance;
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }