Beispiel #1
0
        public IElement CreateElement(IElementOwner owner, ElementMetadata elementMetadata)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (elementMetadata == null)
            {
                throw new ArgumentNullException(nameof(elementMetadata));
            }

            //Find the factory
            var factory = _factoryManager.GetFactory(elementMetadata.ElementTypeId);

            //Create the context
            var context = new ElementCreationContext(owner, elementMetadata.Data, factory);

            //Create the element
            var element = factory.Create(context);

            SetElementProperties(element, elementMetadata);

            //Blocks
            if (elementMetadata.Blocks != null)
            {
                foreach (var blockMetadata in elementMetadata.Blocks)
                {
                    var block = element.Blocks.FirstOrDefault(b => b.Id == blockMetadata.Id);

                    if (block == null)
                    {
                        Console.WriteLine("Whoa - didn't find a block");
                    }
                    else
                    {
                        SetElementProperties(block, blockMetadata);

                        if (blockMetadata.Elements != null)
                        {
                            //Add the block children
                            block.Elements.AddRange(blockMetadata.Elements.Select(e => CreateElement(owner, e)).ToArray());
                        }
                    }
                }
            }

            return(element);
        }
Beispiel #2
0
        public IElement CreateElement(IElementOwner owner, ElementMetadata elementMetadata)
        {
            if (owner == null) throw new ArgumentNullException(nameof(owner));
            if (elementMetadata == null) throw new ArgumentNullException(nameof(elementMetadata));

            //Find the factory
            var factory = _factoryManager.GetFactory(elementMetadata.ElementTypeId);

            //Create the context
            var context = new ElementCreationContext(owner, elementMetadata.Data, factory);

            //Create the element
            var element = factory.Create(context);

            SetElementProperties(element, elementMetadata);

            //Blocks
            if (elementMetadata.Blocks != null)
            {
                foreach (var blockMetadata in elementMetadata.Blocks)
                {
                    var block = element.Blocks.FirstOrDefault(b => b.Id == blockMetadata.Id);

                    if (block == null)
                    {
                        Console.WriteLine("Whoa - didn't find a block");
                    }
                    else
                    {
                        SetElementProperties(block, blockMetadata);

                        if (blockMetadata.Elements != null)
                        {
                            //Add the block children
                            block.Elements.AddRange(blockMetadata.Elements.Select(e => CreateElement(owner, e)).ToArray());
                        }
                    }
                }
            }

            return element;
        }