Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Checks that templates are valid for nodes.
        /// </summary>
        /// <param name="nodeTemplateTable">Table of templates.</param>
        public virtual bool IsValid(IFrameTemplateReadOnlyDictionary nodeTemplateTable)
        {
            Debug.Assert(nodeTemplateTable != null);

            IFrameTemplateDictionary DefaultDictionary = CreateDefaultTemplateDictionary();

            bool IsValid = true;

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

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

                IsValid &= Template.IsValid;
                IsValid &= IsValidNodeType(NodeType, Template.NodeType);
                IsValid &= Template.Root.IsValid(NodeType, nodeTemplateTable, ref CommentFrameCount);
                IsValid &= CommentFrameCount == 1;
                Debug.Assert(IsValid);
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }
Exemple #3
0
        private protected virtual IFrameTemplateReadOnlyDictionary BuildDefaultNodeTemplateTable()
        {
            IFrameTemplateDictionary DefaultDictionary = CreateDefaultTemplateDictionary();

            List <Type> Keys = new List <Type>(DefaultDictionary.Keys);

            foreach (Type Key in Keys)
            {
                SetNodeTypeToDefault(DefaultDictionary, Key);
            }

            return(DefaultDictionary.ToReadOnly());
        }
Exemple #4
0
        private protected virtual void SetNodeTypeToDefault(IFrameTemplateDictionary dictionary, Type nodeType)
        {
            Debug.Assert(dictionary.ContainsKey(nodeType));
            Debug.Assert(dictionary[nodeType] == null);

            FrameHorizontalPanelFrame RootFrame    = (FrameHorizontalPanelFrame)CreateHorizontalPanelFrame();
            FrameNodeTemplate         RootTemplate = (FrameNodeTemplate)CreateNodeTemplate();

            RootTemplate.NodeType = nodeType;
            RootTemplate.Root     = RootFrame;

            // Set the template, even if empty, in case the node recursively refers to itself (ex: expressions).
            dictionary[nodeType] = RootTemplate;

            RootFrame.Items.Add(CreateCommentFrame());

            Type           ChildNodeType;
            IList <string> Properties = NodeTreeHelper.EnumChildNodeProperties(nodeType);

            foreach (string PropertyName in Properties)
            {
                bool IsHandled = false;

                if (NodeTreeHelperChild.IsChildNodeProperty(nodeType, PropertyName, out ChildNodeType))
                {
                    FramePlaceholderFrame NewFrame = (FramePlaceholderFrame)CreatePlaceholderFrame();
                    NewFrame.PropertyName = PropertyName;
                    RootFrame.Items.Add(NewFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelperOptional.IsOptionalChildNodeProperty(nodeType, PropertyName, out ChildNodeType))
                {
                    FrameOptionalFrame NewFrame = (FrameOptionalFrame)CreateOptionalFrame();
                    NewFrame.PropertyName = PropertyName;
                    RootFrame.Items.Add(NewFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelperList.IsNodeListProperty(nodeType, PropertyName, out Type ListNodeType))
                {
                    FrameHorizontalListFrame NewFrame = (FrameHorizontalListFrame)CreateHorizontalListFrame();
                    NewFrame.PropertyName = PropertyName;
                    RootFrame.Items.Add(NewFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelperBlockList.IsBlockListProperty(nodeType, PropertyName, out Type ChildInterfaceType, out Type ChildItemType))
                {
                    FrameHorizontalBlockListFrame NewFrame = (FrameHorizontalBlockListFrame)CreateHorizontalBlockListFrame();
                    NewFrame.PropertyName = PropertyName;
                    RootFrame.Items.Add(NewFrame);
                    IsHandled = true;
                }
 public FrameTemplateReadOnlyDictionary(IFrameTemplateDictionary dictionary)
     : base(dictionary)
 {
 }