/// <summary> /// Method to search for valid contacts from XDB /// </summary> /// <param name="email"></param> /// <param name="isvalidUser"></param> /// <returns></returns> private static bool SearchContacts(XConnectClient client, string email) { var isvalidUser = false; // using (XConnectClient client = GetClient()) { var references = new List <IEntityReference <Sitecore.XConnect.Contact> >() { // Username new IdentifiedContactReference("", email), }; string emailsFacetKey = Sitecore.XConnect.Collection.Model.CollectionModel.FacetKeys.EmailAddressList; // Pass the facet name into the ContactExpandOptions constructor var contactsTask = client.Get <Sitecore.XConnect.Contact>(references, new ContactExpandOptions(emailsFacetKey) { }); IReadOnlyCollection <IEntityLookupResult <Contact> > contacts = contactsTask; if (contacts != null && contacts.Any()) { foreach (var contact in contacts) { // For each contact, retrieve the facet - will return null if contact does not have this facet set EmailAddressList emailsFacetData = contact.Entity.GetFacet <EmailAddressList>(emailsFacetKey); if (emailsFacetData != null) { isvalidUser = true; break; } } } } return(isvalidUser); }
public bool SaveFacet <T>(Sitecore.XConnect.Contact contact, string FacetKey, T Facet) where T : Facet { using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient()) { try { client.SetFacet(contact, FacetKey, Facet); client.Submit(); return(true); } catch (XdbExecutionException ex) { Log.Error($"XConnectContactRepository: Error saving contact data to xConnect. Facet: '{Facet}' Contact: '{contact.Id}'", ex, this); return(false); } catch (Exception ex) { Log.Error("XConnectContactRepository: Error communication with the xConnect colllection service", ex, this); return(false); } } }
public IWeKnowTree GetWhatWeKnowTreeFromXConnectContact(Sitecore.XConnect.Contact XConnectContact) { Sitecore.Diagnostics.Log.Debug(ProjConstants.Logger.Prefix + "s) GetWhatWeKnowTreeFromXConnectContact"); IWeKnowTree toReturn = new Concretions.WhatWeKnowTree("What We Know", Options); using (XConnectClient xConnectClient = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var tier1Nodes = new Tier1Nodes(XConnectContact, Options); toReturn.Root.AddNodes(tier1Nodes.Tier1NodeBuilder(null, xConnectClient, XConnectContact)); } catch (XdbExecutionException ex) { Sitecore.Diagnostics.Log.Error(ProjConstants.Logger.Prefix + ex.Message, this); } } Sitecore.Diagnostics.Log.Debug(ProjConstants.Logger.Prefix + "e) GetWhatWeKnowTreeFromXConnectContact"); return(toReturn); }
public bool Evaluate(IRuleExecutionContext context) { var contact = RuleExecutionContextExtensions.Fact <Contact>(context); XConnectClient client = XConnectClientReference.GetClient(); Contact existingContact = client.Get <Contact>(contact, new ContactExpandOptions(CvPersonFacet.DefaultFacetKey)); CvPersonFacet personFacet = existingContact.GetFacet <CvPersonFacet>(CvPersonFacet.DefaultFacetKey); if (personFacet?.BadgeText == null) { return(false); } bool result = personFacet.BadgeText .Any(line => line.IndexOf(this.BadgeText, StringComparison.OrdinalIgnoreCase) >= 0); Log.Information("BadgeTextMatches result == " + result); return(result); }
public void AddContactToList(Guid listId) { if (Tracker.Current == null) { Tracker.StartTracking(); } try { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { var contact = client.Get <Contact>(GetIdentifier(), new Sitecore.XConnect.ContactExpandOptions("ListSubscriptions")); if (contact == null) { SaveContact(); contact = client.Get <Contact>(GetIdentifier(), new Sitecore.XConnect.ContactExpandOptions("ListSubscriptions")); } if (contact != null) { if (contact.Identifiers.All(x => x.Source != "ListManager")) { client.AddContactIdentifier(contact, new ContactIdentifier("ListManager", Guid.NewGuid().ToString(), ContactIdentifierType.Known)); } var subscriptions = contact.ListSubscriptions() ?? new ListSubscriptions(); var subscription = new ContactListSubscription(DateTime.UtcNow, true, listId); subscriptions.Subscriptions.Add(subscription); client.SetListSubscriptions(contact, subscriptions); } } } catch (XdbExecutionException ex) { // Manage conflicts / exceptions Sitecore.Diagnostics.Log.Error("Error Setting List Subscription", ex, this); } }
public void RecordInteractionFacet(XConnectClient client, Contact knownContact) { var channelId = Const.XConnect.ChannelIds.OtherEvent; var offlineGoal = Const.XConnect.Goals.WatchedDemo; // Create a new interaction for that contact Interaction interaction = new Interaction(knownContact, InteractionInitiator.Brand, channelId, ""); // add events - all interactions must have at least one event var xConnectEvent = new Goal(offlineGoal, DateTime.UtcNow); interaction.Events.Add(xConnectEvent); IpInfo ipInfo = new IpInfo("127.0.0.1"); ipInfo.BusinessName = "Home"; client.SetFacet <IpInfo>(interaction, IpInfo.DefaultFacetKey, ipInfo); // Add the contact and interaction client.AddInteraction(interaction); }
public void RegisterInteractionEvent(Event interactionEvent) { var trackerIdentifier = GetContactReference(); using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient()) { var contact = client.Get <Contact>(trackerIdentifier, new ExpandOptions()); if (contact != null) { var interaction = new Sitecore.XConnect.Interaction(contact, InteractionInitiator.Brand, Guid.NewGuid(), "Experience Forms"); interaction.Events.Add(interactionEvent); client.AddInteraction(interaction); client.Submit(); ReloadContactDataIntoSession(); } } }
/// <summary> /// Get all contacts in xDB and their identifiers. /// </summary> /// <returns>Returns an HTML-ready list of all contacts in xDB and any identifiers associated to the account.</returns> /// <remarks>This is primarily a debugging method.</remarks> public string GetAllContacts() { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var contactSB = new StringBuilder(); foreach (Contact contact in client.Contacts.AsEnumerable()) { contactSB.Append("contact ID = "); contactSB.Append(contact.Id.ToString()); foreach (var id in contact.Identifiers) { contactSB.Append(", identifier = "); contactSB.Append(id.Identifier); contactSB.Append(", source = "); contactSB.Append(id.Source); contactSB.Append(", identifier type = "); contactSB.Append(id.IdentifierType.ToString()); } contactSB.Append(" "); contactSB.AppendLine("<br /><br />"); contactSB.AppendLine(); } return(contactSB.ToString()); } catch (XdbExecutionException ex) { //oh f**k return(ex.Message + ex.StackTrace); } } }
public PersonalInformation RetrieveExistingContactFacetData(XConnectClient client, Contact existingContact) { PersonalInformation existingContactFacet = null; try { if (existingContact != null) { existingContactFacet = existingContact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); } else { Console.WriteLine($"Identifier {CollectionConst.XConnect.ContactIdentifiers.ExampleData.MyrtleIdentifier} not found"); } } catch (Exception) { // Deal with exception } return(existingContactFacet); }
/// <summary> /// Use for Batch Updates of Settings within an Area /// </summary> /// <param name="area"></param> /// <param name="areaSettings"></param> public void UpdateArea(string area, Dictionary <string, string> areaSettings) { if (Tracker.Current == null) { Tracker.StartTracking(); } try { using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { var contact = EnsureContact(client); if (contact != null) { var userSettings = contact.GetFacet <Foundation.Facets.UserSettings>(); if (userSettings == null) { userSettings = new Facets.UserSettings(); } if (userSettings.Settings.ContainsKey(area)) { userSettings.Settings.Remove(area); } userSettings.Settings.Add(area, areaSettings); client.SetFacet(contact, FacetNames.UserSettings, userSettings); client.Submit(); } } } catch (XdbExecutionException ex) { // Manage conflicts / exceptions Sitecore.Diagnostics.Log.Error("Error SAving Custom UserSettings Facet", ex, this); } }
private XConnectClient BuildClient() { string XconnectUrl = ConfigurationManager.ConnectionStrings["xconnect.collection"].ConnectionString; string XconnectThumbprint = ConfigurationManager.ConnectionStrings["xconnect.collection.certificate"].ConnectionString; XConnectClientConfiguration cfg; if (string.IsNullOrEmpty(XconnectThumbprint)) { cfg = new XConnectClientConfiguration( new XdbRuntimeModel(FaceApiModel.Model), new Uri(XconnectUrl), new Uri(XconnectUrl)); } else { CertificateWebRequestHandlerModifierOptions options = CertificateWebRequestHandlerModifierOptions.Parse(XconnectThumbprint); var certificateModifier = new CertificateWebRequestHandlerModifier(options); // Step 2 - Client Configuration var collectionClient = new CollectionWebApiClient(new Uri(XconnectUrl + "/odata"), null, new[] { certificateModifier }); var searchClient = new SearchWebApiClient(new Uri(XconnectUrl + "/odata"), null, new[] { certificateModifier }); var configurationClient = new ConfigurationWebApiClient(new Uri(XconnectUrl + "/configuration"), null, new[] { certificateModifier }); cfg = new XConnectClientConfiguration( new XdbRuntimeModel(FaceApiModel.Model), collectionClient, searchClient, configurationClient); } cfg.Initialize(); var client = new XConnectClient(cfg); return(client); }
public ActionResult Create(ContactModel contactInfo) { if (!ModelState.IsValid) { return(View(contactInfo)); } XConnect xconnect = new XConnect(); XConnectClient client = xconnect.GetClient(); if (client == null) { ViewBag.message = "Something went wrong while connecting with xConnect, please retry!.."; return(View(contactInfo)); } xDBContact contact = new xDBContact(); contact.AddContact(client, contactInfo); contact.AddInteraction(client, contactInfo); ViewBag.message = contact.GetContact(client, contactInfo) ? "Contact added successfully!" : "Something went wrong while creating contact in xDB"; return(View(contactInfo)); }
private static void UpdateAvatarFacet(XConnectClient client, Contact contact) { var facet = contact.GetFacet <Avatar>(Avatar.DefaultFacetKey); Image image = Image.FromFile(_fakeContact.AvatarImage); if (image == null) { return; } if (facet != null) { facet.MimeType = GetImageMimeType(image); facet.Picture = GetAvatarImage(image); client.SetFacet(contact, Avatar.DefaultFacetKey, facet); } else { Avatar addresses = new Avatar(GetImageMimeType(image), GetAvatarImage(image)); client.SetFacet(contact, Avatar.DefaultFacetKey, addresses); } }
private async Task <Contact> RetrieveContactAsync(XConnectClient client, string MarketingIdentifier) { Contact toReturn = null; try { var identifierContactReference = new IdentifiedContactReference(MarketingConst.XConnect.ContactIdentifiers.Sources.Marketing, MarketingIdentifier); var expandOptions = new ContactExpandOptions( AddressList.DefaultFacetKey, EmailAddressList.DefaultFacetKey, CinemaBusinessMarketing.DefaultFacetKey, PersonalInformation.DefaultFacetKey ); toReturn = await client.GetAsync(identifierContactReference, expandOptions); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(toReturn); }
private bool SetEmail(ContactFacetData data, XConnect.Contact contact, XConnectClient client) { var email = data.EmailAddress; var emailKey = data.EmailKey; if (string.IsNullOrEmpty(email)) { return(false); } if (contact.Emails() != null) { contact.Emails().PreferredEmail = new EmailAddress(email, true); contact.Emails().PreferredKey = emailKey; client.SetFacet(contact, EmailAddressList.DefaultFacetKey, contact.Emails()); } else { client.SetFacet(contact, EmailAddressList.DefaultFacetKey, new EmailAddressList(new EmailAddress(email, true), emailKey)); } return(true); }
private bool SetPhone(ContactFacetData data, XConnect.Contact contact, XConnectClient client) { var phoneNumber = data.PhoneNumber; var phoneKey = data.PhoneKey; if (string.IsNullOrEmpty(phoneNumber)) { return(false); } if (contact.PhoneNumbers() != null) { contact.PhoneNumbers().PreferredPhoneNumber = new Sitecore.XConnect.Collection.Model.PhoneNumber(string.Empty, phoneNumber); contact.PhoneNumbers().PreferredKey = phoneKey; client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, contact.PhoneNumbers()); } else { client.SetFacet(contact, PhoneNumberList.DefaultFacetKey, new PhoneNumberList(new PhoneNumber(string.Empty, phoneNumber), phoneKey)); } return(true); }
public bool Evaluate(IRuleExecutionContext context) { var contact = RuleExecutionContextExtensions.Fact <Contact>(context); XConnectClient client = XConnectClientReference.GetClient(); Contact existingContact = client.Get <Contact>(contact, new ContactExpandOptions(PersonalInformation.DefaultFacetKey)); PersonalInformation personFacet = existingContact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (string.IsNullOrEmpty(personFacet?.Gender)) { return(false); } bool result = personFacet.Gender.Equals(this.Gender, StringComparison.OrdinalIgnoreCase); Log.Information("GenderMatches personFacet.Gender == " + personFacet.Gender); Log.Information("GenderMatches result == " + result); return(result); }
public bool IsGoalTriggered(ID goalId, decimal hours) { Assert.IsNotNull(Tracker.Current, "Tracker.Current"); Assert.IsNotNull(Tracker.Current.Session, "Tracker.Current.Session"); Assert.IsNotNull(goalId, "goalId"); Assert.IsNotNull(hours, "hours"); using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var time = Decimal.ToDouble(hours); var allInteractionsExpandOptions = new ContactExpandOptions() { Interactions = new RelatedInteractionsExpandOptions() { Limit = int.MaxValue } }; var reference = new IdentifiedContactReference("xDB.Tracker", Tracker.Current.Session.Contact.ContactId.ToString("N")); var actualContact = client.Get(reference, allInteractionsExpandOptions); var interactions = actualContact.Interactions; var goals = interactions.Select(x => x.Events.OfType <Goal>()).SelectMany(x => x).OrderByDescending(x => x.Timestamp); var desiredGoal = goals.FirstOrDefault(x => TypeExtensions.ToID(x.DefinitionId) == goalId); return(desiredGoal?.Timestamp.AddHours(time) >= DateTime.UtcNow); } catch (XdbExecutionException ex) { Log.Error(ex.Message, ex, this); } } return(false); }
private async System.Threading.Tasks.Task CreateOneContactAsync(XConnectClient client, CandidateMockContactInfo candidateContactInfo) { try { var identifierId = "MockContact." + Guid.NewGuid(); ContactIdentifier identifier = new ContactIdentifier(CollectionConst.XConnect.ContactIdentifiers.Sources.SitecoreCinema, identifierId, ContactIdentifierType.Known); Contact contact = new Contact(new ContactIdentifier[] { identifier }); client.AddContact(contact); PersonalInformation personalInfo = new PersonalInformation() { FirstName = candidateContactInfo.FirstName, LastName = candidateContactInfo.LastName, Birthdate = DateTime.Now, Gender = candidateContactInfo.Gender, }; client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo); var emailAddress = new EmailAddress(candidateContactInfo.EmailAddress, true); var address = new EmailAddressList(emailAddress, CollectionConst.XConnect.EmailPreferredKey); client.SetFacet(contact, EmailAddressList.DefaultFacetKey, address); Interaction interaction = new Interaction(contact, InteractionInitiator.Brand, CollectionConst.XConnect.Channels.RegisterInteractionCode, string.Empty); interaction.Events.Add(new Goal(CollectionConst.XConnect.Goals.RegistrationGoal, DateTime.UtcNow)); client.AddInteraction(interaction); await client.SubmitAsync(); } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } }
public IWeKnowTree GetWeKnowTreeFromTrackingContact(Sitecore.Analytics.Tracking.Contact trackingContact) { Sitecore.Diagnostics.Log.Debug(ProjConstants.Logger.Prefix + "s) GetWhatWeKnowTree"); IWeKnowTree toReturn = new Concretions.WhatWeKnowTree("What We Know", Options); using (XConnectClient xConnectClient = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { IdentifiedContactReference IdentifiedContactReference = xConnectHelper.GetIdentifierFromTrackingContact(trackingContact); Contact XConnectContact = xConnectHelper.IdentifyKnownContact(IdentifiedContactReference); var tier1Nodes = new Tier1Nodes(trackingContact, Options); toReturn.Root.AddNodes(tier1Nodes.Tier1NodeBuilder(trackingContact, xConnectClient, XConnectContact)); } catch (XdbExecutionException ex) { Sitecore.Diagnostics.Log.Error(ProjConstants.Logger.Prefix + ex.Message, this); } } Sitecore.Diagnostics.Log.Debug(ProjConstants.Logger.Prefix + "e) GetWhatWeKnowTree"); return(toReturn); }
private static async Task RunDemo(XConnectClient client) { var contactCountSolr = await client.Contacts.Where(x => x.Identifiers.Any(i => i.Source == "datagenerationapp")).Count(); int contactNumber = 6; await AddContacts(client, contactNumber); #region Reading all Contacts Console.WriteLine("Total contacts in the system: " + await client.Contacts.Count()); Console.WriteLine("Contacts returned by search:"); var watch = Stopwatch.StartNew(); var contacts = await client.Contacts.Where(c => c.LastModified > DateTime.UtcNow.AddMonths(-1)).GetBatchEnumerator(10000); var parallelContactSearches = await contacts.CreateSplits(2); var totalContactsReturned = 0; await Task.WhenAll(parallelContactSearches.Select(search => { var contactsReturned = 0; return(search.ForEachAsync(c => { if (++contactsReturned % 10000 == 0) { Console.Write("\r" + Interlocked.Add(ref totalContactsReturned, 10000)); } })); })); watch.Stop(); Console.WriteLine(""); Console.WriteLine("Finished reading all contacts in " + watch.Elapsed); #endregion }
public void IdentifyContact(XConnectClient client, string source, string identifier, bool force = false) { if (!IsActive) { return; } if (Configuration.Factory.CreateObject("tracking/contactManager", true) is Sitecore.Analytics.Tracking.ContactManager manager) { if (force || Tracker.Current.Contact.IsNew || Tracker.Current.Contact.IdentificationLevel == ContactIdentificationLevel.Anonymous) { Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave; manager.SaveContactToCollectionDb(Tracker.Current.Contact); manager.AddIdentifier(Tracker.Current.Contact.ContactId, new Sitecore.Analytics.Model.Entities.ContactIdentifier(source, identifier, ContactIdentificationLevel.Known)); // Now that the contact is saved, you can retrieve it using the tracker identifier // NOTE: Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource is marked internal in 9.0 Initial - use "xDB.Tracker" var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, Tracker.Current.Contact.ContactId.ToString("N")); try { var contact = client.Get(trackerIdentifier, new ContactExpandOptions()); if (contact != null) { manager.RemoveFromSession(Tracker.Current.Contact.ContactId); Tracker.Current.Session.Contact = manager.LoadContact(Tracker.Current.Contact.ContactId); } } catch (XdbExecutionException) { // Manage conflicts / exceptions } } } }
public void AddInteraction(XConnectClient client, ContactModel contactModel) { var contactReference = new IdentifiedContactReference("twitter", contactModel.FirstName + contactModel.LastName); var contact = client.Get(contactReference, new ExpandOptions() { FacetKeys = { "Personal" } }); if (contact != null) { // Item ID of the "Enter Store" Offline Channel at // /sitecore/system/Marketing Control Panel/Taxonomies/Channel/Offline/Store/Enter store var enterStoreChannelId = Guid.Parse("{3FC61BB8-0D9F-48C7-9BBD-D739DCBBE032}"); var userAgent = "xConnect MVC app"; var interaction = new Interaction(contact, InteractionInitiator.Contact, enterStoreChannelId, userAgent); var productPurchaseOutcomeId = Guid.Parse("{9016E456-95CB-42E9-AD58-997D6D77AE83}"); var outcome = new Outcome(productPurchaseOutcomeId, DateTime.UtcNow, "USD", 42.90m); interaction.Events.Add(outcome); client.AddInteraction(interaction); client.Submit(); } }
public void AddContact(XConnectClient client, ContactModel contactModel) { var identifiers = new ContactIdentifier[] { new ContactIdentifier("twitter", contactModel.FirstName + contactModel.LastName, ContactIdentifierType.Known) }; var contact = new Contact(identifiers); var personalInfoFacet = new PersonalInformation { FirstName = contactModel.FirstName, LastName = contactModel.LastName }; client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet); var emailFacet = new EmailAddressList(new EmailAddress(contactModel.Email, true), "twitter"); client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet); client.AddContact(contact); client.Submit(); }
private async Task CreateOneContactAsync(XConnectClient client, CandidateMockContactInfo candidate) { try { var operationsHelper = new OperationsDataHelper(candidate); var contact = operationsHelper.CreateContact(); client.AddContact(contact); client.SetFacet(contact, PersonalInformation.DefaultFacetKey, operationsHelper.MakeFacetPersonalInformation()); client.SetFacet(contact, EmailAddressList.DefaultFacetKey, operationsHelper.MakeFacetEmailAddressList()); client.SetFacet(contact, AddressList.DefaultFacetKey, operationsHelper.MakeFacetAddress()); client.SetFacet(contact, CinemaBusinessMarketing.DefaultFacetKey, operationsHelper.MakeFacetMarketing()); client.AddInteraction(operationsHelper.SetRegistrationGoalInteraction(contact)); DrawCandidateDataToConsole(candidate); await client.SubmitAsync(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void ValidateReadWrite() { try { using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient()) { if (Tracker.Current.Contact.IsNew) { var manager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as Sitecore.Analytics.Tracking.ContactManager; Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave; manager.SaveContactToCollectionDb(Tracker.Current.Contact); manager.RemoveFromSession(Tracker.Current.Contact.ContactId); Tracker.Current.Session.Contact = manager.LoadContact(Tracker.Current.Contact.ContactId); } else { var id = Tracker.Current.Contact.Identifiers.FirstOrDefault(); client.Get <Contact>(new IdentifiedContactReference(id.Source, id.Identifier), new ContactExpandOptions()); } Messages.Add("Status: OK"); Error = false; } } catch (XdbCollectionUnavailableException ex) { Messages.Add($"NOT AVAILABLE: {ex.Message}"); Error = true; } catch (Exception ex) { Messages.Add($"FAILED: {ex.Message}"); Error = true; } }
/// <summary> /// Add Contact /// </summary> /// <param name="identifier">Email</param> /// <param name="firstName"></param> /// <param name="lastName"></param> public void AddContact(string identifier, string firstName, string lastName) { using (XConnectClient client = GetClient()) { var identifiers = new ContactIdentifier[] { new ContactIdentifier(Constans.xConnectApiSource, identifier, ContactIdentifierType.Known) }; var contact = new Contact(identifiers); var personalInfoFacet = new PersonalInformation { FirstName = firstName, LastName = lastName }; client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet); var emailFacet = new EmailAddressList(new EmailAddress(identifier, true), Constans.xConnectApiSource); client.SetFacet <EmailAddressList>(contact, EmailAddressList.DefaultFacetKey, emailFacet); client.AddContact(contact); client.Submit(); } }
/// <summary> /// Given an existing identifier, find and delete the Contact /// </summary> /// <param name="cfg">The configuration to use to load the Contact</param> /// <param name="twitterId">The identifier for the contact</param> public virtual async Task <Contact> DeleteContact(XConnectClientConfiguration cfg, string twitterId) { Logger.WriteLine("Deleting Contact with Identifier:" + twitterId); //Get the existing contact that we want to delete var contactLoader = new GetContactTutorial() { Logger = this.Logger }; var existingContact = await contactLoader.GetContact(cfg, twitterId); if (existingContact != null) { using (var client = new XConnectClient(cfg)) { try { //Add the delete operation onto the client for the specified contact and execute client.DeleteContact(existingContact); await client.SubmitAsync(); Logger.WriteLine(">> Contact successfully deleted."); } catch (XdbExecutionException ex) { Logger.WriteError("Exception deleting the Contact", ex); } } } else { Logger.WriteLine("WARNING: No Contact found with Identifier:" + twitterId + ". Cannot delete Contact."); } return(existingContact); }
public async Task <IReadOnlyDictionary <string, Facet> > GetContactFacets(Guid contactId) { using (XConnectClient client = GetClient()) { try { var availableFacetDefinitions = client.Model.Facets.Where(f => f.Target == EntityType.Contact); List <string> availableKeys = new List <string>(); foreach (var defenition in availableFacetDefinitions) { availableKeys.Add(defenition.Name); } ContactReference reference = new ContactReference(contactId); var contactTask = client.GetAsync <Contact>( reference, new ContactExpandOptions(availableKeys.ToArray()) ); var contact = await contactTask; if (contact == null) { return(null); } return(contact.Facets); } catch (XdbExecutionException ex) { } } return(null); }
private static void GetValidContactsFromXdb(XConnectClient client) { HttpServiceHelper obj = new HttpServiceHelper(); var listOfEmails = OutlookUtility.ReadEmailsFromInbox(); var emailList = JsonConvert.DeserializeObject <List <OutlookEmailModel> >(listOfEmails); if (emailList == null) { return; } bool isvalidUser = false; foreach (var outlookEmailModel in emailList) { isvalidUser = SearchContacts(client, outlookEmailModel.EmailFrom); if (isvalidUser) { string LUISAppUrl = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatLUISAppUrl]; string oleAppId = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatOleAppId]; string oleAppkey = ConfigurationManager.AppSettings[Constants.CognitiveServiceOleChatOleAppkey]; string apiToTrigger = ConfigurationManager.AppSettings[Constants.APIToTriggerGoals]; var query = String.Concat(LUISAppUrl, oleAppId, "", oleAppkey, "" + outlookEmailModel.EmailBody); var data = obj.GetServiceResponse <LuisResult>(query, false); if (data != null) { outlookEmailModel.Intent = data.TopScoringIntent.Intent.ToLower(); // Call sitecore api controller to trigger call; obj.HttpGet(apiToTrigger); } } } }