コード例 #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(FrameTemplateReadOnlyDictionary blockTemplateTable, FrameTemplateReadOnlyDictionary nodeTemplateTable)
        {
            Contract.RequireNotNull(blockTemplateTable, out FrameTemplateReadOnlyDictionary BlockTemplateTable);
            Contract.RequireNotNull(nodeTemplateTable, out FrameTemplateReadOnlyDictionary NodeTemplateTable);

            IList <Type> BlockKeys = NodeHelper.GetNodeKeys();

            FrameTemplateDictionary 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.IsBlockInterfaceType(NodeType);
                IsValid &= Template.IsValid;
                IsValid &= Template.Root.IsValid(NodeType, NodeTemplateTable, ref CommentFrameCount);
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }
コード例 #2
0
        /// <summary>
        /// Checks that templates are valid for nodes.
        /// </summary>
        /// <param name="nodeTemplateTable">Table of templates.</param>
        public virtual bool IsValid(FrameTemplateReadOnlyDictionary nodeTemplateTable)
        {
            Contract.RequireNotNull(nodeTemplateTable, out FrameTemplateReadOnlyDictionary NodeTemplateTable);

            FrameTemplateDictionary 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);
        }
コード例 #3
0
        private protected virtual FrameTemplateReadOnlyDictionary BuildDefaultNodeTemplateTable()
        {
            FrameTemplateDictionary DefaultDictionary = CreateDefaultTemplateDictionary();

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

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

            return(DefaultDictionary.ToReadOnly());
        }
コード例 #4
0
        private protected virtual void AddBlockNodeTypes(FrameTemplateDictionary dictionary, Type nodeType)
        {
            IList <string> Properties = NodeTreeHelper.EnumChildNodeProperties(nodeType);

            foreach (string PropertyName in Properties)
            {
                if (NodeTreeHelperBlockList.IsBlockListProperty(nodeType, PropertyName, /*out Type ChildInterfaceType,*/ out Type ChildItemType))
                {
                    Type BlockListType = NodeTreeHelperBlockList.BlockListBlockType(nodeType, PropertyName);

                    if (!dictionary.ContainsKey(BlockListType))
                    {
                        dictionary.Add(BlockListType, null);
                    }
                }
            }
        }
コード例 #5
0
        private protected virtual FrameTemplateReadOnlyDictionary BuildDefaultBlockListTemplate()
        {
            IList <Type> NodeKeys = NodeHelper.GetNodeKeys();

            FrameTemplateDictionary DefaultDictionary = CreateEmptyTemplateDictionary();

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

            FramePlaceholderFrame PatternFrame = (FramePlaceholderFrame)CreatePlaceholderFrame();

            PatternFrame.PropertyName = nameof(IBlock.ReplicationPattern);

            FramePlaceholderFrame SourceFrame = (FramePlaceholderFrame)CreatePlaceholderFrame();

            SourceFrame.PropertyName = nameof(IBlock.SourceIdentifier);

            IFrameHorizontalCollectionPlaceholderFrame CollectionPlaceholderFrame = CreateHorizontalCollectionPlaceholderFrame();

            IFrameHorizontalPanelFrame RootFrame = CreateHorizontalPanelFrame();

            RootFrame.Items.Add(PatternFrame);
            RootFrame.Items.Add(SourceFrame);
            RootFrame.Items.Add(CollectionPlaceholderFrame);

            FrameBlockTemplate RootTemplate = (FrameBlockTemplate)CreateBlockTemplate();

            RootTemplate.NodeType = Type.FromTypeof <IBlock>();
            RootTemplate.Root     = RootFrame;

            RootFrame.UpdateParent(RootTemplate, GetRoot());

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

            foreach (Type Key in BlockKeys)
            {
                DefaultDictionary[Key] = RootTemplate;
            }

            return(DefaultDictionary.ToReadOnly());
        }
コード例 #6
0
 /// <inheritdoc/>
 public FrameTemplateReadOnlyDictionary(FrameTemplateDictionary dictionary)
     : base(dictionary)
 {
 }
コード例 #7
0
        private protected virtual void SetNodeTypeToDefault(FrameTemplateDictionary 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;
                }
                else if (NodeTreeHelper.IsBooleanProperty(nodeType, PropertyName))
                {
                    FrameDiscreteFrame NewDiscreteFrame = (FrameDiscreteFrame)CreateDiscreteFrame();
                    NewDiscreteFrame.PropertyName = PropertyName;

                    FrameKeywordFrame KeywordFalseFrame = (FrameKeywordFrame)CreateKeywordFrame();
                    KeywordFalseFrame.Text = $"{PropertyName}=False";
                    NewDiscreteFrame.Items.Add(KeywordFalseFrame);

                    FrameKeywordFrame KeywordTrueFrame = (FrameKeywordFrame)CreateKeywordFrame();
                    KeywordTrueFrame.Text = $"{PropertyName}=True";
                    NewDiscreteFrame.Items.Add(KeywordTrueFrame);

                    RootFrame.Items.Add(NewDiscreteFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelper.IsEnumProperty(nodeType, PropertyName))
                {
                    NodeTreeHelper.GetEnumRange(nodeType, PropertyName, out int Min, out int Max);

                    FrameDiscreteFrame NewDiscreteFrame = (FrameDiscreteFrame)CreateDiscreteFrame();
                    NewDiscreteFrame.PropertyName = PropertyName;

                    for (int i = Min; i <= Max; i++)
                    {
                        FrameKeywordFrame KeywordFrame = (FrameKeywordFrame)CreateKeywordFrame();
                        KeywordFrame.Text = $"{PropertyName}={i}";
                        NewDiscreteFrame.Items.Add(KeywordFrame);
                    }

                    RootFrame.Items.Add(NewDiscreteFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelper.IsStringProperty(nodeType, PropertyName))
                {
                    FrameTextValueFrame NewDiscreteFrame = (FrameTextValueFrame)CreateTextValueFrame();
                    NewDiscreteFrame.PropertyName = PropertyName;
                    RootFrame.Items.Add(NewDiscreteFrame);
                    IsHandled = true;
                }
                else if (NodeTreeHelper.IsGuidProperty(nodeType, PropertyName))
                {
                    IsHandled = true;
                }
                else if (NodeTreeHelper.IsDocumentProperty(nodeType, PropertyName))
                {
                    IsHandled = true;
                }

                Debug.Assert(IsHandled);
            }

            RootFrame.UpdateParent(RootTemplate, GetRoot());
        }