Example #1
0
        public void CanCreateGetListAndUpdateCrossConnnections()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var customerExpressRouteClient = GetCustomerExpressRouteManagementClient();
                var providerExpressRouteClient = GetProviderExpressRouteManagementClient();
                var provider =
                    customerExpressRouteClient.DedicatedCircuitServiceProviders.List()
                    .Single(
                        p =>
                        p.Name.Equals(GetProviderName(),
                                      StringComparison.CurrentCultureIgnoreCase));
                var location         = provider.DedicatedCircuitLocations.Split(',').First();
                var bandwidth        = provider.DedicatedCircuitBandwidths[4].Bandwidth;
                var circuitName      = TestUtilities.GenerateName("circuit");
                var newCircuitParams = new DedicatedCircuitNewParameters()
                {
                    Bandwidth           = bandwidth,
                    CircuitName         = circuitName,
                    Location            = location,
                    ServiceProviderName = provider.Name
                };
                var newResponse = customerExpressRouteClient.DedicatedCircuits.New(newCircuitParams);
                TestUtilities.ValidateOperationResponse(newResponse);
                Guid serviceKey;
                Assert.True(Guid.TryParse(newResponse.Data, out serviceKey));

                newResponse = providerExpressRouteClient.CrossConnections.New(serviceKey.ToString());
                TestUtilities.ValidateOperationResponse(newResponse);

                CrossConnectionGetResponse getResponse =
                    providerExpressRouteClient.CrossConnections.Get(serviceKey.ToString());

                TestUtilities.ValidateOperationResponse(getResponse);
                Assert.Equal((uint)getResponse.CrossConnection.Bandwidth, bandwidth);
                Assert.Equal(getResponse.CrossConnection.Status, DedicatedCircuitState.Enabled.ToString());
                Assert.Equal(getResponse.CrossConnection.ProvisioningState,
                             ProviderProvisioningState.Provisioning.ToString());
                CrossConnectionListResponse listResponse = providerExpressRouteClient.CrossConnections.List();
                Assert.NotEmpty(listResponse.CrossConnections[0].ServiceKey);

                var updateParams = new CrossConnectionUpdateParameters()
                {
                    Operation         = UpdateCrossConnectionOperation.NotifyCrossConnectionProvisioned,
                    ProvisioningError = ""
                };
                var updateResponse = providerExpressRouteClient.CrossConnections.Update(serviceKey.ToString(),
                                                                                        updateParams);
            }
        }
Example #2
0
        /// <summary>
        /// The List Cross Connection operation retrieves a list of cross
        /// connections owned by the provider.
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The List Cross Connection operation response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.CrossConnectionListResponse> ListAsync(CancellationToken cancellationToken)
        {
            // Validate

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

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

            // Construct URL
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            string url     = "/" + this.Client.Credentials.SubscriptionId.Trim() + "/services/networking/crossconnections?api-version=1.0";

            // 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;

            // 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), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

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

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

                    XElement crossConnectionsSequenceElement = responseDoc.Element(XName.Get("CrossConnections", "http://schemas.microsoft.com/windowsazure"));
                    if (crossConnectionsSequenceElement != null && crossConnectionsSequenceElement.IsEmpty == false)
                    {
                        foreach (XElement crossConnectionsElement in crossConnectionsSequenceElement.Elements(XName.Get("CrossConnection", "http://schemas.microsoft.com/windowsazure")))
                        {
                            CrossConnectionListResponse.CrossConnection crossConnectionInstance = new CrossConnectionListResponse.CrossConnection();
                            result.CrossConnections.Add(crossConnectionInstance);

                            XElement bandwidthElement = crossConnectionsElement.Element(XName.Get("Bandwidth", "http://schemas.microsoft.com/windowsazure"));
                            if (bandwidthElement != null && bandwidthElement.IsEmpty == false)
                            {
                                int bandwidthInstance = int.Parse(bandwidthElement.Value, CultureInfo.InvariantCulture);
                                crossConnectionInstance.Bandwidth = bandwidthInstance;
                            }

                            XElement primaryAzurePortElement = crossConnectionsElement.Element(XName.Get("PrimaryAzurePort", "http://schemas.microsoft.com/windowsazure"));
                            if (primaryAzurePortElement != null && primaryAzurePortElement.IsEmpty == false)
                            {
                                string primaryAzurePortInstance = primaryAzurePortElement.Value;
                                crossConnectionInstance.PrimaryAzurePort = primaryAzurePortInstance;
                            }

                            XElement provisioningStateElement = crossConnectionsElement.Element(XName.Get("ProvisioningState", "http://schemas.microsoft.com/windowsazure"));
                            if (provisioningStateElement != null && provisioningStateElement.IsEmpty == false)
                            {
                                string provisioningStateInstance = provisioningStateElement.Value;
                                crossConnectionInstance.ProvisioningState = provisioningStateInstance;
                            }

                            XElement secondaryAzurePortElement = crossConnectionsElement.Element(XName.Get("SecondaryAzurePort", "http://schemas.microsoft.com/windowsazure"));
                            if (secondaryAzurePortElement != null && secondaryAzurePortElement.IsEmpty == false)
                            {
                                string secondaryAzurePortInstance = secondaryAzurePortElement.Value;
                                crossConnectionInstance.SecondaryAzurePort = secondaryAzurePortInstance;
                            }

                            XElement sTagElement = crossConnectionsElement.Element(XName.Get("STag", "http://schemas.microsoft.com/windowsazure"));
                            if (sTagElement != null && sTagElement.IsEmpty == false)
                            {
                                int sTagInstance = int.Parse(sTagElement.Value, CultureInfo.InvariantCulture);
                                crossConnectionInstance.STag = sTagInstance;
                            }

                            XElement statusElement = crossConnectionsElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
                            if (statusElement != null && statusElement.IsEmpty == false)
                            {
                                string statusInstance = statusElement.Value;
                                crossConnectionInstance.Status = statusInstance;
                            }
                        }
                    }

                    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();
                }
            }
        }