/// <summary> /// Creates a screen from the given charts, reports and forms. /// </summary> /// <param name="alias">The alias given to the screen.</param> /// <param name="name">The name given to the screen.</param> /// <param name="description">The description given to the screen.</param> /// <param name="charts">The charts to add.</param> /// <param name="reports">The reports to add.</param> /// <param name="forms">The form to add.</param> /// <param name="containers">A lookup to all the container controls that were created.</param> /// <returns>The created and saved screen entity.</returns> public static StructureControlOnForm CreateScreen(string alias, string name, string description, IList <Chart> charts, IList <Report> reports, IList <CustomEditForm> forms, out Dictionary <string, ControlOnForm> containers) { containers = new Dictionary <string, ControlOnForm>(); var screen = Entity.Create("console:screen").As <StructureControlOnForm>(); screen.Alias = alias; screen.Name = name; screen.Description = description; var containedControls = new List <ControlOnForm>(); foreach (var chart in charts) { if (chart == null) { continue; } var idx = charts.IndexOf(chart); var controlName = "Chart" + idx; var chartComponent = Entity.Create("console:chartRenderControl").AsWritable <ControlOnForm>(); chartComponent.Alias = alias + controlName; chartComponent.SetRelationships("console:renderingVerticalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeFifty") }, Direction.Forward); chartComponent.SetRelationships("console:renderingHorizontalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeSpring") }, Direction.Forward); chartComponent.SetRelationships("console:chartToRender", new EntityRelationship <IEntity>(chart).ToEntityRelationshipCollection(), Direction.Forward); containedControls.Add(chartComponent); containers.Add(controlName, chartComponent); } foreach (var report in reports) { if (report == null) { continue; } var idx = reports.IndexOf(report); var controlName = "Report" + idx; var reportComponent = Entity.Create("console:reportRenderControl").AsWritable <ControlOnForm>(); reportComponent.Alias = alias + controlName; reportComponent.SetRelationships("console:renderingVerticalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeFifty") }, Direction.Forward); reportComponent.SetRelationships("console:renderingHorizontalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeSpring") }, Direction.Forward); reportComponent.SetRelationships("console:reportToRender", new EntityRelationship <IEntity>(report).ToEntityRelationshipCollection(), Direction.Forward); if (reports.Count > idx) { var contextProvider = containedControls.FirstOrDefault(c => c.Alias == (alias + "Chart" + idx)); if (contextProvider != null) { reportComponent.SetRelationships("console:receiveContextFrom", new EntityRelationship <IEntity>(contextProvider).ToEntityRelationshipCollection(), Direction.Forward); } } containedControls.Add(reportComponent); containers.Add(controlName, reportComponent); } foreach (var form in forms) { if (form == null) { continue; } var idx = forms.IndexOf(form); var controlName = "Form" + idx; var formComponent = Entity.Create("console:formRenderControl").AsWritable <ControlOnForm>(); formComponent.Alias = alias + controlName; formComponent.SetRelationships("console:renderingVerticalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeFifty") }, Direction.Forward); formComponent.SetRelationships("console:renderingHorizontalResizeMode", new EntityRelationshipCollection <IEntity> { Entity.Get <IEntity>("console:resizeSpring") }, Direction.Forward); formComponent.SetRelationships("console:formToRender", new EntityRelationship <IEntity>(form).ToEntityRelationshipCollection(), Direction.Forward); if (reports.Count > idx) { var contextProvider = containedControls.FirstOrDefault(c => c.Alias == (alias + "Report" + idx)); if (contextProvider != null) { formComponent.SetRelationships("console:receiveContextFrom", new EntityRelationship <IEntity>(contextProvider).ToEntityRelationshipCollection(), Direction.Forward); } } containedControls.Add(formComponent); containers.Add(controlName, formComponent); } containedControls.Reverse(); screen.ContainedControlsOnForm.AddRange(new EntityRelationshipCollection <ControlOnForm>(containedControls)); screen.Save(); Entity.Save(containedControls); return(screen); }