예제 #1
0
        private Element LoadElement(JToken node, Container parent, int index, DescribeElementsContext describeContext) {
            var type = (string)node["type"];
            var map = SelectMap(x => x.LayoutElementType == type);
            var element = map.ToElement(_elementManager, describeContext, node);

            element.Container = parent;
            element.Index = index;

            return element;
        }
예제 #2
0
        private Element ParseEditorNode(JToken node, Container parent, int index, DescribeElementsContext describeContext) {
            var element = LoadElement(node, parent, index, describeContext);
            var childNodes = (JArray)node["children"];
            var container = element as Container;

            if (container != null)
                container.Elements = childNodes != null
                    ? childNodes.Select((x, i) => ParseEditorNode(x, container, i, describeContext)).Where(x => x != null).ToList()
                    : new List<Element>();

            return element;
        }
예제 #3
0
        public Element ParseNode(JToken node, Container parent, int index, DescribeElementsContext describeContext) {
            var elementTypeName = (string)node["typeName"];

            if (String.IsNullOrWhiteSpace(elementTypeName))
                return null;

            var data = (string)node["data"];
            var htmlId = (string)node["htmlId"];
            var htmlClass = (string)node["htmlClass"];
            var htmlStyle = (string)node["htmlStyle"];
            var rule = (string)node["rule"];
            var elementData = ElementDataHelper.Deserialize(data);
            var exportableData = ElementDataHelper.Deserialize((string)node["exportableData"]);
            var childNodes = node["elements"];
            var elementDescriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, elementTypeName);

            if (elementDescriptor == null)
                return null; // This happens if an element exists in a layout, but its type is no longer available due to its feature being disabled.

            var element = _elementFactory.Activate(elementDescriptor, e => {
                e.Container = parent;
                e.Index = index;
                e.Data = elementData;
                e.ExportableData = exportableData;
                e.HtmlId = htmlId;
                e.HtmlClass = htmlClass;
                e.HtmlStyle = htmlStyle;
                e.Rule = rule;
            });

            var container = element as Container;

            if (container != null)
                container.Elements = childNodes != null
                    ? childNodes.Select((x, i) => ParseNode(x, container, i, describeContext)).Where(x => x != null).ToList()
                    : new List<Element>();

            element.IsTemplated = node.Value<bool>("isTemplated");

            return element;
        }