/// <summary> /// Creates a link or updates an existing link in the hub. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='hubName'> /// The name of the hub. /// </param> /// <param name='linkName'> /// The name of the link. /// </param> /// <param name='parameters'> /// Parameters supplied to the CreateOrUpdate Link operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <LinkResourceFormat> CreateOrUpdateAsync(this ILinksOperations operations, string resourceGroupName, string hubName, string linkName, LinkResourceFormat parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, hubName, linkName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a link or updates an existing link in the hub. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='hubName'> /// The name of the hub. /// </param> /// <param name='linkName'> /// The name of the link. /// </param> /// <param name='parameters'> /// Parameters supplied to the CreateOrUpdate Link operation. /// </param> public static LinkResourceFormat CreateOrUpdate(this ILinksOperations operations, string resourceGroupName, string hubName, string linkName, LinkResourceFormat parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, hubName, linkName, parameters).GetAwaiter().GetResult()); }
public void SuggestRelationshipLinks() { using (var context = MockContext.Start(this.GetType().FullName)) { var aciClient = context.GetServiceClient <CustomerInsightsManagementClient>(); var profileName1 = TestUtilities.GenerateName("testProfile"); var profileName2 = TestUtilities.GenerateName("testProfile"); var interactionName1 = TestUtilities.GenerateName("testInteraction"); var profileResourceFormat1 = new ProfileResourceFormat { ApiEntitySetName = profileName1, Fields = new[] { new PropertyDefinition { FieldName = "ContactId", FieldType = "Edm.String", IsArray = false, IsRequired = true } }, StrongIds = new List <StrongId> { new StrongId { StrongIdName = "ContactId", KeyPropertyNames = new List <string> { "ContactId" } } } }; var profileResourceFormat2 = new ProfileResourceFormat { ApiEntitySetName = profileName2, Fields = new[] { new PropertyDefinition { FieldName = "BranchId", FieldType = "Edm.String", IsArray = false, IsRequired = true } }, StrongIds = new List <StrongId> { new StrongId { StrongIdName = "BranchId", KeyPropertyNames = new List <string> { "BranchId" } } } }; aciClient.Profiles.CreateOrUpdate(ResourceGroupName, HubName, profileName1, profileResourceFormat1); aciClient.Profiles.CreateOrUpdate(ResourceGroupName, HubName, profileName2, profileResourceFormat2); var interactionResourceFormat = new InteractionResourceFormat { ApiEntitySetName = interactionName1, Fields = new[] { new PropertyDefinition { FieldName = "ContactId", FieldType = "Edm.String" }, new PropertyDefinition { FieldName = "BranchId", FieldType = "Edm.String" } } }; aciClient.Interactions.CreateOrUpdate( ResourceGroupName, HubName, interactionName1, interactionResourceFormat); var linkName1 = TestUtilities.GenerateName("linkTest"); var linkName2 = TestUtilities.GenerateName("linkTest"); var linkResourceFormat1 = new LinkResourceFormat { TargetProfileType = profileName1, SourceInteractionType = interactionName1, ParticipantPropertyReferences = new[] { new ParticipantPropertyReference { ProfilePropertyName = "ContactId", InteractionPropertyName = "ContactId" } } }; var link1 = aciClient.Links.CreateOrUpdate(ResourceGroupName, HubName, linkName1, linkResourceFormat1); var linkResourceFormat2 = new LinkResourceFormat { TargetProfileType = profileName2, SourceInteractionType = interactionName1, ParticipantPropertyReferences = new[] { new ParticipantPropertyReference { ProfilePropertyName = "BranchId", InteractionPropertyName = "BranchId" } } }; var link2 = aciClient.Links.CreateOrUpdate(ResourceGroupName, HubName, linkName2, linkResourceFormat2); TestUtilities.Wait(5000); var suggestedRelationshipLinks = aciClient.Interactions.SuggestRelationshipLinks( ResourceGroupName, HubName, interactionName1); Assert.Equal(2, suggestedRelationshipLinks.SuggestedRelationships.Count); Assert.Equal(interactionName1, suggestedRelationshipLinks.InteractionName); Assert.True( ((suggestedRelationshipLinks.SuggestedRelationships[0].ProfileName == profileName1) && (suggestedRelationshipLinks.SuggestedRelationships[0].RelatedProfileName == profileName2)) || ((suggestedRelationshipLinks.SuggestedRelationships[0].ProfileName == profileName2) && (suggestedRelationshipLinks.SuggestedRelationships[0].RelatedProfileName == profileName1))); } }
public void CrdLinksFullCycle() { using (var context = MockContext.Start(this.GetType().FullName)) { var aciClient = context.GetServiceClient <CustomerInsightsManagementClient>(); var profileName = TestUtilities.GenerateName("testProfile"); var interactionName1 = TestUtilities.GenerateName("testInteraction"); var linkName = TestUtilities.GenerateName("linkTest"); var profileResourceFomrat = Helpers.GetTestProfile(profileName); aciClient.Profiles.CreateOrUpdate(ResourceGroupName, HubName, profileName, profileResourceFomrat); var interactionResourceFormat = Helpers.GetTestInteraction(interactionName1, "profile1");; var linkResourceFormat = new LinkResourceFormat { TargetProfileType = profileName, SourceInteractionType = interactionName1, DisplayName = new Dictionary <string, string> { { "en-us", "Link DisplayName" } }, Description = new Dictionary <string, string> { { "en-us", "Link Description" } }, Mappings = new[] { new TypePropertiesMapping { InteractionTypePropertyName = interactionName1, ProfileTypePropertyName = profileName, IsProfileTypeId = true, LinkType = LinkTypes.UpdateAlways } }, ParticipantPropertyReferences = new[] { new ParticipantPropertyReference { ProfilePropertyName = "ProfileId", InteractionPropertyName = interactionName1 } } }; aciClient.Interactions.CreateOrUpdate( ResourceGroupName, HubName, interactionName1, interactionResourceFormat); var createLinkResult = aciClient.Links.CreateOrUpdate( ResourceGroupName, HubName, linkName, linkResourceFormat); Assert.Equal(linkName, createLinkResult.LinkName); Assert.Equal(createLinkResult.Name, HubName + "/" + linkName, StringComparer.OrdinalIgnoreCase); Assert.Equal( "Microsoft.CustomerInsights/hubs/links", createLinkResult.Type, StringComparer.OrdinalIgnoreCase); var getLinkResult = aciClient.Links.Get(ResourceGroupName, HubName, linkName); Assert.Equal(linkName, getLinkResult.LinkName); Assert.Equal(getLinkResult.Name, HubName + "/" + linkName, StringComparer.OrdinalIgnoreCase); Assert.Equal( "Microsoft.CustomerInsights/hubs/links", getLinkResult.Type, StringComparer.OrdinalIgnoreCase); var listlinkResult = aciClient.Links.ListByHub(ResourceGroupName, HubName); Assert.True(listlinkResult.ToList().Count >= 1); Assert.Contains(listlinkResult.ToList(), linkReturned => linkName == linkReturned.LinkName); } }
/// <summary> /// Creates a link or updates an existing link in the hub. /// </summary> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='hubName'> /// The name of the hub. /// </param> /// <param name='linkName'> /// The name of the link. /// </param> /// <param name='parameters'> /// Parameters supplied to the CreateOrUpdate Link operation. /// </param> /// <param name='customHeaders'> /// The headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public async Task <AzureOperationResponse <LinkResourceFormat> > CreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string hubName, string linkName, LinkResourceFormat parameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { // Send Request AzureOperationResponse <LinkResourceFormat> _response = await BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, hubName, linkName, parameters, customHeaders, cancellationToken).ConfigureAwait(false); return(await Client.GetPutOrPatchOperationResultAsync(_response, customHeaders, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Creates a link or updates an existing link in the hub. /// </summary> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='hubName'> /// The name of the hub. /// </param> /// <param name='linkName'> /// The name of the link. /// </param> /// <param name='parameters'> /// Parameters supplied to the CreateOrUpdate Link operation. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <LinkResourceFormat> > BeginCreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string hubName, string linkName, LinkResourceFormat parameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (hubName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "hubName"); } if (linkName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "linkName"); } if (linkName != null) { if (linkName.Length > 512) { throw new ValidationException(ValidationRules.MaxLength, "linkName", 512); } if (linkName.Length < 1) { throw new ValidationException(ValidationRules.MinLength, "linkName", 1); } if (!System.Text.RegularExpressions.Regex.IsMatch(linkName, "^[a-zA-Z][a-zA-Z0-9_]+$")) { throw new ValidationException(ValidationRules.Pattern, "linkName", "^[a-zA-Z][a-zA-Z0-9_]+$"); } } if (parameters == null) { throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); } if (parameters != null) { parameters.Validate(); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("hubName", hubName); tracingParameters.Add("linkName", linkName); tracingParameters.Add("parameters", parameters); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "BeginCreateOrUpdate", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/links/{linkName}").ToString(); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{hubName}", System.Uri.EscapeDataString(hubName)); _url = _url.Replace("{linkName}", System.Uri.EscapeDataString(linkName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new System.Net.Http.HttpRequestMessage(); System.Net.Http.HttpResponseMessage _httpResponse = null; _httpRequest.Method = new System.Net.Http.HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (parameters != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); _httpRequest.Content = new System.Net.Http.StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 202) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_httpResponse.Headers.Contains("x-ms-request-id")) { ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <LinkResourceFormat>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <LinkResourceFormat>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }