-
-
Save jhorsman/e7b73c8d3025833cd034 to your computer and use it in GitHub Desktop.
Listing all Ambient Data Framework claims in ASP .NET. Also see the JSP version in https://gist.github.com/jhorsman/8348d20b82c82efb02ea. See https://code.google.com/p/tridion-practice/wiki/AmbientDataFrameworkTestPage for an improved version from Peter Kjaer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@Page Language="C#"%> | |
<%@Import Namespace="Tridion.ContentDelivery.AmbientData" %> | |
<%@Import Namespace="System.Collections.Generic" %> | |
<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) | |
{ | |
if (value == null) | |
{ | |
Response.Write(string.Format("<tr><td>{0}</td><td>(null)</td><td>(null)</td></tr>", label)); | |
return; | |
} | |
Response.Write(string.Format("<tr><td>{0}</td><td>{1}</td><td class='typeColumn'>{2}</td></tr>", label, value, value != null ? value.GetType().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 SortedDictionary<string, object> SortDictionary(IDictionary dictionary) | |
{ | |
SortedDictionary<string, object> result = new SortedDictionary<string, object>(); | |
foreach (DictionaryEntry entry in dictionary) | |
{ | |
result.Add(entry.Key.ToString(), entry.Value); | |
} | |
return result; | |
} | |
protected void OutputAllClaimValues() | |
{ | |
WriteHeader("All claim store values"); | |
System.Collections.Generic.IDictionary<System.Uri, object> values = _store.GetAll(); | |
SortedDictionary<string, object> sorted = SortDictionary((IDictionary)values); | |
foreach (System.Collections.Generic.KeyValuePair<string, object> entry in sorted) | |
{ | |
if (entry.Value is IDictionary) | |
{ | |
string result = ""; | |
foreach (DictionaryEntry childValue in (IDictionary)entry.Value) | |
{ | |
if (childValue.Value is object[]) | |
{ | |
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); | |
} | |
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); | |
} | |
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); | |
} | |
else | |
{ | |
WriteRow(entry.Key.ToString(), entry.Value); | |
} | |
} | |
WriteFooter(); | |
} | |
protected void AbandonSession_Click(object sender, EventArgs e) | |
{ | |
Session.Abandon(); | |
Outcome.Text = "You've abandoned the session. Poor thing."; | |
} | |
</script> | |
</head> | |
<body> | |
<form id="MainForm" runat="server"> | |
<asp:Button ID="AbandonSession" Text="Abandon session" OnClick="AbandonSession_Click" runat="server" /> | |
<asp:Label ID="Outcome" Text="" runat="server" /> | |
</form> | |
<!-- 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment