-
Notifications
You must be signed in to change notification settings - Fork 6
/
ShapeTranslate.cs
68 lines (55 loc) · 2.32 KB
/
ShapeTranslate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Orchard;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.DisplayManagement.Shapes;
using Morphous.Api.ViewModels;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Morphous.Api.DisplayManagement {
public class ShapeTranslate : ApiShapesBase, IShapeTranslate {
private readonly IDisplayHelperFactory _displayHelperFactory;
private readonly IWorkContextAccessor _workContextAccessor;
private readonly HttpContextBase _httpContextBase;
private readonly RequestContext _requestContext;
public ShapeTranslate(
IDisplayHelperFactory displayHelperFactory,
IWorkContextAccessor workContextAccessor,
HttpContextBase httpContextBase,
RequestContext requestContext) {
_displayHelperFactory = displayHelperFactory;
_workContextAccessor = workContextAccessor;
_httpContextBase = httpContextBase;
_requestContext = requestContext;
}
public object Display(Shape shape) {
return Display((object)shape);
}
public object Display(object shape) {
var viewContext = new ViewContext {
HttpContext = _httpContextBase,
RequestContext = _requestContext
};
viewContext.RouteData.DataTokens["IWorkContextAccessor"] = _workContextAccessor;
var display = _displayHelperFactory.CreateHelper(viewContext, new ViewDataContainer());
((DisplayHelper)display).ShapeExecute(shape);
return display.ViewDataContainer.Model.Properties;
}
public IEnumerable<object> Display(IEnumerable<object> shapes) {
return shapes.Select(s => Display(s));
}
public class ViewDataContainer : IViewDataContainer {
public ViewDataDictionary ViewData { get; set; }
public dynamic Model { get; set; }
public dynamic CurrentNode { get; set; }
public ViewDataContainer() {
Model = new ViewModelBuilder();
CurrentNode = Model;
ViewData = new ViewDataDictionary();
}
}
}
}