Skip to content

Instantly share code, notes, and snippets.

@steviemcg
Created January 31, 2018 16:47
Show Gist options
  • Select an option

  • Save steviemcg/10c227189726532f9b66ddbd8b4f416d to your computer and use it in GitHub Desktop.

Select an option

Save steviemcg/10c227189726532f9b66ddbd8b4f416d to your computer and use it in GitHub Desktop.
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Sitecore.sitecore.admin.AdminPage" %>
<%@ Import Namespace="Sitecore.XConnect.Client.Configuration" %>
<%@ Import Namespace="Sitecore.XConnect.Client.Serialization" %>
<%@ Import Namespace="Sitecore.XConnect.Collection.Model" %>
<%@ Import Namespace="Sitecore.XConnect" %>
<%@ Import Namespace="Sitecore.XConnect.Client" %>
<%@ Import Namespace="Newtonsoft.Json" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Contact Viewer</title>
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
CheckSecurity(true);
}
protected void OnClick_LoadContact(object sender, EventArgs e)
{
tbContactDetails.Text = string.Empty;
using (var client = SitecoreXConnectClientConfiguration.GetClient())
{
try
{
ContactReference contactReference = null;
IdentifiedContactReference identifiedContactReference = null;
if (!string.IsNullOrWhiteSpace(tbcontactId.Text))
{
contactReference = new ContactReference(Guid.Parse(tbcontactId.Text));
}
else if (!string.IsNullOrWhiteSpace(tbContactIdentifierSource.Text) && !string.IsNullOrWhiteSpace(tbContactIdentifierValue.Text))
{
identifiedContactReference = new IdentifiedContactReference(tbContactIdentifierSource.Text, tbContactIdentifierValue.Text);
}
Contact contact = client.Get((IEntityReference<Contact>)contactReference ?? identifiedContactReference, new ContactExpandOptions(CollectionModel.FacetKeys.EmailAddressList,
CollectionModel.FacetKeys.PersonalInformation,
CollectionModel.FacetKeys.ConsentInformation,
CollectionModel.FacetKeys.ContactBehaviorProfile,
CollectionModel.FacetKeys.ListSubscriptions,
CollectionModel.FacetKeys.AutomationPlanEnrollmentCache,
CollectionModel.FacetKeys.AutomationPlanExit)
{
Interactions = new RelatedInteractionsExpandOptions()
{
StartDateTime = DateTime.MinValue,
Limit = int.MaxValue
}
});
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new XdbJsonContractResolver(client.Model,
serializeFacets: true,
serializeContactInteractions: true),
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DefaultValueHandling = DefaultValueHandling.Ignore,
Formatting = Formatting.Indented
};
tbContactDetails.Text = JsonConvert.SerializeObject(contact, serializerSettings);
}
catch (Exception ex)
{
tbContactDetails.Text = ex.ToString();
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>
Enter:<br/>
Contact id: <asp:TextBox runat="server" id="tbcontactId" Width="400px" /><br />
or<br/>
Contact identifier source: <asp:TextBox runat="server" Text="ListManager" id="tbContactIdentifierSource" Width="400px" /><br />
Contact identifier value: <asp:TextBox runat="server" id="tbContactIdentifierValue" Width="400px" /><br />
<asp:Button Text="Load contact" runat="server" OnClick="OnClick_LoadContact"/><br />
Contact details: <asp:TextBox runat="server" id="tbContactDetails" Width="600px" TextMode="MultiLine" Height="600px" />
</p>
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment