public static IUiControl Render(
            string consoleId,
            string elementProviderName,
            FlowToken flowToken,
            FormFlowUiDefinition formFlowUiCommand,
            IFormChannelIdentifier channel,
            bool debugMode,
            FlowControllerServicesContainer servicesContainer)
        {
            FlowControllerServicesContainer formServicesContainer = new FlowControllerServicesContainer(servicesContainer);
            formServicesContainer.AddService(new FormFlowRenderingService());
            formServicesContainer.AddService(new FormFlowWebRenderingService());

            IFormMarkupProvider formMarkupProvider = formFlowUiCommand.MarkupProvider;
            IFormMarkupProvider customToolbarItemsMarkupProvider = formFlowUiCommand.CustomToolbarItemsMarkupProvider;
            Dictionary<string, object> innerFormBindings = formFlowUiCommand.BindingsProvider.GetBindings();
            Dictionary<IFormEventIdentifier, FormFlowEventHandler> eventHandlers = formFlowUiCommand.EventHandlers;
            Dictionary<string, List<ClientValidationRule>> bindingsValidationRules = formFlowUiCommand.BindingsValidationRules;

            FormTreeCompiler formCompiler = new FormTreeCompiler();
            IUiContainer renderingContainer = GetRenderingContainer(channel, formFlowUiCommand.UiContainerType);

            // Setting state related objects so the delegate below can access them "fresh"
            CurrentFormTreeCompiler = formCompiler;
            CurrentInnerFormBindings = innerFormBindings;
            CurrentControlContainer = (IWebUiContainer)renderingContainer;


            Dictionary<string, object> containerEventHandlerStubs = new Dictionary<string, object>();

            foreach (IFormEventIdentifier eventIdentifier in eventHandlers.Keys)
            {
                IFormEventIdentifier localScopeEventIdentifier = eventIdentifier;  // See: Local variable usage with anonymous methods within loop control structures

                EventHandler handlerStub = delegate(object sender, EventArgs e)
                {
                    try
                    {
                        BaseEventHandler(consoleId, elementProviderName, flowToken, formFlowUiCommand, servicesContainer, eventHandlers, localScopeEventIdentifier, formServicesContainer);
                    }
                    catch (Exception ex)
                    {
                        formServicesContainer.GetService<IManagementConsoleMessageService>().ShowLogEntry(typeof(FormFlowUiDefinitionRenderer), ex);
                        throw;
                    }
                };

                containerEventHandlerStubs.Add(eventIdentifier.BindingName, handlerStub);

                if (innerFormBindings.ContainsKey(eventIdentifier.BindingName))
                {
                    innerFormBindings.Remove(eventIdentifier.BindingName);
                }

                innerFormBindings.Add(eventIdentifier.BindingName, handlerStub);
            }

            XDocument document;

            using (XmlReader formMarkupReader = formMarkupProvider.GetReader())
            {
                document = XDocument.Load(formMarkupReader);
                formMarkupReader.Close();
            }

            formCompiler.Compile(document, channel, innerFormBindings, debugMode, "", bindingsValidationRules);

            IUiControl innerForm = formCompiler.UiControl;

            IUiControl customToolbarItems = null;
            if (customToolbarItemsMarkupProvider != null)
            {
                FormTreeCompiler toolbarCompiler = new FormTreeCompiler();
                using (XmlReader formMarkupReader = customToolbarItemsMarkupProvider.GetReader())
                {
                    toolbarCompiler.Compile(formMarkupReader, channel, innerFormBindings, debugMode, bindingsValidationRules);
                }
                customToolbarItems = toolbarCompiler.UiControl;
            }

            CurrentControlTreeRoot = (IWebUiControl)innerForm;

            string label = formCompiler.Label;
            if(label.IsNullOrEmpty())
            {
                label = formFlowUiCommand.ContainerLabel ?? "";
            }

            string labelField = GetFormLabelField(document);
            ResourceHandle containerIcon = formCompiler.Icon;

            return renderingContainer.Render(formCompiler.UiControl, customToolbarItems, channel, containerEventHandlerStubs, label, labelField, containerIcon);
        }
Exemplo n.º 2
0
        private void ShowServerValidationErrors(FormTreeCompiler formTreeCompiler, Dictionary<string, Exception> serverValidationErrors)
        {
            foreach (var serverValidationError in serverValidationErrors)
            {
                string controlId = formTreeCompiler.GetBindingToClientIDMapping()[serverValidationError.Key];
                string message = StringResourceSystemFacade.ParseString(serverValidationError.Value.Message);

                plhErrors.Controls.Add(new FieldMessage(controlId, message));
            }
        }