Exemplo n.º 1
0
        private void CreateContacts()
        {
            using (IXdbContext client = _xConnectClientFactory.GetXConnectClient())
            {
                try
                {
                    var numberOfContacts = int.Parse(tbNumberOfContacts.Text, CultureInfo.CurrentCulture);

                    var goalIds    = tbGoalIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse);
                    var eventIds   = tbEventIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse);
                    var outcomeIds = tbOutcomeIds.Text.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse);

                    var listId     = !string.IsNullOrWhiteSpace(tbListId.Text) ? Guid.Parse(tbListId.Text) : Guid.Empty;
                    var campaignId = !string.IsNullOrWhiteSpace(tbCampaignId.Text) ? Guid.Parse(tbCampaignId.Text) : Guid.Empty;

                    for (var i = 0; i < numberOfContacts; i++)
                    {
                        string email = GetEmailAddress(i);

                        var contact = new Contact(new ContactIdentifier("ListManager", email, ContactIdentifierType.Known));

                        client.AddContact(contact);

                        AddPreferredEmail(i, client, contact, email);

                        AddPhoneNumber(client, contact, tbPhoneNumber.Text);

                        AddPersonalInfo(client, contact, tbPreferredLanguage.Text);

                        AddListSubscription(listId, client, contact);

                        AddConsentInformation(client, contact);

                        AddProfileScore(client, contact);

                        AddEngagementValue(client, contact);

                        AddInteraction(client, contact, goalIds, outcomeIds, eventIds, campaignId);

                        if (i % 10 != 0)
                        {
                            continue;
                        }

                        var numberOfContactsBeingSubmitted = i / 1 > 0 ? i / 1 : 1;

                        Logger.Info($"Submitting {numberOfContactsBeingSubmitted} contacts", this);
                        client.Submit();
                    }

                    client.Submit();
                }
                catch (Exception ex)
                {
                    Logger.Error("Failed to submit contacts", ex, this);
                }
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> GenerateUsers()
        {
            using (IXdbContext xdbContext = SitecoreXConnectClientConfiguration.GetClient())
            {
                var ovais = new Contact(new ContactIdentifier("letsplay", "*****@*****.**",
                                                              ContactIdentifierType.Known));
                var sumith = new Contact(new ContactIdentifier("letsplay", "*****@*****.**",
                                                               ContactIdentifierType.Known));

                xdbContext.AddContact(ovais);
                xdbContext.AddContact(sumith);


                await xdbContext.SubmitAsync();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> GenerateData(int amountOfContacts = 10, int amountOfInteractions = 10)
        {
            using (IXdbContext xdbContext = SitecoreXConnectClientConfiguration.GetClient())
            {
                for (var c = 0; c < amountOfContacts; c++)
                {
                    var contact = new Contact(new ContactIdentifier("sitecore.demo", Guid.NewGuid().ToString(),
                                                                    ContactIdentifierType.Known));

                    var currentDate = DateTime.UtcNow;
                    xdbContext.AddContact(contact);

                    for (var i = 1; i <= amountOfInteractions; i++)
                    {
                        // Even are morning runners. 10AM for morning runner and 6PM for evening one. :
                        var startTime   = 10 + c % 2 * 8;
                        var startDate   = currentDate.Date.AddDays(-i).AddHours(startTime);
                        var endDate     = startDate.AddHours(1);
                        var interaction =
                            new Interaction(contact, InteractionInitiator.Contact, /*TODO: Channel ID*/ Guid.NewGuid(),
                                            "Some Agent")
                        {
                            Events =
                            {
                                new RunStarted(/*TODO: Definition ID*/ Guid.NewGuid(), startDate)
                                {
                                    Time = startDate
                                },
                                new RunEnded(/*TODO: Definition ID*/ Guid.NewGuid(), endDate)
                                {
                                    Time = endDate
                                }
                            }
                        };

                        xdbContext.AddInteraction(interaction);
                    }
                }

                await xdbContext.SubmitAsync();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }