private bool TryHandleBeginNewAsync(IServiceOperations <ExpressRouteManagementClient> client, IDictionary <string, object> parameters, out Action undoFunction) { undoFunction = null; string serviceKey; string authId; DedicatedCircuitLinkAuthorizationMicrosoftIdNewParameters newParameters = null; if (TryAssignParameter <string>("serviceKey", parameters, out serviceKey) && TryAssignParameter <string>("authId", parameters, out authId) && TryAssignParameter <DedicatedCircuitLinkAuthorizationMicrosoftIdNewParameters>("parameters", parameters, out newParameters) && !string.IsNullOrEmpty(serviceKey) && !string.IsNullOrEmpty(authId) && newParameters != null) { undoFunction = () => { using (ExpressRouteManagementClient expressRouteClient = GetClientFromOperations(client)) { expressRouteClient.DedicatedCircuitLinkAuthorizationMicrosoftIds.Remove(serviceKey, authId, (new DedicatedCircuitLinkAuthorizationMicrosoftIdRemoveParameters() { MicrosoftIds = newParameters.MicrosoftIds })); } }; return(true); } TraceParameterError(this, "BeginNewAsync", parameters); return(false); }
/// <summary> /// Adds Microsoft Ids to the specified authorization /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitLinkAuthorizationMicrosoftIdOperations. /// </param> /// <param name='serviceKey'> /// Required. The service key representing the circuit. /// </param> /// <param name='authId'> /// Required. The GUID representing the authorization /// </param> /// <param name='parameters'> /// Required. Parameters supplied to add new Microsoft Ids /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> NewAsync(this IDedicatedCircuitLinkAuthorizationMicrosoftIdOperations operations, string serviceKey, string authId, DedicatedCircuitLinkAuthorizationMicrosoftIdNewParameters parameters) { return(operations.NewAsync(serviceKey, authId, parameters, CancellationToken.None)); }
/// <summary> /// Adds Microsoft Ids to the specified authorization /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitLinkAuthorizationMicrosoftIdOperations. /// </param> /// <param name='serviceKey'> /// Required. The service key representing the circuit. /// </param> /// <param name='authId'> /// Required. The GUID representing the authorization /// </param> /// <param name='parameters'> /// Required. Parameters supplied to add new Microsoft Ids /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse New(this IDedicatedCircuitLinkAuthorizationMicrosoftIdOperations operations, string serviceKey, string authId, DedicatedCircuitLinkAuthorizationMicrosoftIdNewParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IDedicatedCircuitLinkAuthorizationMicrosoftIdOperations)s).NewAsync(serviceKey, authId, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Adds Microsoft Ids to the specified authorization /// </summary> /// <param name='serviceKey'> /// Required. The service key representing the circuit. /// </param> /// <param name='authId'> /// Required. The GUID representing the authorization /// </param> /// <param name='parameters'> /// Required. Parameters supplied to add new Microsoft Ids /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <OperationResponse> NewAsync(string serviceKey, string authId, DedicatedCircuitLinkAuthorizationMicrosoftIdNewParameters parameters, CancellationToken cancellationToken) { // Validate if (serviceKey == null) { throw new ArgumentNullException("serviceKey"); } if (authId == null) { throw new ArgumentNullException("authId"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } // 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("serviceKey", serviceKey); tracingParameters.Add("authId", authId); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "NewAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/networking/dedicatedcircuits/" + serviceKey.Trim() + "/authorizations/" + authId.Trim() + "/microsoftids?api-version=1.0"; 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.Post; 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); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement dedicatedCircuitLinkAuthorizationMicrosoftIdsElement = new XElement(XName.Get("DedicatedCircuitLinkAuthorizationMicrosoftIds", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(dedicatedCircuitLinkAuthorizationMicrosoftIdsElement); if (parameters.MicrosoftIds != null) { XElement microsoftIdsElement = new XElement(XName.Get("MicrosoftIds", "http://schemas.microsoft.com/windowsazure")); microsoftIdsElement.Value = parameters.MicrosoftIds; dedicatedCircuitLinkAuthorizationMicrosoftIdsElement.Add(microsoftIdsElement); } requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml"); // 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, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; result = new OperationResponse(); 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(); } } }