/// <summary> /// Initializes a new instance of the LinkedService class with required arguments. /// </summary> public LinkedService(string name, LinkedServiceProperties properties) : this() { Ensure.IsNotNullOrEmpty(name, "name"); Ensure.IsNotNull(properties, "properties"); this.Name = name; this.Properties = properties; }
/// <summary> /// Initializes a new instance of the LinkedService class with required arguments. /// </summary> public LinkedService(string name, LinkedServiceProperties properties) : this() { Ensure.IsNotNullOrEmpty(name, "name"); Ensure.IsNotNull(properties, "properties"); this.Name = name; this.Properties = properties; }
public void CanSetNonGenericTypePropertiesWithoutTypeName() { var storageLinkedService = new AzureStorageLinkedService(); Assert.DoesNotThrow( () => { var ls = new LinkedServiceProperties(storageLinkedService); ls.TypeProperties = storageLinkedService; }); }
public void CreatingGenericLinkedServiceWithoutTypeNameThrowsExceptionTest() { string expectedError = "cannot be used if its value is GenericLinkedService, GenericTable or GenericActivity"; var genericLinkedService = new GenericLinkedService(); ArgumentException ex = Assert.Throws <ArgumentException>(() => new LinkedServiceProperties(genericLinkedService)); Assert.Contains(expectedError, ex.Message); ex = Assert.Throws <ArgumentException>( () => { var ls = new LinkedServiceProperties(genericLinkedService, "somename"); ls.TypeProperties = genericLinkedService; }); Assert.Contains(expectedError, ex.Message); }
/// <summary> /// Convert <see cref="Microsoft.Azure.Management.DataFactories.Core.Models.LinkedService"/> /// to a <see cref="Microsoft.Azure.Management.DataFactories.Models.LinkedService"/> instance. /// </summary> /// <param name="internalLinkedService"> /// The <see cref="Microsoft.Azure.Management.DataFactories.Core.Models.LinkedService"/> /// instance to convert.</param> /// <returns>A <see cref="LinkedService"/> instance equivalent to <paramref name="internalLinkedService"/>.</returns> public override LinkedService ToWrapperType(Core.Models.LinkedService internalLinkedService) { Ensure.IsNotNull(internalLinkedService, "internalLinkedService"); Ensure.IsNotNull(internalLinkedService.Properties, "internalLinkedService.Properties"); Type type; LinkedServiceTypeProperties typeProperties = this.DeserializeTypeProperties( internalLinkedService.Properties.Type, internalLinkedService.Properties.TypeProperties, out type); string typeName = GetTypeName(type, internalLinkedService.Properties.Type); LinkedServiceProperties properties = new LinkedServiceProperties(typeProperties, typeName) { Description = internalLinkedService.Properties.Description, ErrorMessage = internalLinkedService.Properties.ErrorMessage, HubName = internalLinkedService.Properties.HubName, ProvisioningState = internalLinkedService.Properties.ProvisioningState }; return(new LinkedService() { Name = internalLinkedService.Name, Properties = properties }); }
public static string ToFormattedString(this LinkedServiceProperties properties) { return(JsonConvert.SerializeObject(properties)); }
public void CanSetNonGenericTypePropertiesWithoutTypeName() { var storageLinkedService = new AzureStorageLinkedService(); Assert.DoesNotThrow( () => { var ls = new LinkedServiceProperties(storageLinkedService); ls.TypeProperties = storageLinkedService; }); }
public void CreatingGenericLinkedServiceWithoutTypeNameThrowsExceptionTest() { string expectedError = "cannot be used if its value is GenericLinkedService, GenericTable or GenericActivity"; var genericLinkedService = new GenericLinkedService(); ArgumentException ex = Assert.Throws<ArgumentException>(() => new LinkedServiceProperties(genericLinkedService)); Assert.Contains(expectedError, ex.Message); ex = Assert.Throws<ArgumentException>( () => { var ls = new LinkedServiceProperties(genericLinkedService, "somename"); ls.TypeProperties = genericLinkedService; }); Assert.Contains(expectedError, ex.Message); }
/// <summary> /// Gets the next page of linked service instances with the link to the /// next page. /// </summary> /// <param name='nextLink'> /// Required. The url to the next linked service page. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The list linked service operation response. /// </returns> public async Task <LinkedServiceListResponse> ListNextAsync(string nextLink, CancellationToken cancellationToken) { // Validate if (nextLink == null) { throw new ArgumentNullException("nextLink"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("nextLink", nextLink); TracingAdapter.Enter(invocationId, this, "ListNextAsync", tracingParameters); } // Construct URL string url = ""; url = url + nextLink; 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-client-request-id", Guid.NewGuid().ToString()); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.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) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result LinkedServiceListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new LinkedServiceListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { LinkedService linkedServiceInstance = new LinkedService(); result.LinkedServices.Add(linkedServiceInstance); JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); linkedServiceInstance.Id = idInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); linkedServiceInstance.Name = nameInstance; } JToken typeValue = valueValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); linkedServiceInstance.Type = typeInstance; } JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { LinkedServiceProperties propertiesInstance = new LinkedServiceProperties(); linkedServiceInstance.Properties = propertiesInstance; JToken resourceIdValue = propertiesValue["resourceId"]; if (resourceIdValue != null && resourceIdValue.Type != JTokenType.Null) { string resourceIdInstance = ((string)resourceIdValue); propertiesInstance.ResourceId = resourceIdInstance; } } } } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); result.NextLink = nextLinkInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Create or update a linked service. /// </summary> /// <param name='resourceGroupName'> /// Required. The resource group name of the linked service. /// </param> /// <param name='workspaceName'> /// Required. The name of the parent workspace that will contain the /// linked service /// </param> /// <param name='parameters'> /// Required. The parameters required to create or update a linked /// service. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The create or update linked service operation response. /// </returns> public async Task <LinkedServiceCreateOrUpdateResponse> CreateOrUpdateAsync(string resourceGroupName, string workspaceName, LinkedServiceCreateOrUpdateParameters parameters, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (workspaceName == null) { throw new ArgumentNullException("workspaceName"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.Name == null) { throw new ArgumentNullException("parameters.Name"); } if (parameters.Properties == null) { throw new ArgumentNullException("parameters.Properties"); } if (parameters.Properties.ResourceId == null) { throw new ArgumentNullException("parameters.Properties.ResourceId"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("workspaceName", workspaceName); tracingParameters.Add("parameters", parameters); TracingAdapter.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourcegroups/"; url = url + Uri.EscapeDataString(resourceGroupName); url = url + "/providers/Microsoft.OperationalInsights/workspaces/"; url = url + Uri.EscapeDataString(workspaceName); url = url + "/linkedServices/"; url = url + Uri.EscapeDataString(parameters.Name); List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-11-01-preview"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } 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.Put; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-client-request-id", Guid.NewGuid().ToString()); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject linkedServiceCreateOrUpdateParametersValue = new JObject(); requestDoc = linkedServiceCreateOrUpdateParametersValue; linkedServiceCreateOrUpdateParametersValue["name"] = parameters.Name; JObject propertiesValue = new JObject(); linkedServiceCreateOrUpdateParametersValue["properties"] = propertiesValue; propertiesValue["resourceId"] = parameters.Properties.ResourceId; requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result LinkedServiceCreateOrUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new LinkedServiceCreateOrUpdateResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { LinkedService linkedServiceInstance = new LinkedService(); result.LinkedService = linkedServiceInstance; JToken idValue = responseDoc["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); linkedServiceInstance.Id = idInstance; } JToken nameValue = responseDoc["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); linkedServiceInstance.Name = nameInstance; } JToken typeValue = responseDoc["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); linkedServiceInstance.Type = typeInstance; } JToken propertiesValue2 = responseDoc["properties"]; if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null) { LinkedServiceProperties propertiesInstance = new LinkedServiceProperties(); linkedServiceInstance.Properties = propertiesInstance; JToken resourceIdValue = propertiesValue2["resourceId"]; if (resourceIdValue != null && resourceIdValue.Type != JTokenType.Null) { string resourceIdInstance = ((string)resourceIdValue); propertiesInstance.ResourceId = resourceIdInstance; } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }