Skip to content

Commit

Permalink
+ Updated Lava debug display to only display each object type/id once…
Browse files Browse the repository at this point in the history
…, and limit itterations to first two items (Fixes #1365).
  • Loading branch information
azturner committed Feb 16, 2016
1 parent 4c4278c commit 3707c39
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions Rock/Utility/ExtensionMethods/LavaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using DotLiquid;
using Rock.Data;
using Rock.Model;
using Rock.Web.Cache;

namespace Rock
{
Expand Down Expand Up @@ -78,7 +79,7 @@ public static string lavaDebugInfo( this object lavaObject, RockContext rockCont
/// <param name="rockContext">The rock context.</param>
/// <param name="parentElement">The parent element.</param>
/// <returns></returns>
private static object LiquidizeChildren( this object myObject, int levelsDeep = 0, RockContext rockContext = null, string parentElement = "" )
private static object LiquidizeChildren( this object myObject, int levelsDeep = 0, RockContext rockContext = null, Dictionary<int, List<int>> entityHistory = null, string parentElement = "" )
{
// Add protection for stack-overflow if property attributes are not set correctly resulting in child/parent objects being evaluated in loop
levelsDeep++;
Expand Down Expand Up @@ -118,6 +119,29 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
entityType = entityType.BaseType;
}

// If this is an IEntity, check to see if it's already been liquidized in prev heirarchy. If so, just return string indicating "--See Previous Entry--"
if ( myObject is IEntity )
{
var entity = myObject as IEntity;
var entityTypeCache = EntityTypeCache.Read( entityType, false, rockContext );
if ( entity != null && entityTypeCache != null )
{
if ( entityHistory == null )
{
entityHistory = new Dictionary<int, List<int>>();
}
entityHistory.AddOrIgnore( entityTypeCache.Id, new List<int>() );
if ( entityHistory[entityTypeCache.Id].Contains( entity.Id ) )
{
return "--See Previous Entry--";
}
else
{
entityHistory[entityTypeCache.Id].Add( entity.Id );
}
}
}

// If the object is a Liquid Drop object, return a list of all of the object's properties
if ( myObject is Drop )
{
Expand All @@ -132,7 +156,7 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
{
try
{
result.Add( propInfo.Name, propInfo.GetValue( myObject, null ).LiquidizeChildren( levelsDeep, rockContext ) );
result.Add( propInfo.Name, propInfo.GetValue( myObject, null ).LiquidizeChildren( levelsDeep, rockContext, entityHistory ) );
}
catch ( Exception ex )
{
Expand All @@ -158,7 +182,7 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
{
try
{
result.Add( propInfo.Name, propInfo.GetValue( myObject, null ).LiquidizeChildren( levelsDeep, rockContext, parentElement + "." + propName ) );
result.Add( propInfo.Name, propInfo.GetValue( myObject, null ).LiquidizeChildren( levelsDeep, rockContext, entityHistory, parentElement + "." + propName ) );
}
catch ( Exception ex )
{
Expand Down Expand Up @@ -192,7 +216,7 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
object propValue = liquidObject[key];
if ( propValue != null )
{
result.Add( key, propValue.LiquidizeChildren( levelsDeep, rockContext, parentElement + "." + key ) );
result.Add( key, propValue.LiquidizeChildren( levelsDeep, rockContext, entityHistory, parentElement + "." + key ) );
}
else
{
Expand Down Expand Up @@ -241,7 +265,7 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
{
try
{
result.Add( keyValue.Key, keyValue.Value.LiquidizeChildren( levelsDeep, rockContext, keyValue.Key ) );
result.Add( keyValue.Key, keyValue.Value.LiquidizeChildren( levelsDeep, rockContext, entityHistory, keyValue.Key ) );
}
catch ( Exception ex )
{
Expand All @@ -261,7 +285,7 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
{
try
{
result.Add( keyValue.Key, keyValue.Value.LiquidizeChildren( levelsDeep, rockContext, keyValue.Key ) );
result.Add( keyValue.Key, keyValue.Value.LiquidizeChildren( levelsDeep, rockContext, entityHistory, keyValue.Key ) );
}
catch ( Exception ex )
{
Expand Down Expand Up @@ -289,13 +313,22 @@ private static object LiquidizeChildren( this object myObject, int levelsDeep =
{
var result = new List<object>();

// Only show first two items in an enumerable list
int iEnumCount = 1;
foreach ( var value in ( (IEnumerable)myObject ) )
{
if ( iEnumCount > 2 )
{
result.Add( "..." );
break;
}
iEnumCount++;
try
{
result.Add( value.LiquidizeChildren( levelsDeep, rockContext, parentElement ) );
result.Add( value.LiquidizeChildren( levelsDeep, rockContext, entityHistory, parentElement ) );
}
catch { }

}

return result;
Expand Down

0 comments on commit 3707c39

Please sign in to comment.