public static void Render(WidgetDefinition widget, HttpContextBase context, TextWriter writer) { Require.NotNull(widget, "widget"); Require.NotNull(context, "context"); Require.NotNull(writer, "writer"); var page = new WidgetRenderingHostPage(); var control = WidgetControlLoader.Load(widget, page, true); page.Controls.Add(control); var widgetControl = control as WidgetControlBase; if (widgetControl == null) { var cachingControl = control as PartialCachingControl; if (cachingControl != null) { widgetControl = cachingControl.CachedControl as WidgetControlBase; } } if (widgetControl != null) { widgetControl.Widget = widget; widgetControl.IsInDesignMode = true; // TODO: Need also the current page info } context.Server.Execute(page, writer, true); }
public static Control Load(WidgetDefinition widget, Page hostingPage, bool loadInDesignMode) { Require.NotNull(widget, "widget"); Require.NotNull(hostingPage, "hostingPage"); Control control = null; if (loadInDesignMode) { if (File.Exists(HostingEnvironment.MapPath(widget.DesignerVirtualPath))) { control = hostingPage.LoadControl(widget.DesignerVirtualPath); } else { control = new DefaultWidgetControl(); } } else { control = hostingPage.LoadControl(widget.WidgetControlVirtualPath); } return control; }
private LocatedWidget ProcessStateItem(LocatedWidgetViewModel locatedWidgetModel, WidgetDefinition widget) { var zone = CurrentPage.Layout.FindZone(locatedWidgetModel.ZoneName); if (zone == null) throw new InvalidOperationException("Zone \"" + locatedWidgetModel.ZoneName + "\" was not found."); LocatedWidget locatedWidget = null; if (locatedWidgetModel.State == WidgetState.Added) { locatedWidget = CurrentPage.AddWidgetToZone(zone, widget, locatedWidgetModel.Order); } else if (locatedWidgetModel.State == WidgetState.Removed) { locatedWidget = CurrentPage.LocatedWidgets.FirstOrDefault(it => it.Id == locatedWidgetModel.Id); if (locatedWidget == null) throw new InvalidOperationException("Cannot find located widget with id: " + locatedWidgetModel.Id + "."); CurrentPage.LocatedWidgets.Remove(locatedWidget); } else if (locatedWidgetModel.State == WidgetState.Changed) { locatedWidget = CurrentPage.LocatedWidgets.FirstOrDefault(it => it.Id == locatedWidgetModel.Id); if (locatedWidget == null) throw new InvalidOperationException("Cannot find located widget with id: " + locatedWidgetModel.Id + "."); locatedWidget.ZoneName = zone.Name; locatedWidget.Order = locatedWidgetModel.Order; } if (locatedWidgetModel.State != WidgetState.Removed) { foreach (var attr in locatedWidgetModel.Attributes) { locatedWidget.Attributes.AddOrSet(attr.Key, attr.Value); } } return locatedWidget; }
public WidgetViewDefinition(WidgetDefinition widget) { Widget = widget; }