Ejemplo n.º 1
0
        public async Task <Contact> RetrieveExistingContactAsync(XConnectClient client)
        {
            Contact existingContact = null;

            try
            {
                IdentifiedContactReference reference = new IdentifiedContactReference(CollectionConst.XConnect.ContactIdentifiers.Sources.Twitter, CollectionConst.XConnect.ContactIdentifiers.ExampleData.MyrtleIdentifier);

                var interactions = new RelatedInteractionsExpandOptions(IpInfo.DefaultFacetKey)
                {
                    StartDateTime = DateTime.MinValue,
                    EndDateTime   = DateTime.MaxValue
                };

                var targetedFacets = new string[]
                {
                    PersonalInformation.DefaultFacetKey
                };

                var contactExpandOptions = new ContactExpandOptions(targetedFacets)
                {
                    Interactions = interactions
                };

                existingContact = await client.GetAsync <Contact>(reference, contactExpandOptions);
            }
            catch (Exception ex)
            {
                throw;
            }

            return(existingContact);
        }
        public async Task <Contact> GetXConnectContactByIdentifierAsync(string source, string identifier)
        {
            Contact toReturn = null;

            if (!string.IsNullOrEmpty(identifier))
            {
                var IdentifiedContactReference = new IdentifiedContactReference(source, identifier);
                if (Client != null)
                {
                    try
                    {
                        var interactions = new RelatedInteractionsExpandOptions(IpInfo.DefaultFacetKey)
                        {
                            StartDateTime = DateTime.MinValue,
                            EndDateTime   = DateTime.MaxValue
                        };

                        var expandOptions = CollectionConst.ContactExandOptions.AllContactExpandOptions;
                        expandOptions.Interactions = interactions;

                        toReturn = await Client.GetAsync(IdentifiedContactReference, expandOptions);
                    }
                    catch (Exception ex)
                    {
                        Errors.Add(ex.Message);
                    }
                }
                else
                {
                    Errors.Add("client was null");
                }
            }
            else
            {
                Errors.Add("Identifier was null");
            }

            if (Errors.Any())
            {
                toReturn = null;
            }
            return(toReturn);
        }
Ejemplo n.º 3
0
        public FileContentResult ExportProfile(string startDate, string endDate)
        {
            try
            {
                List <ExperienceProfileDetail> export = new List <ExperienceProfileDetail>();
                string[] paramiters      = { WebVisit.DefaultFacetKey, LocaleInfo.DefaultFacetKey, IpInfo.DefaultFacetKey };
                var      interactionsobj = new RelatedInteractionsExpandOptions(paramiters);
                DateTime sdate           = DateTime.Now;
                DateTime edate           = DateTime.Now;

                if (!string.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out sdate))
                {
                    interactionsobj.StartDateTime = sdate.AddDays(1).ToUniversalTime();
                }
                else
                {
                    interactionsobj.StartDateTime = DateTime.UtcNow.AddDays(-30);
                }
                if (!string.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out edate))
                {
                    interactionsobj.EndDateTime = edate.AddDays(1).ToUniversalTime();
                }
                else
                {
                    interactionsobj.EndDateTime = DateTime.UtcNow;
                }
                interactionsobj.Limit = int.MaxValue;
                ExportDataResult exportResult;
                using (Sitecore.XConnect.Client.XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
                {
                    List <Contact> contactList      = new List <Contact>();
                    bool           includeAnonymous = false;
                    var            settingvalue     = Sitecore.Configuration.Settings.GetSetting("IncludeAnonymous");
                    bool.TryParse(settingvalue, out includeAnonymous);
                    var Contactsid = client.Contacts.Where(d => d.Interactions.Any(i => i.StartDateTime >= interactionsobj.StartDateTime && i.EndDateTime <= interactionsobj.EndDateTime)).AsAsyncQueryable();
                    if (!includeAnonymous)
                    {
                        Contactsid = Contactsid.Where(c => c.Identifiers.Any(t => t.IdentifierType == Sitecore.XConnect.ContactIdentifierType.Known));
                    }

                    contactList = Contactsid.ToList().Result;
                    var references = new List <IEntityReference <Sitecore.XConnect.Contact> >();
                    references.AddRange(contactList);
                    var contacts = client.Get <Contact>(references, new Sitecore.XConnect.ContactExpandOptions(PersonalInformation.DefaultFacetKey)
                    {
                        Interactions = interactionsobj
                    }.Expand <EmailAddressList>().Expand <AddressList>().Expand <PhoneNumberList>());
                    exportResult = new ExportDataResult()
                    {
                        Content   = GenerateFileContent(contacts),
                        FileName  = GenerateFileName(interactionsobj.StartDateTime.Value, interactionsobj.EndDateTime.Value),
                        MediaType = "application/octet-stream"
                    };
                }

                FileContentResult fileresult;
                if (exportResult != null)
                {
                    fileresult = new FileContentResult(exportResult.Content, exportResult.MediaType);
                    fileresult.FileDownloadName = exportResult.FileName;
                }
                else
                {
                    fileresult = new FileContentResult(null, "application/octet-stream")
                    {
                        FileDownloadName = "NoData.csv"
                    };
                }
                return(fileresult);
            }
            catch (Exception ex)
            {
                Log.Error("ERROR IN EXPORT PROFILE GETDATA:", ex.Message);
                return(new FileContentResult(null, "application/octet-stream")
                {
                    FileDownloadName = "NoData.csv"
                });
            }
        }