/// <summary>
 /// Creates a profile within a Hub, or updates an existing profile.
 /// </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='profileName'>
 /// The name of the profile.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create/delete Profile type operation
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ProfileResourceFormat> CreateOrUpdateAsync(this IProfilesOperations operations, string resourceGroupName, string hubName, string profileName, ProfileResourceFormat parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, hubName, profileName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        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)));
            }
        }
 /// <summary>
 /// Creates a profile within a Hub, or updates an existing profile.
 /// </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='profileName'>
 /// The name of the profile.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create/delete Profile type operation
 /// </param>
 public static ProfileResourceFormat CreateOrUpdate(this IProfilesOperations operations, string resourceGroupName, string hubName, string profileName, ProfileResourceFormat parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, hubName, profileName, parameters).GetAwaiter().GetResult());
 }