Beispiel #1
0
        public string SerializeObject(Object xconnectObject)
        {
            var toReturn = string.Empty;

            if (XConnectClient != null)
            {
                var ContractResolver = new XdbJsonContractResolver(XConnectClient.Model, true, true);

                var serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver     = ContractResolver,
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                    Formatting           = Formatting.Indented,
                };

                var serialized = string.Empty;

                try
                {
                    serialized = JsonConvert.SerializeObject(xconnectObject, serializerSettings);
                    toReturn   = serialized;
                }
                catch (System.Exception ex)
                {
                    toReturn = "{couldn't serialize}";
                    Sitecore.Diagnostics.Log.Error("Couldn't serialize", ex, this);
                }
            }

            return(toReturn);
        }
Beispiel #2
0
        public IWeKnowTreeNode TrackingContactNode(Sitecore.Analytics.Tracking.Contact trackingContact, XConnectClient xConnectClient)
        {
            WeKnowTreeNode toReturn = null;

            if (trackingContact != null && TreeOptions.IncludeTrackingContact)
            {
                toReturn = new WeKnowTreeNode("Tracking Contact", TreeOptions);

                toReturn.AddNode(new WeKnowTreeNode("Is New", trackingContact.IsNew.ToString(), TreeOptions));
                toReturn.AddNode(new WeKnowTreeNode("Contact Id", trackingContact.ContactId.ToString(), TreeOptions));
                toReturn.AddNode(new WeKnowTreeNode("Identification Level", trackingContact.IdentificationLevel.ToString(), TreeOptions));

                var ContractResolver = new XdbJsonContractResolver(xConnectClient.Model, true, true);

                var serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver     = ContractResolver,
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                    Formatting           = Formatting.Indented
                };

                var serialized = JsonConvert.SerializeObject(trackingContact, serializerSettings);

                toReturn.AddRawNode(serialized);
            }

            return(toReturn);
        }
        //  XConnectConfigHelper configHelper = new XConnectConfigHelper();
        //  XConnectClientConfiguration cfg = await configHelper.ConfigureClient();
        //  using (var Client = new XConnectClient(cfg))
        //  {
        //    try
        //    {
        //      var xConnectClientHelper = new XConnectClientHelper(Client);
        //      var xConnectContact = await xConnectClientHelper.GetXConnectContactByIdentifierAsync(Const.XConnect.ContactIdentifiers.Sources.SitecoreCinema, Identifier);
        //      if (xConnectContact != null)
        //      {
        //        toReturn = GetKnownDataFromXConnectContact(xConnectContact);
        //      }
        //    }
        //    catch (XdbExecutionException ex)
        //    {
        //      Sitecore.Diagnostics.Log.Error(Const.Logger.CinemaPrefix + ex.Message, this);
        //    }
        //  }

        //public async Task<KnownDataXConnect> GetKnownDataByIdentifierViaXConnect(string Identifier)
        //{
        //  KnownDataXConnect toReturn = null;
        private List <InteractionProxy> GetKnownInteractions(Contact xconnectContact, XConnectClient xConnectClient)
        {
            var toReturn = new List <InteractionProxy>();

            //xConnectClient.Get<Interaction>(interactionRef,
            //    new Sitecore.XConnect.InteractionExpandOptions(AllFacetKeys));

            if (xconnectContact?.Interactions != null && xconnectContact.Interactions.Any())
            {
                var ContractResolver = new XdbJsonContractResolver(xConnectClient.Model, true, true);

                var serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver     = ContractResolver,
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                    Formatting           = Formatting.Indented
                };

                foreach (var interaction in xconnectContact.Interactions)
                {
                    toReturn.Add(new InteractionProxy()
                    {
                        ChannelId   = interaction.ChannelId,
                        ChannelName = GetDisplayName(interaction.ChannelId),

                        RawInteraction   = interaction,
                        Events           = interaction.Events,
                        EventsB          = GetEvents(interaction.Events),
                        DeviceProfile    = interaction.DeviceProfile,
                        StartDateTime    = interaction.StartDateTime,
                        EndDateTime      = interaction.EndDateTime,
                        InitiatorStr     = interaction.Initiator.ToString(),
                        Id               = interaction.Id,
                        Duration         = interaction.Duration,
                        CampaignId       = interaction.CampaignId,
                        SerializedAsJson = JsonConvert.SerializeObject(interaction, serializerSettings)
                    });
                }
            }

            return(toReturn);
        }