Exemplo n.º 1
0
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType     = null,
            IUpdateModel updater   = null,
            string renderEventName = null,
            string renderEventArgs = null)
        {
            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element     = element,
                DisplayType = displayType,
                Content     = content,
            };

            element.Descriptor.CreatingDisplay(createShapeContext);

            var typeName = element.GetType().Name;
            var category = element.Category.ToSafeName();
            var drivers  = element.Descriptor.GetDrivers();
            var elementShapeArguments = CreateArguments(element, content);
            var elementShape          = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));


            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayContext = new ElementDisplayContext {
                Element         = element,
                ElementShape    = elementShape,
                DisplayType     = displayType,
                Content         = content,
                Updater         = updater,
                RenderEventName = renderEventName,
                RenderEventArgs = renderEventArgs
            };

            _elementEventHandlerHandler.Displaying(displayContext);
            InvokeDrivers(drivers, driver => driver.Displaying(displayContext));
            element.Descriptor.Display(displayContext);

            var container = element as Container;

            if (container != null)
            {
                if (container.Elements.Any())
                {
                    foreach (var child in container.Elements)
                    {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);
                        childShape.Parent = elementShape;
                        elementShape.Add(childShape);
                    }
                }
            }

            return(elementShape);
        }
        public override void CreatingDisplay(ElementCreatingDisplayShapeContext context) {
            if (context.DisplayType == "Design")
                return;

            if (String.IsNullOrWhiteSpace(context.Element.Rule))
                return;

            context.Cancel = !EvaluateRule(context.Element.Rule);
        }
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType = null,
            IUpdateModel updater = null,
            string renderEventName = null,
            string renderEventArgs = null) {

            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element = element,
                DisplayType = displayType,
                Content = content,
            };

            element.Descriptor.CreatingDisplay(createShapeContext);

            var typeName = element.GetType().Name;
            var category = element.Category.ToSafeName();
            var drivers = element.Descriptor.GetDrivers();
            var elementShapeArguments = CreateArguments(element, content);
            var elementShape = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));
            

            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayContext = new ElementDisplayContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater,
                RenderEventName = renderEventName,
                RenderEventArgs = renderEventArgs
            };

            _elementEventHandlerHandler.Displaying(displayContext);
            InvokeDrivers(drivers, driver => driver.Displaying(displayContext));
            element.Descriptor.Display(displayContext);

            var container = element as Container;

            if (container != null) {
                if (container.Elements.Any()) {
                    foreach (var child in container.Elements) {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);
                        childShape.Parent = elementShape;
                        elementShape.Add(childShape);
                    }
                }
            }

            return elementShape;
        }
        private void CreatingDisplay(ElementCreatingDisplayShapeContext context)
        {
            // this is actualy need to put into ElementEventHandlerBase.Created method
            // but now it's impossible because child elements will be overriden by ElementSerializer.ParseNode method (((
            // there is a copy of this code in DefaultModelMaps class
            var compound = context.Element as Compound;

            compound.IsTemplated = false;
            var modifiedElements = compound.Elements;
            var originalElements = _layoutSerializer.Value.Deserialize(
                    compound.Descriptor.StateBag["LayoutData"] != null ? compound.Descriptor.StateBag["LayoutData"].ToString() : null,
                    new DescribeElementsContext { Content = context.Content })
                .ToList();
            compound.Elements = originalElements;
            MakeTemplated(compound.Elements);
            modifiedElements = modifiedElements.Flatten().ToList();
            foreach (var originalElement in compound.Elements.Flatten())
            {
                var originalElementIdentifier = originalElement.GetIdentifier();
                if (originalElementIdentifier == null)
                    continue;

                var modifiedElement = modifiedElements.FirstOrDefault(e => e.GetIdentifier() == originalElementIdentifier);
                if (modifiedElement == null)
                    continue;
                
                originalElement.Data = modifiedElement.Data;

                var originalElementContainer = originalElement as Container;
                if (originalElementContainer != null && !originalElementContainer.Elements.Any())
                {
                    originalElementContainer.Elements = (modifiedElement as Container).Elements;
                }
            }

            
        }
 private void CreatingDisplay(ElementCreatingDisplayShapeContext context, ElementBlueprint blueprint) {
     var bluePrintState = ElementDataHelper.Deserialize(blueprint.BaseElementState);
     context.Element.Data = bluePrintState;
 }
 void IElementEventHandler.CreatingDisplay(ElementCreatingDisplayShapeContext context) { }
Exemplo n.º 7
0
 public virtual void CreatingDisplay(ElementCreatingDisplayShapeContext context)
 {
 }
Exemplo n.º 8
0
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType = null,
            IUpdateModel updater = null)
        {
            var typeName = element.GetType().Name;
            var category = element.Category.ToSafeName();
            var drivers = element.Descriptor.GetDrivers().ToList();
            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element = element,
                DisplayType = displayType,
                Content = content,
            };

            _elementEventHandlerHandler.CreatingDisplay(createShapeContext);
            drivers.Invoke(driver => driver.CreatingDisplay(createShapeContext), Logger);
            if (element.Descriptor.CreatingDisplay != null)
                element.Descriptor.CreatingDisplay(createShapeContext);

            if (createShapeContext.Cancel)
                return null;

            var elementShapeArguments = CreateArguments(element, content);
            var elementShape = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));

            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayingContext = new ElementDisplayingContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater
            };

            _elementEventHandlerHandler.Displaying(displayingContext);
            drivers.Invoke(driver => driver.Displaying(displayingContext), Logger);

            if (element.Descriptor.Displaying != null)
                element.Descriptor.Displaying(displayingContext);

            var container = element as Container;

            if (container != null) {
                if (container.Elements.Any()) {
                    var childIndex = 0;
                    foreach (var child in container.Elements) {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);

                        if (childShape != null) {
                            childShape.Parent = elementShape;
                            elementShape.Add(childShape, childIndex++.ToString());
                        }
                    }
                }
            }

            var displayedContext = new ElementDisplayedContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater
            };

            _elementEventHandlerHandler.Displayed(displayedContext);
            drivers.Invoke(driver => driver.Displayed(displayedContext), Logger);

            if (element.Descriptor.Displayed != null)
                element.Descriptor.Displayed(displayedContext);

            return elementShape;
        }
Exemplo n.º 9
0
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType   = null,
            IUpdateModel updater = null)
        {
            var typeName           = element.GetType().Name;
            var category           = element.Category.ToSafeName();
            var drivers            = element.Descriptor.GetDrivers().ToList();
            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element     = element,
                DisplayType = displayType,
                Content     = content,
            };

            _elementEventHandlerHandler.CreatingDisplay(createShapeContext);
            drivers.Invoke(driver => driver.CreatingDisplay(createShapeContext), Logger);
            if (element.Descriptor.CreatingDisplay != null)
            {
                element.Descriptor.CreatingDisplay(createShapeContext);
            }

            if (createShapeContext.Cancel)
            {
                return(null);
            }

            var elementShapeArguments = CreateArguments(element, content);
            var elementShape          = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));

            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayingContext = new ElementDisplayingContext {
                Element      = element,
                ElementShape = elementShape,
                DisplayType  = displayType,
                Content      = content,
                Updater      = updater
            };

            _elementEventHandlerHandler.Displaying(displayingContext);
            drivers.Invoke(driver => driver.Displaying(displayingContext), Logger);

            if (element.Descriptor.Displaying != null)
            {
                element.Descriptor.Displaying(displayingContext);
            }

            var container = element as Container;

            if (container != null)
            {
                if (container.Elements.Any())
                {
                    var childIndex = 0;
                    foreach (var child in container.Elements)
                    {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);

                        if (childShape != null)
                        {
                            childShape.Parent = elementShape;
                            elementShape.Add(childShape, childIndex++.ToString());
                        }
                    }
                }
            }

            var displayedContext = new ElementDisplayedContext {
                Element      = element,
                ElementShape = elementShape,
                DisplayType  = displayType,
                Content      = content,
                Updater      = updater
            };

            _elementEventHandlerHandler.Displayed(displayedContext);
            drivers.Invoke(driver => driver.Displayed(displayedContext), Logger);

            if (element.Descriptor.Displayed != null)
            {
                element.Descriptor.Displayed(displayedContext);
            }

            return(elementShape);
        }