Пример #1
0
        public void UpdateAirQualityForContactsBatch(int size)
        {
            using (var client = SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var goalId = Guid.Parse(RegisterGoalId);
                    IAsyncQueryable <Contact> queryable = client.Contacts
                                                          .Where(c => c.Interactions.Any(f => f.Events.OfType <Goal>().Any(a => a.DefinitionId == goalId)))
                                                          .WithExpandOptions(new ContactExpandOptions()
                    {
                        Interactions = new RelatedInteractionsExpandOptions()
                        {
                            Limit = 10
                        }
                    });

                    var enumerable = queryable.GetBatchEnumeratorSync(size);
                    while (enumerable.MoveNext())
                    {
                        foreach (var contact in enumerable.Current)
                        {
                            UpdateAirQualityForContact(contact);
                        }
                    }
                }
                catch (XdbExecutionException ex)
                {
                    Log.Error($"Error updating air quality in batch", ex, this);
                }
            }
        }
        public static int GetPageViewsCount(string itemId)
        {
            int counter = 0;

            using (var client = XConnectHelper.GetClient())
            {
                try
                {
                    IAsyncQueryable <Sitecore.XConnect.Contact> queryable = client.Contacts
                                                                            .Where(c => c.Interactions.Any(f => f.Events.OfType <PageViewEvent>().Any()))
                                                                            .WithExpandOptions(new Sitecore.XConnect.ContactExpandOptions()
                    {
                        Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions()
                        {
                            Limit = 2000      // Returns top 20 of all contact's interactions - interactions not affected by query
                        }
                    });

                    var enumerable = queryable.GetBatchEnumeratorSync(10);
                    var urlList    = new List <string>();
                    while (enumerable.MoveNext())
                    {
                        foreach (var contact in enumerable.Current)
                        {
                            InteractionReference interactionReference = new InteractionReference((Guid)contact.Id, (Guid)contact.Interactions.ElementAt(0).Id);

                            Interaction interaction = client.Get <Interaction>(interactionReference, new InteractionExpandOptions(new string[] { IpInfo.DefaultFacetKey })
                            {
                                Contact = new RelatedContactExpandOptions(new string[] { PersonalInformation.DefaultFacetKey })
                            });
                            var pageViews = interaction.Events.OfType <PageViewEvent>().OrderBy(ev => ev.Timestamp).ToList();
                            foreach (var page in pageViews)
                            {
                                // item id is in page
                                if (page.ItemId.Equals(Guid.Parse(itemId)))
                                {
                                    counter++;
                                }
                                urlList.Add(page.Url);
                            }

                            Console.WriteLine("Page Url: " + pageViews.FirstOrDefault().Url);
                        }
                    }

                    //var count = urlList.GroupBy(x => x).Select(y => new { } x.Count());

                    var count = urlList.GroupBy(n => n).Select(c => new { Key = c.Key, total = c.Count() });
                    return(counter);
                }
                catch (XdbExecutionException ex)
                {
                }
                return(counter);
            }
        }
        void ListBind()
        {
            List <ListViewModel> list = new List <ListViewModel>();

            DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0);
            DateTime endDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var goalGuid = Guid.Parse("C22B6C5B-3065-46B4-8E10-A559AED540D2");

                    IAsyncQueryable <Sitecore.XConnect.Contact> queryable = client.Contacts
                                                                            .Where(c => c.Interactions.Any(f => f.Events.OfType <Goal>().Any(a => a.DefinitionId == goalGuid)))
                                                                            .Where(c => c.Interactions.Any(x => x.StartDateTime >= startDate.ToUniversalTime() && x.StartDateTime <= endDate.ToUniversalTime()))
                                                                            .WithExpandOptions(new Sitecore.XConnect.ContactExpandOptions()
                    {
                        Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions()
                        {
                            Limit = 100     // Returns top 100 of all contact's interactions - interactions not affected by query
                        }
                    });

                    var enumerable = queryable.GetBatchEnumeratorSync(100);

                    while (enumerable.MoveNext())
                    {
                        foreach (var contact in enumerable.Current)
                        {
                            Sitecore.XConnect.Collection.Model.EmailAddressList obj = contact.Emails();
                            list.Add(new ListViewModel
                            {
                                id        = contact.Id.Value.ToString(),
                                FirstName = contact.Personal().FirstName,
                                LastName  = contact.Personal().LastName,
                                Email     = obj.PreferredEmail.SmtpAddress.ToString()
                            });


                            // Do something with contacts
                        }
                    }
                }
                catch (XdbExecutionException ex)
                {
                    // Handle exception
                }
            }

            ListView1.DataSource = list;
            ListView1.DataBind();
        }
Пример #4
0
        /// <summary>
        /// Gets a list of the worst commenters.
        /// </summary>
        /// <returns>A list of commenters sorted by percentage of warnings received over total comments.</returns>
        public Dictionary <string, CommentsAndWarnings> GetWorstCommenters()
        {
            //var contacts = new List<ScoredContact>();
            var contacts = new Dictionary <string, CommentsAndWarnings>();

            using (XConnectClient client =
                       Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    IAsyncQueryable <Interaction> queryable = client.Interactions
                                                              .Where(x => x.Events.OfType <Event>().Any());

                    var enumerable = queryable.GetBatchEnumeratorSync(20);

                    while (enumerable.MoveNext())
                    {
                        var interactionBatch = enumerable.Current;

                        foreach (var interaction in interactionBatch)
                        {
                            // if event is a search event and if it begins with our magic string, f*****g parse that shit
                            var searchEvents = interaction.Events.OfType <SearchEvent>();
                            foreach (var searchEvent in searchEvents)
                            {
                                // sorry
                                if (searchEvent.Data.StartsWith(Comments.CommentPrefix))
                                {
                                    // Congratulations! It's a comment!
                                    string s1                 = searchEvent.Data.Substring(Comments.CommentPrefix.Length);
                                    int    index              = s1.IndexOf(Comments.WarningPrefix);
                                    string comment            = s1.Substring(0, index); //we don't need this in v1
                                    string warningCountString = s1.Substring(index + Comments.WarningPrefix.Length);
                                    int    warningCount       = 0;
                                    Int32.TryParse(warningCountString, out warningCount);

                                    IEntityReference <Contact> reference = interaction.Contact;

                                    Contact contact    = client.Get(reference, new ExpandOptions());
                                    string  identifier = GetIdentifier(contact);
                                    SaveInformation(contacts, identifier, warningCount);


                                    // not sorry
                                }
                            }
                        }
                    }


                    return(contacts);
                }


                catch (Exception ex)
                {
                    // Awww jeez, this is bad
                    Sitecore.Diagnostics.Log.Error("Tried to create the list of worst commenters, but we failed :(",
                                                   ex, this);

                    return(null);
                }
            }
        }
Пример #5
0
        public void GetAllEvents()
        {
            using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                //var eventGuid = Guid.Parse("c91ce6eb-c346-447e-b65d-1f0f90b520e5"); // Replace with the ID of a real event definition item

                //var e = interaction.Events.OfType<Event>().Where(x => x.DefinitionId == eventGuid);

                try
                {
                    IAsyncQueryable <Sitecore.XConnect.Interaction> queryable = client.Interactions;

                    var enumerable = queryable.GetBatchEnumeratorSync(20);

                    while (enumerable.MoveNext())
                    {
                        var interactionBatch = enumerable.Current; // Batch of <= 20 interactions

                        foreach (var interaction in interactionBatch)
                        {
                            var all = interaction.Events;

                            var matchingGoals = interaction.Events.OfType <Goal>();
                        }
                    }
                }
                catch (XdbExecutionException ex)
                {
                    // Handle exception
                }

                try
                {
                    IAsyncQueryable <Sitecore.XConnect.Contact> queryable = client.Contacts;

                    var enumerable = queryable.GetBatchEnumeratorSync(20);

                    while (enumerable.MoveNext())
                    {
                        var contacts = enumerable.Current; // Batch of <= 20 interactions

                        foreach (var contact in contacts)
                        {
                        }
                    }
                }
                catch (XdbExecutionException ex)
                {
                    // Handle exception
                }
            }



            using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                //var interactions = client.Interactions.Take(50).ToSearchResults().Result;

                //var contacts = client.Contacts.Take(50).ToSearchResults().Result;


                //var queryable = client.Interactions.Where(c => c.Interactions.Any(x => x.StartDateTime > DateTime.UtcNow.AddDays(-30))).WithExpandOptions(new ContactExpandOptions("Personal"));

                //var results = queryable.ToSearchResults();
                //var contacts = results.Select(x => x.Item).ToList();
                //foreach (var contact in contacts)
                //{
                //    Console.WriteLine($&quot;
                //    { contact.Personal().FirstName}
                //    { contact.Personal().LastName}
                //    &quot;);
                //}
            }
        }