Example #1
0
        public override void Process(CommitSessionPipelineArgs args)
        {
            var facets = args.Session.Contact.GetXConnectFacets();

            if (facets == null)
            {
                Log.Warn($"**HF** UpdateFacetsFromTracker.Process(). XConnectFacets could not be loaded for contact {args.Session.Contact.ContactId.ToString()}", this);
                return;
            }

            if (identificationService == null || demographicsService == null || sportsService == null || stringValueListFacetService == null)
            {
                Log.Error($"**HF** UpdateFacetsFromTracker.Process(). skips, some services were not resolved.", this);
                return;
            }

            using (var client = SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var contact = client.GetContactIdFromDevice();
                    if (contact == null)
                    {
                        Log.Fatal("**HF** UpdateFacetsFromTracker.Process(). Cannot resolve contact id from device", this);
                        return;
                    }

                    identificationService.SetPersonalFacet(facets, client, contact);
                    identificationService.SetEmailFacet(facets, client, contact);
                    demographicsService.SetFacet(facets, client, contact);
                    sportsService.SetFacet(facets, client, contact);

                    stringValueListFacetService.SetFacet(facets, client, contact, FacetIDs.FavoriteEvents);
                    stringValueListFacetService.SetFacet(facets, client, contact, FacetIDs.RegisteredEvents);
                    stringValueListFacetService.SetFacet(facets, client, contact, FacetIDs.Subscriptions);
                    stringValueListFacetService.SetFacet(facets, client, contact, FacetIDs.SubscriptionTokens);

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                    Log.Error("UpdateFacetsFromTracker failed miserably.", ex, this);
                }
            }
        }