--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-04-06 16:37:08 -07:00
9 changed files with 89 additions and 129 deletions

View File

@@ -4,7 +4,6 @@ if (!window.shapeTracingMetadataHost) {
window.shapeTracingMetadataHost.placement = {
'n/a': 'n/a'
};
window.shapeTracingMetadataHost.references = {};
}
jQuery(function ($) {
@@ -407,7 +406,7 @@ jQuery(function ($) {
});
// open the root node (Model)
openExpando(shapeTracingMetaContent.find('.expando-glyph-container:first'))
shapeTracingMetaContent.find('.expando-glyph-container:first').click();
defaultTab = displayTabModel;
};

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using ClaySharp;
using ClaySharp.Behaviors;
@@ -11,25 +10,22 @@ using Orchard.ContentManagement;
using Orchard.DisplayManagement;
namespace Orchard.DesignerTools.Services {
public class ObjectDumper {
private const int MaxStringLength = 60;
private readonly Stack<object> _parents = new Stack<object>();
private readonly Stack<XElement> _currents = new Stack<XElement>();
private readonly int _levels;
private readonly Dictionary<int, XElement> _local;
private readonly Dictionary<int, XElement> _global;
private readonly XDocument _xdoc;
private XElement _current;
// object/key/dump
public ObjectDumper(int levels, Dictionary<int, XElement> local, Dictionary<int, XElement> global) {
public ObjectDumper(int levels)
{
_levels = levels;
_local = local;
_global = global;
_xdoc = new XDocument();
_xdoc.Add(_current = new XElement("ul"));
}
@@ -40,6 +36,7 @@ namespace Orchard.DesignerTools.Services {
}
_parents.Push(o);
// starts a new container
EnterNode("li");
@@ -51,20 +48,11 @@ namespace Orchard.DesignerTools.Services {
DumpValue(o, name);
}
else {
int hashCode = RuntimeHelpers.GetHashCode(o);
// if the object has already been processed, return a named ref to it
if (_global.ContainsKey(hashCode)) {
_current.Add(
new XElement("h1", new XText(name)),
new XElement("span", FormatType(o)),
new XElement("a", new XAttribute("href", hashCode.ToString()))
);
}
else {
_global.Add(hashCode, _current);
_local.Add(hashCode, _current);
DumpObject(o, name);
if (_parents.Count >= _levels) {
return _current;
}
DumpObject(o, name);
}
}
finally {
@@ -87,29 +75,31 @@ namespace Orchard.DesignerTools.Services {
_current.Add(
new XElement("h1", new XText(name)),
new XElement("span", FormatType(o))
);
);
EnterNode("ul");
if (_parents.Count >= _levels) {
return;
}
try {
if (o is IDictionary) {
DumpDictionary((IDictionary) o);
}
else if (o is IShape) {
DumpShape((IShape) o);
if (o is IDictionary) {
DumpDictionary((IDictionary)o);
}
else if (o is IShape) {
DumpShape((IShape)o);
// a shape can also be IEnumerable
if (o is IEnumerable) {
// a shape can also be IEnumerable
if (o is IEnumerable) {
DumpEnumerable((IEnumerable) o);
}
}
else if (o is IEnumerable) {
DumpEnumerable((IEnumerable) o);
}
else {
DumpMembers(o);
}
}
else if (o is IEnumerable)
{
DumpEnumerable((IEnumerable)o);
}
else {
DumpMembers(o);
finally {
RestoreCurrentNode();
}
}
@@ -124,55 +114,41 @@ namespace Orchard.DesignerTools.Services {
return;
}
EnterNode("ul");
try{
foreach (var member in members) {
if (o is ContentItem && member.Name == "ContentManager"
|| o is Delegate) {
continue;
}
SafeCall(() => DumpMember(o, member));
foreach (var member in members) {
if (o is ContentItem && member.Name == "ContentManager"
|| o is Delegate) {
continue;
}
SafeCall(() => DumpMember(o, member));
}
// process ContentItem.Parts specifically
foreach (var member in members) {
if (o is ContentItem && member.Name == "Parts") {
foreach (var part in ((ContentItem) o).Parts) {
SafeCall(() => Dump(part, part.PartDefinition.Name));
}
}
}
foreach (var member in members) {
// process ContentPart.Fields specifically
if (o is ContentPart && member.Name == "Fields") {
foreach (var field in ((ContentPart) o).Fields) {
SafeCall(() => Dump(field, field.Name));
}
// process ContentItem.Parts specifically
foreach (var member in members) {
if (o is ContentItem && member.Name == "Parts") {
foreach (var part in ((ContentItem) o).Parts) {
SafeCall(() => Dump(part, part.PartDefinition.Name));
}
}
}
finally {
RestoreCurrentNode();
foreach (var member in members) {
// process ContentPart.Fields specifically
if (o is ContentPart && member.Name == "Fields") {
foreach (var field in ((ContentPart) o).Fields) {
SafeCall(() => Dump(field, field.Name));
}
}
}
}
private void DumpEnumerable(IEnumerable enumerable) {
if(!enumerable.GetEnumerator().MoveNext()) {
if (!enumerable.GetEnumerator().MoveNext()) {
return;
}
EnterNode("ul");
try {
int i = 0;
foreach (var child in enumerable) {
Dump(child, string.Format("[{0}]", i++));
}
}
finally {
RestoreCurrentNode();
int i = 0;
foreach (var child in enumerable) {
Dump(child, string.Format("[{0}]", i++));
}
}
@@ -181,21 +157,14 @@ namespace Orchard.DesignerTools.Services {
return;
}
EnterNode("ul");
try {
foreach (var key in dictionary.Keys) {
Dump(dictionary[key], string.Format("[\"{0}\"]", key));
}
}
finally {
RestoreCurrentNode();
foreach (var key in dictionary.Keys) {
Dump(dictionary[key], string.Format("[\"{0}\"]", key));
}
}
private void DumpShape(IShape shape) {
var b = ((IClayBehaviorProvider)(dynamic)shape).Behavior as ClayBehaviorCollection;
var b = ((IClayBehaviorProvider) (dynamic) shape).Behavior as ClayBehaviorCollection;
if (b == null)
return;
@@ -216,19 +185,12 @@ namespace Orchard.DesignerTools.Services {
return;
}
EnterNode("ul");
try {
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 props.Keys) {
// ignore private members (added dynmically by the shape wrapper)
if (key.ToString().StartsWith("_")) {
continue;
}
}
finally {
RestoreCurrentNode();
Dump(props[key], key.ToString());
}
}
@@ -305,9 +267,22 @@ namespace Orchard.DesignerTools.Services {
_current = _currents.Pop();
}
private void EnterNode(string tag) {
private XElement EnterNode(string tag) {
SaveCurrentNode();
_current.Add(_current = new XElement(tag));
return _current;
}
private int MaxNodesLength(XElement el) {
int max = 1;
var local = 0;
foreach(var node in el.Elements()) {
local = Math.Max(local, MaxNodesLength(node));
}
return max + local;
}
}
public class DumpMap : Dictionary<int, XElement> {}
}

View File

@@ -23,7 +23,7 @@ namespace Orchard.DesignerTools.Services {
private readonly IWebSiteFolder _webSiteFolder;
private readonly IAuthorizer _authorizer;
private int _shapeId;
private readonly Dictionary<int, XElement> _dumped = new Dictionary<int, XElement>(1000);
private readonly DumpMap _dumped = new DumpMap();
public ShapeTracingFactory(
WorkContext workContext,
@@ -96,17 +96,11 @@ namespace Orchard.DesignerTools.Services {
var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
// dump the Shape's content
var local = new Dictionary<int, XElement>();
new ObjectDumper(6, local, _dumped).Dump(context.Shape, "Model");
context.Shape.Reference = RuntimeHelpers.GetHashCode(context.Shape);
var dump = new ObjectDumper(6).Dump(context.Shape, "Model");
var sb = new StringBuilder();
context.Shape.LocalReferences = new Dictionary<int, string>();
foreach (var key in local.Keys) {
sb.Clear();
ConvertToJSon(local[key], sb);
((Dictionary<int, string>) context.Shape.LocalReferences)[key] = sb.ToString();
}
ConvertToJSon(dump, sb);
shape.Dump = sb.ToString();
shape.Template = null;
shape.OriginalTemplate = descriptor.BindingSource;
@@ -158,7 +152,7 @@ namespace Orchard.DesignerTools.Services {
public void Displayed(ShapeDisplayedContext context) {
}
private static void ConvertToJSon(XElement x, StringBuilder sb) {
public static void ConvertToJSon(XElement x, StringBuilder sb) {
if(x == null) {
return;
}
@@ -177,21 +171,18 @@ namespace Orchard.DesignerTools.Services {
sb.AppendFormat("name: \"{0}\", ", FormatJsonValue(name));
sb.AppendFormat("value: \"{0}\"", FormatJsonValue(value));
var a = x.Element("a");
if (a != null) {
sb.AppendFormat(", children: shapeTracingMetadataHost.references[{0}]", a.Attribute("href").Value);
}
var ul = x.Element("ul");
if (ul != null) {
if (ul != null && ul.Descendants().Any()) {
sb.Append(", children: [");
foreach (var li in ul.Elements()) {
sb.Append("{ ");
ConvertToJSon(li, sb);
sb.Append(" },");
sb.Append(" }");
sb.Append(", ");
}
sb.Append("]");
}
break;
}
}

View File

@@ -20,10 +20,6 @@
<script type="text/javascript">
shapeTracingMetadataHost[@Model.ShapeId] = {};
@foreach (var pair in Model.LocalReferences) {
<text>shapeTracingMetadataHost.references[@pair.Key] = { @(new MvcHtmlString(pair.Value)) };</text>
}
shapeTracingMetadataHost[@Model.ShapeId].shape = {
type: '@Model.ShapeType',
template: '@Model.Template',
@@ -50,7 +46,7 @@ shapeTracingMetadataHost[@Model.ShapeId].shape = {
],
html: '@RemoveEmptyLines(RemoveBeacons(Display(Model.ChildContent).ToString())).Replace(Environment.NewLine, "\\n")',
templateContent: '@(String.IsNullOrWhiteSpace((string)Model.TemplateContent) ? @T("Content not available as coming from source code.") : @Model.TemplateContent.Replace(Environment.NewLine, "\\n"))',
model: shapeTracingMetadataHost.references[@Model.Reference]
model: { @(new MvcHtmlString((string)@Model.Dump)) }
};
@if(!String.IsNullOrEmpty((string)Model.PlacementSource) && !TempData.ContainsKey((string)Model.PlacementSource)) {

View File

@@ -40,7 +40,6 @@
Wrappers: Model.Metadata.Wrappers,
ChildContent: Model.Metadata.ChildContent,
ShapeId: Model.ShapeId,
Reference: Model.Reference,
LocalReferences: Model.LocalReferences
Dump: Model.Dump
));
}

View File

@@ -84,7 +84,7 @@
@if (!string.IsNullOrEmpty(item.ProjectUrl)) { <a href="@item.ProjectUrl">@item.ProjectUrl</a> } else { @T("Unknown").ToString() }
</li>
<li class="rating">&nbsp;&#124;&nbsp;@T("Rating: ")
<div class="ratings" style="width:@(15 * 5)px" title="@T("Ratings: {0} ({1})", item.Rating, item.RatingsCount)">
<div class="ratings" style="width:@(15 * 5)px" title="@T("Rating: {0} out of 5 ({1} total).", item.Rating, item.RatingsCount)">
<div class="score" style="width:@(15 * (item.Rating))px">&nbsp;</div>
</div>
</li>

View File

@@ -88,7 +88,7 @@
@if (!string.IsNullOrEmpty(item.ProjectUrl)) { <a href="@item.ProjectUrl">@item.ProjectUrl</a> } else { @T("Unknown").ToString() }
</li>
<li class="rating">&nbsp;&#124;&nbsp;@T("Rating: ")
<div class="ratings" style="width:@(15 * 5)px" title="@T("Ratings: {0} ({1})", item.Rating, item.RatingsCount)">
<div class="ratings" style="width:@(15 * 5)px" title="@T("Rating: {0} out of 5 ({1} total).", item.Rating, item.RatingsCount)">
<div class="score" style="width:@(15 * (item.Rating))px">&nbsp;</div>
</div>
</li>

View File

@@ -65,7 +65,7 @@
@if (!string.IsNullOrEmpty(module.NewVersionToInstall.ProjectUrl)) { <a href="@module.NewVersionToInstall.ProjectUrl">@module.NewVersionToInstall.ProjectUrl</a> } else { @T("Unknown").ToString() }
</li>
<li><div>&nbsp;&#124;&nbsp;@T("Rating: ")
<div class="ratings" style="width:@(15 * 5)px" title="@T("Ratings: {0} ({1})", module.NewVersionToInstall.Rating, module.NewVersionToInstall.RatingsCount)">
<div class="ratings" style="width:@(15 * 5)px" title="@T("Rating: {0} out of 5 ({1} total).", module.NewVersionToInstall.Rating, module.NewVersionToInstall.RatingsCount)">
<div class="score" style="width:@(15 * (module.NewVersionToInstall.Rating))px">&nbsp;</div>
</div>
</div>

View File

@@ -70,7 +70,7 @@
@if (!string.IsNullOrEmpty(theme.NewVersionToInstall.ProjectUrl)) { <a href="@theme.NewVersionToInstall.ProjectUrl">@theme.NewVersionToInstall.ProjectUrl</a> } else { @T("Unknown").ToString() }
</li>
<li><div>&nbsp;&#124;&nbsp;@T("Rating: ")
<div class="ratings" style="width:@(15 * 5)px" title="@T("Ratings: {0} ({1})", theme.NewVersionToInstall.Rating, theme.NewVersionToInstall.RatingsCount)">
<div class="ratings" style="width:@(15 * 5)px" title="@T("Rating: {0} out of 5 ({1} total).", theme.NewVersionToInstall.Rating, theme.NewVersionToInstall.RatingsCount)">
<div class="score" style="width:@(15 * (theme.NewVersionToInstall.Rating))px">&nbsp;</div>
</div>
</div>