private Control GetViewModel(DesignMediaType designMediaType) { var controlIdParam = this.GetControlIdParam(); if (!controlIdParam.HasValue) { return(null); } var controlId = controlIdParam.Value; var manager = this.GetControlManager(designMediaType); var viewModel = manager.LoadControl(manager.GetControl <ObjectData>(controlId)); var widgetProxy = viewModel as MvcWidgetProxy; if (widgetProxy != null) { if (widgetProxy.Controller.RouteData == null) { widgetProxy.Controller.ControllerContext = new ControllerContext(new RequestContext(this.HttpContext, new RouteData()), widgetProxy.Controller); } widgetProxy.Controller.RouteData.Values["controller"] = widgetProxy.WidgetName; } return(viewModel); }
private IControlManager GetControlManager(DesignMediaType designMediaType) { if (designMediaType == DesignMediaType.Form) { return(FormsManager.GetManager()); } else { return(PageManager.GetManager()); } }
private Control LoadControl(Guid controlId, DesignMediaType designMediaType) { if (controlId != Guid.Empty) { var manager = this.GetControlManager(designMediaType); var objectData = manager.GetControl <ObjectData>(controlId); var controlData = objectData as ControlData; if (controlData != null && !controlData.Caption.IsNullOrEmpty()) { this.Caption = controlData.Caption; } return(manager.LoadControl(objectData)); } else { return(null); } }
/// <summary> /// Gets the model of the designer. /// </summary> private IDesignerModel GetModel(string widgetName, Guid controlId, string moduleName = null, DesignMediaType designMediaType = DesignMediaType.Page) { var viewFilesMappgings = new Dictionary <string, string>(); var constructorParameters = new Dictionary <string, object> { { "views", this.GetPartialViews(ref viewFilesMappgings, moduleName) }, { "viewLocations", this.GetPartialViewLocations() }, { "widgetName", widgetName }, { "controlId", controlId }, { "preselectedView", this.Request != null ? this.Request["view"] : null }, { "viewFilesMappings", viewFilesMappgings }, { "mediaType", designMediaType } }; return(ControllerModelFactory.GetModel <IDesignerModel>(typeof(DesignerController), constructorParameters)); }
public DesignerModel(IEnumerable <string> views, IEnumerable <string> viewLocations, string widgetName, Guid controlId, string preselectedView, Dictionary <string, string> viewFilesMappings, DesignMediaType mediaType) { this.Caption = widgetName; var formatedViewsDictionary = this.GetViews(views, preselectedView); var viewConfigs = this.GetViewConfigs(formatedViewsDictionary, viewLocations, viewFilesMappings); if (string.IsNullOrEmpty(preselectedView)) { this.views = formatedViewsDictionary.Values.Where(v => !viewConfigs.Any(vc => vc.Key == v) || viewConfigs.Single(vc => vc.Key == v).Value.Hidden == false).ToArray(); viewConfigs = viewConfigs.Where(c => !c.Value.Hidden).ToList(); } else { this.views = formatedViewsDictionary.Values; } // If no configs have set priority and at least one config is generated - set its priority to 1. if (!viewConfigs.Any(c => c.Value.Priority != 0) && viewConfigs.Any(c => c.Value.IsGenerated)) { viewConfigs.FirstOrDefault(c => c.Value.IsGenerated).Value.Priority = 1; } this.PopulateDependencies(widgetName, viewConfigs); this.defaultView = viewConfigs.OrderByDescending(c => c.Value.Priority).Select(c => c.Key).FirstOrDefault(); this.Control = this.LoadControl(controlId, mediaType); }