コード例 #1
0
        private ProfileScores GetProfileScores(IContactProcessingContext context)
        {
            //ContactBehaviorProfile contactFacet = this.GetContactFacet<ContactBehaviorProfile>(context.Contact);

            XConnectClient client = XConnectClientReference.GetClient();

            Contact existingContact = client.Get <Contact>(
                (IEntityReference <Contact>)context.Contact,
                new ContactExpandOptions(ContactBehaviorProfile.DefaultFacetKey));

            ContactBehaviorProfile contactFacet = existingContact.GetFacet <ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey);

            if (contactFacet == null)
            {
                contactFacet = new ContactBehaviorProfile();
            }

            ChangeContactBehaviorProfileValue.UpdateContactBehaviorProfile(contactFacet.Scores, (IEnumerable <BehaviorProfileValue>) this.BehaviorProfileValues);
            ProfileScores profileScores = new ProfileScores();

            foreach (KeyValuePair <Guid, ProfileScore> keyValuePair in contactFacet.Scores)
            {
                profileScores.Scores.Add(keyValuePair.Key, keyValuePair.Value);
            }

            foreach (var profileScore in profileScores.Scores)
            {
                Log.Debug("profileScore kv Key = " + profileScore.Key);
                Log.Debug("profileScore kv Value = " + profileScore.Value);
            }

            return(profileScores);
        }
コード例 #2
0
        private void ApplyPatternCard(Contact contact, TwitterStatus tweet, PatternCard patternCard)
        {
            using (var client = XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // Get updated contact with ContactBehaviorProfile facet
                    var updatedContact = client.Get(new IdentifiedContactReference("twitter", tweet.User.ScreenName),
                                                    new ContactExpandOptions(ContactBehaviorProfile.DefaultFacetKey));
                    if (updatedContact == null)
                    {
                        return;
                    }

                    // Retrieve facet or create new
                    var isNewFacet = false;
                    var facet      =
                        updatedContact.GetFacet <ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey);
                    if (facet == null)
                    {
                        isNewFacet = true;
                        facet      = new ContactBehaviorProfile();
                    }

                    // Change facet properties
                    var score = new ProfileScore {
                        ProfileDefinitionId = patternCard.GetProfile().ID.ToGuid()
                    };
                    if (score.Values == null)
                    {
                        score.Values = new Dictionary <Guid, double>();
                    }
                    var patterns = patternCard.GetPatterns();
                    foreach (var pair in patterns)
                    {
                        score.Values.Add(pair.Key, pair.Value);
                    }

                    if (facet.Scores.ContainsKey(patternCard.GetProfile().ID.Guid))
                    {
                        facet.Scores[patternCard.GetProfile().ID.Guid] = score;
                    }
                    else
                    {
                        facet.Scores.Add(patternCard.GetProfile().ID.Guid, score);
                    }

                    // Save the facet
                    if (isNewFacet)
                    {
                        client.SetFacet <ContactBehaviorProfile>(updatedContact, ContactBehaviorProfile.DefaultFacetKey, facet);
                    }
                    else
                    {
                        client.SetFacet(updatedContact, ContactBehaviorProfile.DefaultFacetKey, facet);
                    }

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                    Diagnostics.Log.Error(
                        $"[HashTagMonitor] Error applying Patter Card to Contact '{contact.Personal().Nickname}'",
                        ex, GetType());
                }
            }
        }
コード例 #3
0
ファイル: Xservice.cs プロジェクト: mzeen/Sym17.Demo
        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);
        }