internal ElementClipboardDataItem(IElementFactory elementFactory, ElementMetadata elementMetadata)
        {
            if (elementMetadata == null && elementFactory == null)
                throw new ArgumentException("Both arguments cannot not be null.");

            _elementFactory = elementFactory;
            _elementMetadata = elementMetadata;
        }
Example #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;
        }
Example #3
0
        public static IElementClipboardData CreateFunctionCallClipboardData(Guid functionId)
        {
            var data = new CommonFunctionBehavior.CallFunctionData()
            {
                FunctionId = functionId
            };

            var elementMetadata = new ElementMetadata()
            {
                Data = JsonConvert.SerializeObject(data),
                ElementTypeId = PluginElementIds.CallFunction
            };

            return new ElementClipboardData(new ElementMetadata[]
            {
                elementMetadata
            });
        }
Example #4
0
        public static ElementMetadata ToMetadata(this IElement element)
        {
            if (element == null)
                return null;

            var elementMetadata =  new ElementMetadata()
            {
                Data = element.GetData(),
                Parameters = element.Parameters.ToMetadata(),
                Blocks = element.Blocks.ToMetadata(),
                ElementTypeId = element.ElementTypeId
            };

            return elementMetadata;
        }
Example #5
0
        private bool RequiresConversion(ElementMetadata elementMetadata)
        {
            if (elementMetadata == null) throw new ArgumentNullException(nameof(elementMetadata));

            if (elementMetadata.Next != null)
                return true;

            if (elementMetadata.Blocks != null)
            {
                if (elementMetadata.Blocks.Any(b => b.Next != null))
                {
                    return true;
                }
            }

            return false;
        }
Example #6
0
#pragma warning disable CS0618
        private static IEnumerable<ElementMetadata> EnumerateElementsWhileFixingBlocks(ElementMetadata first)
        {
            var current = first;

            while (current != null)
            {
                if (current.Blocks != null)
                {
                    foreach (var block in current.Blocks)
                    {
                        FixBlock(block);
                    }
                }

                yield return current;

                current = current.Next;
            }
        }