From 0394a5f78fb7a9bf62dd30aa12c0ef48a1d9bfbf Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Thu, 26 Aug 2010 15:07:10 -0700 Subject: [PATCH] More adjustments to namespace... Some planning... --HG-- branch : mvc3p1 --- .../DisplayManagement/ShapeFactoryTests.cs | 1 + .../DisplayManagement/SubsystemTests.cs | 1 - .../Controllers/HomeController.cs | 20 +++++++++---------- .../Modules/Orchard.DevTools/Shapes.cs | 7 ++++--- .../Modules/Orchard.Setup/SetupMode.cs | 1 - .../IDisplayHelperFactory.cs | 3 +-- src/Orchard/DisplayManagement/IShape.cs | 5 +---- .../DisplayManagement/IShapeFactory.cs | 1 - .../Implementation/DefaultDisplayManager.cs | 14 +++++++------ .../Implementation/DefaultShapeFactory.cs | 3 ++- .../Implementation/DisplayContext.cs | 10 ++-------- .../Implementation/DisplayHelper.cs | 7 ++----- .../Implementation/DisplayHelperFactory.cs | 4 +--- .../Speculation/DefaultShapeTableFactory.cs | 1 + .../Speculation/ShapeTable.cs | 1 + 15 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs b/src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs index 9a9dd9995..46051cba2 100644 --- a/src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs +++ b/src/Orchard.Tests/DisplayManagement/ShapeFactoryTests.cs @@ -5,6 +5,7 @@ using System.Text; using Autofac; using NUnit.Framework; using Orchard.DisplayManagement; +using Orchard.DisplayManagement.Implementation; using Orchard.DisplayManagement.Shapes; namespace Orchard.Tests.DisplayManagement { diff --git a/src/Orchard.Tests/DisplayManagement/SubsystemTests.cs b/src/Orchard.Tests/DisplayManagement/SubsystemTests.cs index 8bae3877d..c898bf87d 100644 --- a/src/Orchard.Tests/DisplayManagement/SubsystemTests.cs +++ b/src/Orchard.Tests/DisplayManagement/SubsystemTests.cs @@ -8,7 +8,6 @@ using Autofac; using NUnit.Framework; using Orchard.DisplayManagement; using Orchard.DisplayManagement.Implementation; -using Orchard.DisplayManagement.Secondary; using Orchard.DisplayManagement.Shapes; namespace Orchard.Tests.DisplayManagement { diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs b/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs index f510ff119..df1e45ac1 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Controllers/HomeController.cs @@ -20,10 +20,10 @@ namespace Orchard.DevTools.Controllers { public HomeController(INotifier notifier, IShapeHelperFactory shapeHelperFactory) { _notifier = notifier; T = NullLocalizer.Instance; - New = shapeHelperFactory.CreateHelper(); + Shape = shapeHelperFactory.CreateHelper(); } - dynamic New { get; set; } + dynamic Shape { get; set; } public Localizer T { get; set; } @@ -58,18 +58,18 @@ namespace Orchard.DevTools.Controllers { public ActionResult UsingShapes() { - ViewModel.Page = New.Page() - .Main(New.Zone(typeof (Array), Name: "Main")) - .Messages(New.Zone(typeof (Array), Name: "Messages")) - .Sidebar(New.Zone(typeof (Array), Name: "Sidebar")); + ViewModel.Page = Shape.Page() + .Main(Shape.Zone(typeof (Array), Name: "Main")) + .Messages(Shape.Zone(typeof (Array), Name: "Messages")) + .Sidebar(Shape.Zone(typeof (Array), Name: "Sidebar")); - ViewModel.Page.Add("Messages:5", New.Message(Content: T("This is a test"), Severity: "Really bad!!!")); + //ViewModel.Page.Add("Messages:5", New.Message(Content: T("This is a test"), Severity: "Really bad!!!")); ViewModel.Page.Messages.Add( - New.Message(Content: T("This is a test"), Severity: "Really bad!!!")); + Shape.Message(Content: T("This is a test"), Severity: "Really bad!!!")); - var model = New.Message( - Content: New.Explosion(Height: 100, Width: 200), + var model = Shape.Message( + Content: Shape.Explosion(Height: 100, Width: 200), Severity: "Meh"); ViewModel.Page.Messages.Add(new HtmlString("
abuse
")); diff --git a/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs b/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs index 9a9063318..5bc4d1c5e 100644 --- a/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs +++ b/src/Orchard.Web/Modules/Orchard.DevTools/Shapes.cs @@ -24,15 +24,16 @@ namespace Orchard.DevTools { tag.GenerateId("zone-" + Shape.Name); tag.AddCssClass("zone-" + Shape.Name); tag.AddCssClass("zone"); - tag.InnerHtml = Smash(DisplayAll(Display, Shape)).ToString(); + tag.InnerHtml = Combine(DisplayAll(Display, Shape).ToArray()).ToString(); return new HtmlString(tag.ToString()); } - + public IHtmlString Message(dynamic Display, object Content, string Severity) { return Display(new HtmlString("

"), Severity ?? "Neutral", ": ", Content, new HtmlString("

")); } - private static IHtmlString Smash(IEnumerable contents) { + + static IHtmlString Combine(IEnumerable contents) { return new HtmlString(contents.Aggregate("", (a, b) => a + b)); } diff --git a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs index b017a90f1..1eb5f213c 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/SetupMode.cs @@ -13,7 +13,6 @@ using Orchard.Data.Providers; using Orchard.Data.Migration; using Orchard.DisplayManagement; using Orchard.DisplayManagement.Implementation; -using Orchard.DisplayManagement.Secondary; using Orchard.DisplayManagement.Shapes; using Orchard.Environment.Extensions; using Orchard.Localization; diff --git a/src/Orchard/DisplayManagement/IDisplayHelperFactory.cs b/src/Orchard/DisplayManagement/IDisplayHelperFactory.cs index 00d10f904..c2ac7a631 100644 --- a/src/Orchard/DisplayManagement/IDisplayHelperFactory.cs +++ b/src/Orchard/DisplayManagement/IDisplayHelperFactory.cs @@ -1,5 +1,4 @@ -using System.Runtime.CompilerServices; -using System.Web.Mvc; +using System.Web.Mvc; namespace Orchard.DisplayManagement { /// diff --git a/src/Orchard/DisplayManagement/IShape.cs b/src/Orchard/DisplayManagement/IShape.cs index 8b19cf297..d6ee8dcc4 100644 --- a/src/Orchard/DisplayManagement/IShape.cs +++ b/src/Orchard/DisplayManagement/IShape.cs @@ -1,7 +1,4 @@ -using System.Runtime.CompilerServices; -using Orchard.DisplayManagement.Shapes; - -namespace Orchard.DisplayManagement { +namespace Orchard.DisplayManagement { /// /// Interface present on dynamic shapes. /// May be used to access attributes in a strongly typed fashion. diff --git a/src/Orchard/DisplayManagement/IShapeFactory.cs b/src/Orchard/DisplayManagement/IShapeFactory.cs index 2383544b3..acb725ee7 100644 --- a/src/Orchard/DisplayManagement/IShapeFactory.cs +++ b/src/Orchard/DisplayManagement/IShapeFactory.cs @@ -1,5 +1,4 @@ using ClaySharp; -using Orchard.DisplayManagement.Shapes; namespace Orchard.DisplayManagement { /// diff --git a/src/Orchard/DisplayManagement/Implementation/DefaultDisplayManager.cs b/src/Orchard/DisplayManagement/Implementation/DefaultDisplayManager.cs index 440b9926d..79c6f8422 100644 --- a/src/Orchard/DisplayManagement/Implementation/DefaultDisplayManager.cs +++ b/src/Orchard/DisplayManagement/Implementation/DefaultDisplayManager.cs @@ -3,21 +3,20 @@ using System.Dynamic; using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Web; -using System.Web.Mvc; using Microsoft.CSharp.RuntimeBinder; -using Orchard.DisplayManagement.Implementation; using Orchard.DisplayManagement.Shapes; using Orchard.Localization; -namespace Orchard.DisplayManagement.Secondary { +namespace Orchard.DisplayManagement.Implementation { public class DefaultDisplayManager : IDisplayManager { private readonly IShapeTableFactory _shapeTableFactory; - private static CallSite> _convertAsShapeCallsite = CallSite>.Create( + // this need to be Shape instead of IShape - cast to interface throws error on clr types like HtmlString + private static readonly CallSite> _convertAsShapeCallsite = CallSite>.Create( new ForgivingConvertBinder( (ConvertBinder)Binder.Convert( - CSharpBinderFlags.ConvertExplicit | CSharpBinderFlags.CheckedContext, - typeof(IShape), + CSharpBinderFlags.ConvertExplicit, + typeof(Shape), null/*typeof(DefaultDisplayManager)*/))); public DefaultDisplayManager(IShapeTableFactory shapeTableFactory) { @@ -41,10 +40,13 @@ namespace Orchard.DisplayManagement.Secondary { return CoerceHtmlString(context.Value); var shapeTable = _shapeTableFactory.CreateShapeTable(); + //preproc loop / event (alter shape, swapping type) + ShapeTable.Entry entry; if (shapeTable.Entries.TryGetValue(shapeAttributes.Type, out entry)) { return Process(entry, shape, context); } + //postproc / content html alteration/wrapping/etc throw new OrchardException(T("Shape type {0} not found", shapeAttributes.Type)); } diff --git a/src/Orchard/DisplayManagement/Implementation/DefaultShapeFactory.cs b/src/Orchard/DisplayManagement/Implementation/DefaultShapeFactory.cs index 6cd78d1bf..c82f3b620 100644 --- a/src/Orchard/DisplayManagement/Implementation/DefaultShapeFactory.cs +++ b/src/Orchard/DisplayManagement/Implementation/DefaultShapeFactory.cs @@ -1,8 +1,9 @@ using System; using System.Linq; using ClaySharp; +using Orchard.DisplayManagement.Shapes; -namespace Orchard.DisplayManagement.Shapes { +namespace Orchard.DisplayManagement.Implementation { public class DefaultShapeFactory : IShapeFactory { public IShape Create(string shapeType, INamedEnumerable parameters) { diff --git a/src/Orchard/DisplayManagement/Implementation/DisplayContext.cs b/src/Orchard/DisplayManagement/Implementation/DisplayContext.cs index 655efdcc0..398b3c0ae 100644 --- a/src/Orchard/DisplayManagement/Implementation/DisplayContext.cs +++ b/src/Orchard/DisplayManagement/Implementation/DisplayContext.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Web.Mvc; -using Orchard.DisplayManagement.Shapes; +using System.Web.Mvc; -namespace Orchard.DisplayManagement { +namespace Orchard.DisplayManagement.Implementation { public class DisplayContext { public DisplayHelper Display { get; set; } public ViewContext ViewContext { get; set; } diff --git a/src/Orchard/DisplayManagement/Implementation/DisplayHelper.cs b/src/Orchard/DisplayManagement/Implementation/DisplayHelper.cs index 8f94b7733..78f3b9547 100644 --- a/src/Orchard/DisplayManagement/Implementation/DisplayHelper.cs +++ b/src/Orchard/DisplayManagement/Implementation/DisplayHelper.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ClaySharp; -using Orchard.DisplayManagement.Implementation; -using Orchard.DisplayManagement.Shapes; -namespace Orchard.DisplayManagement { +namespace Orchard.DisplayManagement.Implementation { /// /// Refactor: I this doesn't really need to exist, does it? diff --git a/src/Orchard/DisplayManagement/Implementation/DisplayHelperFactory.cs b/src/Orchard/DisplayManagement/Implementation/DisplayHelperFactory.cs index 5936aefd9..274a9adea 100644 --- a/src/Orchard/DisplayManagement/Implementation/DisplayHelperFactory.cs +++ b/src/Orchard/DisplayManagement/Implementation/DisplayHelperFactory.cs @@ -1,10 +1,8 @@ using System; using System.Web.Mvc; using ClaySharp; -using Orchard.DisplayManagement.Implementation; -using Orchard.DisplayManagement.Shapes; -namespace Orchard.DisplayManagement { +namespace Orchard.DisplayManagement.Implementation { public class DisplayHelperFactory : IDisplayHelperFactory { static private readonly DisplayHelperBehavior[] _behaviors = new[] { new DisplayHelperBehavior() }; private readonly IDisplayManager _displayManager; diff --git a/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs b/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs index 0faabbab7..559bdfda9 100644 --- a/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs +++ b/src/Orchard/DisplayManagement/Speculation/DefaultShapeTableFactory.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Web; using Microsoft.CSharp.RuntimeBinder; +using Orchard.DisplayManagement.Implementation; using Binder = Microsoft.CSharp.RuntimeBinder.Binder; namespace Orchard.DisplayManagement { diff --git a/src/Orchard/DisplayManagement/Speculation/ShapeTable.cs b/src/Orchard/DisplayManagement/Speculation/ShapeTable.cs index f55b2ad2c..6e7bbd9e4 100644 --- a/src/Orchard/DisplayManagement/Speculation/ShapeTable.cs +++ b/src/Orchard/DisplayManagement/Speculation/ShapeTable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Web; +using Orchard.DisplayManagement.Implementation; namespace Orchard.DisplayManagement { public class ShapeTable {