Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Last active May 2, 2017 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorsman/0e44d86518b807485fdf to your computer and use it in GitHub Desktop.
Save jhorsman/0e44d86518b807485fdf to your computer and use it in GitHub Desktop.
AmbientDataFrameworkTestPage from https://code.google.com/p/tridion-practice/wiki/AmbientDataFrameworkTestPage For lsting call claims in the Tridion ADF Ambient Data Framework.
<%@Page Language="C#"%>
<%@Import Namespace="Tridion.ContentDelivery.AmbientData" %>
<html>
<head>
<title>Ambient Data Framework Test Page</title>
<style type="text/css">
table
{
border-width: 1px;
border-spacing: 2px;
border-style: outset;
border-color: gray;
border-collapse: separate;
margin-bottom: 20px;
}
td, th
{
padding-right: 15px;
border-width: 1px;
border-style: inset;
white-space: normal;
}
.typeColumn { color: Navy; }
</style>
<script language="c#" runat="server">
protected ClaimStore _store = null;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["noContact"] == "1")
{
Session.Remove("taf:claim:audiencemanager:contact:id");
}
_store = AmbientDataContext.CurrentClaimStore;
if (_store == null)
{
WriteHeader("Claim store not present.");
return;
}
OutputAllClaimValues();
}
public string StringArrayToString(object value)
{
if (value is string)
{
return (string)value;
}
if (value is string[])
{
return string.Join(" | ", ((string[])value));
}
return null;
}
protected Uri GetUri(string uri)
{
return new Uri(uri, UriKind.RelativeOrAbsolute);
}
protected void WriteHeader(string header)
{
Response.Write(string.Format("<h2>{0}</h2><table><thead><th>Name</th><th>Value</th><th>Type</th></thead><tbody>", header));
}
protected void WriteFooter()
{
Response.Write("</tbody></table>");
}
protected void WriteRow(string label, object value, Type type = null)
{
if (value == null)
{
Response.Write(string.Format("<tr><td>{0}</td><td>(null)</td><td>(null)</td></tr>", label));
return;
}
if (type == null)
{
type = value.GetType();
}
Response.Write(string.Format("<tr><td>{0}</td><td>{1}</td><td class='typeColumn'>{2}</td></tr>", label, value, value != null ? type.FullName : "null"));
}
protected void OutputStringClaim(string uri)
{
string claimValue = _store.Get<string>(GetUri(uri));
WriteRow(uri, claimValue);
}
protected void OutputNumberClaim(string uri)
{
long? claimValue = _store.Get<long?>(GetUri(uri));
WriteRow(uri, claimValue);
}
protected void OutputBooleanClaim(string uri)
{
bool? claimValue = _store.Get<bool?>(GetUri(uri));
WriteRow(uri, claimValue);
}
protected void OutputStringArrayClaim(string uri)
{
string[] claimValue = _store.Get<string[]>(GetUri(uri));
WriteRow(uri, StringArrayToString(claimValue));
}
protected void OutputAllClaimValues()
{
WriteHeader("All claim store values");
var values = _store.GetAll();
foreach (System.Collections.Generic.KeyValuePair<System.Uri, object> entry in values)
{
if (entry.Value is IDictionary)
{
string result = "";
foreach (DictionaryEntry childValue in (IDictionary)entry.Value)
{
if (childValue.Value is object[])
{
result += childValue.Key;
result += "<ul>";
foreach (object grandChild in (object[])childValue.Value)
{
result += string.Format("<li>{0}</li>", grandChild);
}
result += "</ul>";
continue;
}
result += string.Format("<li>{0} = {1}</li>", childValue.Key, childValue.Value);
}
WriteRow(entry.Key.ToString(), result, entry.Value.GetType());
}
else if (entry.Value is System.Collections.Generic.List<object>)
{
string result = "";
foreach (object childValue in (System.Collections.Generic.List<object>)entry.Value)
{
result += string.Format("<li>{0}</li>", childValue);
}
WriteRow(entry.Key.ToString(), result, entry.Value.GetType());
}
else if (entry.Value is object[])
{
string result = "";
foreach (object childValue in (object[])entry.Value)
{
result += string.Format("<li>{0}</li>", childValue);
}
WriteRow(entry.Key.ToString(), result, entry.Value.GetType());
}
else
{
WriteRow(entry.Key.ToString(), entry.Value);
}
}
WriteFooter();
}
</script>
</head>
<body>
<%--
<!-- Page Settings: {"PageID":"tcm:1-236-64","PageModified":"2012-03-21T14:45:30","PageTemplateID":"tcm:1-235-128","PageTemplateModified":"2012-03-21T14:44:45"} -->
<script type="text/javascript" language="javascript" defer="defer" src="http://web2008r2.ams.dev/WebUI/Editors/SiteEdit/Views/Bootstrap/Bootstrap.aspx?mode=js" id="tridion.siteedit"></script></html>
--%>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment