Adding Shape debug viewers

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-05-24 16:34:42 -07:00
parent e3a3753d53
commit e193b4e3c7
7 changed files with 73 additions and 32 deletions

Binary file not shown.

View File

@@ -43,6 +43,7 @@ namespace Orchard.Core.Shapes {
.OnCreating(creating => creating.Behaviors.Add(new ZoneHoldingBehavior(() => creating.New.Zone())))
.OnCreated(created => {
var layout = created.Shape;
layout.Head = created.New.DocumentZone(ZoneName: "Head");
layout.Body = created.New.DocumentZone(ZoneName: "Body");
layout.Tail = created.New.DocumentZone(ZoneName: "Tail");

View File

@@ -5,7 +5,6 @@ using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using ClaySharp;
using ClaySharp.Behaviors;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
@@ -168,34 +167,12 @@ namespace Orchard.DesignerTools.Services {
}
private void DumpShape(IShape shape) {
var members = new Dictionary<string, object>();
((IClayBehaviorProvider) (dynamic) shape).Behavior.GetMembers(() => null, shape, members);
var b = ((IClayBehaviorProvider) (dynamic) shape).Behavior as ClayBehaviorCollection;
if (b == null)
return;
// seek the PropBehavior if exists
var propBehavior = b.OfType<PropBehavior>().FirstOrDefault();
if (propBehavior == null)
return;
// retrieve the internal dictionary for properties
var props = propBehavior.GetType().GetField("_props", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).GetValue(propBehavior) as Dictionary<object, object>;
if (props == null)
return;
if (props.Keys.Count == 0) {
return;
}
foreach (var key in props.Keys) {
// ignore private members (added dynmically by the shape wrapper)
if (key.ToString().StartsWith("_")) {
continue;
}
Dump(props[key], key.ToString());
foreach (var key in members.Keys.Where(key => !key.StartsWith("_"))) {
// ignore private members (added dynamically by the shape wrapper)
Dump(members[key], key);
}
}

View File

@@ -1,4 +1,5 @@
using Orchard.DisplayManagement.Shapes;
using System.Diagnostics;
using Orchard.DisplayManagement.Shapes;
namespace Orchard.DisplayManagement {
/// <summary>

View File

@@ -1,9 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Mvc;
namespace Orchard.DisplayManagement.Shapes {
[DebuggerTypeProxy(typeof(ShapeDebugView))]
public class Shape : IShape, IEnumerable {
private const string DefaultPosition = "5";
@@ -46,7 +48,5 @@ namespace Orchard.DisplayManagement.Shapes {
public virtual IEnumerator GetEnumerator() {
return _items.GetEnumerator();
}
}
}

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ClaySharp;
namespace Orchard.DisplayManagement.Shapes {
public class ShapeDebugView {
private readonly Shape _shape;
public ShapeDebugView(Shape shape) {
_shape = shape;
}
public ShapeMetadata Metadata { get { return _shape.Metadata; } }
public string Id { get { return _shape.Id; } }
public IList<string> Classes { get { return _shape.Classes; } }
public IDictionary<string, string> Attributes { get { return _shape.Attributes; } }
public IEnumerable<dynamic> Items { get { return _shape.Items; } }
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePairs[] ClayProperties {
get {
var members = new Dictionary<string, object>();
((IClayBehaviorProvider)_shape).Behavior.GetMembers(() => null, _shape, members);
return members.Keys.Select(key => new KeyValuePairs(key, members[key])).ToArray();
}
}
[DebuggerDisplay(" { _shapeType == null ? _value : \"Shape: \" + _shapeType}", Name = "{_key,nq}")]
public class KeyValuePairs {
public KeyValuePairs(object key, object value) {
try {
var dynProxyGetTarget = value.GetType().GetMethod("DynProxyGetTarget");
if (dynProxyGetTarget != null) {
_value = dynProxyGetTarget.Invoke(value, null);
_shapeType = ((IShape)_value).Metadata.Type;
}
else {
_value = value;
}
}
catch {
_value = value;
}
_key = key;
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private object _key;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private object _shapeType;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
private object _value;
}
}
}

View File

@@ -172,6 +172,7 @@
<Compile Include="DisplayManagement\Descriptors\ShapeTableBuilder.cs" />
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
<Compile Include="DisplayManagement\Shapes\ShapeDebugView.cs" />
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
<Compile Include="Environment\Extensions\OrchardSuppressDependencyAttribute.cs" />
<Compile Include="Environment\Features\IFeatureManager.cs" />
@@ -868,7 +869,6 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.