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 (string.IsNullOrEmpty(personFacet?.Company)) { return(false); } //string[] partnersList = Partners.Split(';'); //bool result = partnersList.Any(p => p.IndexOf(personFacet.Company, StringComparison.OrdinalIgnoreCase) > 0); bool result = Partners.IndexOf(personFacet.Company, StringComparison.OrdinalIgnoreCase) > 0; Log.Information("PartnerListMatches result == " + (result).ToString()); return(result); }
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); Log.Information("AgeMatches personFacet is null == " + (personFacet == null).ToString()); if (personFacet == null || personFacet.Age == 0) { return(false); } Log.Information("AgeMatches personFacet.Age == " + personFacet.Age); bool result = NumericOperationTypeExtensions.Evaluate(this.Comparison, personFacet.Age, this.Age); Log.Information("AgeMatches result == " + result.ToString()); return(result); }
public void UpdateContact(string source, string identifier, ContactViewModel data) { using (XConnectClient client = GetClient()) { try { IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, CvPersonFacet.DefaultFacetKey) ); if (existingContact == null) { return; } PersonalInformation personalInformation = existingContact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (personalInformation == null) { personalInformation = new PersonalInformation(); } personalInformation.FirstName = data.FirstName; personalInformation.LastName = data.LastName; personalInformation.Gender = data.Gender; client.SetFacet <PersonalInformation>(existingContact, PersonalInformation.DefaultFacetKey, personalInformation); CvPersonFacet personFacet = existingContact.GetFacet <CvPersonFacet>(CvPersonFacet.DefaultFacetKey); if (personFacet == null) { personFacet = new CvPersonFacet(); } personFacet.Company = data.Company; personFacet.Age = data.Age; client.SetFacet <CvPersonFacet>(existingContact, CvPersonFacet.DefaultFacetKey, personFacet); client.Submit(); ReadOnlyCollection <IXdbOperation> operations = client.LastBatch; } catch (XdbExecutionException ex) { } } }
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 AddContact(string source, string identifier, ImageProcessingContact data) { using (XConnectClient client = GetClient()) { try { // Get a known contact IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, CvPersonFacet.DefaultFacetKey, Avatar.DefaultFacetKey)); if (existingContact != null) { return; } var contactIdentifier = new[] { new ContactIdentifier(source, identifier, ContactIdentifierType.Known) }; Contact contact = new Contact(contactIdentifier); PersonalInformation personalInformation = new PersonalInformation { FirstName = data.FirstName, LastName = data.LastName, Gender = data.Gender }; CvPersonFacet cvPersonFacet = new CvPersonFacet { Id = data.Id, Age = data.Age, Company = data.Company, FirstName = data.FirstName, LastName = data.LastName, Photo = data.Photo48, Gender = data.Gender }; if (!string.IsNullOrWhiteSpace(data.ParsedText)) { cvPersonFacet.BadgeText = data.ParsedText .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .ToList(); } Avatar avatarFacet = new Avatar(string.Empty, new byte[] { }); if (data.Photo48 != null) { avatarFacet.MimeType = "image/jpg"; avatarFacet.Picture = Convert.FromBase64String(data.Photo48); } client.SetFacet <Avatar>(contact, Avatar.DefaultFacetKey, avatarFacet); client.SetFacet <PersonalInformation>(contact, PersonalInformation.DefaultFacetKey, personalInformation); client.SetFacet <CvPersonFacet>(contact, CvPersonFacet.DefaultFacetKey, cvPersonFacet); client.AddContact(contact); client.Submit(); } catch (Sitecore.XConnect.XdbExecutionException ex) { } } }
public ContactViewModel GetContact(string source, string identifier) { ContactViewModel result = new ContactViewModel(); using (XConnectClient client = GetClient()) { try { IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, CvPersonFacet.DefaultFacetKey, Avatar.DefaultFacetKey, ContactBehaviorProfile.DefaultFacetKey)); if (existingContact == null) { return(null); } PersonalInformation personalInformation = existingContact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (personalInformation == null) { return(null); } result.FirstName = personalInformation.FirstName; result.LastName = personalInformation.LastName; result.Gender = personalInformation.Gender; result.Id = identifier; Avatar avatar = existingContact.GetFacet <Avatar>(Avatar.DefaultFacetKey); if (avatar?.Picture != null) { result.AvatarImage = Convert.ToBase64String(avatar.Picture); } CvPersonFacet cvPerson = existingContact.GetFacet <CvPersonFacet>(CvPersonFacet.DefaultFacetKey); if (cvPerson != null) { result.LastName = cvPerson.LastName; result.FirstName = cvPerson.FirstName; result.Id = cvPerson.Id; result.Age = cvPerson.Age; result.Gender = cvPerson.Gender; } ContactBehaviorProfile behaviorProfile = existingContact.ContactBehaviorProfile(); if (behaviorProfile?.Scores != null) { if (behaviorProfile.Scores.ContainsKey(Settings.RelationshipProfileId)) { ProfileScore behaviorProfileScore = behaviorProfile.Scores[Settings.RelationshipProfileId]; result.ClientScore = behaviorProfileScore.Values.ContainsKey(Settings.ClientBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.ClientBehaviorProfileId] : 0; result.PartnerScore = behaviorProfileScore.Values.ContainsKey(Settings.PartnerBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.PartnerBehaviorProfileId] : 0; result.SitecoreScore = behaviorProfileScore.Values.ContainsKey(Settings.SitecoreBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.SitecoreBehaviorProfileId] : 0; } if (behaviorProfile.Scores.ContainsKey(Settings.RoleProfileId)) { var behaviorProfileScore = behaviorProfile.Scores[Settings.RoleProfileId]; result.DevelopmentScore = behaviorProfileScore.Values.ContainsKey(Settings.DevelopmentBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.DevelopmentBehaviorProfileId] : 0; result.BusinessDevelopmentScore = behaviorProfileScore.Values.ContainsKey(Settings.BusinessDevelopmentBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.BusinessDevelopmentBehaviorProfileId] : 0; result.MarketingScore = behaviorProfileScore.Values.ContainsKey(Settings.MarketingBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.MarketingBehaviorProfileId] : 0; } } return(result); } catch (XdbExecutionException ex) { } } return(null); }