2011-02-25 16:49:49 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using Orchard.DisplayManagement.Descriptors;
|
|
|
|
|
|
using Orchard.DisplayManagement.Implementation;
|
|
|
|
|
|
using Orchard.DisplayManagement.Shapes;
|
2011-02-08 17:52:53 -08:00
|
|
|
|
using Orchard.Environment.Extensions;
|
2011-02-25 16:49:49 -08:00
|
|
|
|
using Orchard.FileSystems.WebSite;
|
|
|
|
|
|
using Orchard.Themes;
|
2011-02-08 17:52:53 -08:00
|
|
|
|
|
|
|
|
|
|
namespace Orchard.DesignerTools.Services {
|
|
|
|
|
|
[OrchardFeature("Orchard.DesignerTools")]
|
2011-02-25 16:49:49 -08:00
|
|
|
|
public class ShapeTracingFactory : IShapeFactoryEvents, IShapeDisplayEvents {
|
|
|
|
|
|
private readonly WorkContext _workContext;
|
|
|
|
|
|
private readonly IShapeTableManager _shapeTableManager;
|
|
|
|
|
|
private readonly IThemeManager _themeManager;
|
|
|
|
|
|
private readonly IWebSiteFolder _webSiteFolder;
|
|
|
|
|
|
|
|
|
|
|
|
public ShapeTracingFactory(WorkContext workContext, IShapeTableManager shapeTableManager, IThemeManager themeManager, IWebSiteFolder webSiteFolder) {
|
|
|
|
|
|
_workContext = workContext;
|
|
|
|
|
|
_shapeTableManager = shapeTableManager;
|
|
|
|
|
|
_themeManager = themeManager;
|
|
|
|
|
|
_webSiteFolder = webSiteFolder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-08 17:52:53 -08:00
|
|
|
|
public void Creating(ShapeCreatingContext context) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Created(ShapeCreatedContext context) {
|
2011-02-14 17:19:44 -08:00
|
|
|
|
if (context.ShapeType != "Layout"
|
|
|
|
|
|
&& context.ShapeType != "DocumentZone"
|
|
|
|
|
|
&& context.ShapeType != "PlaceChildContent"
|
|
|
|
|
|
&& context.ShapeType != "ContentZone"
|
2011-02-25 16:49:49 -08:00
|
|
|
|
&& context.ShapeType != "ShapeTracingMeta") {
|
|
|
|
|
|
|
|
|
|
|
|
var shape = context.Shape;
|
|
|
|
|
|
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
|
|
|
|
|
|
|
|
|
|
|
|
var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
|
|
|
|
|
|
|
|
|
|
|
|
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
|
|
|
|
|
|
|
|
|
|
|
|
if(!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var descriptor = shapeTable.Descriptors[shapeMetadata.Type];
|
|
|
|
|
|
|
|
|
|
|
|
shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
|
|
|
|
|
|
|
|
|
|
|
|
shape.Definition = descriptor.BindingSource;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (_webSiteFolder.FileExists(descriptor.BindingSource)) {
|
|
|
|
|
|
shape.DefinitionContent = _webSiteFolder.ReadFile(descriptor.BindingSource);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch {
|
|
|
|
|
|
// the url might be invalid in case of a code shape
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
shape.Dump = DumpObject(shape);
|
2011-02-08 17:52:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2011-02-25 16:49:49 -08:00
|
|
|
|
|
|
|
|
|
|
static string DumpObject(object o) {
|
|
|
|
|
|
var dumper = new ObjectDumper(6);
|
|
|
|
|
|
var el = dumper.Dump(o, "Model");
|
|
|
|
|
|
using (var sw = new StringWriter()) {
|
|
|
|
|
|
el.WriteTo(new XmlTextWriter(sw) { Formatting = Formatting.Indented });
|
|
|
|
|
|
return sw.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Displaying(ShapeDisplayingContext context) {
|
|
|
|
|
|
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
|
|
|
|
|
|
|
|
|
|
|
|
if(!shapeMetadata.Wrappers.Contains("ShapeTracingWrapper")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( shapeMetadata.PlacementSource != null && _webSiteFolder.FileExists(shapeMetadata.PlacementSource)) {
|
|
|
|
|
|
context.Shape.PlacementContent = _webSiteFolder.ReadFile(shapeMetadata.PlacementSource);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Displayed(ShapeDisplayedContext context) {
|
|
|
|
|
|
}
|
2011-02-08 17:52:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|