/// <exclude />
        public static Control GetFlowUi(FlowHandle flowHandle, string elementProviderName, string consoleId, out string uiContainerName)
        {
            uiContainerName = null;

            try
            {
                Control webControl = null;
                string  viewId     = ViewTransitionHelper.MakeViewId(flowHandle.Serialize());

                FlowControllerServicesContainer flowServicesContainer = new FlowControllerServicesContainer();
                flowServicesContainer.AddService(new ActionExecutionService(elementProviderName, consoleId));
                flowServicesContainer.AddService(new ManagementConsoleMessageService(consoleId, viewId));
                flowServicesContainer.AddService(new ElementDataExchangeService(elementProviderName));

                FlowToken         flowToken        = flowHandle.FlowToken;
                IFlowUiDefinition flowUiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken, flowServicesContainer);

                var formFlowUiDefinition = flowUiDefinition as FormFlowUiDefinition;
                if (formFlowUiDefinition != null)
                {
                    uiContainerName = formFlowUiDefinition.UiContainerType.ContainerName;

                    IUiControl    uiForm  = FormFlowUiDefinitionRenderer.Render(consoleId, elementProviderName, flowToken, formFlowUiDefinition, WebManagementChannel.Identifier, false, flowServicesContainer);
                    IWebUiControl webForm = (IWebUiControl)uiForm;
                    webControl = webForm.BuildWebControl();

                    if (string.IsNullOrEmpty(webControl.ID))
                    {
                        webControl.ID = "FlowUI";
                    }

                    if (RuntimeInformation.TestAutomationEnabled)
                    {
                        var testAutomationLocatorInformation = formFlowUiDefinition.MarkupProvider as ITestAutomationLocatorInformation;
                        if (testAutomationLocatorInformation != null)
                        {
                            var htmlform = webControl.Controls.OfType <HtmlForm>().FirstOrDefault();
                            if (htmlform != null)
                            {
                                htmlform.Attributes.Add("data-qa", testAutomationLocatorInformation.TestAutomationLocator);
                            }
                        }
                    }
                }

                return(webControl);
            }
            catch (Exception ex)
            {
                ErrorServices.DocumentAdministrativeError(ex);
                ErrorServices.RedirectUserToErrorPage(uiContainerName, ex);
            }

            return(new LiteralControl("ERROR"));
        }
        public void Execute(EntityToken entityToken, ActionToken actionToken, TaskManagerEvent taskManagerEvent)
        {
            var flowServicesContainer = new FlowControllerServicesContainer(
                new ManagementConsoleMessageService(this.ConsoleId),
                new ElementDataExchangeService(this.ElementProviderName),
                this
                );

            FlowToken flowToken = ActionExecutorFacade.Execute(entityToken, actionToken, flowServicesContainer, taskManagerEvent);

            IFlowUiDefinition uiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken, flowServicesContainer);

            if (uiDefinition is FlowUiDefinitionBase flowUiDefinition)
            {
                string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken, true);
                ViewTransitionHelper.HandleNew(this.ConsoleId, this.ElementProviderName, serializedEntityToken, flowToken, flowUiDefinition);
            }
        }
        /// <exclude />
        public static IFlowUiDefinition GetCurrentUiDefinition(FlowToken flowToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            if (flowToken == null)
            {
                throw new ArgumentNullException("flowToken");
            }

            IFlowController flowExecutor = FlowControllerCache.GetFlowController(flowToken, flowControllerServicesContainer);

            IFlowUiDefinition flowResult = flowExecutor.GetCurrentUiDefinition(flowToken);

            if (flowResult == null)
            {
                flowResult = new NullFlowUiDefinition();
            }

            return(flowResult);
        }
Exemplo n.º 4
0
        public static void ExecuteElementAction(ElementHandle elementHandle, ActionHandle actionHandle, string consoleId)
        {
            var flowServicesContainer = new FlowControllerServicesContainer(
                new ManagementConsoleMessageService(consoleId),
                new ElementDataExchangeService(elementHandle.ProviderName),
                new ActionExecutionService(elementHandle.ProviderName, consoleId),
                new ElementInformationService(elementHandle)
                );

            FlowToken flowToken = ActionExecutorFacade.Execute(elementHandle.EntityToken, actionHandle.ActionToken, flowServicesContainer);

            IFlowUiDefinition uiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken, flowServicesContainer);

            if (uiDefinition is FlowUiDefinitionBase flowUiDefinition)
            {
                string serializedEntityToken = EntityTokenSerializer.Serialize(elementHandle.EntityToken, true);
                ViewTransitionHelper.HandleNew(consoleId, elementHandle.ProviderName, serializedEntityToken, flowToken, flowUiDefinition);
            }
        }
Exemplo n.º 5
0
        public void Execute(EntityToken entityToken, ActionToken actionToken, TaskManagerEvent taskManagerEvent)
        {
            FlowControllerServicesContainer flowServicesContainer = new FlowControllerServicesContainer();

            flowServicesContainer.AddService(new ManagementConsoleMessageService(this.ConsoleId));
            flowServicesContainer.AddService(new ElementDataExchangeService(this.ElementProviderName));
            flowServicesContainer.AddService(this);

            FlowToken flowToken = ActionExecutorFacade.Execute(entityToken, actionToken, flowServicesContainer, taskManagerEvent);

            IFlowUiDefinition uiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken, flowServicesContainer);

            ActionResult result = new ActionResult();

            if (typeof(FlowUiDefinitionBase).IsAssignableFrom(uiDefinition.GetType()))
            {
                string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken, true);
                ViewTransitionHelper.HandleNew(this.ConsoleId, this.ElementProviderName, serializedEntityToken, flowToken, (FlowUiDefinitionBase)uiDefinition);
            }
        }
        private static void BaseEventHandler(string consoleId,
                                             string elementProviderName,
                                             FlowToken flowToken,
                                             FormFlowUiDefinition formFlowUiCommand,
                                             FlowControllerServicesContainer servicesContainer,
                                             Dictionary <IFormEventIdentifier, FormFlowEventHandler> eventHandlers,
                                             IFormEventIdentifier localScopeEventIdentifier,
                                             FlowControllerServicesContainer formServicesContainer)
        {
            FormTreeCompiler            activeFormTreeCompiler  = CurrentFormTreeCompiler;
            Dictionary <string, object> activeInnerFormBindings = CurrentInnerFormBindings;

            FormFlowEventHandler           handler       = eventHandlers[localScopeEventIdentifier];
            Dictionary <string, Exception> bindingErrors = activeFormTreeCompiler.SaveAndValidateControlProperties();

            FormTreeCompiler activeCustomToolbarFormTreeCompiler = CurrentCustomToolbarFormTreeCompiler;

            if (activeCustomToolbarFormTreeCompiler != null)
            {
                var toolbarBindingErrors = activeCustomToolbarFormTreeCompiler.SaveAndValidateControlProperties();
                foreach (var pair in toolbarBindingErrors)
                {
                    bindingErrors.Add(pair.Key, pair.Value);
                }
            }

            formServicesContainer.AddService(new BindingValidationService(bindingErrors));

            handler.Invoke(flowToken, activeInnerFormBindings, formServicesContainer);

            if (formServicesContainer.GetService <IManagementConsoleMessageService>().CloseCurrentViewRequested)
            {
                ViewTransitionHelper.HandleCloseCurrentView(formFlowUiCommand.UiContainerType);
                return;
            }

            var  formFlowService   = formServicesContainer.GetService <IFormFlowRenderingService>();
            bool replacePageOutput = (formServicesContainer.GetService <IFormFlowWebRenderingService>().NewPageOutput != null);

            bool rerenderView = formFlowService.RerenderViewRequested;

            if (formFlowService.BindingPathedMessages != null)
            {
                ShowFieldMessages(CurrentControlTreeRoot, formFlowService.BindingPathedMessages, CurrentControlContainer,
                                  servicesContainer);
            }

            List <bool> boolCounterList = new List <bool> {
                replacePageOutput, rerenderView
            };

            if (boolCounterList.Count(f => f) > 1)
            {
                StringBuilder sb = new StringBuilder("Flow returned conflicting directives for post handling:\n");
                if (replacePageOutput)
                {
                    sb.AppendLine(" - Replace page output with new web control.");
                }
                if (rerenderView)
                {
                    sb.AppendLine(" - Rerender view.");
                }

                throw new InvalidOperationException(sb.ToString());
            }

            if (rerenderView)
            {
                Log.LogVerbose("FormFlowRendering", "Re-render requested");
                IFlowUiDefinition newFlowUiDefinition = FlowControllerFacade.GetCurrentUiDefinition(flowToken,
                                                                                                    servicesContainer);
                if (!(newFlowUiDefinition is FlowUiDefinitionBase))
                {
                    throw new NotImplementedException("Unable to handle transitions to ui definition of type " +
                                                      newFlowUiDefinition.GetType());
                }
                ViewTransitionHelper.HandleRerender(consoleId, elementProviderName, flowToken, formFlowUiCommand,
                                                    (FlowUiDefinitionBase)newFlowUiDefinition, servicesContainer);
            }

            if (replacePageOutput)
            {
                Log.LogVerbose("FormFlowRendering", "Replace pageoutput requested");
                IFormFlowWebRenderingService webRenderingService =
                    formServicesContainer.GetService <IFormFlowWebRenderingService>();
                Control newPageOutput = webRenderingService.NewPageOutput;

                foreach (Control control in GetNestedControls(newPageOutput).Where(f => f is ScriptManager).ToList())
                {
                    control.Parent.Controls.Remove(control);
                }

                Page currentPage = HttpContext.Current.Handler as Page;

                HtmlHead newHeadControl = GetNestedControls(newPageOutput).FirstOrDefault(f => f is HtmlHead) as HtmlHead;

                HtmlHead oldHeadControl = currentPage.Header;

                ControlCollection headContainer = null;
                bool headersHasToBeSwitched     = newHeadControl != null && oldHeadControl != null;
                if (headersHasToBeSwitched)
                {
                    headContainer = newHeadControl.Parent.Controls;
                    headContainer.Remove(newHeadControl);
                }

                currentPage.Controls.Clear();
                if (string.IsNullOrEmpty(webRenderingService.NewPageMimeType))
                {
                    currentPage.Response.ContentType = "text/html";
                }
                else
                {
                    currentPage.Response.ContentType = webRenderingService.NewPageMimeType;
                }
                currentPage.Controls.Add(newPageOutput);

                if (headersHasToBeSwitched)
                {
                    oldHeadControl.Controls.Clear();
                    oldHeadControl.InnerHtml = "";
                    oldHeadControl.InnerText = "";
                    if (newHeadControl.ID != null)
                    {
                        oldHeadControl.ID = newHeadControl.ID;
                    }
                    oldHeadControl.Title = newHeadControl.Title;

                    headContainer.AddAt(0, oldHeadControl);

                    foreach (Control c in newHeadControl.Controls.Cast <Control>().ToList())
                    {
                        oldHeadControl.Controls.Add(c);
                    }
                }
            }
        }