public async Task <ActionResult> RegisterInteractionsExportToJson() { using (IXdbContext client = SitecoreXConnectClientConfiguration.GetClient()) { var interactionFacets = client.Model.Facets.Where(c => c.Target == EntityType.Interaction).Select(x => x.Name); var contactFacets = client.Model.Facets.Where(c => c.Target == EntityType.Contact).Select(x => x.Name); var expandOptions = new InteractionExpandOptions(interactionFacets.ToArray()) { Contact = new RelatedContactExpandOptions(contactFacets.ToArray()) }; InteractionDataSourceOptionsDictionary interactionDataSourceOptionsDictionary = new InteractionDataSourceOptionsDictionary(expandOptions, 1000, 1000); var workerOptions = new Dictionary <string, string>(); var taskId = await _taskManager.RegisterDistributedTaskAsync( interactionDataSourceOptionsDictionary, new DistributedWorkerOptionsDictionary( "XcExport.Cortex.Workers.ExportInteractionsToJson, XcExport.Cortex", workerOptions), null, TimeSpan.FromHours(1)); return(Json(new { TaskId = taskId.ToString() }, JsonRequestBehavior.AllowGet)); } }
public void SetFacets_SameBirthday_ShouldReturnFalse(Contact xdbContact, IXdbContext xdbContext, DateTime birthday) { birthday = birthday.Date; void SetValue(PersonalInformation facet) => facet.Birthdate = birthday; this.SetFacets_SameValue_ShouldReturnFalse(xdbContact, xdbContext, Accounts.Constants.UserProfile.Fields.Birthday, birthday.ToLongDateString(), SetValue); }
public async Task <ActionResult> RegisterContactsExportToMsSql() { using (IXdbContext client = SitecoreXConnectClientConfiguration.GetClient()) { var interactionFacets = client.Model.Facets.Where(c => c.Target == EntityType.Interaction).Select(x => x.Name); var contactFacets = client.Model.Facets.Where(c => c.Target == EntityType.Contact).Select(x => x.Name); var searchRequest = client.Contacts .Where(c => c.Interactions.Any()) .WithExpandOptions(new ContactExpandOptions(contactFacets.ToArray()) { Interactions = new RelatedInteractionsExpandOptions(interactionFacets.ToArray()) { //StartDateTime = DateTime.Now.AddDays(-3), //EndDateTime = DateTime.Now, Limit = int.MaxValue } }) .GetSearchRequest(); var dataSourceOptions = new ContactSearchDataSourceOptionsDictionary(searchRequest, 1000, 1000); var workerOptions = new Dictionary <string, string>(); var taskId = await _taskManager.RegisterDistributedTaskAsync( dataSourceOptions, new DistributedWorkerOptionsDictionary( "XcExport.Cortex.Workers.ExportContactsToMsSql, XcExport.Cortex", workerOptions), null, TimeSpan.FromHours(1)); return(Json(new { TaskId = taskId.ToString() }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> RegisterExportToGoogleBigQuery() { using (IXdbContext client = SitecoreXConnectClientConfiguration.GetClient()) { var searchRequest = client.Contacts .Where(c => c.Interactions.Any(i => i.Events.OfType <RunEnded>().Any(x => true))) .WithExpandOptions(new ContactExpandOptions(RunnerFacet.DefaultFacetKey) { Interactions = new RelatedInteractionsExpandOptions { Limit = int.MaxValue } }) .GetSearchRequest(); var dataSourceOptions = new ContactSearchDataSourceOptionsDictionary(searchRequest, 100, 100); var workerOptions = new Dictionary <string, string>(); var taskId = await _taskManager.RegisterDistributedTaskAsync( dataSourceOptions, new DistributedWorkerOptionsDictionary( "Sitecore.Demo.CortexWorkers.ExportToBigQueryWorker, Sitecore.Demo.CortexWorkers", workerOptions), null, TimeSpan.FromHours(1)); return(new ContentResult { Content = taskId.ToString() }); } }
/// <summary> /// Sets the <see cref="EmailAddressList"/> facet of the specified <paramref name="contact" />. /// </summary> /// <param name="email">The email address.</param> /// <param name="contact">The contact.</param> /// <param name="client">The client.</param> private static void SetEmail(string email, Contact contact, IXdbContext client) { if (string.IsNullOrEmpty(email)) { return; } EmailAddressList emailFacet = contact.Emails(); if (emailFacet == null) { emailFacet = new EmailAddressList(new EmailAddress(email, false), "Preferred"); } else { if (emailFacet.PreferredEmail?.SmtpAddress == email) { return; } emailFacet.PreferredEmail = new EmailAddress(email, false); } client.SetEmails(contact, emailFacet); }
public bool SetFacets(UserProfile profile, Contact contact, IXdbContext client) { var phoneNumber = profile[Accounts.Constants.UserProfile.Fields.PhoneNumber]; if (string.IsNullOrEmpty(phoneNumber)) { return(false); } var phoneNumbers = contact.GetFacet <PhoneNumberList>(PhoneNumberList.DefaultFacetKey); if (phoneNumbers == null) { phoneNumbers = new PhoneNumberList(new PhoneNumber(null, phoneNumber), null); } else { if (phoneNumbers.PreferredPhoneNumber?.Number == phoneNumber) { return(false); } phoneNumbers.PreferredPhoneNumber = new PhoneNumber(null, phoneNumber); } client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, phoneNumbers); return(true); }
private void AddProfileScore(IXdbContext client, Contact contact) { if (string.IsNullOrWhiteSpace(tbProfileScore.Text) || string.IsNullOrWhiteSpace(tbProfileKeyId.Text) || string.IsNullOrWhiteSpace(tbProfileId.Text)) { return; } Guid profileId = Guid.Parse(tbProfileId.Text); Guid profileKeyId = Guid.Parse(tbProfileKeyId.Text); int score = int.Parse(tbProfileScore.Text, CultureInfo.CurrentCulture); var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); var engagementValueEvent = new Event(ProfileScoreChangeEventDefinitionId, DateTime.UtcNow); interaction.Events.Add(engagementValueEvent); client.AddInteraction(interaction); var profileScores = new ProfileScores(); var profileScore = new ProfileScore { Values = { [profileKeyId] = score } }; profileScores.Scores.Add(profileId, profileScore); client.SetProfileScores(interaction, profileScores); }
private static void AddInteraction( IXdbContext client, Contact contact, IEnumerable <Guid> goalIds, IEnumerable <Guid> outcomeIds, IEnumerable <Guid> eventIds, Guid campaignId) { var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); foreach (Guid goalId in goalIds) { var goal = new Goal(goalId, DateTime.UtcNow) { Duration = new TimeSpan(0, 0, 30) }; interaction.Events.Add(goal); } foreach (Guid outcomeId in outcomeIds) { var outcome = new Outcome(outcomeId, DateTime.UtcNow, "usd", 100.00m); interaction.Events.Add(outcome); } foreach (Guid eventId in eventIds) { var pageEvent = new Event(eventId, DateTime.UtcNow) { Duration = new TimeSpan(0, 0, 30) }; interaction.Events.Add(pageEvent); } interaction.CampaignId = campaignId; client.AddInteraction(interaction); }
public bool SetFacets(UserProfile profile, Contact contact, IXdbContext client) { var email = profile.Email; if (string.IsNullOrEmpty(email)) { return(false); } var emails = contact.GetFacet <EmailAddressList>(EmailAddressList.DefaultFacetKey); if (emails == null) { emails = new EmailAddressList(new EmailAddress(email, false), null); } else { if (emails.PreferredEmail?.SmtpAddress == email) { return(false); } emails.PreferredEmail = new EmailAddress(email, false); } client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emails); return(true); }
public void SetFacets_NoBirthday_ShouldSetFacet(Contact xdbContact, IXdbContext xdbContext, DateTime birthday) { birthday = birthday.Date; bool AssertValue(PersonalInformation facet) => facet.Birthdate == birthday; this.SetFacets_NoExistingValue_ShouldSetfacet(xdbContact, xdbContext, Accounts.Constants.UserProfile.Fields.Birthday, birthday.ToLongDateString(), AssertValue); }
public ExecuteRightToBeForgottenActivity(IXdbContext xdbContext, ILogger <ExecuteRightToBeForgottenActivity> logger) { Condition.Requires(xdbContext, nameof(xdbContext)).IsNotNull(); Condition.Requires(logger, nameof(logger)).IsNotNull(); _xdbContext = xdbContext; _logger = logger; }
public RecommendationFacetStorageWorker(ITableStoreFactory tableStoreFactory, IXdbContext xdbContext, IReadOnlyDictionary <string, string> options) { _tableName = options[OptionTableName]; var schemaName = options[OptionSchemaName]; _tableStore = tableStoreFactory.Create(schemaName); _xdbContext = xdbContext; }
private void CreateContacts() { using (IXdbContext client = _xConnectClientFactory.GetXConnectClient()) { try { var numberOfContacts = int.Parse(tbNumberOfContacts.Text, CultureInfo.CurrentCulture); var goalIds = tbGoalIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse); var eventIds = tbEventIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse); var outcomeIds = tbOutcomeIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse); var listId = !string.IsNullOrWhiteSpace(tbListId.Text) ? Guid.Parse(tbListId.Text) : Guid.Empty; var campaignId = !string.IsNullOrWhiteSpace(tbCampaignId.Text) ? Guid.Parse(tbCampaignId.Text) : Guid.Empty; for (var i = 0; i < numberOfContacts; i++) { string email = GetEmailAddress(i); var contact = new Contact(new ContactIdentifier("ListManager", email, ContactIdentifierType.Known)); client.AddContact(contact); AddPreferredEmail(i, client, contact, email); AddPhoneNumber(client, contact, tbPhoneNumber.Text); AddPersonalInfo(client, contact, tbPreferredLanguage.Text); AddListSubscription(listId, client, contact); AddConsentInformation(client, contact); AddProfileScore(client, contact); AddEngagementValue(client, contact); AddInteraction(client, contact, goalIds, outcomeIds, eventIds, campaignId); if (i % 10 != 0) { continue; } var numberOfContactsBeingSubmitted = i / 1 > 0 ? i / 1 : 1; Logger.Info($"Submitting {numberOfContactsBeingSubmitted} contacts", this); client.Submit(); } client.Submit(); } catch (Exception ex) { Logger.Error("Failed to submit contacts", ex, this); } } }
private void AddPhoneNumber(IXdbContext client, Contact contact, string text) { if (string.IsNullOrWhiteSpace(text)) { return; } client.SetPhoneNumbers(contact, new PhoneNumberList(new PhoneNumber("0045", text), "Preferred")); }
private static void MakeContactKnown(IXdbContext client, Sitecore.XConnect.Contact contact) { if (contact.IsKnown) { return; } client.AddContactIdentifier(contact, new ContactIdentifier("exm-known", Guid.NewGuid().ToString("N"), ContactIdentifierType.Known)); }
private void AddConsentInformation(IXdbContext client, Contact contact) { if (checkBoxConsentRevoked.Checked || checkBoxDoNotMarket.Checked) { client.SetConsentInformation(contact, new ConsentInformation() { ConsentRevoked = checkBoxConsentRevoked.Checked, DoNotMarket = checkBoxDoNotMarket.Checked }); } }
private static void MakeContactKnown(IXdbContext client, Contact contact) { if (contact.IsKnown) { return; } if (!Sitecore.Configuration.Settings.GetBoolSetting("MakeContactKnownOnFormsUpdate", true)) { return; } client.AddContactIdentifier(contact, new ContactIdentifier("scformsextension-known", Guid.NewGuid().ToString("N"), ContactIdentifierType.Known)); }
public void SetFacets_NoProfilePhone_ShouldReturnFalse(Contact xdbContact, IXdbContext xdbContext) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); var facetUpdater = new PhoneFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeFalse(); xdbContext.DidNotReceiveWithAnyArgs().RegisterOperation(Arg.Any <IXdbOperation>()); }
private static void AddPersonalInfo(IXdbContext client, Contact contact, string preferredLanguage = null) { var personalInformation = new PersonalInformation { FirstName = Name.First(), LastName = Name.Last(), }; if (!string.IsNullOrWhiteSpace(preferredLanguage)) { personalInformation.PreferredLanguage = preferredLanguage; } client.SetPersonal(contact, personalInformation); }
public void SetFacets_NoChanges_ShouldReturnFalse(Contact xdbContact, IXdbContext xdbContext, string email) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile.Email.Returns(email); Sitecore.XConnect.Serialization.DeserializationHelpers.SetFacet(xdbContact, EmailAddressList.DefaultFacetKey, new EmailAddressList(new EmailAddress(email, false), null)); var facetUpdater = new EmailFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeFalse(); xdbContext.DidNotReceiveWithAnyArgs().RegisterOperation(Arg.Any <IXdbOperation>()); }
public bool SetFacets(UserProfile profile, Contact contact, IXdbContext client) { var changed = false; var personalInfo = contact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey) ?? new PersonalInformation(); changed |= this.SetBirthdate(profile, personalInfo); changed |= this.SetName(profile, personalInfo); changed |= this.SetGender(profile, personalInfo); changed |= this.SetLanguage(profile, personalInfo); if (!changed) { return(false); } client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo); return(true); }
public void SetFacets_NoChanges_ShouldReturnFalse(Contact xdbContact, IXdbContext xdbContext, string phone) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[Accounts.Constants.UserProfile.Fields.PhoneNumber] = phone; Sitecore.XConnect.Serialization.DeserializationHelpers.SetFacet(xdbContact, PhoneNumberList.DefaultFacetKey, new PhoneNumberList(new PhoneNumber(null, phone), null)); var facetUpdater = new PhoneFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeFalse(); xdbContext.DidNotReceiveWithAnyArgs().RegisterOperation(Arg.Any <IXdbOperation>()); }
public void SetFacets_NoEmailList_ShouldSetFacet(Contact xdbContact, IXdbContext xdbContext, string email) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile.Email.Returns(email); var facetUpdater = new EmailFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation>(x => x.FacetReference.FacetKey == EmailAddressList.DefaultFacetKey && ((EmailAddressList)x.Facet).PreferredEmail.SmtpAddress == email)); }
private static void AddListSubscription(Guid listId, IXdbContext client, Contact contact) { if (listId != Guid.Empty) { client.SetListSubscriptions(contact, new ListSubscriptions() { Subscriptions = new List <ContactListSubscription>() { // 9.1 only //new ContactListSubscription(DateTime.UtcNow, true, listId) //{ // SourceDefinitionId = KnownIdentifiers.EmailExperienceManagerSubscriptionId //} } }); } }
public void SetFacets_NoPhoneList_ShouldSetFacet(Contact xdbContact, IXdbContext xdbContext, string phone) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[Accounts.Constants.UserProfile.Fields.PhoneNumber] = phone; var facetUpdater = new PhoneFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation>(x => x.FacetReference.FacetKey == PhoneNumberList.DefaultFacetKey && ((PhoneNumberList)x.Facet).PreferredPhoneNumber.Number == phone)); }
private void SetFacets_NoExistingValue_ShouldSetfacet(Contact xdbContact, IXdbContext xdbContext, string profileKey, string value, Func <PersonalInformation, bool> assertValue) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[profileKey] = value; var facetUpdater = new PersonalInformationFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeTrue(); xdbContext.Received(1).RegisterOperation(Arg.Is <SetFacetOperation <PersonalInformation> >(x => x.FacetReference.FacetKey == PersonalInformation.DefaultFacetKey && assertValue(x.Facet))); }
public async Task <ActionResult> GenerateUsers() { using (IXdbContext xdbContext = SitecoreXConnectClientConfiguration.GetClient()) { var ovais = new Contact(new ContactIdentifier("letsplay", "*****@*****.**", ContactIdentifierType.Known)); var sumith = new Contact(new ContactIdentifier("letsplay", "*****@*****.**", ContactIdentifierType.Known)); xdbContext.AddContact(ovais); xdbContext.AddContact(sumith); await xdbContext.SubmitAsync(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task <ActionResult> GenerateData(int amountOfContacts = 10, int amountOfInteractions = 10) { using (IXdbContext xdbContext = SitecoreXConnectClientConfiguration.GetClient()) { for (var c = 0; c < amountOfContacts; c++) { var contact = new Contact(new ContactIdentifier("sitecore.demo", Guid.NewGuid().ToString(), ContactIdentifierType.Known)); var currentDate = DateTime.UtcNow; xdbContext.AddContact(contact); for (var i = 1; i <= amountOfInteractions; i++) { // Even are morning runners. 10AM for morning runner and 6PM for evening one. : var startTime = 10 + c % 2 * 8; var startDate = currentDate.Date.AddDays(-i).AddHours(startTime); var endDate = startDate.AddHours(1); var interaction = new Interaction(contact, InteractionInitiator.Contact, /*TODO: Channel ID*/ Guid.NewGuid(), "Some Agent") { Events = { new RunStarted(/*TODO: Definition ID*/ Guid.NewGuid(), startDate) { Time = startDate }, new RunEnded(/*TODO: Definition ID*/ Guid.NewGuid(), endDate) { Time = endDate } } }; xdbContext.AddInteraction(interaction); } } await xdbContext.SubmitAsync(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
private void AddEngagementValue(IXdbContext client, Contact contact) { if (string.IsNullOrWhiteSpace(tbEngagementValue.Text)) { return; } int engagementValue = int.Parse(tbEngagementValue.Text, CultureInfo.CurrentCulture); var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); var engagementValueEvent = new Event(Guid.NewGuid(), DateTime.UtcNow) { EngagementValue = engagementValue }; interaction.Events.Add(engagementValueEvent); client.AddInteraction(interaction); }
private void SetFacets_SameValue_ShouldReturnFalse(Contact xdbContact, IXdbContext xdbContext, string profileKey, string value, Action <PersonalInformation> setValue) { // Arrange var userProfile = Substitute.For <Sitecore.Security.UserProfile>(); userProfile[profileKey] = value; var personalInformation = new PersonalInformation(); setValue(personalInformation); Sitecore.XConnect.Serialization.DeserializationHelpers.SetFacet(xdbContact, PersonalInformation.DefaultFacetKey, personalInformation); var facetUpdater = new PersonalInformationFacetUpdater(); // Act var changed = facetUpdater.SetFacets(userProfile, xdbContact, xdbContext); // Assert changed.Should().BeFalse(); xdbContext.DidNotReceiveWithAnyArgs().RegisterOperation(Arg.Any <IXdbOperation>()); }