Пример #1
0
        public IUiControl Render(
            IUiControl innerForm, 
            IUiControl customToolbarItems, 
            IFormChannelIdentifier channel, 
            IDictionary<string, object> eventHandlerBindings, 
            string containerLabel, 
            string containerLabelField, 
            ResourceHandle containerIcon)
        {
            if (string.IsNullOrEmpty(_templateFormVirtualPath) == false)
            {
                WebEmbeddedFormUiControl document = new WebEmbeddedFormUiControl(channel);
                document.FormPath = _templateFormVirtualPath; // "/Composite/Templates/Document.xml";

                document.Bindings = new Dictionary<string, object>(eventHandlerBindings);
                document.Bindings.Add("Form", innerForm);
                if (customToolbarItems != null)
                {
                    document.Bindings.Add("CustomToolbarItems", customToolbarItems);
                }

                _webDocument = new TemplatedExecutionContainer(document, _templateUserControlType, containerLabel, containerLabelField, containerIcon);
            }
            else
            {
                _webDocument = new TemplatedExecutionContainer((IWebUiControl)innerForm, _templateUserControlType, containerLabel, containerLabelField, containerIcon);
            }

            return _webDocument;
        }
Пример #2
0
        public IUiControl Render(
            IUiControl innerForm,
            IUiControl customToolbarItems,
            IFormChannelIdentifier channel,
            IDictionary <string, object> eventHandlerBindings,
            string containerLabel,
            string containerLabelField,
            ResourceHandle containerIcon)
        {
            if (string.IsNullOrEmpty(_templateFormVirtualPath) == false)
            {
                WebEmbeddedFormUiControl document = new WebEmbeddedFormUiControl(channel);
                document.FormPath = _templateFormVirtualPath; // "/Composite/Templates/Document.xml";

                document.Bindings = new Dictionary <string, object>(eventHandlerBindings);
                document.Bindings.Add("Form", innerForm);
                if (customToolbarItems != null)
                {
                    document.Bindings.Add("CustomToolbarItems", customToolbarItems);
                }

                _webDocument = new TemplatedExecutionContainer(document, _templateUserControlType, containerLabel, containerLabelField, containerIcon);
            }
            else
            {
                _webDocument = new TemplatedExecutionContainer((IWebUiControl)innerForm, _templateUserControlType, containerLabel, containerLabelField, containerIcon);
            }

            return(_webDocument);
        }
        public static IUiControl CreateControl(IFormChannelIdentifier channel, string namespaceName, string name)
        {
            string compositeName = string.Format("{0}->{1}->{2}", channel.ChannelName, namespaceName, name);

            if (false == _resourceLocker.Resources.FactoryCache.ContainsKey(compositeName))
            {
                try
                {
                    IUiControlFactory uiControlFactory = _resourceLocker.Resources.Factory.Create(compositeName);

                    using (_resourceLocker.Locker)
                    {
                        if (_resourceLocker.Resources.FactoryCache.ContainsKey(compositeName) == false)
                        {
                            _resourceLocker.Resources.FactoryCache.Add(compositeName, uiControlFactory);
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    HandleControlConfigurationError(ex, compositeName);
                }
                catch (ConfigurationErrorsException ex)
                {
                    HandleControlConfigurationError(ex, compositeName);
                }
            }


            IUiControlFactory factory = _resourceLocker.Resources.FactoryCache[compositeName];
            IUiControl        control = factory.CreateControl();

            control.UiControlChannel = channel;
            return(control);
        }
        /// <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"));
        }
Пример #5
0
        public void ExtractUiArtifacts(CompileTreeNode node, out IUiControl uiControl, out string label, out string iconhandle)
        {
            foreach (PropertyCompileTreeNode n in node.DefaultProperties)
            {
                if (n.Value is LayoutProducer)
                {
                    LayoutProducer lp = (n.Value as LayoutProducer);
                    uiControl  = lp.UiControl;
                    label      = lp.label;
                    iconhandle = lp.iconhandle;

                    return;
                }
            }

            throw new FormCompileException("No layout defined in the source file", node.XmlSourceNodeInformation);
        }
Пример #6
0
        public void ExtractUiArtifacts(CompileTreeNode node, out IUiControl uiControl, out string label, out string iconhandle )
        {
            foreach (PropertyCompileTreeNode n in node.DefaultProperties)
            {
                if (n.Value is LayoutProducer)
                {
                    LayoutProducer lp = (n.Value as LayoutProducer);
                    uiControl = lp.UiControl;
                    label = lp.label;
                    iconhandle = lp.iconhandle;

                    return;
                }
            }

            throw new FormCompileException("No layout defined in the source file", node.XmlSourceNodeInformation);
        }
Пример #7
0
        private static void SetPropertyOnProducer(ElementCompileTreeNode element, string propertyName, PropertyCompileTreeNode property, CompileContext compileContext)
        {
            SetPropertyOnProducer2(element, propertyName, property, compileContext);

            IUiControl uiControl = element.Producer as IUiControl;

            if (uiControl != null && property.ClientValidationRules != null)
            {
                if (uiControl.ClientValidationRules != null && uiControl.ClientValidationRules.Count > 0)
                {
                    uiControl.ClientValidationRules.AddRange(property.ClientValidationRules);
                }
                else
                {
                    uiControl.ClientValidationRules = property.ClientValidationRules;
                }
            }
        }
Пример #8
0
        public static int CalculateStartX(IUiControl control, int parentWidth)
        {
            int startX = 0;

            switch (control.HorizontalPosition)
            {
                case UIHorizontalPosition.Left:
                    startX = 0;
                    break;
                case UIHorizontalPosition.Center:
                    startX = (parentWidth / 2) - (control.Width / 2);
                    break;
                case UIHorizontalPosition.Right:
                    startX = parentWidth - control.Width;
                    break;
            }
            return startX;
        }
Пример #9
0
        public static int CalculateStartY(IUiControl control, int parentHeight)
        {
            int startY = 0;

            switch (control.VerticalPosition)
            {
                case UIVerticalPosition.Top:
                    startY = 0;
                    break;
                case UIVerticalPosition.Middle:
                    startY = (parentHeight / 2) - (control.Height / 2);
                    break;
                case UIVerticalPosition.Bottom:
                    startY = parentHeight - control.Height;
                    break;
            }

            return startY;
        }
Пример #10
0
        private static void EvalutePropertyBinding(ElementCompileTreeNode element, PropertyCompileTreeNode property, CompileContext compileContext, MethodInfo sourceGetMethodInfo, string bindSourceName, string[] propertyPath, bool makeBinding)
        {
            if (makeBinding)
            {
                bool?optional = ((BindingsProducer)compileContext.BindingsProducer).GetOptionalValueByName(bindSourceName);
                if (!optional.HasValue)
                {
                    throw new FormCompileException(string.Format("{1} binds to an undeclared binding name '{0}'. All binding names must be declared in /cms:formdefinition/cms:bindings", bindSourceName, element.XmlSourceNodeInformation.XPath), element, property);
                }
                if (optional.Value)
                {
                    throw new FormCompileException(string.Format("Property binding to the optional object named '{0}' is not allowed", bindSourceName), element, property);
                }

                if (compileContext.IsUniqueSourceObjectBinding(bindSourceName))
                {
                    throw new FormCompileException(string.Format("{0} binds to {1} which is already object bound. Property bindings to a source object which is object bound is not allowed.", element.XmlSourceNodeInformation.XPath, bindSourceName), element, property);
                }

                var uniquePropertyName = new StringBuilder();
                for (int i = 0; i < propertyPath.Length; ++i)
                {
                    uniquePropertyName.Append(propertyPath[i]);
                }
                if (!compileContext.RegisterUniqueSourcePropertyBinding(bindSourceName, uniquePropertyName.ToString()))
                {
                    throw new FormCompileException(string.Format("{0} binds to {1} which is already bound. Multiple bindings to the same source object property is not allowed.", element.XmlSourceNodeInformation.XPath, uniquePropertyName), element, property);
                }
            }


            object     value, propertyOwner;
            MethodInfo getMethodInfo, setMethodInfo;
            string     propertyName;
            Type       type;

            ResolvePropertyBinding(element, property, compileContext, bindSourceName, propertyPath,
                                   out value, out type, out propertyOwner, out propertyName, out getMethodInfo, out setMethodInfo);

            if (makeBinding)
            {
                if (setMethodInfo == null)
                {
                    throw new FormCompileException(string.Format("The type {0} does not have a set property named {1}", type, propertyName), element, property);
                }

                compileContext.Rebindings.Add(new CompileContext.PropertyRebinding(
                                                  element.Producer,
                                                  sourceGetMethodInfo,
                                                  propertyOwner,
                                                  setMethodInfo,
                                                  getMethodInfo.ReturnType,
                                                  bindSourceName,
                                                  propertyName));
            }

            property.Value = value;

            IUiControl uiControl = element.Producer as IUiControl;

            if (uiControl != null)
            {
                uiControl.ClientValidationRules = ClientValidationRuleFacade.GetClientValidationRules(propertyOwner, propertyName);
            }
        }
Пример #11
0
 /// <summary>
 /// Creates new UIPanel and sets IUIControl given by constructor
 /// </summary>
 /// <param name="control"></param>
 public UIPanel(IUiControl control)
 {
     setContainingPanel(control);
 }
Пример #12
0
 /// <summary>
 /// Sets or replaces UIControl in the Panel. For example: VerticalContainer or an Image
 /// </summary>
 /// <param name="control">Control binded to the UIPanel</param>
 public void setContainingPanel(IUiControl control)
 {
     this._uiControl = control;
     this._uiControl.Parent = this;
 }
Пример #13
0
 public void add(IUiControl control)
 {
     control.Parent = this;
     _controls.Add(control);
 }
        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)
            {
                var toolbarCompiler = new FormTreeCompiler();
                CurrentCustomToolbarFormTreeCompiler = toolbarCompiler;

                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, formCompiler.Tooltip, containerIcon));
        }
Пример #15
0
 public static int CalculateStartX(IUiControl control, IUiControl parentControl)
 {
     return 0;
 }
Пример #16
0
 public void AddElement(IUiControl element)
 {
     elements.Add(element);
 }
Пример #17
0
 public void remove(IUiControl control)
 {
     _controls.Remove(control);
 }
        private ElementCompileTreeNode HandleProducerElement(ElementCompileTreeNode element, List <PropertyCompileTreeNode> newProperties, string defaultOverloadPropertyName)
        {
            PropertyAssigner.AssignPropertiesToProducer(element, _compileContext);

            string replacingPropertyName = CompilerGlobals.DefaultPropertyName;

            if (defaultOverloadPropertyName != null)
            {
                replacingPropertyName = defaultOverloadPropertyName;
            }

            var    replacingProperty = new PropertyCompileTreeNode(replacingPropertyName, element.XmlSourceNodeInformation);
            object result            = ProducerMediatorPluginFacade.EvaluateProducer(element.XmlSourceNodeInformation.NamespaceURI, element.Producer);

            if (result is BindingProducer)
            {
                var bindingProducer = (BindingProducer)result;

                if (string.IsNullOrEmpty(bindingProducer.name))
                {
                    throw new FormCompileException("A binding declaraions is missing its name attribute", element.XmlSourceNodeInformation);
                }

                if (!_compileContext.RegistarBindingName(bindingProducer.name))
                {
                    throw new FormCompileException(string.Format("Name binding name {0} is used twice which is not allowed", bindingProducer.name), element.XmlSourceNodeInformation);
                }

                //if (_compileContext.GetBindingObject(bindingProducer.name) == null && !bindingProducer.optional)
                //{
                //    throw new FormCompileException(string.Format("The non optional binding {0} is missing its binding value", bindingProducer.name), element.XmlSourceNodeInformation);
                //}

                Type type = TypeManager.GetType(bindingProducer.type);

                _compileContext.SetBindingType(bindingProducer.name, type);
            }
            else if (_withDebug && result is IUiControl)
            {
                IUiControl uiControl = result as IUiControl;

                string debugControlNamespace;
                string debugControlName;
                UiControlFactoryPluginFacade.GetDebugControlName(_compileContext.CurrentChannel, out debugControlNamespace, out debugControlName);

                DebugUiControl debug = ProducerMediatorPluginFacade.CreateProducer(_compileContext.CurrentChannel, debugControlNamespace, debugControlName) as DebugUiControl;
                debug.UiControlID = _compileContext.GetNextDebugControlId;
                debug.UiControl   = uiControl;
                result            = debug;

                debug.UiControlID        = uiControl.UiControlID;
                debug.TagName            = element.XmlSourceNodeInformation.TagName;
                debug.SourceElementXPath = element.XmlSourceNodeInformation.XPath;


                foreach (CompileContext.IRebinding rd in _compileContext.Rebindings)
                {
                    if (ReferenceEquals(uiControl, rd.SourceProducer))
                    {
                        debug.Bindings.Add(new DebugUiControl.BindingInformation(
                                               rd.BindingObjectName,
                                               rd.DestinationObjectType,
                                               rd.PropertyName));
                    }
                }
            }

            replacingProperty.Value = result;

            newProperties.Add(replacingProperty);

            return(null);
        }