Esempio n. 1
0
 /// <summary>
 /// Removes selectors from the table.
 /// </summary>
 /// <param name="selectors">Selectors to add.</param>
 public virtual void RemoveSelectors(FocusFrameSelectorList selectors)
 {
     foreach (IFocusFrameSelector Item in selectors)
     {
         Debug.Assert(SelectorTable.ContainsKey(Item.SelectorType));
         SelectorTable.Remove(Item.SelectorType);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Adds new selectors to the table.
 /// </summary>
 /// <param name="selectors">Selectors to add.</param>
 public virtual void AddSelectors(FocusFrameSelectorList selectors)
 {
     foreach (IFocusFrameSelector Item in selectors)
     {
         Debug.Assert(!SelectorTable.ContainsKey(Item.SelectorType));
         SelectorTable.Add(Item.SelectorType, Item.SelectorName);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Removes selectors from the table.
        /// This method is allowed to substitute one selector substituted with <see cref="AddOrReplaceSelectors"/>.
        /// </summary>
        /// <param name="selectors">Selectors to add.</param>
        /// <param name="oldSelectorType">Previous value for a substituted selector type.</param>
        /// <param name="oldSelectorName">Previous value for a substituted selector name.</param>
        public virtual void RemoveOrRestoreSelectors(FocusFrameSelectorList selectors, Type oldSelectorType, string oldSelectorName)
        {
            foreach (IFocusFrameSelector Item in selectors)
            {
                Debug.Assert(SelectorTable.ContainsKey(Item.SelectorType));

                if (Item.SelectorType == oldSelectorType)
                {
                    SelectorTable[oldSelectorType] = oldSelectorName;
                }
                else
                {
                    SelectorTable.Remove(Item.SelectorType);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds new selectors to the table. This method is allowed to substitute one selector.
        /// </summary>
        /// <param name="selectors">Selectors to add.</param>
        /// <param name="oldSelectorType">Previous value for a substituted selector type upon return. Null if none.</param>
        /// <param name="oldSelectorName">Previous value for a substituted selector name upon return. Null if none.</param>
        public virtual void AddOrReplaceSelectors(FocusFrameSelectorList selectors, out Type oldSelectorType, out string oldSelectorName)
        {
            oldSelectorType = Type.Missing;
            oldSelectorName = string.Empty;

            foreach (IFocusFrameSelector Item in selectors)
            {
                if (SelectorTable.ContainsKey(Item.SelectorType))
                {
                    Debug.Assert(oldSelectorType == Type.Missing);
                    Debug.Assert(oldSelectorName == string.Empty);

                    oldSelectorType = Item.SelectorType;
                    oldSelectorName = SelectorTable[Item.SelectorType];

                    SelectorTable[Item.SelectorType] = Item.SelectorName;
                }
                else
                {
                    SelectorTable.Add(Item.SelectorType, Item.SelectorName);
                }
            }
        }
        /// <summary>
        /// Checks that a frame is correctly constructed.
        /// </summary>
        /// <param name="nodeType">Type of the node this frame can describe.</param>
        /// <param name="nodeTemplateTable">Table of templates with all frames.</param>
        /// <param name="commentFrameCount">Number of comment frames found so far.</param>
        public override bool IsValid(Type nodeType, FrameTemplateReadOnlyDictionary nodeTemplateTable, ref int commentFrameCount)
        {
            bool IsValid = true;

            IsValid &= base.IsValid(nodeType, nodeTemplateTable, ref commentFrameCount);
            IsValid &= Items.Count > 0;
            IsValid &= IsParentRoot;

            List <string> NameList = new List <string>();
            int           SelectionCommentFrameCount = -1;
            List <Dictionary <string, FocusFrameSelectorList> > SelectorTableList = new List <Dictionary <string, FocusFrameSelectorList> >();
            Dictionary <string, FocusFrameSelectorList>         SelectorTable;

            foreach (IFocusSelectableFrame Item in Items)
            {
                int SelectableCommentFrameCount = 0;
                IsValid &= Item.IsValid(nodeType, nodeTemplateTable, ref SelectableCommentFrameCount);
                IsValid &= !NameList.Contains(Item.Name);

                // Use the count for the first frame as base count.
                if (SelectionCommentFrameCount < 0)
                {
                    SelectionCommentFrameCount = SelectableCommentFrameCount;
                }

                // All selectable frames must have the same count.
                IsValid &= SelectionCommentFrameCount == SelectableCommentFrameCount;

                NameList.Add(Item.Name);

                SelectorTable = new Dictionary <string, FocusFrameSelectorList>();
                Item.CollectSelectors(SelectorTable);
                SelectorTableList.Add(SelectorTable);
            }

            // Use the common count of all selectable frames as the count of the selection frame.
            commentFrameCount += SelectionCommentFrameCount;

            // Check that all selectable have the same nested selectors. See FrameSelectorForProperty().
            SelectorTable = new Dictionary <string, FocusFrameSelectorList>();
            CollectSelectors(SelectorTable);
            Debug.Assert(SelectorTable.Count == 0);

            List <string> PropertyNameList = new List <string>();

            foreach (Dictionary <string, FocusFrameSelectorList> Table in SelectorTableList)
            {
                foreach (KeyValuePair <string, FocusFrameSelectorList> Entry in Table)
                {
                    if (!PropertyNameList.Contains(Entry.Key))
                    {
                        PropertyNameList.Add(Entry.Key);
                    }
                }
            }

            foreach (string PropertyName in PropertyNameList)
            {
                List <FocusFrameSelectorList> TableWithPropertyList = new List <FocusFrameSelectorList>();
                foreach (Dictionary <string, FocusFrameSelectorList> Table in SelectorTableList)
                {
                    if (Table.ContainsKey(PropertyName))
                    {
                        TableWithPropertyList.Add(Table[PropertyName]);
                    }
                }

                Debug.Assert(TableWithPropertyList.Count > 0);
                FocusFrameSelectorList FirstItem = TableWithPropertyList[0];

                CompareEqual Comparer = CompareEqual.New(canReturnFalse: true);
                for (int i = 1; i < TableWithPropertyList.Count; i++)
                {
                    IsValid &= FirstItem.IsEqual(Comparer, TableWithPropertyList[i]);
                }
            }

            if (!IsValid)
            {
            }

            Debug.Assert(IsValid);
            return(IsValid);
        }
Esempio n. 6
0
 /// <inheritdoc/>
 public FocusFrameSelectorReadOnlyList(FocusFrameSelectorList list)
     : base(list)
 {
 }