/// <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.IsTestEnvironment)
                    {
                        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");
        }
        internal static void HandleNew(string consoleId, string elementProviderName, string serializedEntityToken, FlowToken flowToken, FlowUiDefinitionBase uiDefinition)
        {
            ActionResultResponseType actionViewType = uiDefinition.UiContainerType.ActionResultResponseType;

            if (actionViewType != ActionResultResponseType.None)
            {
                FlowHandle flowHandle = new FlowHandle(flowToken);
                string serializedFlowHandle = flowHandle.Serialize();
                string viewId = MakeViewId(serializedFlowHandle);

                ViewType viewType;
                switch (actionViewType)
                {
                    case ActionResultResponseType.OpenDocument:
                        viewType = ViewType.Main;
                        break;
                    case ActionResultResponseType.OpenModalDialog:
                        viewType = ViewType.ModalDialog;
                        break;
                    default:
                        throw new Exception("unknown action response type");
                }

                string url = string.Format("{0}?consoleId={1}&flowHandle={2}&elementProvider={3}",
                    UrlUtils.ResolveAdminUrl("content/flow/FlowUi.aspx"),
                    consoleId,
                    HttpUtility.UrlEncode(serializedFlowHandle),
                    HttpUtility.UrlEncode(elementProviderName));

                OpenViewMessageQueueItem openView = new OpenViewMessageQueueItem
                {
                    ViewType = viewType,
                    EntityToken = serializedEntityToken,
                    FlowHandle = flowHandle.Serialize(),
                    Url = url,
                    ViewId = viewId
                };

                if (uiDefinition is VisualFlowUiDefinitionBase)
                {
                    VisualFlowUiDefinitionBase visualUiDefinition = (VisualFlowUiDefinitionBase)uiDefinition;
                    if (string.IsNullOrEmpty(visualUiDefinition.ContainerLabel) == false) openView.Label = visualUiDefinition.ContainerLabel;
                }

                ConsoleMessageQueueFacade.Enqueue(openView, consoleId);
            }
        }