void IElementEventHandler.Displayed(ElementDisplayedContext context) { }
        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);
            InvokeDrivers(drivers, driver => driver.CreatingDisplay(createShapeContext));
            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);
            InvokeDrivers(drivers, driver => driver.Displaying(displayingContext));

            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);
            InvokeDrivers(drivers, driver => driver.Displayed(displayedContext));

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

            return elementShape;
        }
Esempio n. 3
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);
            InvokeDrivers(drivers, driver => driver.CreatingDisplay(createShapeContext));
            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);
            InvokeDrivers(drivers, driver => driver.Displaying(displayingContext));

            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);
            InvokeDrivers(drivers, driver => driver.Displayed(displayedContext));

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

            return(elementShape);
        }
 public virtual void Displayed(ElementDisplayedContext context)
 {
 }