Exemplo n.º 1
0
        /// <summary>
        /// Checks that templates are valid for blocks.
        /// </summary>
        /// <param name="blockTemplateTable">Table of templates.</param>
        /// <param name="nodeTemplateTable">Table of templates with all frames.</param>
        public virtual bool IsBlockValid(IFrameTemplateReadOnlyDictionary blockTemplateTable, IFrameTemplateReadOnlyDictionary nodeTemplateTable)
        {
            Debug.Assert(blockTemplateTable != null);

            List <Type> BlockKeys = new List <Type>(NodeHelper.CreateNodeDictionary <object>().Keys);

            IFrameTemplateDictionary DefaultDictionary = CreateEmptyTemplateDictionary();

            foreach (Type Key in BlockKeys)
            {
                AddBlockNodeTypes(DefaultDictionary, Key);
            }

            bool IsValid = true;

            foreach (KeyValuePair <Type, IFrameTemplate> Entry in DefaultDictionary)
            {
                IsValid &= blockTemplateTable.ContainsKey(Entry.Key);
            }

            foreach (KeyValuePair <Type, IFrameTemplate> Entry in blockTemplateTable)
            {
                Type           NodeType          = Entry.Key;
                IFrameTemplate Template          = Entry.Value;
                int            CommentFrameCount = 0;

                IsValid &= NodeTreeHelper.IsBlockType(NodeType);
                IsValid &= Template.IsValid;
                IsValid &= Template.Root.IsValid(NodeType, nodeTemplateTable, ref CommentFrameCount);
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks that a frame selector is correctly constructed.
        /// </summary>
        /// <param name="nodeType">Type of the node this frame selector can describe.</param>
        /// <param name="nodeTemplateTable">Table of templates with all frames.</param>
        /// <param name="propertyName">The property for which frames can be selected.</param>
        public virtual bool IsValid(Type nodeType, IFocusTemplateReadOnlyDictionary nodeTemplateTable, string propertyName)
        {
            bool IsValid = true;

            IsValid &= SelectorType != null;
            IsValid &= !string.IsNullOrEmpty(SelectorName);

            Type ChildInterfaceType, ChildNodeType;

            IsValid &= NodeTreeHelperChild.IsChildNodeProperty(nodeType, propertyName, out ChildInterfaceType) ||
                       NodeTreeHelperOptional.IsOptionalChildNodeProperty(nodeType, propertyName, out ChildInterfaceType) ||
                       NodeTreeHelperList.IsNodeListProperty(nodeType, propertyName, out ChildInterfaceType) ||
                       NodeTreeHelperBlockList.IsBlockListProperty(nodeType, propertyName, out ChildInterfaceType, out ChildNodeType) ||
                       (NodeTreeHelper.IsBlockType(nodeType) && propertyName == nameof(BaseNode.IBlock.NodeList));

            IsValid &= nodeTemplateTable.ContainsKey(SelectorType);

            IFocusNodeTemplate Template = nodeTemplateTable[SelectorType] as IFocusNodeTemplate;

            Debug.Assert(Template != null);

            IFocusSelectionFrame AsSelectionFrame = Template.Root as IFocusSelectionFrame;

            IsValid &= AsSelectionFrame != null;

            if (IsValid)
            {
                IFocusSelectableFrame SelectedItem = null;
                foreach (IFocusSelectableFrame Item in AsSelectionFrame.Items)
                {
                    if (Item.Name == SelectorName)
                    {
                        SelectedItem = Item;
                        break;
                    }
                }

                IsValid &= SelectedItem != null;
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }