mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Rough intermediate state
display and shape are a work in progress coarse grained service interfaces and relationships forming --HG-- branch : mvc3p1
This commit is contained in:
BIN
lib/clay/ClaySharp.dll
Normal file
BIN
lib/clay/ClaySharp.dll
Normal file
Binary file not shown.
BIN
lib/clay/ClaySharp.pdb
Normal file
BIN
lib/clay/ClaySharp.pdb
Normal file
Binary file not shown.
@@ -16,7 +16,8 @@
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0"/>
|
||||
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
33
src/Orchard.Tests/DisplayManagement/ArgsUtility.cs
Normal file
33
src/Orchard.Tests/DisplayManagement/ArgsUtility.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Routing;
|
||||
using ClaySharp;
|
||||
using ClaySharp.Implementation;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
public static class ArgsUtility {
|
||||
public static INamedEnumerable<T> Named<T>(IDictionary<string, T> args) {
|
||||
return FromDictionary(args);
|
||||
}
|
||||
|
||||
public static INamedEnumerable<object> Named(object args) {
|
||||
return FromDictionary(new RouteValueDictionary(args));
|
||||
}
|
||||
public static INamedEnumerable<T> Empty<T>() {
|
||||
return Arguments.FromT(Enumerable.Empty<T>(), Enumerable.Empty<string>());
|
||||
}
|
||||
public static INamedEnumerable<object> Empty() {
|
||||
return Empty<object>();
|
||||
}
|
||||
|
||||
static INamedEnumerable<T> FromDictionary<T>(IDictionary<string, T> args) {
|
||||
return Arguments.FromT(args.Values, args.Keys);
|
||||
}
|
||||
|
||||
public static INamedEnumerable<object> Positional(params object[] args) {
|
||||
return Arguments.From(args, Enumerable.Empty<string>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class DefaultDisplayManagerTests {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class DefaultShapeTableFactoryTests {
|
||||
static IShapeTableFactory CreateShapeTableFactory(Action<ContainerBuilder> config) {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultShapeTableFactory>().As<IShapeTableFactory>();
|
||||
config(builder);
|
||||
var container = builder.Build();
|
||||
return container.Resolve<IShapeTableFactory>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShapeTableRecognizesMethodNames() {
|
||||
var stf = CreateShapeTableFactory(cfg => cfg.RegisterType<Test>().As<IShapeProvider>());
|
||||
var shapeTable = stf.CreateShapeTable();
|
||||
Assert.That(shapeTable.Entries.Count(), Is.EqualTo(2));
|
||||
Assert.That(shapeTable.Entries.ContainsKey("Pager"));
|
||||
Assert.That(shapeTable.Entries.ContainsKey("Email"));
|
||||
}
|
||||
|
||||
public class Test : IShapeProvider {
|
||||
public void Pager() {
|
||||
}
|
||||
|
||||
public void Email(string text, string address) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
64
src/Orchard.Tests/DisplayManagement/DisplayHelperTests.cs
Normal file
64
src/Orchard.Tests/DisplayManagement/DisplayHelperTests.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using ClaySharp.Implementation;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class DisplayHelperTests {
|
||||
[Test]
|
||||
public void DisplayingShapeWithArgumentsStatically() {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var displayHelper = displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
|
||||
displayHelper.Invoke("Pager", ArgsUtility.Positional(1, 2, 3, 4));
|
||||
|
||||
shapeFactory.Verify(sf=>sf.Build("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
displayManager.Verify(dm => dm.Execute(It.IsAny<Shape>(), viewContext, null));
|
||||
}
|
||||
[Test]
|
||||
public void DisplayingShapeWithArgumentsDynamically() {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var display = (dynamic)displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
|
||||
display.Pager(1, 2, 3, 4);
|
||||
|
||||
shapeFactory.Verify(sf => sf.Build("Pager", It.IsAny<INamedEnumerable<object>>()));
|
||||
displayManager.Verify(dm => dm.Execute(It.IsAny<Shape>(), viewContext, null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void UsingDisplayAsFunctionAndPassingInTheShape() {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
var displayManager = new Mock<IDisplayManager>();
|
||||
var shapeFactory = new Mock<IShapeBuilder>();
|
||||
|
||||
var displayHelperFactory = new DisplayHelperFactory(displayManager.Object, shapeFactory.Object);
|
||||
var display = (dynamic)displayHelperFactory.CreateDisplayHelper(viewContext, null);
|
||||
var outline = new Shape { Attributes = new ShapeAttributes { Type = "Outline" } };
|
||||
display(outline);
|
||||
|
||||
displayManager.Verify(dm => dm.Execute(outline, viewContext, null));
|
||||
}
|
||||
}
|
||||
}
|
37
src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs
Normal file
37
src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class DefaultShapeBuilderTests {
|
||||
private IContainer _container;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShapeHasAttributesType() {
|
||||
var factory = _container.Resolve<IShapeBuilder>();
|
||||
dynamic foo = factory.Build("Foo", ArgsUtility.Empty());
|
||||
ShapeAttributes attributes = foo.Attributes;
|
||||
Assert.That(attributes.Type, Is.EqualTo("Foo"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateShapeWithNamedArguments() {
|
||||
var factory = _container.Resolve<IShapeBuilder>();
|
||||
var foo = factory.Build("Foo", ArgsUtility.Named(new { one = 1, two = "dos" }));
|
||||
}
|
||||
}
|
||||
}
|
55
src/Orchard.Tests/DisplayManagement/ShapeHelperTests.cs
Normal file
55
src/Orchard.Tests/DisplayManagement/ShapeHelperTests.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class ShapeHelperTests {
|
||||
private IContainer _container;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
_container = builder.Build();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatingNewShapeTypeByName() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
|
||||
var alpha = shape.Alpha();
|
||||
|
||||
Assert.That(alpha.Attributes.Type, Is.EqualTo("Alpha"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatingShapeWithAdditionalNamedParameters() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
|
||||
var alpha = shape.Alpha(one: 1, two: "dos");
|
||||
|
||||
Assert.That(alpha.Attributes.Type, Is.EqualTo("Alpha"));
|
||||
Assert.That(alpha.one, Is.EqualTo(1));
|
||||
Assert.That(alpha.two, Is.EqualTo("dos"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithPropertyBearingObjectInsteadOfNamedParameters() {
|
||||
dynamic shape = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
|
||||
var alpha = shape.Alpha(new { one = 1, two = "dos" });
|
||||
|
||||
Assert.That(alpha.Attributes.Type, Is.EqualTo("Alpha"));
|
||||
Assert.That(alpha.one, Is.EqualTo(1));
|
||||
Assert.That(alpha.two, Is.EqualTo("dos"));
|
||||
}
|
||||
}
|
||||
}
|
57
src/Orchard.Tests/DisplayManagement/SubsystemTests.cs
Normal file
57
src/Orchard.Tests/DisplayManagement/SubsystemTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Secondary;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
[TestFixture]
|
||||
public class SubsystemTests {
|
||||
private IContainer _container;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
||||
builder.RegisterType<DefaultShapeBuilder>().As<IShapeBuilder>();
|
||||
builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
|
||||
builder.RegisterType<ShapeHelperFactory>().As<IShapeHelperFactory>();
|
||||
builder.RegisterType<DefaultShapeTableFactory>().As<IShapeTableFactory>();
|
||||
builder.RegisterType<SimpleShapes>().As<IShapeProvider>();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
public class SimpleShapes : IShapeProvider {
|
||||
public IHtmlString Something() {
|
||||
return new HtmlString("<br/>");
|
||||
}
|
||||
|
||||
public IHtmlString Pager() {
|
||||
return new HtmlString("<div>hello</div>");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderingSomething() {
|
||||
var viewContext = new ViewContext();
|
||||
|
||||
dynamic Display = _container.Resolve<IDisplayHelperFactory>().CreateDisplayHelper(viewContext, null);
|
||||
|
||||
dynamic New = _container.Resolve<IShapeHelperFactory>().CreateShapeHelper();
|
||||
|
||||
var result1 = Display.Something();
|
||||
var result2 = ((DisplayHelper)Display).ShapeExecute((Shape)New.Pager());
|
||||
|
||||
Display(New.Pager());
|
||||
|
||||
Assert.That(result1.ToString(), Is.EqualTo("<br/>"));
|
||||
Assert.That(result2.ToString(), Is.EqualTo("<div>hello</div>"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -75,10 +75,12 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.DynamicProxy2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClaySharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
|
||||
@@ -190,6 +192,13 @@
|
||||
<Compile Include="Data\Builders\SessionFactoryBuilderTests.cs" />
|
||||
<Compile Include="Data\RepositoryTests.cs" />
|
||||
<Compile Include="Data\StubLocator.cs" />
|
||||
<Compile Include="DisplayManagement\ArgsUtility.cs" />
|
||||
<Compile Include="DisplayManagement\DefaultDisplayManagerTests.cs" />
|
||||
<Compile Include="DisplayManagement\DefaultShapeTableFactoryTests.cs" />
|
||||
<Compile Include="DisplayManagement\DisplayHelperTests.cs" />
|
||||
<Compile Include="DisplayManagement\ShapeFactoryTests.cs" />
|
||||
<Compile Include="DisplayManagement\SubsystemTests.cs" />
|
||||
<Compile Include="DisplayManagement\ShapeHelperTests.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\AutofacTests.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyTests.cs" />
|
||||
<Compile Include="Environment\Extensions\ExtensionLoaderCoordinatorTests.cs" />
|
||||
@@ -270,7 +279,9 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Environment\Extensions\FoldersData\Sample1\Module.txt" />
|
||||
|
51
src/Orchard/DisplayManagement/DisplayHelper.cs
Normal file
51
src/Orchard/DisplayManagement/DisplayHelper.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
|
||||
|
||||
public class DisplayHelper {
|
||||
private readonly IDisplayManager _displayManager;
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public DisplayHelper(
|
||||
IDisplayManager displayManager,
|
||||
IShapeBuilder shapeBuilder,
|
||||
ViewContext viewContext,
|
||||
IViewDataContainer viewDataContainer) {
|
||||
_displayManager = displayManager;
|
||||
_shapeBuilder = shapeBuilder;
|
||||
ViewContext = viewContext;
|
||||
ViewDataContainer = viewDataContainer;
|
||||
}
|
||||
|
||||
public ViewContext ViewContext { get; set; }
|
||||
public IViewDataContainer ViewDataContainer { get; set; }
|
||||
|
||||
public object Invoke(string name, INamedEnumerable<object> parameters) {
|
||||
if (!string.IsNullOrEmpty(name)) {
|
||||
return ShapeTypeExecute(name, parameters);
|
||||
}
|
||||
|
||||
if (parameters.Positional.Count() == 1 && parameters.Positional.All(arg => arg is Shape)) {
|
||||
var shape = (Shape)parameters.Positional.Single();
|
||||
return ShapeExecute(shape);
|
||||
}
|
||||
|
||||
throw new NotImplementedException("Need to handle multiple shapes, as well as other object types");
|
||||
}
|
||||
|
||||
private object ShapeTypeExecute(string name, INamedEnumerable<object> parameters) {
|
||||
var shape = _shapeBuilder.Build(name, parameters);
|
||||
return ShapeExecute(shape);
|
||||
}
|
||||
|
||||
public object ShapeExecute(Shape shape) {
|
||||
return _displayManager.Execute(shape, ViewContext, ViewDataContainer);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class DisplayHelperFactory : IDisplayHelperFactory {
|
||||
static private readonly DisplayHelperBehavior[] _behaviors = new[] { new DisplayHelperBehavior() };
|
||||
private readonly IDisplayManager _displayManager;
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public DisplayHelperFactory(IDisplayManager displayManager, IShapeBuilder shapeBuilder) {
|
||||
_displayManager = displayManager;
|
||||
_shapeBuilder = shapeBuilder;
|
||||
}
|
||||
|
||||
public DisplayHelper CreateDisplayHelper(ViewContext viewContext, IViewDataContainer viewDataContainer) {
|
||||
return (DisplayHelper)ClayActivator.CreateInstance<DisplayHelper>(
|
||||
_behaviors,
|
||||
_displayManager,
|
||||
_shapeBuilder,
|
||||
viewContext,
|
||||
viewDataContainer);
|
||||
}
|
||||
|
||||
class DisplayHelperBehavior : ClayBehavior {
|
||||
public override object InvokeMember(Func<object> proceed, object target, string name, INamedEnumerable<object> args) {
|
||||
return ((DisplayHelper)target).Invoke(name, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IDisplayHelperFactory : ISingletonDependency {
|
||||
DisplayHelper CreateDisplayHelper(ViewContext viewContext, IViewDataContainer viewDataContainer);
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeHelperFactory : ISingletonDependency {
|
||||
ShapeHelper CreateShapeHelper();
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class ShapeHelperFactory : IShapeHelperFactory {
|
||||
static private readonly ShapeHelperBehavior[] _behaviors = new[] { new ShapeHelperBehavior() };
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public ShapeHelperFactory(IShapeBuilder shapeBuilder) {
|
||||
_shapeBuilder = shapeBuilder;
|
||||
}
|
||||
|
||||
public ShapeHelper CreateShapeHelper() {
|
||||
return (ShapeHelper)ClayActivator.CreateInstance<ShapeHelper>(
|
||||
_behaviors,
|
||||
_shapeBuilder);
|
||||
}
|
||||
|
||||
class ShapeHelperBehavior : ClayBehavior {
|
||||
public override object InvokeMember(Func<object> proceed, object target, string name, INamedEnumerable<object> args) {
|
||||
return ((ShapeHelper)target).CreateShapeType(name, args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
12
src/Orchard/DisplayManagement/IDisplayManager.cs
Normal file
12
src/Orchard/DisplayManagement/IDisplayManager.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IDisplayManager : ISingletonDependency {
|
||||
object Execute(Shape shape, ViewContext viewContext, IViewDataContainer viewDataContainer);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.DisplayManagement.Secondary {
|
||||
public class DefaultDisplayManager : IDisplayManager {
|
||||
private readonly IShapeTableFactory _shapeTableFactory;
|
||||
|
||||
public DefaultDisplayManager(IShapeTableFactory shapeTableFactory) {
|
||||
_shapeTableFactory = shapeTableFactory;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public object Execute(Shape shape, ViewContext viewContext, IViewDataContainer viewDataContainer) {
|
||||
ShapeAttributes shapeAttributes = ((dynamic)shape).Attributes;
|
||||
var shapeTable = _shapeTableFactory.CreateShapeTable();
|
||||
ShapeTable.Entry entry;
|
||||
if (shapeTable.Entries.TryGetValue(shapeAttributes.Type, out entry)) {
|
||||
return Process(entry, shape, viewContext, viewDataContainer);
|
||||
}
|
||||
throw new OrchardException(T("Shape name not found"));
|
||||
}
|
||||
|
||||
private object Process(ShapeTable.Entry entry, Shape shape, ViewContext viewContext, IViewDataContainer viewDataContainer) {
|
||||
var displayContext = new DisplayContext { ViewContext = viewContext, Shape = shape };
|
||||
return entry.Target(displayContext);
|
||||
}
|
||||
}
|
||||
}
|
20
src/Orchard/DisplayManagement/ShapeHelper.cs
Normal file
20
src/Orchard/DisplayManagement/ShapeHelper.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ClaySharp;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class ShapeHelper {
|
||||
private readonly IShapeBuilder _shapeBuilder;
|
||||
|
||||
public ShapeHelper(IShapeBuilder shapeBuilder) {
|
||||
_shapeBuilder = shapeBuilder;
|
||||
}
|
||||
|
||||
public Shape CreateShapeType(string shapeType, INamedEnumerable<object> parameters) {
|
||||
return _shapeBuilder.Build(shapeType, parameters);
|
||||
}
|
||||
}
|
||||
}
|
28
src/Orchard/DisplayManagement/Shapes/DefaultShapeBuilder.cs
Normal file
28
src/Orchard/DisplayManagement/Shapes/DefaultShapeBuilder.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Linq;
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class DefaultShapeBuilder : IShapeBuilder {
|
||||
public Shape Build(string shapeType, INamedEnumerable<object> parameters) {
|
||||
var shape = ClayActivator.CreateInstance<Shape>(new IClayBehavior[]{
|
||||
new ClaySharp.Behaviors.InterfaceProxyBehavior(),
|
||||
new ClaySharp.Behaviors.PropBehavior(),
|
||||
new ClaySharp.Behaviors.NilResultBehavior()});
|
||||
|
||||
shape.Attributes = new ShapeAttributes { Type = shapeType };
|
||||
|
||||
if (parameters.Positional.Any()) {
|
||||
var initializer = parameters.Positional.Single();
|
||||
foreach (var prop in initializer.GetType().GetProperties()) {
|
||||
shape[prop.Name] = prop.GetValue(initializer, null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in parameters.Named) {
|
||||
shape[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
return shape;
|
||||
}
|
||||
}
|
||||
}
|
7
src/Orchard/DisplayManagement/Shapes/IShapeBuilder.cs
Normal file
7
src/Orchard/DisplayManagement/Shapes/IShapeBuilder.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using ClaySharp;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public interface IShapeBuilder {
|
||||
Shape Build(string shapeType, INamedEnumerable<object> parameters);
|
||||
}
|
||||
}
|
10
src/Orchard/DisplayManagement/Shapes/Shape.cs
Normal file
10
src/Orchard/DisplayManagement/Shapes/Shape.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class Shape {
|
||||
public virtual ShapeAttributes Attributes { get; set; }
|
||||
}
|
||||
}
|
6
src/Orchard/DisplayManagement/Shapes/ShapeAttributes.cs
Normal file
6
src/Orchard/DisplayManagement/Shapes/ShapeAttributes.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.DisplayManagement.Shapes {
|
||||
public class ShapeAttributes {
|
||||
public string Type { get; set; }
|
||||
public string Position { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class DefaultShapeTableFactory : IShapeTableFactory {
|
||||
private readonly IEnumerable<IShapeProvider> _shapeProviders;
|
||||
|
||||
public DefaultShapeTableFactory(IEnumerable<IShapeProvider> shapeProviders) {
|
||||
_shapeProviders = shapeProviders;
|
||||
}
|
||||
|
||||
public ShapeTable CreateShapeTable() {
|
||||
var table = new ShapeTable { Entries = GetEntries().ToDictionary(e => e.ShapeType) };
|
||||
return table;
|
||||
}
|
||||
|
||||
private IEnumerable<ShapeTable.Entry> GetEntries() {
|
||||
foreach (var shapeProvider in _shapeProviders) {
|
||||
foreach (var methodInfo in shapeProvider.GetType().GetMethods().Where(IsAcceptableMethod)) {
|
||||
var info = methodInfo;
|
||||
var provider = shapeProvider;
|
||||
yield return new ShapeTable.Entry {
|
||||
ShapeType = methodInfo.Name,
|
||||
Target = ctx => info.Invoke(provider, new object[0])
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsAcceptableMethod(MethodInfo methodInfo) {
|
||||
if (methodInfo.IsSpecialName)
|
||||
return false;
|
||||
if (methodInfo.DeclaringType == typeof(object))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
14
src/Orchard/DisplayManagement/Speculation/DisplayContext.cs
Normal file
14
src/Orchard/DisplayManagement/Speculation/DisplayContext.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class DisplayContext {
|
||||
public ViewContext ViewContext { get; set; }
|
||||
public Shape Shape { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeProvider : ISingletonDependency{}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public interface IShapeTableFactory : ISingletonDependency {
|
||||
ShapeTable CreateShapeTable();
|
||||
}
|
||||
}
|
14
src/Orchard/DisplayManagement/Speculation/ShapeTable.cs
Normal file
14
src/Orchard/DisplayManagement/Speculation/ShapeTable.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.DisplayManagement {
|
||||
public class ShapeTable {
|
||||
public IDictionary<string, Entry> Entries { get; set; }
|
||||
|
||||
public class Entry {
|
||||
public string ShapeType { get; set; }
|
||||
public Func<DisplayContext, object> Target { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,11 +36,16 @@ namespace Orchard.Environment {
|
||||
TryResolveAtScope(Scope.CurrentLifetimeScope, key, serviceType, out value);
|
||||
}
|
||||
|
||||
static object CreateInstance(Type t) {
|
||||
object CreateInstance(Type t) {
|
||||
if (t.IsAbstract || t.IsInterface)
|
||||
return null;
|
||||
|
||||
return Activator.CreateInstance(t);
|
||||
var instance = Activator.CreateInstance(t);
|
||||
if (instance is IContextualizable) {
|
||||
var effectiveContainer = Scope.CurrentLifetimeScope ?? _container;
|
||||
(instance as IContextualizable).Hook(() => effectiveContainer.InjectUnsetProperties(instance));
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
TService Resolve<TService>(Type serviceType, TService defaultValue = default(TService)) {
|
||||
|
7
src/Orchard/Environment/IContextualizable.cs
Normal file
7
src/Orchard/Environment/IContextualizable.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
public interface IContextualizable {
|
||||
void Hook(params Action[] contextualizers);
|
||||
}
|
||||
}
|
@@ -3,34 +3,54 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using ClaySharp;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Mvc.ViewEngines.Razor {
|
||||
public abstract class WebViewPage : WebViewPage<object> {
|
||||
}
|
||||
|
||||
public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel> {
|
||||
public WebViewPage() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>, IContextualizable {
|
||||
private object _display;
|
||||
private Localizer _localizer = NullLocalizer.Instance;
|
||||
private IEnumerable<Action> _contexturalizers = Enumerable.Empty<Action>();
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public Localizer T { get { return _localizer; } }
|
||||
public dynamic Display { get { return _display; } }
|
||||
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
|
||||
|
||||
public IAuthorizer Authorizer { get; set; }
|
||||
|
||||
public override void InitHelpers() {
|
||||
base.InitHelpers();
|
||||
T = LocalizationUtilities.Resolve(ViewContext, VirtualPath);
|
||||
|
||||
foreach (var contextualize in _contexturalizers)
|
||||
contextualize();
|
||||
|
||||
_localizer = LocalizationUtilities.Resolve(ViewContext, VirtualPath);
|
||||
_display = DisplayHelperFactory.CreateDisplayHelper(ViewContext, this);
|
||||
}
|
||||
|
||||
public MvcHtmlString H(string value) {
|
||||
return MvcHtmlString.Create(Html.Encode(value));
|
||||
}
|
||||
|
||||
public bool AuthorizedFor(Permission permission) {
|
||||
return Html.Resolve<IAuthorizer>().Authorize(permission);
|
||||
return Authorizer.Authorize(permission);
|
||||
}
|
||||
|
||||
void IContextualizable.Hook(params Action[] contextualizers) {
|
||||
if (contextualizers != null && contextualizers.Any()) {
|
||||
_contexturalizers = (_contexturalizers.Any()) ? _contexturalizers.Concat(contextualizers) : contextualizers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class WebViewPage : WebViewPage<object> {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -77,6 +77,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.DynamicProxy2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClaySharp">
|
||||
<HintPath>..\..\lib\clay\ClaySharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentNHibernate, Version=1.0.0.593, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
|
||||
@@ -85,6 +88,7 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sharpziplib\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\aspnetmvc\Microsoft.WebPages.dll</HintPath>
|
||||
@@ -376,6 +380,24 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DataMigrations\FrameworkDataMigration.cs" />
|
||||
<Compile Include="DisplayManagement\Secondary\DefaultDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\DefaultShapeBuilder.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\IShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\IDisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\Shape.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\ShapeAttributes.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\DefaultShapeTableFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\DisplayContext.cs" />
|
||||
<Compile Include="DisplayManagement\DisplayHelper.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\DisplayHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\IDisplayManager.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\IShapeBuilder.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\IShapeProvider.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\IShapeTableFactory.cs" />
|
||||
<Compile Include="DisplayManagement\ShapeHelper.cs" />
|
||||
<Compile Include="DisplayManagement\HelperFactories\ShapeHelperFactory.cs" />
|
||||
<Compile Include="DisplayManagement\Speculation\ShapeTable.cs" />
|
||||
<Compile Include="Environment\IContextualizable.cs" />
|
||||
<Compile Include="Environment\IHostLocalRestart.cs" />
|
||||
<Compile Include="Environment\IShellContainerRegistrations.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\DynamicModuleVirtualPathProvider.cs" />
|
||||
@@ -792,6 +814,7 @@
|
||||
<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.
|
||||
|
Reference in New Issue
Block a user