Пример #1
0
        private void UpdateContact(object sender, ActiveVisitorChangedEventArgs e)
        {
            ImageProcessingContact c = e.ImageProcessingContact;

            ActiveVisitorHub.Change(c);

            Xservice xservice = new Xservice();

            var contact = xservice.GetContact(Settings.FaceApiIdentificationSource, c.Id);

            if (contact == null)
            {
                xservice.AddContact(Settings.FaceApiIdentificationSource, c.Id, c);

                var faceApiFacet = new FaceApiFacet
                {
                    NeutralValue   = c.Neutral,
                    HappinessValue = c.Happiness,
                    SmileValue     = c.Smile,
                    AngerValue     = c.Anger,
                    SurpriseValue  = c.Surprise,
                    SadnessValue   = c.Sadness,
                    FearValue      = c.Fear,
                    DisgustValue   = c.Disgust,
                    ContemptValue  = c.Contempt
                };

                xservice.RegisterOfflineInteraction(Settings.FaceApiIdentificationSource, c.Id, faceApiFacet);
            }
        }
Пример #2
0
        public void RegisterOfflineInteraction(string source, string identifier, FaceApiFacet face)
        {
            using (XConnectClient client = GetClient())
            {
                try
                {
                    IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier);

                    Contact existingContact = client.Get <Contact>(
                        reference,
                        new ContactExpandOptions(PersonalInformation.DefaultFacetKey));

                    if (existingContact == null)
                    {
                        return;
                    }

                    Interaction interaction = new Interaction(existingContact, InteractionInitiator.Contact, channelId: Settings.OfflineChannelId, userAgent: "video camera");

                    //Add Device profile
                    DeviceProfile newDeviceProfile = new DeviceProfile(Guid.NewGuid());
                    newDeviceProfile.LastKnownContact = existingContact;
                    client.AddDeviceProfile(newDeviceProfile);
                    interaction.DeviceProfile = newDeviceProfile;

                    //Add fake Ip info
                    IpInfo fakeIpInfo = new IpInfo("127.0.0.1");
                    fakeIpInfo.BusinessName = "Home";
                    client.SetFacet <IpInfo>(interaction, IpInfo.DefaultFacetKey, fakeIpInfo);

                    //Add fake webvisit
                    WebVisit fakeWebVisit = new WebVisit();
                    fakeWebVisit.SiteName = "Offline";
                    client.SetFacet <WebVisit>(interaction, WebVisit.DefaultFacetKey, fakeWebVisit);

                    //Adding FaceApi facet
                    client.SetFacet <FaceApiFacet>(interaction, FaceApiFacet.DefaultFacetKey, face);

                    Outcome outcome = new Outcome(Settings.OfflineGoalId, DateTime.UtcNow, "USD", 0);
                    outcome.EngagementValue = 10;
                    outcome.Text            = "Face recognized";
                    interaction.Events.Add(outcome);

                    client.AddInteraction(interaction);

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                }
            }
        }